OLD | NEW |
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" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 const std::string& name, | 119 const std::string& name, |
120 const cricket::Candidate& candidate) | 120 const cricket::Candidate& candidate) |
121 : name(name), | 121 : name(name), |
122 candidate(candidate) { | 122 candidate(candidate) { |
123 } | 123 } |
124 | 124 |
125 // static | 125 // static |
126 bool JingleMessage::IsJingleMessage(const buzz::XmlElement* stanza) { | 126 bool JingleMessage::IsJingleMessage(const buzz::XmlElement* stanza) { |
127 return stanza->Name() == QName(kJabberNamespace, "iq") && | 127 return stanza->Name() == QName(kJabberNamespace, "iq") && |
128 stanza->Attr(QName(std::string(), "type")) == "set" && | 128 stanza->Attr(QName(std::string(), "type")) == "set" && |
129 stanza->FirstNamed(QName(kJingleNamespace, "jingle")) != NULL; | 129 stanza->FirstNamed(QName(kJingleNamespace, "jingle")) != nullptr; |
130 } | 130 } |
131 | 131 |
132 // static | 132 // static |
133 std::string JingleMessage::GetActionName(ActionType action) { | 133 std::string JingleMessage::GetActionName(ActionType action) { |
134 return ValueToName(kActionTypes, action); | 134 return ValueToName(kActionTypes, action); |
135 } | 135 } |
136 | 136 |
137 JingleMessage::JingleMessage() | 137 JingleMessage::JingleMessage() |
138 : action(UNKNOWN_ACTION), | 138 : action(UNKNOWN_ACTION), |
139 reason(UNKNOWN_REASON) { | 139 reason(UNKNOWN_REASON) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 187 } |
188 | 188 |
189 if (action == SESSION_INFO) { | 189 if (action == SESSION_INFO) { |
190 // session-info messages may contain arbitrary information not | 190 // session-info messages may contain arbitrary information not |
191 // defined by the Jingle protocol. We don't need to parse it. | 191 // defined by the Jingle protocol. We don't need to parse it. |
192 const XmlElement* child = jingle_tag->FirstElement(); | 192 const XmlElement* child = jingle_tag->FirstElement(); |
193 if (child) { | 193 if (child) { |
194 // session-info is allowed to be empty. | 194 // session-info is allowed to be empty. |
195 info.reset(new XmlElement(*child)); | 195 info.reset(new XmlElement(*child)); |
196 } else { | 196 } else { |
197 info.reset(NULL); | 197 info.reset(nullptr); |
198 } | 198 } |
199 return true; | 199 return true; |
200 } | 200 } |
201 | 201 |
202 const XmlElement* reason_tag = | 202 const XmlElement* reason_tag = |
203 jingle_tag->FirstNamed(QName(kJingleNamespace, "reason")); | 203 jingle_tag->FirstNamed(QName(kJingleNamespace, "reason")); |
204 if (reason_tag && reason_tag->FirstElement()) { | 204 if (reason_tag && reason_tag->FirstElement()) { |
205 if (!NameToValue(kReasons, reason_tag->FirstElement()->Name().LocalPart(), | 205 if (!NameToValue(kReasons, reason_tag->FirstElement()->Name().LocalPart(), |
206 &reason)) { | 206 &reason)) { |
207 reason = UNKNOWN_REASON; | 207 reason = UNKNOWN_REASON; |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 if (action == SESSION_TERMINATE) | 211 if (action == SESSION_TERMINATE) |
212 return true; | 212 return true; |
213 | 213 |
214 const XmlElement* content_tag = | 214 const XmlElement* content_tag = |
215 jingle_tag->FirstNamed(QName(kJingleNamespace, "content")); | 215 jingle_tag->FirstNamed(QName(kJingleNamespace, "content")); |
216 if (!content_tag) { | 216 if (!content_tag) { |
217 *error = "content tag is missing"; | 217 *error = "content tag is missing"; |
218 return false; | 218 return false; |
219 } | 219 } |
220 | 220 |
221 std::string content_name = content_tag->Attr(QName(kEmptyNamespace, "name")); | 221 std::string content_name = content_tag->Attr(QName(kEmptyNamespace, "name")); |
222 if (content_name != ContentDescription::kChromotingContentName) { | 222 if (content_name != ContentDescription::kChromotingContentName) { |
223 *error = "Unexpected content name: " + content_name; | 223 *error = "Unexpected content name: " + content_name; |
224 return false; | 224 return false; |
225 } | 225 } |
226 | 226 |
227 description.reset(NULL); | 227 description.reset(nullptr); |
228 if (action == SESSION_INITIATE || action == SESSION_ACCEPT) { | 228 if (action == SESSION_INITIATE || action == SESSION_ACCEPT) { |
229 const XmlElement* description_tag = content_tag->FirstNamed( | 229 const XmlElement* description_tag = content_tag->FirstNamed( |
230 QName(kChromotingXmlNamespace, "description")); | 230 QName(kChromotingXmlNamespace, "description")); |
231 if (!description_tag) { | 231 if (!description_tag) { |
232 *error = "Missing chromoting content description"; | 232 *error = "Missing chromoting content description"; |
233 return false; | 233 return false; |
234 } | 234 } |
235 | 235 |
236 description = ContentDescription::ParseXml(description_tag); | 236 description = ContentDescription::ParseXml(description_tag); |
237 if (!description.get()) { | 237 if (!description.get()) { |
238 *error = "Failed to parse content description"; | 238 *error = "Failed to parse content description"; |
239 return false; | 239 return false; |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 candidates.clear(); | 243 candidates.clear(); |
244 const XmlElement* transport_tag = content_tag->FirstNamed( | 244 const XmlElement* transport_tag = content_tag->FirstNamed( |
245 QName(kP2PTransportNamespace, "transport")); | 245 QName(kP2PTransportNamespace, "transport")); |
246 if (transport_tag) { | 246 if (transport_tag) { |
247 QName qn_candidate(kP2PTransportNamespace, "candidate"); | 247 QName qn_candidate(kP2PTransportNamespace, "candidate"); |
248 for (const XmlElement* candidate_tag = | 248 for (const XmlElement* candidate_tag = |
249 transport_tag->FirstNamed(qn_candidate); | 249 transport_tag->FirstNamed(qn_candidate); |
250 candidate_tag != NULL; | 250 candidate_tag != nullptr; |
251 candidate_tag = candidate_tag->NextNamed(qn_candidate)) { | 251 candidate_tag = candidate_tag->NextNamed(qn_candidate)) { |
252 NamedCandidate candidate; | 252 NamedCandidate candidate; |
253 if (!ParseCandidate(candidate_tag, &candidate)) { | 253 if (!ParseCandidate(candidate_tag, &candidate)) { |
254 *error = "Failed to parse candidates"; | 254 *error = "Failed to parse candidates"; |
255 return false; | 255 return false; |
256 } | 256 } |
257 candidates.push_back(candidate); | 257 candidates.push_back(candidate); |
258 } | 258 } |
259 } | 259 } |
260 | 260 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 if (type == REPLY_RESULT) { | 356 if (type == REPLY_RESULT) { |
357 iq->SetAttr(QName(kEmptyNamespace, "type"), "result"); | 357 iq->SetAttr(QName(kEmptyNamespace, "type"), "result"); |
358 return iq.Pass(); | 358 return iq.Pass(); |
359 } | 359 } |
360 | 360 |
361 DCHECK_EQ(type, REPLY_ERROR); | 361 DCHECK_EQ(type, REPLY_ERROR); |
362 | 362 |
363 iq->SetAttr(QName(kEmptyNamespace, "type"), "error"); | 363 iq->SetAttr(QName(kEmptyNamespace, "type"), "error"); |
364 | 364 |
365 for (const buzz::XmlElement* child = request_stanza->FirstElement(); | 365 for (const buzz::XmlElement* child = request_stanza->FirstElement(); |
366 child != NULL; child = child->NextElement()) { | 366 child != nullptr; child = child->NextElement()) { |
367 iq->AddElement(new buzz::XmlElement(*child)); | 367 iq->AddElement(new buzz::XmlElement(*child)); |
368 } | 368 } |
369 | 369 |
370 buzz::XmlElement* error = | 370 buzz::XmlElement* error = |
371 new buzz::XmlElement(QName(kJabberNamespace, "error")); | 371 new buzz::XmlElement(QName(kJabberNamespace, "error")); |
372 iq->AddElement(error); | 372 iq->AddElement(error); |
373 | 373 |
374 std::string type; | 374 std::string type; |
375 std::string error_text; | 375 std::string error_text; |
376 QName name; | 376 QName name; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en"); | 421 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en"); |
422 text_elem->SetBodyText(error_text); | 422 text_elem->SetBodyText(error_text); |
423 error->AddElement(text_elem); | 423 error->AddElement(text_elem); |
424 } | 424 } |
425 | 425 |
426 return iq.Pass(); | 426 return iq.Pass(); |
427 } | 427 } |
428 | 428 |
429 } // namespace protocol | 429 } // namespace protocol |
430 } // namespace remoting | 430 } // namespace remoting |
OLD | NEW |