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

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

Issue 10209008: Roll libjingle 132:133 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/jingle_messages.h ('k') | remoting/protocol/jingle_session.h » ('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/string_number_conversions.h" 8 #include "base/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 "third_party/libjingle/source/talk/p2p/base/candidate.h"
12 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 11 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
13 12
14 using buzz::QName; 13 using buzz::QName;
15 using buzz::XmlElement; 14 using buzz::XmlElement;
16 15
17 namespace remoting { 16 namespace remoting {
18 namespace protocol { 17 namespace protocol {
19 18
20 const char kJabberNamespace[] = "jabber:client"; 19 const char kJabberNamespace[] = "jabber:client";
21 const char kJingleNamespace[] = "urn:xmpp:jingle:1"; 20 const char kJingleNamespace[] = "urn:xmpp:jingle:1";
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 64
66 const NameMapElement<JingleMessage::Reason> kReasons[] = { 65 const NameMapElement<JingleMessage::Reason> kReasons[] = {
67 { JingleMessage::SUCCESS, "success" }, 66 { JingleMessage::SUCCESS, "success" },
68 { JingleMessage::DECLINE, "decline" }, 67 { JingleMessage::DECLINE, "decline" },
69 { JingleMessage::CANCEL, "cancel" }, 68 { JingleMessage::CANCEL, "cancel" },
70 { JingleMessage::GENERAL_ERROR, "general-error" }, 69 { JingleMessage::GENERAL_ERROR, "general-error" },
71 { JingleMessage::INCOMPATIBLE_PARAMETERS, "incompatible-parameters" }, 70 { JingleMessage::INCOMPATIBLE_PARAMETERS, "incompatible-parameters" },
72 }; 71 };
73 72
74 bool ParseCandidate(const buzz::XmlElement* element, 73 bool ParseCandidate(const buzz::XmlElement* element,
75 cricket::Candidate* candidate) { 74 JingleMessage::NamedCandidate* candidate) {
76 DCHECK(element->Name() == QName(kP2PTransportNamespace, "candidate")); 75 DCHECK(element->Name() == QName(kP2PTransportNamespace, "candidate"));
77 76
78 const std::string& name = element->Attr(QName(kEmptyNamespace, "name")); 77 const std::string& name = element->Attr(QName(kEmptyNamespace, "name"));
79 const std::string& address = element->Attr(QName(kEmptyNamespace, "address")); 78 const std::string& address = element->Attr(QName(kEmptyNamespace, "address"));
80 const std::string& port_str = element->Attr(QName(kEmptyNamespace, "port")); 79 const std::string& port_str = element->Attr(QName(kEmptyNamespace, "port"));
81 const std::string& type = element->Attr(QName(kEmptyNamespace, "type")); 80 const std::string& type = element->Attr(QName(kEmptyNamespace, "type"));
82 const std::string& protocol = 81 const std::string& protocol =
83 element->Attr(QName(kEmptyNamespace, "protocol")); 82 element->Attr(QName(kEmptyNamespace, "protocol"));
84 const std::string& username = 83 const std::string& username =
85 element->Attr(QName(kEmptyNamespace, "username")); 84 element->Attr(QName(kEmptyNamespace, "username"));
86 const std::string& password = 85 const std::string& password =
87 element->Attr(QName(kEmptyNamespace, "password")); 86 element->Attr(QName(kEmptyNamespace, "password"));
88 const std::string& preference_str = 87 const std::string& preference_str =
89 element->Attr(QName(kEmptyNamespace, "preference")); 88 element->Attr(QName(kEmptyNamespace, "preference"));
90 const std::string& generation_str = 89 const std::string& generation_str =
91 element->Attr(QName(kEmptyNamespace, "generation")); 90 element->Attr(QName(kEmptyNamespace, "generation"));
92 91
93 int port; 92 int port;
94 double preference; 93 double preference;
95 int generation; 94 int generation;
96 if (name.empty() || address.empty() || !base::StringToInt(port_str, &port) || 95 if (name.empty() || address.empty() || !base::StringToInt(port_str, &port) ||
97 port < kPortMin || port > kPortMax || type.empty() || protocol.empty() || 96 port < kPortMin || port > kPortMax || type.empty() || protocol.empty() ||
98 username.empty() || password.empty() || 97 username.empty() || password.empty() ||
99 !base::StringToDouble(preference_str, &preference) || 98 !base::StringToDouble(preference_str, &preference) ||
100 !base::StringToInt(generation_str, &generation)) { 99 !base::StringToInt(generation_str, &generation)) {
101 return false; 100 return false;
102 } 101 }
103 102
104 candidate->set_name(name); 103 candidate->name = name;
105 candidate->set_address(talk_base::SocketAddress(address, port)); 104
106 candidate->set_type(type); 105 candidate->candidate.set_address(talk_base::SocketAddress(address, port));
107 candidate->set_protocol(protocol); 106 candidate->candidate.set_type(type);
108 candidate->set_username(username); 107 candidate->candidate.set_protocol(protocol);
109 candidate->set_password(password); 108 candidate->candidate.set_username(username);
110 candidate->set_preference(static_cast<float>(preference)); 109 candidate->candidate.set_password(password);
111 candidate->set_generation(generation); 110 candidate->candidate.set_preference(static_cast<float>(preference));
111 candidate->candidate.set_generation(generation);
112 112
113 return true; 113 return true;
114 } 114 }
115 115
116 XmlElement* FormatCandidate(const cricket::Candidate& candidate) { 116 XmlElement* FormatCandidate(const JingleMessage::NamedCandidate& candidate) {
117 XmlElement* result = 117 XmlElement* result =
118 new XmlElement(QName(kP2PTransportNamespace, "candidate")); 118 new XmlElement(QName(kP2PTransportNamespace, "candidate"));
119 result->SetAttr(QName(kEmptyNamespace, "name"), candidate.name()); 119 result->SetAttr(QName(kEmptyNamespace, "name"), candidate.name);
120 result->SetAttr(QName(kEmptyNamespace, "address"), 120 result->SetAttr(QName(kEmptyNamespace, "address"),
121 candidate.address().IPAsString()); 121 candidate.candidate.address().IPAsString());
122 result->SetAttr(QName(kEmptyNamespace, "port"), 122 result->SetAttr(QName(kEmptyNamespace, "port"),
123 base::IntToString(candidate.address().port())); 123 base::IntToString(candidate.candidate.address().port()));
124 result->SetAttr(QName(kEmptyNamespace, "type"), candidate.type()); 124 result->SetAttr(QName(kEmptyNamespace, "type"), candidate.candidate.type());
125 result->SetAttr(QName(kEmptyNamespace, "protocol"), candidate.protocol()); 125 result->SetAttr(QName(kEmptyNamespace, "protocol"),
126 result->SetAttr(QName(kEmptyNamespace, "username"), candidate.username()); 126 candidate.candidate.protocol());
127 result->SetAttr(QName(kEmptyNamespace, "password"), candidate.password()); 127 result->SetAttr(QName(kEmptyNamespace, "username"),
128 candidate.candidate.username());
129 result->SetAttr(QName(kEmptyNamespace, "password"),
130 candidate.candidate.password());
128 result->SetAttr(QName(kEmptyNamespace, "preference"), 131 result->SetAttr(QName(kEmptyNamespace, "preference"),
129 base::DoubleToString(candidate.preference())); 132 base::DoubleToString(candidate.candidate.preference()));
130 result->SetAttr(QName(kEmptyNamespace, "generation"), 133 result->SetAttr(QName(kEmptyNamespace, "generation"),
131 base::IntToString(candidate.generation())); 134 base::IntToString(candidate.candidate.generation()));
132 return result; 135 return result;
133 } 136 }
134 137
135 } // namespace 138 } // namespace
136 139
140 JingleMessage::NamedCandidate::NamedCandidate() {
141 }
142
143 JingleMessage::NamedCandidate::NamedCandidate(
144 const std::string& name,
145 const cricket::Candidate& candidate)
146 : name(name),
147 candidate(candidate) {
148 }
149
137 // static 150 // static
138 bool JingleMessage::IsJingleMessage(const buzz::XmlElement* stanza) { 151 bool JingleMessage::IsJingleMessage(const buzz::XmlElement* stanza) {
139 return 152 return
140 stanza->Name() == QName(kJabberNamespace, "iq") && 153 stanza->Name() == QName(kJabberNamespace, "iq") &&
141 stanza->Attr(QName("", "type")) == "set" && 154 stanza->Attr(QName("", "type")) == "set" &&
142 stanza->FirstNamed(QName(kJingleNamespace, "jingle")) != NULL; 155 stanza->FirstNamed(QName(kJingleNamespace, "jingle")) != NULL;
143 } 156 }
144 157
145 // static 158 // static
146 std::string JingleMessage::GetActionName(ActionType action) { 159 std::string JingleMessage::GetActionName(ActionType action) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 268
256 candidates.clear(); 269 candidates.clear();
257 const XmlElement* transport_tag = content_tag->FirstNamed( 270 const XmlElement* transport_tag = content_tag->FirstNamed(
258 QName(kP2PTransportNamespace, "transport")); 271 QName(kP2PTransportNamespace, "transport"));
259 if (transport_tag) { 272 if (transport_tag) {
260 QName qn_candidate(kP2PTransportNamespace, "candidate"); 273 QName qn_candidate(kP2PTransportNamespace, "candidate");
261 for (const XmlElement* candidate_tag = 274 for (const XmlElement* candidate_tag =
262 transport_tag->FirstNamed(qn_candidate); 275 transport_tag->FirstNamed(qn_candidate);
263 candidate_tag != NULL; 276 candidate_tag != NULL;
264 candidate_tag = candidate_tag->NextNamed(qn_candidate)) { 277 candidate_tag = candidate_tag->NextNamed(qn_candidate)) {
265 cricket::Candidate candidate; 278 NamedCandidate candidate;
266 if (!ParseCandidate(candidate_tag, &candidate)) { 279 if (!ParseCandidate(candidate_tag, &candidate)) {
267 *error = "Failed to parse candidates"; 280 *error = "Failed to parse candidates";
268 return false; 281 return false;
269 } 282 }
270 candidates.push_back(candidate); 283 candidates.push_back(candidate);
271 } 284 }
272 } 285 }
273 286
274 return true; 287 return true;
275 } 288 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 content_tag->AddAttr(QName(kEmptyNamespace, "name"), 336 content_tag->AddAttr(QName(kEmptyNamespace, "name"),
324 ContentDescription::kChromotingContentName); 337 ContentDescription::kChromotingContentName);
325 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator"); 338 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator");
326 339
327 if (description.get()) 340 if (description.get())
328 content_tag->AddElement(description->ToXml()); 341 content_tag->AddElement(description->ToXml());
329 342
330 XmlElement* transport_tag = 343 XmlElement* transport_tag =
331 new XmlElement(QName(kP2PTransportNamespace, "transport"), true); 344 new XmlElement(QName(kP2PTransportNamespace, "transport"), true);
332 content_tag->AddElement(transport_tag); 345 content_tag->AddElement(transport_tag);
333 for (std::list<cricket::Candidate>::const_iterator it = candidates.begin(); 346 for (std::list<NamedCandidate>::const_iterator it = candidates.begin();
334 it != candidates.end(); ++it) { 347 it != candidates.end(); ++it) {
335 transport_tag->AddElement(FormatCandidate(*it)); 348 transport_tag->AddElement(FormatCandidate(*it));
336 } 349 }
337 } 350 }
338 351
339 return root.Pass(); 352 return root.Pass();
340 } 353 }
341 354
342 JingleMessageReply::JingleMessageReply() 355 JingleMessageReply::JingleMessageReply()
343 : type(REPLY_RESULT), 356 : type(REPLY_RESULT),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en"); 448 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en");
436 text_elem->SetBodyText(error_text); 449 text_elem->SetBodyText(error_text);
437 error->AddElement(text_elem); 450 error->AddElement(text_elem);
438 } 451 }
439 452
440 return iq.Pass(); 453 return iq.Pass();
441 } 454 }
442 455
443 } // namespace protocol 456 } // namespace protocol
444 } // namespace remoting 457 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/jingle_messages.h ('k') | remoting/protocol/jingle_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698