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 @synthesize tlsCertPolicy = _tlsCertPolicy; |
21 @synthesize hostname = _hostname; | 21 @synthesize hostname = _hostname; |
| 22 @synthesize tlsAlpnProtocols = _tlsAlpnProtocols; |
22 | 23 |
23 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings { | 24 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings { |
24 return [self initWithURLStrings:urlStrings | 25 return [self initWithURLStrings:urlStrings |
25 username:nil | 26 username:nil |
26 credential:nil]; | 27 credential:nil]; |
27 } | 28 } |
28 | 29 |
29 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings | 30 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings |
30 username:(NSString *)username | 31 username:(NSString *)username |
31 credential:(NSString *)credential { | 32 credential:(NSString *)credential { |
(...skipping 12 matching lines...) Expand all Loading... |
44 credential:credential | 45 credential:credential |
45 tlsCertPolicy:tlsCertPolicy | 46 tlsCertPolicy:tlsCertPolicy |
46 hostname:nil]; | 47 hostname:nil]; |
47 } | 48 } |
48 | 49 |
49 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings | 50 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings |
50 username:(NSString *)username | 51 username:(NSString *)username |
51 credential:(NSString *)credential | 52 credential:(NSString *)credential |
52 tlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy | 53 tlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy |
53 hostname:(NSString *)hostname { | 54 hostname:(NSString *)hostname { |
| 55 return [self initWithURLStrings:urlStrings |
| 56 username:username |
| 57 credential:credential |
| 58 tlsCertPolicy:tlsCertPolicy |
| 59 hostname:hostname |
| 60 tlsAlpnProtocols:[NSMutableArray new]]; |
| 61 } |
| 62 |
| 63 - (instancetype)initWithURLStrings:(NSArray<NSString *> *)urlStrings |
| 64 username:(NSString *)username |
| 65 credential:(NSString *)credential |
| 66 tlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy |
| 67 hostname:(NSString *)hostname |
| 68 tlsAlpnProtocols:(NSArray<NSString *> *)tlsAlpnProtocols { |
54 NSParameterAssert(urlStrings.count); | 69 NSParameterAssert(urlStrings.count); |
55 if (self = [super init]) { | 70 if (self = [super init]) { |
56 _urlStrings = [[NSArray alloc] initWithArray:urlStrings copyItems:YES]; | 71 _urlStrings = [[NSArray alloc] initWithArray:urlStrings copyItems:YES]; |
57 _username = [username copy]; | 72 _username = [username copy]; |
58 _credential = [credential copy]; | 73 _credential = [credential copy]; |
59 _tlsCertPolicy = tlsCertPolicy; | 74 _tlsCertPolicy = tlsCertPolicy; |
60 _hostname = [hostname copy]; | 75 _hostname = [hostname copy]; |
| 76 _tlsAlpnProtocols = |
| 77 [[NSArray alloc] initWithArray:tlsAlpnProtocols copyItems:YES]; |
61 } | 78 } |
62 return self; | 79 return self; |
63 } | 80 } |
64 | 81 |
65 - (NSString *)description { | 82 - (NSString *)description { |
66 return [NSString stringWithFormat:@"RTCIceServer:\n%@\n%@\n%@\n%@\n%@", | 83 return [NSString stringWithFormat:@"RTCIceServer:\n%@\n%@\n%@\n%@\n%@\n%@", |
67 _urlStrings, | 84 _urlStrings, |
68 _username, | 85 _username, |
69 _credential, | 86 _credential, |
70 [self stringForTlsCertPolicy:_tlsCertPolicy]
, | 87 [self stringForTlsCertPolicy:_tlsCertPolicy]
, |
71 _hostname]; | 88 _hostname, |
| 89 _tlsAlpnProtocols]; |
72 } | 90 } |
73 | 91 |
74 #pragma mark - Private | 92 #pragma mark - Private |
75 | 93 |
76 - (NSString *)stringForTlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy { | 94 - (NSString *)stringForTlsCertPolicy:(RTCTlsCertPolicy)tlsCertPolicy { |
77 switch (tlsCertPolicy) { | 95 switch (tlsCertPolicy) { |
78 case RTCTlsCertPolicySecure: | 96 case RTCTlsCertPolicySecure: |
79 return @"RTCTlsCertPolicySecure"; | 97 return @"RTCTlsCertPolicySecure"; |
80 case RTCTlsCertPolicyInsecureNoCheck: | 98 case RTCTlsCertPolicyInsecureNoCheck: |
81 return @"RTCTlsCertPolicyInsecureNoCheck"; | 99 return @"RTCTlsCertPolicyInsecureNoCheck"; |
82 } | 100 } |
83 } | 101 } |
84 | 102 |
85 - (webrtc::PeerConnectionInterface::IceServer)nativeServer { | 103 - (webrtc::PeerConnectionInterface::IceServer)nativeServer { |
86 __block webrtc::PeerConnectionInterface::IceServer iceServer; | 104 __block webrtc::PeerConnectionInterface::IceServer iceServer; |
87 | 105 |
88 iceServer.username = [NSString stdStringForString:_username]; | 106 iceServer.username = [NSString stdStringForString:_username]; |
89 iceServer.password = [NSString stdStringForString:_credential]; | 107 iceServer.password = [NSString stdStringForString:_credential]; |
90 iceServer.hostname = [NSString stdStringForString:_hostname]; | 108 iceServer.hostname = [NSString stdStringForString:_hostname]; |
91 | 109 |
| 110 [_tlsAlpnProtocols enumerateObjectsUsingBlock:^(NSString *proto, |
| 111 NSUInteger idx, |
| 112 BOOL *stop) { |
| 113 iceServer.tls_alpn_protocols.push_back(proto.stdString); |
| 114 }]; |
| 115 |
92 [_urlStrings enumerateObjectsUsingBlock:^(NSString *url, | 116 [_urlStrings enumerateObjectsUsingBlock:^(NSString *url, |
93 NSUInteger idx, | 117 NSUInteger idx, |
94 BOOL *stop) { | 118 BOOL *stop) { |
95 iceServer.urls.push_back(url.stdString); | 119 iceServer.urls.push_back(url.stdString); |
96 }]; | 120 }]; |
97 | 121 |
98 switch (_tlsCertPolicy) { | 122 switch (_tlsCertPolicy) { |
99 case RTCTlsCertPolicySecure: | 123 case RTCTlsCertPolicySecure: |
100 iceServer.tls_cert_policy = | 124 iceServer.tls_cert_policy = |
101 webrtc::PeerConnectionInterface::kTlsCertPolicySecure; | 125 webrtc::PeerConnectionInterface::kTlsCertPolicySecure; |
102 break; | 126 break; |
103 case RTCTlsCertPolicyInsecureNoCheck: | 127 case RTCTlsCertPolicyInsecureNoCheck: |
104 iceServer.tls_cert_policy = | 128 iceServer.tls_cert_policy = |
105 webrtc::PeerConnectionInterface::kTlsCertPolicyInsecureNoCheck; | 129 webrtc::PeerConnectionInterface::kTlsCertPolicyInsecureNoCheck; |
106 break; | 130 break; |
107 } | 131 } |
108 return iceServer; | 132 return iceServer; |
109 } | 133 } |
110 | 134 |
111 - (instancetype)initWithNativeServer: | 135 - (instancetype)initWithNativeServer: |
112 (webrtc::PeerConnectionInterface::IceServer)nativeServer { | 136 (webrtc::PeerConnectionInterface::IceServer)nativeServer { |
113 NSMutableArray *urls = | 137 NSMutableArray *urls = |
114 [NSMutableArray arrayWithCapacity:nativeServer.urls.size()]; | 138 [NSMutableArray arrayWithCapacity:nativeServer.urls.size()]; |
115 for (auto const &url : nativeServer.urls) { | 139 for (auto const &url : nativeServer.urls) { |
116 [urls addObject:[NSString stringForStdString:url]]; | 140 [urls addObject:[NSString stringForStdString:url]]; |
117 } | 141 } |
118 NSString *username = [NSString stringForStdString:nativeServer.username]; | 142 NSString *username = [NSString stringForStdString:nativeServer.username]; |
119 NSString *credential = [NSString stringForStdString:nativeServer.password]; | 143 NSString *credential = [NSString stringForStdString:nativeServer.password]; |
120 NSString *hostname = [NSString stringForStdString:nativeServer.hostname]; | 144 NSString *hostname = [NSString stringForStdString:nativeServer.hostname]; |
| 145 NSMutableArray *tlsAlpnProtocols = |
| 146 [NSMutableArray arrayWithCapacity:nativeServer.tls_alpn_protocols.size()]; |
| 147 for (auto const &proto : nativeServer.tls_alpn_protocols) { |
| 148 [tlsAlpnProtocols addObject:[NSString stringForStdString:proto]]; |
| 149 } |
121 RTCTlsCertPolicy tlsCertPolicy; | 150 RTCTlsCertPolicy tlsCertPolicy; |
122 | 151 |
123 switch (nativeServer.tls_cert_policy) { | 152 switch (nativeServer.tls_cert_policy) { |
124 case webrtc::PeerConnectionInterface::kTlsCertPolicySecure: | 153 case webrtc::PeerConnectionInterface::kTlsCertPolicySecure: |
125 tlsCertPolicy = RTCTlsCertPolicySecure; | 154 tlsCertPolicy = RTCTlsCertPolicySecure; |
126 break; | 155 break; |
127 case webrtc::PeerConnectionInterface::kTlsCertPolicyInsecureNoCheck: | 156 case webrtc::PeerConnectionInterface::kTlsCertPolicyInsecureNoCheck: |
128 tlsCertPolicy = RTCTlsCertPolicyInsecureNoCheck; | 157 tlsCertPolicy = RTCTlsCertPolicyInsecureNoCheck; |
129 break; | 158 break; |
130 } | 159 } |
131 | 160 |
132 self = [self initWithURLStrings:urls | 161 self = [self initWithURLStrings:urls |
133 username:username | 162 username:username |
134 credential:credential | 163 credential:credential |
135 tlsCertPolicy:tlsCertPolicy | 164 tlsCertPolicy:tlsCertPolicy |
136 hostname:hostname]; | 165 hostname:hostname |
| 166 tlsAlpnProtocols:tlsAlpnProtocols]; |
137 return self; | 167 return self; |
138 } | 168 } |
139 | 169 |
140 @end | 170 @end |
OLD | NEW |