mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-24 00:00:05 +08:00
Wrap content list
This commit is contained in:
@@ -12,6 +12,17 @@
|
|||||||
|
|
||||||
@interface OpenVPNConfiguration : NSObject
|
@interface OpenVPNConfiguration : NSObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
OpenVPN profile as a NSData
|
||||||
|
*/
|
||||||
@property (nullable, nonatomic) NSData *fileContent;
|
@property (nullable, nonatomic) NSData *fileContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
OpenVPN profile as series of key/value pairs (may be provided exclusively
|
||||||
|
or in addition to file content).
|
||||||
|
*/
|
||||||
|
@property (nullable, nonatomic) NSDictionary<NSString *, NSString *> *settings;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#import "OpenVPNConfiguration.h"
|
#import "OpenVPNConfiguration.h"
|
||||||
#import "OpenVPNConfiguration+Internal.h"
|
#import "OpenVPNConfiguration+Internal.h"
|
||||||
|
|
||||||
|
using namespace openvpn;
|
||||||
|
|
||||||
@interface OpenVPNConfiguration () {
|
@interface OpenVPNConfiguration () {
|
||||||
ClientAPI::Config _config;
|
ClientAPI::Config _config;
|
||||||
}
|
}
|
||||||
@@ -25,7 +27,7 @@
|
|||||||
|
|
||||||
@implementation OpenVPNConfiguration
|
@implementation OpenVPNConfiguration
|
||||||
|
|
||||||
-(NSData *)fileContent {
|
- (NSData *)fileContent {
|
||||||
return _config.content.size() != 0 ? [NSData dataWithBytes:_config.content.data() length:_config.content.size()] : nil;
|
return _config.content.size() != 0 ? [NSData dataWithBytes:_config.content.data() length:_config.content.size()] : nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,4 +35,30 @@
|
|||||||
_config.content = fileContent != nil ? std::string((const char *)fileContent.bytes) : "";
|
_config.content = fileContent != nil ? std::string((const char *)fileContent.bytes) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSDictionary<NSString *,NSString *> *)settings {
|
||||||
|
if (_config.contentList.size() == 0) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMutableDictionary *settings = [NSMutableDictionary new];
|
||||||
|
|
||||||
|
for (ClientAPI::KeyValue param : _config.contentList) {
|
||||||
|
NSString *key = [NSString stringWithCString:param.key.c_str() encoding:NSUTF8StringEncoding];
|
||||||
|
NSString *value = [NSString stringWithCString:param.value.c_str() encoding:NSUTF8StringEncoding];
|
||||||
|
|
||||||
|
settings[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [settings copy];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setSettings:(NSDictionary<NSString *,NSString *> *)settings {
|
||||||
|
_config.contentList.clear();
|
||||||
|
|
||||||
|
[settings enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull obj, BOOL * _Nonnull stop) {
|
||||||
|
ClientAPI::KeyValue param = ClientAPI::KeyValue(std::string([key UTF8String]), std::string([obj UTF8String]));
|
||||||
|
_config.contentList.push_back(param);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user