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 |
51 - (NSString*)describeTlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy { | |
tkchin_webrtc
2017/02/02 17:54:00
nit: (NSString *)
to follow other places in the s
hnsl1
2017/02/02 19:50:08
Done.
| |
52 switch (tlsCertPolicy) { | |
53 case RTCTlsCertPolicySecure: | |
54 return @"RTCTlsCertPolicySecure"; | |
55 case RTCTlsCertPolicyInsecureNoCheck: | |
56 return @"RTCTlsCertPolicyInsecureNoCheck"; | |
57 default: | |
58 return @"RTCTlsCertPolicyUnknown"; | |
59 } | |
60 } | |
61 | |
40 - (NSString *)description { | 62 - (NSString *)description { |
41 return [NSString stringWithFormat:@"RTCIceServer:\n%@\n%@\n%@", | 63 return |
42 _urlStrings, | 64 [NSString stringWithFormat:@"RTCIceServer:\n%@\n%@\n%@\n%@", _urlStrings, |
43 _username, | 65 _username, _credential, |
44 _credential]; | 66 [self describeTlsCertPolicy:_tlsCertPolicy]]; |
45 } | 67 } |
46 | 68 |
47 #pragma mark - Private | 69 #pragma mark - Private |
48 | 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 default: | |
tkchin_webrtc
2017/02/02 17:54:00
remove default case so that compiler will complain
hnsl1
2017/02/02 19:50:08
Done.
| |
93 iceServer.tls_cert_policy = | |
94 webrtc::PeerConnectionInterface::kTlsCertPolicySecure; | |
95 break; | |
96 } | |
60 return iceServer; | 97 return iceServer; |
61 } | 98 } |
62 | 99 |
63 - (instancetype)initWithNativeServer: | 100 - (instancetype)initWithNativeServer: |
64 (webrtc::PeerConnectionInterface::IceServer)nativeServer { | 101 (webrtc::PeerConnectionInterface::IceServer)nativeServer { |
65 NSMutableArray *urls = | 102 NSMutableArray *urls = |
66 [NSMutableArray arrayWithCapacity:nativeServer.urls.size()]; | 103 [NSMutableArray arrayWithCapacity:nativeServer.urls.size()]; |
67 for (auto const &url : nativeServer.urls) { | 104 for (auto const &url : nativeServer.urls) { |
68 [urls addObject:[NSString stringForStdString:url]]; | 105 [urls addObject:[NSString stringForStdString:url]]; |
69 } | 106 } |
70 NSString *username = [NSString stringForStdString:nativeServer.username]; | 107 NSString *username = [NSString stringForStdString:nativeServer.username]; |
71 NSString *credential = [NSString stringForStdString:nativeServer.password]; | 108 NSString *credential = [NSString stringForStdString:nativeServer.password]; |
109 RTCTlsCertPolicy tlsCertPolicy; | |
110 | |
111 switch (nativeServer.tls_cert_policy) { | |
112 case webrtc::PeerConnectionInterface::kTlsCertPolicySecure: | |
113 tlsCertPolicy = RTCTlsCertPolicySecure; | |
114 break; | |
115 case webrtc::PeerConnectionInterface::kTlsCertPolicyInsecureNoCheck: | |
116 tlsCertPolicy = RTCTlsCertPolicyInsecureNoCheck; | |
117 break; | |
118 default: | |
tkchin_webrtc
2017/02/02 17:54:00
ditto
hnsl1
2017/02/02 19:50:08
Done.
| |
119 tlsCertPolicy = RTCTlsCertPolicySecure; | |
120 break; | |
121 } | |
122 | |
72 self = [self initWithURLStrings:urls | 123 self = [self initWithURLStrings:urls |
73 username:username | 124 username:username |
74 credential:credential]; | 125 credential:credential |
126 tlsCertPolicy:tlsCertPolicy]; | |
75 return self; | 127 return self; |
76 } | 128 } |
77 | 129 |
78 @end | 130 @end |
OLD | NEW |