Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: remoting/protocol/jingle_messages.cc

Issue 1099203005: Revert of Use standard ICE in Chromoting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/jingle_messages.h ('k') | remoting/protocol/jingle_messages_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/protocol/jingle_messages.h" 5 #include "remoting/protocol/jingle_messages.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "remoting/base/constants.h" 9 #include "remoting/base/constants.h"
10 #include "remoting/protocol/content_description.h" 10 #include "remoting/protocol/content_description.h"
11 #include "remoting/protocol/name_value_map.h" 11 #include "remoting/protocol/name_value_map.h"
12 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" 12 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
13 13
14 using buzz::QName; 14 using buzz::QName;
15 using buzz::XmlElement; 15 using buzz::XmlElement;
16 16
17 namespace remoting { 17 namespace remoting {
18 namespace protocol { 18 namespace protocol {
19 19
20 namespace {
21
22 const char kJabberNamespace[] = "jabber:client"; 20 const char kJabberNamespace[] = "jabber:client";
23 const char kJingleNamespace[] = "urn:xmpp:jingle:1"; 21 const char kJingleNamespace[] = "urn:xmpp:jingle:1";
22 const char kP2PTransportNamespace[] = "http://www.google.com/transport/p2p";
24 23
25 // Namespace for transport messages for legacy GICE. 24 namespace {
26 const char kGiceTransportNamespace[] = "http://www.google.com/transport/p2p";
27
28 // Namespace for transport messages when using standard ICE.
29 const char kIceTransportNamespace[] = "google:remoting:ice";
30 25
31 const char kEmptyNamespace[] = ""; 26 const char kEmptyNamespace[] = "";
32 const char kXmlNamespace[] = "http://www.w3.org/XML/1998/namespace"; 27 const char kXmlNamespace[] = "http://www.w3.org/XML/1998/namespace";
33 28
34 const int kPortMin = 1000; 29 const int kPortMin = 1000;
35 const int kPortMax = 65535; 30 const int kPortMax = 65535;
36 31
37 const NameMapElement<JingleMessage::ActionType> kActionTypes[] = { 32 const NameMapElement<JingleMessage::ActionType> kActionTypes[] = {
38 { JingleMessage::SESSION_INITIATE, "session-initiate" }, 33 { JingleMessage::SESSION_INITIATE, "session-initiate" },
39 { JingleMessage::SESSION_ACCEPT, "session-accept" }, 34 { JingleMessage::SESSION_ACCEPT, "session-accept" },
40 { JingleMessage::SESSION_TERMINATE, "session-terminate" }, 35 { JingleMessage::SESSION_TERMINATE, "session-terminate" },
41 { JingleMessage::SESSION_INFO, "session-info" }, 36 { JingleMessage::SESSION_INFO, "session-info" },
42 { JingleMessage::TRANSPORT_INFO, "transport-info" }, 37 { JingleMessage::TRANSPORT_INFO, "transport-info" },
43 }; 38 };
44 39
45 const NameMapElement<JingleMessage::Reason> kReasons[] = { 40 const NameMapElement<JingleMessage::Reason> kReasons[] = {
46 { JingleMessage::SUCCESS, "success" }, 41 { JingleMessage::SUCCESS, "success" },
47 { JingleMessage::DECLINE, "decline" }, 42 { JingleMessage::DECLINE, "decline" },
48 { JingleMessage::CANCEL, "cancel" }, 43 { JingleMessage::CANCEL, "cancel" },
49 { JingleMessage::GENERAL_ERROR, "general-error" }, 44 { JingleMessage::GENERAL_ERROR, "general-error" },
50 { JingleMessage::INCOMPATIBLE_PARAMETERS, "incompatible-parameters" }, 45 { JingleMessage::INCOMPATIBLE_PARAMETERS, "incompatible-parameters" },
51 }; 46 };
52 47
53 bool ParseIceCredentials(const buzz::XmlElement* element, 48 bool ParseCandidate(const buzz::XmlElement* element,
54 JingleMessage::IceCredentials* credentials) { 49 JingleMessage::NamedCandidate* candidate) {
55 DCHECK(element->Name() == QName(kIceTransportNamespace, "credentials")); 50 DCHECK(element->Name() == QName(kP2PTransportNamespace, "candidate"));
56
57 const std::string& channel = element->Attr(QName(kEmptyNamespace, "channel"));
58 const std::string& ufrag =
59 element->Attr(QName(kEmptyNamespace, "ufrag"));
60 const std::string& password =
61 element->Attr(QName(kEmptyNamespace, "password"));
62
63 if (channel.empty() || ufrag.empty() || password.empty()) {
64 return false;
65 }
66
67 credentials->channel = channel;
68 credentials->ufrag = ufrag;
69 credentials->password = password;
70
71 return true;
72 }
73
74 bool ParseIceCandidate(const buzz::XmlElement* element,
75 JingleMessage::NamedCandidate* candidate) {
76 DCHECK(element->Name() == QName(kIceTransportNamespace, "candidate"));
77
78 const std::string& name = element->Attr(QName(kEmptyNamespace, "name"));
79 const std::string& foundation =
80 element->Attr(QName(kEmptyNamespace, "foundation"));
81 const std::string& address = element->Attr(QName(kEmptyNamespace, "address"));
82 const std::string& port_str = element->Attr(QName(kEmptyNamespace, "port"));
83 const std::string& type = element->Attr(QName(kEmptyNamespace, "type"));
84 const std::string& protocol =
85 element->Attr(QName(kEmptyNamespace, "protocol"));
86 const std::string& priority_str =
87 element->Attr(QName(kEmptyNamespace, "priority"));
88 const std::string& generation_str =
89 element->Attr(QName(kEmptyNamespace, "generation"));
90
91 int port;
92 unsigned priority;
93 int generation;
94 if (name.empty() || foundation.empty() || address.empty() ||
95 !base::StringToInt(port_str, &port) || port < kPortMin ||
96 port > kPortMax || type.empty() || protocol.empty() ||
97 !base::StringToUint(priority_str, &priority) ||
98 !base::StringToInt(generation_str, &generation)) {
99 return false;
100 }
101
102 candidate->name = name;
103
104 candidate->candidate.set_foundation(foundation);
105 candidate->candidate.set_address(rtc::SocketAddress(address, port));
106 candidate->candidate.set_type(type);
107 candidate->candidate.set_protocol(protocol);
108 candidate->candidate.set_priority(priority);
109 candidate->candidate.set_generation(generation);
110
111 return true;
112 }
113
114 bool ParseIceTransportInfo(
115 const buzz::XmlElement* element,
116 std::list<JingleMessage::IceCredentials>* ice_credentials,
117 std::list<JingleMessage::NamedCandidate>* candidates) {
118 DCHECK(element->Name() == QName(kIceTransportNamespace, "transport"));
119
120 ice_credentials->clear();
121 candidates->clear();
122
123 QName qn_credentials(kIceTransportNamespace, "credentials");
124 for (const XmlElement* credentials_tag = element->FirstNamed(qn_credentials);
125 credentials_tag;
126 credentials_tag = credentials_tag->NextNamed(qn_credentials)) {
127 JingleMessage::IceCredentials credentials;
128 if (!ParseIceCredentials(credentials_tag, &credentials))
129 return false;
130 ice_credentials->push_back(credentials);
131 }
132
133 QName qn_candidate(kIceTransportNamespace, "candidate");
134 for (const XmlElement* candidate_tag = element->FirstNamed(qn_candidate);
135 candidate_tag; candidate_tag = candidate_tag->NextNamed(qn_candidate)) {
136 JingleMessage::NamedCandidate candidate;
137 if (!ParseIceCandidate(candidate_tag, &candidate))
138 return false;
139 candidates->push_back(candidate);
140 }
141
142 return true;
143 }
144
145 bool ParseGiceCandidate(const buzz::XmlElement* element,
146 JingleMessage::NamedCandidate* candidate) {
147 DCHECK(element->Name() == QName(kGiceTransportNamespace, "candidate"));
148 51
149 const std::string& name = element->Attr(QName(kEmptyNamespace, "name")); 52 const std::string& name = element->Attr(QName(kEmptyNamespace, "name"));
150 const std::string& address = element->Attr(QName(kEmptyNamespace, "address")); 53 const std::string& address = element->Attr(QName(kEmptyNamespace, "address"));
151 const std::string& port_str = element->Attr(QName(kEmptyNamespace, "port")); 54 const std::string& port_str = element->Attr(QName(kEmptyNamespace, "port"));
152 const std::string& type = element->Attr(QName(kEmptyNamespace, "type")); 55 const std::string& type = element->Attr(QName(kEmptyNamespace, "type"));
153 const std::string& protocol = 56 const std::string& protocol =
154 element->Attr(QName(kEmptyNamespace, "protocol")); 57 element->Attr(QName(kEmptyNamespace, "protocol"));
155 const std::string& username = 58 const std::string& username =
156 element->Attr(QName(kEmptyNamespace, "username")); 59 element->Attr(QName(kEmptyNamespace, "username"));
157 const std::string& password = 60 const std::string& password =
(...skipping 20 matching lines...) Expand all
178 candidate->candidate.set_type(type); 81 candidate->candidate.set_type(type);
179 candidate->candidate.set_protocol(protocol); 82 candidate->candidate.set_protocol(protocol);
180 candidate->candidate.set_username(username); 83 candidate->candidate.set_username(username);
181 candidate->candidate.set_password(password); 84 candidate->candidate.set_password(password);
182 candidate->candidate.set_preference(static_cast<float>(preference)); 85 candidate->candidate.set_preference(static_cast<float>(preference));
183 candidate->candidate.set_generation(generation); 86 candidate->candidate.set_generation(generation);
184 87
185 return true; 88 return true;
186 } 89 }
187 90
188 bool ParseGiceTransportInfo( 91 XmlElement* FormatCandidate(const JingleMessage::NamedCandidate& candidate) {
189 const buzz::XmlElement* element,
190 std::list<JingleMessage::NamedCandidate>* candidates) {
191 DCHECK(element->Name() == QName(kGiceTransportNamespace, "transport"));
192
193 candidates->clear();
194
195 QName qn_candidate(kGiceTransportNamespace, "candidate");
196 for (const XmlElement* candidate_tag = element->FirstNamed(qn_candidate);
197 candidate_tag; candidate_tag = candidate_tag->NextNamed(qn_candidate)) {
198 JingleMessage::NamedCandidate candidate;
199 if (!ParseGiceCandidate(candidate_tag, &candidate))
200 return false;
201 candidates->push_back(candidate);
202 }
203
204 return true;
205 }
206
207 XmlElement* FormatIceCredentials(
208 const JingleMessage::IceCredentials& credentials) {
209 XmlElement* result = 92 XmlElement* result =
210 new XmlElement(QName(kIceTransportNamespace, "credentials")); 93 new XmlElement(QName(kP2PTransportNamespace, "candidate"));
211 result->SetAttr(QName(kEmptyNamespace, "channel"), credentials.channel);
212 result->SetAttr(QName(kEmptyNamespace, "ufrag"), credentials.ufrag);
213 result->SetAttr(QName(kEmptyNamespace, "password"), credentials.password);
214 return result;
215 }
216
217 XmlElement* FormatIceCandidate(const JingleMessage::NamedCandidate& candidate) {
218 XmlElement* result =
219 new XmlElement(QName(kIceTransportNamespace, "candidate"));
220 result->SetAttr(QName(kEmptyNamespace, "name"), candidate.name);
221 result->SetAttr(QName(kEmptyNamespace, "foundation"),
222 candidate.candidate.foundation());
223 result->SetAttr(QName(kEmptyNamespace, "address"),
224 candidate.candidate.address().ipaddr().ToString());
225 result->SetAttr(QName(kEmptyNamespace, "port"),
226 base::IntToString(candidate.candidate.address().port()));
227 result->SetAttr(QName(kEmptyNamespace, "type"), candidate.candidate.type());
228 result->SetAttr(QName(kEmptyNamespace, "protocol"),
229 candidate.candidate.protocol());
230 result->SetAttr(QName(kEmptyNamespace, "priority"),
231 base::DoubleToString(candidate.candidate.priority()));
232 result->SetAttr(QName(kEmptyNamespace, "generation"),
233 base::IntToString(candidate.candidate.generation()));
234 return result;
235 }
236
237 XmlElement* FormatGiceCandidate(
238 const JingleMessage::NamedCandidate& candidate) {
239 XmlElement* result =
240 new XmlElement(QName(kGiceTransportNamespace, "candidate"));
241 result->SetAttr(QName(kEmptyNamespace, "name"), candidate.name); 94 result->SetAttr(QName(kEmptyNamespace, "name"), candidate.name);
242 result->SetAttr(QName(kEmptyNamespace, "address"), 95 result->SetAttr(QName(kEmptyNamespace, "address"),
243 candidate.candidate.address().ipaddr().ToString()); 96 candidate.candidate.address().ipaddr().ToString());
244 result->SetAttr(QName(kEmptyNamespace, "port"), 97 result->SetAttr(QName(kEmptyNamespace, "port"),
245 base::IntToString(candidate.candidate.address().port())); 98 base::IntToString(candidate.candidate.address().port()));
246 result->SetAttr(QName(kEmptyNamespace, "type"), candidate.candidate.type()); 99 result->SetAttr(QName(kEmptyNamespace, "type"), candidate.candidate.type());
247 result->SetAttr(QName(kEmptyNamespace, "protocol"), 100 result->SetAttr(QName(kEmptyNamespace, "protocol"),
248 candidate.candidate.protocol()); 101 candidate.candidate.protocol());
249 result->SetAttr(QName(kEmptyNamespace, "username"), 102 result->SetAttr(QName(kEmptyNamespace, "username"),
250 candidate.candidate.username()); 103 candidate.candidate.username());
251 result->SetAttr(QName(kEmptyNamespace, "password"), 104 result->SetAttr(QName(kEmptyNamespace, "password"),
252 candidate.candidate.password()); 105 candidate.candidate.password());
253 result->SetAttr(QName(kEmptyNamespace, "preference"), 106 result->SetAttr(QName(kEmptyNamespace, "preference"),
254 base::DoubleToString(candidate.candidate.preference())); 107 base::DoubleToString(candidate.candidate.preference()));
255 result->SetAttr(QName(kEmptyNamespace, "generation"), 108 result->SetAttr(QName(kEmptyNamespace, "generation"),
256 base::IntToString(candidate.candidate.generation())); 109 base::IntToString(candidate.candidate.generation()));
257 return result; 110 return result;
258 } 111 }
259 112
260 } // namespace 113 } // namespace
261 114
115 JingleMessage::NamedCandidate::NamedCandidate() {
116 }
117
262 JingleMessage::NamedCandidate::NamedCandidate( 118 JingleMessage::NamedCandidate::NamedCandidate(
263 const std::string& name, 119 const std::string& name,
264 const cricket::Candidate& candidate) 120 const cricket::Candidate& candidate)
265 : name(name), 121 : name(name),
266 candidate(candidate) { 122 candidate(candidate) {
267 } 123 }
268 124
269 JingleMessage::IceCredentials::IceCredentials(std::string channel,
270 std::string ufrag,
271 std::string password)
272 : channel(channel), ufrag(ufrag), password(password) {
273 }
274
275 // static 125 // static
276 bool JingleMessage::IsJingleMessage(const buzz::XmlElement* stanza) { 126 bool JingleMessage::IsJingleMessage(const buzz::XmlElement* stanza) {
277 return stanza->Name() == QName(kJabberNamespace, "iq") && 127 return stanza->Name() == QName(kJabberNamespace, "iq") &&
278 stanza->Attr(QName(std::string(), "type")) == "set" && 128 stanza->Attr(QName(std::string(), "type")) == "set" &&
279 stanza->FirstNamed(QName(kJingleNamespace, "jingle")) != nullptr; 129 stanza->FirstNamed(QName(kJingleNamespace, "jingle")) != nullptr;
280 } 130 }
281 131
282 // static 132 // static
283 std::string JingleMessage::GetActionName(ActionType action) { 133 std::string JingleMessage::GetActionName(ActionType action) {
284 return ValueToName(kActionTypes, action); 134 return ValueToName(kActionTypes, action);
285 } 135 }
286 136
287 JingleMessage::JingleMessage() { 137 JingleMessage::JingleMessage()
138 : action(UNKNOWN_ACTION),
139 reason(UNKNOWN_REASON) {
288 } 140 }
289 141
290 JingleMessage::JingleMessage(const std::string& to, 142 JingleMessage::JingleMessage(
291 ActionType action, 143 const std::string& to_value,
292 const std::string& sid) 144 ActionType action_value,
293 : to(to), action(action), sid(sid) { 145 const std::string& sid_value)
146 : to(to_value),
147 action(action_value),
148 sid(sid_value),
149 reason(UNKNOWN_REASON) {
294 } 150 }
295 151
296 JingleMessage::~JingleMessage() { 152 JingleMessage::~JingleMessage() {
297 } 153 }
298 154
299 bool JingleMessage::ParseXml(const buzz::XmlElement* stanza, 155 bool JingleMessage::ParseXml(const buzz::XmlElement* stanza,
300 std::string* error) { 156 std::string* error) {
301 if (!IsJingleMessage(stanza)) { 157 if (!IsJingleMessage(stanza)) {
302 *error = "Not a jingle message"; 158 *error = "Not a jingle message";
303 return false; 159 return false;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 return false; 233 return false;
378 } 234 }
379 235
380 description = ContentDescription::ParseXml(description_tag); 236 description = ContentDescription::ParseXml(description_tag);
381 if (!description.get()) { 237 if (!description.get()) {
382 *error = "Failed to parse content description"; 238 *error = "Failed to parse content description";
383 return false; 239 return false;
384 } 240 }
385 } 241 }
386 242
387 const XmlElement* ice_transport_tag = content_tag->FirstNamed( 243 candidates.clear();
388 QName(kIceTransportNamespace, "transport")); 244 const XmlElement* transport_tag = content_tag->FirstNamed(
389 const XmlElement* gice_transport_tag = content_tag->FirstNamed( 245 QName(kP2PTransportNamespace, "transport"));
390 QName(kGiceTransportNamespace, "transport")); 246 if (transport_tag) {
391 if (ice_transport_tag && gice_transport_tag) { 247 QName qn_candidate(kP2PTransportNamespace, "candidate");
392 *error = "ICE and GICE transport information is found in the same message"; 248 for (const XmlElement* candidate_tag =
393 return false; 249 transport_tag->FirstNamed(qn_candidate);
394 } else if (ice_transport_tag) { 250 candidate_tag != nullptr;
395 standard_ice = true; 251 candidate_tag = candidate_tag->NextNamed(qn_candidate)) {
396 if (!ParseIceTransportInfo(ice_transport_tag, &ice_credentials, 252 NamedCandidate candidate;
397 &candidates)) { 253 if (!ParseCandidate(candidate_tag, &candidate)) {
398 *error = "Failed to parse transport info"; 254 *error = "Failed to parse candidates";
399 return false; 255 return false;
400 } 256 }
401 } else if (gice_transport_tag) { 257 candidates.push_back(candidate);
402 standard_ice = false;
403 ice_credentials.clear();
404 if (!ParseGiceTransportInfo(gice_transport_tag, &candidates)) {
405 *error = "Failed to parse transport info";
406 return false;
407 } 258 }
408 } 259 }
409 260
410 return true; 261 return true;
411 } 262 }
412 263
413 scoped_ptr<buzz::XmlElement> JingleMessage::ToXml() const { 264 scoped_ptr<buzz::XmlElement> JingleMessage::ToXml() const {
414 scoped_ptr<XmlElement> root( 265 scoped_ptr<XmlElement> root(
415 new XmlElement(QName("jabber:client", "iq"), true)); 266 new XmlElement(QName("jabber:client", "iq"), true));
416 267
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 new XmlElement(QName(kJingleNamespace, "content")); 306 new XmlElement(QName(kJingleNamespace, "content"));
456 jingle_tag->AddElement(content_tag); 307 jingle_tag->AddElement(content_tag);
457 308
458 content_tag->AddAttr(QName(kEmptyNamespace, "name"), 309 content_tag->AddAttr(QName(kEmptyNamespace, "name"),
459 ContentDescription::kChromotingContentName); 310 ContentDescription::kChromotingContentName);
460 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator"); 311 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator");
461 312
462 if (description.get()) 313 if (description.get())
463 content_tag->AddElement(description->ToXml()); 314 content_tag->AddElement(description->ToXml());
464 315
465 if (standard_ice) { 316 XmlElement* transport_tag =
466 XmlElement* transport_tag = 317 new XmlElement(QName(kP2PTransportNamespace, "transport"), true);
467 new XmlElement(QName(kIceTransportNamespace, "transport"), true); 318 content_tag->AddElement(transport_tag);
468 content_tag->AddElement(transport_tag); 319 for (std::list<NamedCandidate>::const_iterator it = candidates.begin();
469 for (std::list<IceCredentials>::const_iterator it = 320 it != candidates.end(); ++it) {
470 ice_credentials.begin(); 321 transport_tag->AddElement(FormatCandidate(*it));
471 it != ice_credentials.end(); ++it) {
472 transport_tag->AddElement(FormatIceCredentials(*it));
473 }
474 for (std::list<NamedCandidate>::const_iterator it = candidates.begin();
475 it != candidates.end(); ++it) {
476 transport_tag->AddElement(FormatIceCandidate(*it));
477 }
478 } else {
479 XmlElement* transport_tag =
480 new XmlElement(QName(kGiceTransportNamespace, "transport"), true);
481 content_tag->AddElement(transport_tag);
482 for (std::list<NamedCandidate>::const_iterator it = candidates.begin();
483 it != candidates.end(); ++it) {
484 transport_tag->AddElement(FormatGiceCandidate(*it));
485 }
486 } 322 }
487 } 323 }
488 324
489 return root.Pass(); 325 return root.Pass();
490 } 326 }
491 327
492 JingleMessageReply::JingleMessageReply() 328 JingleMessageReply::JingleMessageReply()
493 : type(REPLY_RESULT), 329 : type(REPLY_RESULT),
494 error_type(NONE) { 330 error_type(NONE) {
495 } 331 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en"); 421 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en");
586 text_elem->SetBodyText(error_text); 422 text_elem->SetBodyText(error_text);
587 error->AddElement(text_elem); 423 error->AddElement(text_elem);
588 } 424 }
589 425
590 return iq.Pass(); 426 return iq.Pass();
591 } 427 }
592 428
593 } // namespace protocol 429 } // namespace protocol
594 } // namespace remoting 430 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/jingle_messages.h ('k') | remoting/protocol/jingle_messages_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698