OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #import "RTCIceServer+Private.h" | 11 #import "RTCIceServer+Private.h" |
12 | 12 |
13 #import "NSString+StdString.h" | 13 #import "NSString+StdString.h" |
14 | 14 |
15 @implementation RTCIceServer | 15 @implementation RTCIceServer |
16 | 16 |
17 @synthesize urlStrings = _urlStrings; | 17 @synthesize urlStrings = _urlStrings; |
18 @synthesize username = _username; | 18 @synthesize username = _username; |
19 @synthesize credential = _credential; | 19 @synthesize credential = _credential; |
20 @synthesize tlsCertPolicy = _tlsCertPolicy; | |
20 | 21 |
21 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings { | 22 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings { |
22 NSParameterAssert(urlStrings.count); | |
23 return [self initWithURLStrings:urlStrings | 23 return [self initWithURLStrings:urlStrings |
24 username:nil | 24 username:nil |
25 credential:nil]; | 25 credential:nil]; |
26 } | 26 } |
27 | 27 |
28 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings | 28 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings |
29 username:(NSString *)username | 29 username:(NSString *)username |
30 credential:(NSString *)credential { | 30 credential:(NSString *)credential { |
31 return [self initWithURLStrings:urlStrings | |
32 username:username | |
33 credential:credential | |
34 tlsCertPolicy:RTCTlsCertPolicySecure]; | |
35 } | |
36 | |
37 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings | |
38 username:(NSString *)username | |
39 credential:(NSString *)credential | |
40 tlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy { | |
31 NSParameterAssert(urlStrings.count); | 41 NSParameterAssert(urlStrings.count); |
32 if (self = [super init]) { | 42 if (self = [super init]) { |
33 _urlStrings = [[NSArray alloc] initWithArray:urlStrings copyItems:YES]; | 43 _urlStrings = [[NSArray alloc] initWithArray:urlStrings copyItems:YES]; |
34 _username = [username copy]; | 44 _username = [username copy]; |
35 _credential = [credential copy]; | 45 _credential = [credential copy]; |
46 _tlsCertPolicy = tlsCertPolicy; | |
36 } | 47 } |
37 return self; | 48 return self; |
38 } | 49 } |
39 | 50 |
40 - (NSString *)description { | 51 - (NSString *)description { |
41 return [NSString stringWithFormat:@"RTCIceServer:\n%@\n%@\n%@", | 52 return |
42 _urlStrings, | 53 [NSString stringWithFormat:@"RTCIceServer:\n%@\n%@\n%@\n%@", _urlStrings, |
43 _username, | 54 _username, _credential, |
44 _credential]; | 55 [self stringForTlsCertPolicy:_tlsCertPolicy]]; |
45 } | 56 } |
46 | 57 |
47 #pragma mark - Private | 58 #pragma mark - Private |
48 | 59 |
60 - (NSString *)stringForTlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy { | |
61 switch (tlsCertPolicy) { | |
62 case RTCTlsCertPolicySecure: | |
63 return @"RTCTlsCertPolicySecure"; | |
64 case RTCTlsCertPolicyInsecureNoCheck: | |
65 return @"RTCTlsCertPolicyInsecureNoCheck"; | |
66 default: | |
tkchin_webrtc
2017/02/02 19:51:12
remove default
hnsl1
2017/02/02 19:53:35
Done.
| |
67 return @"RTCTlsCertPolicyUnknown"; | |
68 } | |
69 } | |
70 | |
49 - (webrtc::PeerConnectionInterface::IceServer)nativeServer { | 71 - (webrtc::PeerConnectionInterface::IceServer)nativeServer { |
50 __block webrtc::PeerConnectionInterface::IceServer iceServer; | 72 __block webrtc::PeerConnectionInterface::IceServer iceServer; |
51 | 73 |
52 iceServer.username = [NSString stdStringForString:_username]; | 74 iceServer.username = [NSString stdStringForString:_username]; |
53 iceServer.password = [NSString stdStringForString:_credential]; | 75 iceServer.password = [NSString stdStringForString:_credential]; |
54 | 76 |
55 [_urlStrings enumerateObjectsUsingBlock:^(NSString *url, | 77 [_urlStrings enumerateObjectsUsingBlock:^(NSString *url, |
56 NSUInteger idx, | 78 NSUInteger idx, |
57 BOOL *stop) { | 79 BOOL *stop) { |
58 iceServer.urls.push_back(url.stdString); | 80 iceServer.urls.push_back(url.stdString); |
59 }]; | 81 }]; |
82 | |
83 switch (_tlsCertPolicy) { | |
84 case RTCTlsCertPolicySecure: | |
85 iceServer.tls_cert_policy = | |
86 webrtc::PeerConnectionInterface::kTlsCertPolicySecure; | |
87 break; | |
88 case RTCTlsCertPolicyInsecureNoCheck: | |
89 iceServer.tls_cert_policy = | |
90 webrtc::PeerConnectionInterface::kTlsCertPolicyInsecureNoCheck; | |
91 break; | |
92 } | |
60 return iceServer; | 93 return iceServer; |
61 } | 94 } |
62 | 95 |
63 - (instancetype)initWithNativeServer: | 96 - (instancetype)initWithNativeServer: |
64 (webrtc::PeerConnectionInterface::IceServer)nativeServer { | 97 (webrtc::PeerConnectionInterface::IceServer)nativeServer { |
65 NSMutableArray *urls = | 98 NSMutableArray *urls = |
66 [NSMutableArray arrayWithCapacity:nativeServer.urls.size()]; | 99 [NSMutableArray arrayWithCapacity:nativeServer.urls.size()]; |
67 for (auto const &url : nativeServer.urls) { | 100 for (auto const &url : nativeServer.urls) { |
68 [urls addObject:[NSString stringForStdString:url]]; | 101 [urls addObject:[NSString stringForStdString:url]]; |
69 } | 102 } |
70 NSString *username = [NSString stringForStdString:nativeServer.username]; | 103 NSString *username = [NSString stringForStdString:nativeServer.username]; |
71 NSString *credential = [NSString stringForStdString:nativeServer.password]; | 104 NSString *credential = [NSString stringForStdString:nativeServer.password]; |
105 RTCTlsCertPolicy tlsCertPolicy; | |
106 | |
107 switch (nativeServer.tls_cert_policy) { | |
108 case webrtc::PeerConnectionInterface::kTlsCertPolicySecure: | |
109 tlsCertPolicy = RTCTlsCertPolicySecure; | |
110 break; | |
111 case webrtc::PeerConnectionInterface::kTlsCertPolicyInsecureNoCheck: | |
112 tlsCertPolicy = RTCTlsCertPolicyInsecureNoCheck; | |
113 break; | |
114 } | |
115 | |
72 self = [self initWithURLStrings:urls | 116 self = [self initWithURLStrings:urls |
73 username:username | 117 username:username |
74 credential:credential]; | 118 credential:credential |
119 tlsCertPolicy:tlsCertPolicy]; | |
75 return self; | 120 return self; |
76 } | 121 } |
77 | 122 |
78 @end | 123 @end |
OLD | NEW |