Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 { JingleMessage::SESSION_INITIATE, "session-initiate" }, | 42 { JingleMessage::SESSION_INITIATE, "session-initiate" }, |
| 43 { JingleMessage::SESSION_ACCEPT, "session-accept" }, | 43 { JingleMessage::SESSION_ACCEPT, "session-accept" }, |
| 44 { JingleMessage::SESSION_TERMINATE, "session-terminate" }, | 44 { JingleMessage::SESSION_TERMINATE, "session-terminate" }, |
| 45 { JingleMessage::SESSION_INFO, "session-info" }, | 45 { JingleMessage::SESSION_INFO, "session-info" }, |
| 46 { JingleMessage::TRANSPORT_INFO, "transport-info" }, | 46 { JingleMessage::TRANSPORT_INFO, "transport-info" }, |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 const NameMapElement<JingleMessage::Reason> kReasons[] = { | 49 const NameMapElement<JingleMessage::Reason> kReasons[] = { |
| 50 { JingleMessage::SUCCESS, "success" }, | 50 { JingleMessage::SUCCESS, "success" }, |
| 51 { JingleMessage::DECLINE, "decline" }, | 51 { JingleMessage::DECLINE, "decline" }, |
| 52 { JingleMessage::SECURITY_ERROR, "security-error" }, | |
| 53 { JingleMessage::CANCEL, "cancel" }, | 52 { JingleMessage::CANCEL, "cancel" }, |
| 54 { JingleMessage::EXPIRED, "expired" }, | 53 { JingleMessage::EXPIRED, "expired" }, |
| 55 { JingleMessage::GENERAL_ERROR, "general-error" }, | 54 { JingleMessage::GENERAL_ERROR, "general-error" }, |
| 56 { JingleMessage::FAILED_APPLICATION, "failed-application" }, | 55 { JingleMessage::FAILED_APPLICATION, "failed-application" }, |
| 57 { JingleMessage::INCOMPATIBLE_PARAMETERS, "incompatible-parameters" }, | 56 { JingleMessage::INCOMPATIBLE_PARAMETERS, "incompatible-parameters" }, |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 bool ParseIceCredentials(const buzz::XmlElement* element, | 59 bool ParseIceCredentials(const buzz::XmlElement* element, |
| 61 IceTransportInfo::IceCredentials* credentials) { | 60 IceTransportInfo::IceCredentials* credentials) { |
| 62 DCHECK(element->Name() == QName(kIceTransportNamespace, "credentials")); | 61 DCHECK(element->Name() == QName(kIceTransportNamespace, "credentials")); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 | 335 |
| 337 const XmlElement* reason_tag = | 336 const XmlElement* reason_tag = |
| 338 jingle_tag->FirstNamed(QName(kJingleNamespace, "reason")); | 337 jingle_tag->FirstNamed(QName(kJingleNamespace, "reason")); |
| 339 if (reason_tag && reason_tag->FirstElement()) { | 338 if (reason_tag && reason_tag->FirstElement()) { |
| 340 if (!NameToValue(kReasons, reason_tag->FirstElement()->Name().LocalPart(), | 339 if (!NameToValue(kReasons, reason_tag->FirstElement()->Name().LocalPart(), |
| 341 &reason)) { | 340 &reason)) { |
| 342 reason = UNKNOWN_REASON; | 341 reason = UNKNOWN_REASON; |
| 343 } | 342 } |
| 344 } | 343 } |
| 345 | 344 |
| 345 const XmlElement* error_code_tag = | |
| 346 jingle_tag->FirstNamed(QName(kChromotingXmlNamespace, "error-code")); | |
| 347 if (error_code_tag && error_code_tag->FirstElement()) { | |
| 348 if (!NameToValue(kErrorCodes, | |
| 349 error_code_tag->FirstElement()->Name().LocalPart(), | |
| 350 &error_code)) { | |
| 351 error_code = UNKNOWN_ERROR; | |
|
Sergey Ulanov
2016/06/02 09:26:03
log a warning that the error code wasn't recognize
Hzj_jie
2016/06/02 22:00:18
Done.
| |
| 352 } | |
| 353 } | |
| 354 | |
| 346 if (action == SESSION_TERMINATE) | 355 if (action == SESSION_TERMINATE) |
| 347 return true; | 356 return true; |
| 348 | 357 |
| 349 const XmlElement* content_tag = | 358 const XmlElement* content_tag = |
| 350 jingle_tag->FirstNamed(QName(kJingleNamespace, "content")); | 359 jingle_tag->FirstNamed(QName(kJingleNamespace, "content")); |
| 351 if (!content_tag) { | 360 if (!content_tag) { |
| 352 *error = "content tag is missing"; | 361 *error = "content tag is missing"; |
| 353 return false; | 362 return false; |
| 354 } | 363 } |
| 355 | 364 |
| 356 std::string content_name = content_tag->Attr(QName(kEmptyNamespace, "name")); | 365 std::string content_name = content_tag->Attr(QName(kEmptyNamespace, "name")); |
| 357 if (content_name != ContentDescription::kChromotingContentName) { | 366 if (content_name != ContentDescription::kChromotingContentName) { |
| 358 *error = "Unexpected content name: " + content_name; | 367 *error = "Unexpected content name: " + content_name; |
| 359 return false; | 368 return false; |
| 360 } | 369 } |
| 361 | 370 |
| 362 const XmlElement* webrtc_transport_tag = content_tag->FirstNamed( | 371 const XmlElement* webrtc_transport_tag = content_tag->FirstNamed( |
| 363 QName("google:remoting:webrtc", "transport")); | 372 QName(kWebrtcTransportNamespace, "transport")); |
| 364 if (webrtc_transport_tag) { | 373 if (webrtc_transport_tag) { |
| 365 transport_info.reset(new buzz::XmlElement(*webrtc_transport_tag)); | 374 transport_info.reset(new buzz::XmlElement(*webrtc_transport_tag)); |
| 366 } | 375 } |
| 367 | 376 |
| 368 description.reset(nullptr); | 377 description.reset(nullptr); |
| 369 if (action == SESSION_INITIATE || action == SESSION_ACCEPT) { | 378 if (action == SESSION_INITIATE || action == SESSION_ACCEPT) { |
| 370 const XmlElement* description_tag = content_tag->FirstNamed( | 379 const XmlElement* description_tag = content_tag->FirstNamed( |
| 371 QName(kChromotingXmlNamespace, "description")); | 380 QName(kChromotingXmlNamespace, "description")); |
| 372 if (!description_tag) { | 381 if (!description_tag) { |
| 373 *error = "Missing chromoting content description"; | 382 *error = "Missing chromoting content description"; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 jingle_tag->AddElement(new XmlElement(*info.get())); | 426 jingle_tag->AddElement(new XmlElement(*info.get())); |
| 418 return root; | 427 return root; |
| 419 } | 428 } |
| 420 | 429 |
| 421 if (action == SESSION_INITIATE) | 430 if (action == SESSION_INITIATE) |
| 422 jingle_tag->AddAttr(QName(kEmptyNamespace, "initiator"), initiator); | 431 jingle_tag->AddAttr(QName(kEmptyNamespace, "initiator"), initiator); |
| 423 | 432 |
| 424 if (reason != UNKNOWN_REASON) { | 433 if (reason != UNKNOWN_REASON) { |
| 425 XmlElement* reason_tag = new XmlElement(QName(kJingleNamespace, "reason")); | 434 XmlElement* reason_tag = new XmlElement(QName(kJingleNamespace, "reason")); |
| 426 jingle_tag->AddElement(reason_tag); | 435 jingle_tag->AddElement(reason_tag); |
| 427 const char* reason_string = | 436 const char* reason_string = ValueToName(kReasons, reason); |
| 428 ValueToName(kReasons, reason); | |
| 429 if (!reason_string) | 437 if (!reason_string) |
| 430 LOG(FATAL) << "Invalid reason: " << reason; | 438 LOG(FATAL) << "Invalid reason: " << reason; |
| 431 reason_tag->AddElement(new XmlElement( | 439 reason_tag->AddElement(new XmlElement( |
| 432 QName(kJingleNamespace, reason_string))); | 440 QName(kJingleNamespace, reason_string))); |
| 441 | |
| 442 if (error_code != UNKNOWN_ERROR) { | |
| 443 XmlElement* error_code_tag = | |
| 444 new XmlElement(QName(kChromotingXmlNamespace, "error-code")); | |
| 445 jingle_tag->AddElement(error_code_tag); | |
| 446 const char* error_code_string = ValueToName(kErrorCodes, error_code); | |
| 447 if (!error_code_string) { | |
|
Sergey Ulanov
2016/06/02 09:26:04
replace with DCHECK(error_code_string)
Hzj_jie
2016/06/02 22:00:18
Done.
| |
| 448 LOG(FATAL) << "Invalid error code: " << static_cast<int>(error_code); | |
| 449 } | |
| 450 error_code_tag->AddElement(new XmlElement( | |
|
Sergey Ulanov
2016/06/02 09:26:03
I don't think we want to add the error as element.
Hzj_jie
2016/06/02 22:00:18
I used to implement as a text, but I found it's no
Sergey Ulanov
2016/06/03 08:43:22
I don't see how that can be a problem. When we gen
Hzj_jie
2016/06/03 21:46:33
Done.
| |
| 451 QName(kChromotingXmlNamespace, error_code_string))); | |
| 452 } | |
| 433 } | 453 } |
| 434 | 454 |
| 435 if (action != SESSION_TERMINATE) { | 455 if (action != SESSION_TERMINATE) { |
| 436 XmlElement* content_tag = | 456 XmlElement* content_tag = |
| 437 new XmlElement(QName(kJingleNamespace, "content")); | 457 new XmlElement(QName(kJingleNamespace, "content")); |
| 438 jingle_tag->AddElement(content_tag); | 458 jingle_tag->AddElement(content_tag); |
| 439 | 459 |
| 440 content_tag->AddAttr(QName(kEmptyNamespace, "name"), | 460 content_tag->AddAttr(QName(kEmptyNamespace, "name"), |
| 441 ContentDescription::kChromotingContentName); | 461 ContentDescription::kChromotingContentName); |
| 442 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator"); | 462 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator"); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 result->AddElement(FormatIceCredentials(credentials)); | 621 result->AddElement(FormatIceCredentials(credentials)); |
| 602 } | 622 } |
| 603 for (const NamedCandidate& candidate : candidates) { | 623 for (const NamedCandidate& candidate : candidates) { |
| 604 result->AddElement(FormatIceCandidate(candidate)); | 624 result->AddElement(FormatIceCandidate(candidate)); |
| 605 } | 625 } |
| 606 return result; | 626 return result; |
| 607 } | 627 } |
| 608 | 628 |
| 609 } // namespace protocol | 629 } // namespace protocol |
| 610 } // namespace remoting | 630 } // namespace remoting |
| OLD | NEW |