| 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->BodyText().empty()) { |
| 348 if (!ParseErrorCode(error_code_tag->BodyText(), &error_code)) { |
| 349 LOG(WARNING) << "Unknown error-code received " |
| 350 << error_code_tag->BodyText(); |
| 351 error_code = UNKNOWN_ERROR; |
| 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 = | |
| 428 ValueToName(kReasons, reason); | |
| 429 if (!reason_string) | |
| 430 LOG(FATAL) << "Invalid reason: " << reason; | |
| 431 reason_tag->AddElement(new XmlElement( | 436 reason_tag->AddElement(new XmlElement( |
| 432 QName(kJingleNamespace, reason_string))); | 437 QName(kJingleNamespace, ValueToName(kReasons, reason)))); |
| 438 |
| 439 if (error_code != UNKNOWN_ERROR) { |
| 440 XmlElement* error_code_tag = |
| 441 new XmlElement(QName(kChromotingXmlNamespace, "error-code")); |
| 442 jingle_tag->AddElement(error_code_tag); |
| 443 error_code_tag->SetBodyText(ErrorCodeToString(error_code)); |
| 444 } |
| 433 } | 445 } |
| 434 | 446 |
| 435 if (action != SESSION_TERMINATE) { | 447 if (action != SESSION_TERMINATE) { |
| 436 XmlElement* content_tag = | 448 XmlElement* content_tag = |
| 437 new XmlElement(QName(kJingleNamespace, "content")); | 449 new XmlElement(QName(kJingleNamespace, "content")); |
| 438 jingle_tag->AddElement(content_tag); | 450 jingle_tag->AddElement(content_tag); |
| 439 | 451 |
| 440 content_tag->AddAttr(QName(kEmptyNamespace, "name"), | 452 content_tag->AddAttr(QName(kEmptyNamespace, "name"), |
| 441 ContentDescription::kChromotingContentName); | 453 ContentDescription::kChromotingContentName); |
| 442 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator"); | 454 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)); | 613 result->AddElement(FormatIceCredentials(credentials)); |
| 602 } | 614 } |
| 603 for (const NamedCandidate& candidate : candidates) { | 615 for (const NamedCandidate& candidate : candidates) { |
| 604 result->AddElement(FormatIceCandidate(candidate)); | 616 result->AddElement(FormatIceCandidate(candidate)); |
| 605 } | 617 } |
| 606 return result; | 618 return result; |
| 607 } | 619 } |
| 608 | 620 |
| 609 } // namespace protocol | 621 } // namespace protocol |
| 610 } // namespace remoting | 622 } // namespace remoting |
| OLD | NEW |