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

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

Issue 2026123002: [Chromoting] Use google:remoting namespace to export remoting specific error codes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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 { 20 namespace {
21 21
22 const char kJabberNamespace[] = "jabber:client"; 22 const char kJabberNamespace[] = "jabber:client";
23 const char kJingleNamespace[] = "urn:xmpp:jingle:1"; 23 const char kJingleNamespace[] = "urn:xmpp:jingle:1";
24 24
25 const char kRemotingNamespace[] = "google:remoting";
Sergey Ulanov 2016/06/01 08:52:47 We already have kChromotingXmlNamespace in remotin
Hzj_jie 2016/06/01 23:56:13 Done.
26
25 // Namespace for transport messages when using standard ICE. 27 // Namespace for transport messages when using standard ICE.
26 const char kIceTransportNamespace[] = "google:remoting:ice"; 28 const char kIceTransportNamespace[] = "google:remoting:ice";
27 29
28 const char kWebrtcTransportNamespace[] = "google:remoting:webrtc"; 30 const char kWebrtcTransportNamespace[] = "google:remoting:webrtc";
29 31
30 const char kEmptyNamespace[] = ""; 32 const char kEmptyNamespace[] = "";
31 const char kXmlNamespace[] = "http://www.w3.org/XML/1998/namespace"; 33 const char kXmlNamespace[] = "http://www.w3.org/XML/1998/namespace";
32 34
33 const int kPortMin = 1000; 35 const int kPortMin = 1000;
34 const int kPortMax = 65535; 36 const int kPortMax = 65535;
35 37
36 const NameMapElement<SignalingAddress::Channel> kChannelTypes[] = { 38 const NameMapElement<SignalingAddress::Channel> kChannelTypes[] = {
37 {SignalingAddress::Channel::LCS, "lcs"}, 39 {SignalingAddress::Channel::LCS, "lcs"},
38 {SignalingAddress::Channel::XMPP, "xmpp"}, 40 {SignalingAddress::Channel::XMPP, "xmpp"},
39 }; 41 };
40 42
41 const NameMapElement<JingleMessage::ActionType> kActionTypes[] = { 43 const NameMapElement<JingleMessage::ActionType> kActionTypes[] = {
42 { JingleMessage::SESSION_INITIATE, "session-initiate" }, 44 { JingleMessage::SESSION_INITIATE, "session-initiate" },
43 { JingleMessage::SESSION_ACCEPT, "session-accept" }, 45 { JingleMessage::SESSION_ACCEPT, "session-accept" },
44 { JingleMessage::SESSION_TERMINATE, "session-terminate" }, 46 { JingleMessage::SESSION_TERMINATE, "session-terminate" },
45 { JingleMessage::SESSION_INFO, "session-info" }, 47 { JingleMessage::SESSION_INFO, "session-info" },
46 { JingleMessage::TRANSPORT_INFO, "transport-info" }, 48 { JingleMessage::TRANSPORT_INFO, "transport-info" },
47 }; 49 };
48 50
49 const NameMapElement<JingleMessage::Reason> kReasons[] = { 51 const NameMapElement<JingleMessage::Reason> kReasons[] = {
50 { JingleMessage::SUCCESS, "success" }, 52 { JingleMessage::SUCCESS, "success" },
51 { JingleMessage::DECLINE, "decline" }, 53 { JingleMessage::DECLINE, "decline" },
52 { JingleMessage::SECURITY_ERROR, "security-error" },
53 { JingleMessage::CANCEL, "cancel" }, 54 { JingleMessage::CANCEL, "cancel" },
54 { JingleMessage::EXPIRED, "expired" }, 55 { JingleMessage::EXPIRED, "expired" },
55 { JingleMessage::GENERAL_ERROR, "general-error" }, 56 { JingleMessage::GENERAL_ERROR, "general-error" },
56 { JingleMessage::FAILED_APPLICATION, "failed-application" }, 57 { JingleMessage::FAILED_APPLICATION, "failed-application" },
57 { JingleMessage::INCOMPATIBLE_PARAMETERS, "incompatible-parameters" }, 58 { JingleMessage::INCOMPATIBLE_PARAMETERS, "incompatible-parameters" },
58 }; 59 };
59 60
61 const NameMapElement<JingleMessage::ErrorCode> kErrorCodes[] = {
Sergey Ulanov 2016/06/01 08:52:47 We already have ErrorCodeToString() in errors.cc.
Hzj_jie 2016/06/01 23:56:13 Done.
62 { JingleMessage::ErrorCode::SESSION_REJECTED, "session-rejected" },
63 { JingleMessage::ErrorCode::AUTHENTICATION_FAILED, "authentication-failed" },
64 { JingleMessage::ErrorCode::INVALID_ACCOUNT, "invalid-account" },
65 };
66
60 bool ParseIceCredentials(const buzz::XmlElement* element, 67 bool ParseIceCredentials(const buzz::XmlElement* element,
61 IceTransportInfo::IceCredentials* credentials) { 68 IceTransportInfo::IceCredentials* credentials) {
62 DCHECK(element->Name() == QName(kIceTransportNamespace, "credentials")); 69 DCHECK(element->Name() == QName(kIceTransportNamespace, "credentials"));
63 70
64 const std::string& channel = element->Attr(QName(kEmptyNamespace, "channel")); 71 const std::string& channel = element->Attr(QName(kEmptyNamespace, "channel"));
65 const std::string& ufrag = 72 const std::string& ufrag =
66 element->Attr(QName(kEmptyNamespace, "ufrag")); 73 element->Attr(QName(kEmptyNamespace, "ufrag"));
67 const std::string& password = 74 const std::string& password =
68 element->Attr(QName(kEmptyNamespace, "password")); 75 element->Attr(QName(kEmptyNamespace, "password"));
69 76
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 343
337 const XmlElement* reason_tag = 344 const XmlElement* reason_tag =
338 jingle_tag->FirstNamed(QName(kJingleNamespace, "reason")); 345 jingle_tag->FirstNamed(QName(kJingleNamespace, "reason"));
339 if (reason_tag && reason_tag->FirstElement()) { 346 if (reason_tag && reason_tag->FirstElement()) {
340 if (!NameToValue(kReasons, reason_tag->FirstElement()->Name().LocalPart(), 347 if (!NameToValue(kReasons, reason_tag->FirstElement()->Name().LocalPart(),
341 &reason)) { 348 &reason)) {
342 reason = UNKNOWN_REASON; 349 reason = UNKNOWN_REASON;
343 } 350 }
344 } 351 }
345 352
353 const XmlElement* error_code_tag =
354 jingle_tag->FirstNamed(QName(kRemotingNamespace, "error-code"));
355 if (error_code_tag && error_code_tag->FirstElement()) {
356 if (!NameToValue(kErrorCodes,
357 error_code_tag->FirstElement()->Name().LocalPart(),
358 &error_code)) {
359 error_code = ErrorCode::UNKNOWN;
360 }
361 }
362
346 if (action == SESSION_TERMINATE) 363 if (action == SESSION_TERMINATE)
347 return true; 364 return true;
348 365
349 const XmlElement* content_tag = 366 const XmlElement* content_tag =
350 jingle_tag->FirstNamed(QName(kJingleNamespace, "content")); 367 jingle_tag->FirstNamed(QName(kJingleNamespace, "content"));
351 if (!content_tag) { 368 if (!content_tag) {
352 *error = "content tag is missing"; 369 *error = "content tag is missing";
353 return false; 370 return false;
354 } 371 }
355 372
356 std::string content_name = content_tag->Attr(QName(kEmptyNamespace, "name")); 373 std::string content_name = content_tag->Attr(QName(kEmptyNamespace, "name"));
357 if (content_name != ContentDescription::kChromotingContentName) { 374 if (content_name != ContentDescription::kChromotingContentName) {
358 *error = "Unexpected content name: " + content_name; 375 *error = "Unexpected content name: " + content_name;
359 return false; 376 return false;
360 } 377 }
361 378
362 const XmlElement* webrtc_transport_tag = content_tag->FirstNamed( 379 const XmlElement* webrtc_transport_tag = content_tag->FirstNamed(
363 QName("google:remoting:webrtc", "transport")); 380 QName(kWebrtcTransportNamespace, "transport"));
364 if (webrtc_transport_tag) { 381 if (webrtc_transport_tag) {
365 transport_info.reset(new buzz::XmlElement(*webrtc_transport_tag)); 382 transport_info.reset(new buzz::XmlElement(*webrtc_transport_tag));
366 } 383 }
367 384
368 description.reset(nullptr); 385 description.reset(nullptr);
369 if (action == SESSION_INITIATE || action == SESSION_ACCEPT) { 386 if (action == SESSION_INITIATE || action == SESSION_ACCEPT) {
370 const XmlElement* description_tag = content_tag->FirstNamed( 387 const XmlElement* description_tag = content_tag->FirstNamed(
371 QName(kChromotingXmlNamespace, "description")); 388 QName(kChromotingXmlNamespace, "description"));
372 if (!description_tag) { 389 if (!description_tag) {
373 *error = "Missing chromoting content description"; 390 *error = "Missing chromoting content description";
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 jingle_tag->AddElement(new XmlElement(*info.get())); 434 jingle_tag->AddElement(new XmlElement(*info.get()));
418 return root; 435 return root;
419 } 436 }
420 437
421 if (action == SESSION_INITIATE) 438 if (action == SESSION_INITIATE)
422 jingle_tag->AddAttr(QName(kEmptyNamespace, "initiator"), initiator); 439 jingle_tag->AddAttr(QName(kEmptyNamespace, "initiator"), initiator);
423 440
424 if (reason != UNKNOWN_REASON) { 441 if (reason != UNKNOWN_REASON) {
425 XmlElement* reason_tag = new XmlElement(QName(kJingleNamespace, "reason")); 442 XmlElement* reason_tag = new XmlElement(QName(kJingleNamespace, "reason"));
426 jingle_tag->AddElement(reason_tag); 443 jingle_tag->AddElement(reason_tag);
427 const char* reason_string = 444 const char* reason_string = ValueToName(kReasons, reason);
428 ValueToName(kReasons, reason);
429 if (!reason_string) 445 if (!reason_string)
430 LOG(FATAL) << "Invalid reason: " << reason; 446 LOG(FATAL) << "Invalid reason: " << reason;
431 reason_tag->AddElement(new XmlElement( 447 reason_tag->AddElement(new XmlElement(
432 QName(kJingleNamespace, reason_string))); 448 QName(kJingleNamespace, reason_string)));
449
450 if (error_code != ErrorCode::UNKNOWN) {
451 XmlElement* error_code_tag =
452 new XmlElement(QName(kRemotingNamespace, "error-code"));
453 jingle_tag->AddElement(error_code_tag);
454 const char* error_code_string = ValueToName(kErrorCodes, error_code);
455 if (!error_code_string) {
456 LOG(FATAL) << "Invalid error code: " << static_cast<int>(error_code);
457 }
458 error_code_tag->AddElement(new XmlElement(
459 QName(kRemotingNamespace, error_code_string)));
460 }
433 } 461 }
434 462
435 if (action != SESSION_TERMINATE) { 463 if (action != SESSION_TERMINATE) {
436 XmlElement* content_tag = 464 XmlElement* content_tag =
437 new XmlElement(QName(kJingleNamespace, "content")); 465 new XmlElement(QName(kJingleNamespace, "content"));
438 jingle_tag->AddElement(content_tag); 466 jingle_tag->AddElement(content_tag);
439 467
440 content_tag->AddAttr(QName(kEmptyNamespace, "name"), 468 content_tag->AddAttr(QName(kEmptyNamespace, "name"),
441 ContentDescription::kChromotingContentName); 469 ContentDescription::kChromotingContentName);
442 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator"); 470 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator");
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 result->AddElement(FormatIceCredentials(credentials)); 629 result->AddElement(FormatIceCredentials(credentials));
602 } 630 }
603 for (const NamedCandidate& candidate : candidates) { 631 for (const NamedCandidate& candidate : candidates) {
604 result->AddElement(FormatIceCandidate(candidate)); 632 result->AddElement(FormatIceCandidate(candidate));
605 } 633 }
606 return result; 634 return result;
607 } 635 }
608 636
609 } // namespace protocol 637 } // namespace protocol
610 } // namespace remoting 638 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698