Implement evaluation of the configuration

This commit is contained in:
Sergey Abramchuk
2020-08-18 10:24:25 +03:00
parent ec1477b8a3
commit 78b203ec87
2 changed files with 33 additions and 4 deletions
@@ -126,13 +126,24 @@ NS_SWIFT_NAME(openVPNAdapter(_:handleEvent:message:));
*/ */
@property (nonatomic, readonly) OpenVPNTransportStats *transportStatistics; @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. Applies the given configuration object.
Call this method prior to connecting, this method has no effect after calling connect. Call this method prior to connecting, this method has no effect after calling connect.
@param configuration The configuration object. @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. @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 - (nullable OpenVPNConfigurationEvaluation *)applyConfiguration:(OpenVPNConfiguration *)configuration
error:(NSError **)error error:(NSError **)error
@@ -50,6 +50,24 @@
#pragma mark - OpenVPNClient Lifecycle #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 { - (OpenVPNConfigurationEvaluation *)applyConfiguration:(OpenVPNConfiguration *)configuration error:(NSError * __autoreleasing *)error {
ClientAPI::EvalConfig eval = self.vpnClient->apply_config(configuration.config); ClientAPI::EvalConfig eval = self.vpnClient->apply_config(configuration.config);
@@ -57,9 +75,9 @@
if (error) { if (error) {
NSString *message = [NSString stringWithUTF8String:eval.message.c_str()]; NSString *message = [NSString stringWithUTF8String:eval.message.c_str()];
*error = [NSError ovpn_errorObjectForAdapterError:OpenVPNAdapterErrorConfigurationFailure *error = [NSError ovpn_errorObjectForAdapterError:OpenVPNAdapterErrorConfigurationFailure
description:@"Failed to apply OpenVPN configuration." description:@"Failed to apply OpenVPN configuration."
message:message message:message
fatal:YES]; fatal:YES];
} }
return nil; return nil;