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

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: Resolve review comments 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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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 = ErrorCodeToString(error_code);
447 DCHECK(error_code_string);
Sergey Ulanov 2016/06/07 16:22:23 nit: don't need this. There is already NOTREACHED(
Hzj_jie 2016/06/07 19:29:57 I copied the similar logic from reason node above.
Sergey Ulanov 2016/06/07 20:17:21 I think that check for reason_string was added bef
Hzj_jie 2016/06/07 20:20:43 Yes, both have been removed in the latest iteratio
448 error_code_tag->SetBodyText(error_code_string);
449 }
433 } 450 }
434 451
435 if (action != SESSION_TERMINATE) { 452 if (action != SESSION_TERMINATE) {
436 XmlElement* content_tag = 453 XmlElement* content_tag =
437 new XmlElement(QName(kJingleNamespace, "content")); 454 new XmlElement(QName(kJingleNamespace, "content"));
438 jingle_tag->AddElement(content_tag); 455 jingle_tag->AddElement(content_tag);
439 456
440 content_tag->AddAttr(QName(kEmptyNamespace, "name"), 457 content_tag->AddAttr(QName(kEmptyNamespace, "name"),
441 ContentDescription::kChromotingContentName); 458 ContentDescription::kChromotingContentName);
442 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator"); 459 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator");
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 result->AddElement(FormatIceCredentials(credentials)); 618 result->AddElement(FormatIceCredentials(credentials));
602 } 619 }
603 for (const NamedCandidate& candidate : candidates) { 620 for (const NamedCandidate& candidate : candidates) {
604 result->AddElement(FormatIceCandidate(candidate)); 621 result->AddElement(FormatIceCandidate(candidate));
605 } 622 }
606 return result; 623 return result;
607 } 624 }
608 625
609 } // namespace protocol 626 } // namespace protocol
610 } // namespace remoting 627 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698