2017-04-26 23:06:34 +08:00
|
|
|
//
|
|
|
|
// OpenVPNProperties.m
|
|
|
|
// OpenVPN Adapter
|
|
|
|
//
|
|
|
|
// Created by Sergey Abramchuk on 26.04.17.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <openvpn/common/number.hpp>
|
|
|
|
|
2017-04-28 00:44:52 +08:00
|
|
|
#import "OpenVPNConfiguration+Internal.h"
|
2017-04-26 23:06:34 +08:00
|
|
|
#import "OpenVPNServerEntry+Internal.h"
|
|
|
|
#import "OpenVPNProperties.h"
|
|
|
|
#import "OpenVPNProperties+Internal.h"
|
|
|
|
|
|
|
|
using namespace openvpn;
|
|
|
|
|
|
|
|
@implementation OpenVPNProperties
|
|
|
|
|
|
|
|
- (instancetype)initWithEvalConfig:(ClientAPI::EvalConfig)eval {
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
|
|
|
_username = !eval.userlockedUsername.empty() ? [NSString stringWithUTF8String:eval.userlockedUsername.c_str()] : nil;
|
|
|
|
|
|
|
|
_profileName = !eval.profileName.empty() ? [NSString stringWithUTF8String:eval.profileName.c_str()] : nil;
|
|
|
|
_friendlyName = !eval.friendlyName.empty() ? [NSString stringWithUTF8String:eval.friendlyName.c_str()] : nil;
|
|
|
|
|
|
|
|
_autologin = eval.autologin;
|
|
|
|
|
|
|
|
_staticChallenge = !eval.staticChallenge.empty() ? [NSString stringWithUTF8String:eval.staticChallenge.c_str()] : nil;
|
|
|
|
_staticChallengeEcho = eval.staticChallengeEcho;
|
|
|
|
|
|
|
|
_privateKeyPasswordRequired = eval.privateKeyPasswordRequired;
|
|
|
|
_allowPasswordSave = eval.allowPasswordSave;
|
|
|
|
|
|
|
|
_remoteHost = !eval.remoteHost.empty() ? [NSString stringWithUTF8String:eval.remoteHost.c_str()] : nil;
|
|
|
|
|
|
|
|
uint16_t port = 0;
|
|
|
|
parse_number(eval.remotePort, port);
|
|
|
|
|
|
|
|
_remotePort = port;
|
|
|
|
|
2017-05-10 23:02:09 +08:00
|
|
|
NSString *currentProto = [[[NSString stringWithUTF8String:eval.remoteProto.c_str()] componentsSeparatedByString:@"-"] firstObject];
|
2017-04-28 00:44:52 +08:00
|
|
|
_remoteProto = [OpenVPNConfiguration getTransportProtocolFromValue:currentProto];
|
2017-04-26 23:06:34 +08:00
|
|
|
|
|
|
|
_servers = nil;
|
|
|
|
if (!eval.serverList.empty()) {
|
|
|
|
NSMutableArray *servers = [NSMutableArray new];
|
|
|
|
|
|
|
|
for (ClientAPI::ServerEntry entry : eval.serverList) {
|
|
|
|
OpenVPNServerEntry *serverEntry = [[OpenVPNServerEntry alloc] initWithServerEntry:entry];
|
|
|
|
[servers addObject:serverEntry];
|
|
|
|
}
|
|
|
|
|
|
|
|
_servers = servers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|