mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-24 00:00:05 +08:00
Set username and password via properties instead of adapter method
This commit is contained in:
@@ -32,13 +32,14 @@ NS_SWIFT_NAME(handle(error:));
|
|||||||
|
|
||||||
@interface OpenVPNAdapter (Provider)
|
@interface OpenVPNAdapter (Provider)
|
||||||
|
|
||||||
|
@property (strong, nonatomic, nullable) NSString *username;
|
||||||
|
@property (strong, nonatomic, nullable) NSString *password;
|
||||||
|
|
||||||
@property (weak, nonatomic, null_unspecified) id<OpenVPNAdapterDelegate> delegate;
|
@property (weak, nonatomic, null_unspecified) id<OpenVPNAdapterDelegate> delegate;
|
||||||
|
|
||||||
- (BOOL)configureWithUsername:(nonnull NSString *)username
|
- (BOOL)configureUsing:(nonnull NSData *)settings
|
||||||
password:(nonnull NSString *)password
|
error:(out NSError * __nullable * __nullable)error
|
||||||
configuration:(nonnull NSData *)configuration
|
NS_SWIFT_NAME(configure(using:));
|
||||||
error:(out NSError * __nullable * __nullable)error
|
|
||||||
NS_SWIFT_NAME(configure(username:password:configuration:));
|
|
||||||
|
|
||||||
- (void)connect;
|
- (void)connect;
|
||||||
- (void)disconnect;
|
- (void)disconnect;
|
||||||
|
|||||||
@@ -290,15 +290,19 @@ static void socketCallback(CFSocketRef socket, CFSocketCallBackType type, CFData
|
|||||||
|
|
||||||
@implementation OpenVPNAdapter (Provider)
|
@implementation OpenVPNAdapter (Provider)
|
||||||
|
|
||||||
|
@dynamic username;
|
||||||
|
@dynamic password;
|
||||||
|
|
||||||
|
@dynamic delegate;
|
||||||
|
|
||||||
#pragma mark Client Configuration
|
#pragma mark Client Configuration
|
||||||
|
|
||||||
- (BOOL)configureWithUsername:(NSString *)username password:(NSString *)password configuration:(NSData *)configuration error:(out NSError * __autoreleasing _Nullable *)error {
|
- (BOOL)configureUsing:(NSData *)settings error:(out NSError * __autoreleasing _Nullable *)error {
|
||||||
NSString *vpnConfiguration = [[NSString alloc] initWithData:configuration encoding:NSUTF8StringEncoding];
|
NSString *vpnConfiguration = [[NSString alloc] initWithData:settings encoding:NSUTF8StringEncoding];
|
||||||
|
|
||||||
if (vpnConfiguration == nil) {
|
if (vpnConfiguration == nil) {
|
||||||
if (error) *error = [NSError errorWithDomain:OpenVPNClientErrorDomain code:OpenVPNErrorConfigurationFailure userInfo:@{
|
if (error) *error = [NSError errorWithDomain:OpenVPNClientErrorDomain code:OpenVPNErrorConfigurationFailure userInfo:@{
|
||||||
// TODO: Write error message
|
NSLocalizedDescriptionKey: @"Failed to read VPN configuration"
|
||||||
NSLocalizedDescriptionKey: @"Failed to ..."
|
|
||||||
}];
|
}];
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
@@ -318,8 +322,8 @@ static void socketCallback(CFSocketRef socket, CFSocketCallBackType type, CFData
|
|||||||
}
|
}
|
||||||
|
|
||||||
ClientAPI::ProvideCreds creds;
|
ClientAPI::ProvideCreds creds;
|
||||||
creds.username = [username UTF8String];
|
creds.username = [self.username UTF8String];
|
||||||
creds.password = [password UTF8String];
|
creds.password = [self.password UTF8String];
|
||||||
|
|
||||||
ClientAPI::Status creds_status = self.vpnClient->provide_creds(creds);
|
ClientAPI::Status creds_status = self.vpnClient->provide_creds(creds);
|
||||||
if (creds_status.error) {
|
if (creds_status.error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user