mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-05-13 00:04:14 +08:00
Implement evaluation of the configuration
This commit is contained in:
@@ -126,13 +126,24 @@ NS_SWIFT_NAME(openVPNAdapter(_:handleEvent:message:));
|
||||
*/
|
||||
@property (nonatomic, readonly) OpenVPNTransportStats *transportStatistics;
|
||||
|
||||
/**
|
||||
Evaluate the given configuration object and determine needed credentials.
|
||||
|
||||
@param configuration The configuration object.
|
||||
@param error If there is an error applying the configuration, upon return contains an error object that describes the problem.
|
||||
@return An object describing the configuration which has been evaluated.
|
||||
*/
|
||||
+ (nullable OpenVPNConfigurationEvaluation *)evaluateConfiguration:(OpenVPNConfiguration *)configuration
|
||||
error:(NSError **)error
|
||||
NS_SWIFT_NAME(evaluate(configuration:));
|
||||
|
||||
/**
|
||||
Applies the given configuration object.
|
||||
Call this method prior to connecting, this method has no effect after calling connect.
|
||||
|
||||
@param configuration The configuration object.
|
||||
@param error If there is an error applying the configuration, upon return contains an error object that describes the problem.
|
||||
@return A properties object describing the configuration which has been applied.
|
||||
@return An object describing the configuration which has been applied.
|
||||
*/
|
||||
- (nullable OpenVPNConfigurationEvaluation *)applyConfiguration:(OpenVPNConfiguration *)configuration
|
||||
error:(NSError **)error
|
||||
|
||||
@@ -50,6 +50,24 @@
|
||||
|
||||
#pragma mark - OpenVPNClient Lifecycle
|
||||
|
||||
+ (nullable OpenVPNConfigurationEvaluation *)evaluateConfiguration:(OpenVPNConfiguration *)configuration error:(NSError **)error {
|
||||
ClientAPI::EvalConfig eval = OpenVPNClient::eval_config_static(configuration.config);
|
||||
|
||||
if (eval.error) {
|
||||
if (error) {
|
||||
NSString *message = [NSString stringWithUTF8String:eval.message.c_str()];
|
||||
*error = [NSError ovpn_errorObjectForAdapterError:OpenVPNAdapterErrorConfigurationFailure
|
||||
description:@"Failed to evaluate OpenVPN configuration."
|
||||
message:message
|
||||
fatal:YES];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [[OpenVPNConfigurationEvaluation alloc] initWithEvalConfig:eval];
|
||||
}
|
||||
|
||||
- (OpenVPNConfigurationEvaluation *)applyConfiguration:(OpenVPNConfiguration *)configuration error:(NSError * __autoreleasing *)error {
|
||||
ClientAPI::EvalConfig eval = self.vpnClient->apply_config(configuration.config);
|
||||
|
||||
@@ -57,9 +75,9 @@
|
||||
if (error) {
|
||||
NSString *message = [NSString stringWithUTF8String:eval.message.c_str()];
|
||||
*error = [NSError ovpn_errorObjectForAdapterError:OpenVPNAdapterErrorConfigurationFailure
|
||||
description:@"Failed to apply OpenVPN configuration."
|
||||
message:message
|
||||
fatal:YES];
|
||||
description:@"Failed to apply OpenVPN configuration."
|
||||
message:message
|
||||
fatal:YES];
|
||||
}
|
||||
|
||||
return nil;
|
||||
|
||||
Reference in New Issue
Block a user