| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_number_conversions.h" | 8 #include "base/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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 } // namespace | 98 } // namespace |
| 99 | 99 |
| 100 // static | 100 // static |
| 101 bool JingleMessage::IsJingleMessage(const buzz::XmlElement* stanza) { | 101 bool JingleMessage::IsJingleMessage(const buzz::XmlElement* stanza) { |
| 102 return stanza->FirstNamed(QName(kJingleNamespace, "jingle")) != NULL; | 102 return stanza->FirstNamed(QName(kJingleNamespace, "jingle")) != NULL; |
| 103 } | 103 } |
| 104 | 104 |
| 105 JingleMessage::JingleMessage() | 105 JingleMessage::JingleMessage() |
| 106 : action(UNKNOWN_ACTION), | 106 : action(UNKNOWN_ACTION), |
| 107 termination_reason(kJingleNamespace, "success") { | 107 reason(UNKNOWN_REASON) { |
| 108 } | 108 } |
| 109 | 109 |
| 110 JingleMessage::JingleMessage( | 110 JingleMessage::JingleMessage( |
| 111 const std::string& to_value, | 111 const std::string& to_value, |
| 112 ActionType action_value, | 112 ActionType action_value, |
| 113 const std::string& sid_value) | 113 const std::string& sid_value) |
| 114 : to(to_value), | 114 : to(to_value), |
| 115 action(action_value), | 115 action(action_value), |
| 116 sid(sid_value) { | 116 sid(sid_value) { |
| 117 } | 117 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 147 *error = "Unknown action " + action_str; | 147 *error = "Unknown action " + action_str; |
| 148 return false; | 148 return false; |
| 149 } | 149 } |
| 150 | 150 |
| 151 sid = jingle_tag->Attr(QName(kEmptyNamespace, "sid")); | 151 sid = jingle_tag->Attr(QName(kEmptyNamespace, "sid")); |
| 152 if (sid.empty()) { | 152 if (sid.empty()) { |
| 153 *error = "sid attribute is missing"; | 153 *error = "sid attribute is missing"; |
| 154 return false; | 154 return false; |
| 155 } | 155 } |
| 156 | 156 |
| 157 if (action == SESSION_TERMINATE) { | 157 const XmlElement* reason_tag = |
| 158 const XmlElement* reason_tag = | 158 jingle_tag->FirstNamed(QName(kJingleNamespace, "reason")); |
| 159 jingle_tag->FirstNamed(QName(kJingleNamespace, "reason")); | 159 if (reason_tag && reason_tag->FirstElement()) { |
| 160 if (reason_tag && reason_tag->FirstElement()) | 160 const QName& reason_qname(reason_tag->FirstElement()->Name()); |
| 161 termination_reason = reason_tag->FirstElement()->Name(); | 161 if (reason_qname == QName(kJingleNamespace, "success")) { |
| 162 reason = SUCCESS; |
| 163 } else if (reason_qname == QName(kJingleNamespace, "decline")) { |
| 164 reason = DECLINED; |
| 165 } else if (reason_qname == |
| 166 QName(kJingleNamespace, "incompatible-parameters")) { |
| 167 reason = INCOMPATIBLE_PARAMETERS; |
| 168 } else { |
| 169 reason = UNKNOWN_REASON; |
| 170 } |
| 171 } |
| 172 |
| 173 if (action == SESSION_TERMINATE) |
| 162 return true; | 174 return true; |
| 163 } | |
| 164 | 175 |
| 165 const XmlElement* content_tag = | 176 const XmlElement* content_tag = |
| 166 jingle_tag->FirstNamed(QName(kJingleNamespace, "content")); | 177 jingle_tag->FirstNamed(QName(kJingleNamespace, "content")); |
| 167 if (!content_tag) { | 178 if (!content_tag) { |
| 168 *error = "content tag is missing"; | 179 *error = "content tag is missing"; |
| 169 return false; | 180 return false; |
| 170 } | 181 } |
| 171 | 182 |
| 172 std::string content_name = content_tag->Attr(QName(kEmptyNamespace, "name")); | 183 std::string content_name = content_tag->Attr(QName(kEmptyNamespace, "name")); |
| 173 if (content_name != ContentDescription::kChromotingContentName) { | 184 if (content_name != ContentDescription::kChromotingContentName) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 break; | 254 break; |
| 244 default: | 255 default: |
| 245 NOTREACHED(); | 256 NOTREACHED(); |
| 246 break; | 257 break; |
| 247 } | 258 } |
| 248 jingle_tag->AddAttr(QName(kEmptyNamespace, "action"), action_attr); | 259 jingle_tag->AddAttr(QName(kEmptyNamespace, "action"), action_attr); |
| 249 | 260 |
| 250 if (action == SESSION_INITIATE) | 261 if (action == SESSION_INITIATE) |
| 251 jingle_tag->AddAttr(QName(kEmptyNamespace, "initiator"), from); | 262 jingle_tag->AddAttr(QName(kEmptyNamespace, "initiator"), from); |
| 252 | 263 |
| 253 if (action == SESSION_TERMINATE) { | 264 if (reason != UNKNOWN_REASON) { |
| 254 XmlElement* reason_tag = new XmlElement(QName(kJingleNamespace, "reason")); | 265 XmlElement* reason_tag = new XmlElement(QName(kJingleNamespace, "reason")); |
| 255 jingle_tag->AddElement(reason_tag); | 266 jingle_tag->AddElement(reason_tag); |
| 267 std::string reason_string; |
| 268 switch (reason) { |
| 269 case SUCCESS: |
| 270 reason_string = "success"; |
| 271 break; |
| 272 case DECLINED: |
| 273 reason_string = "decline"; |
| 274 break; |
| 275 case INCOMPATIBLE_PARAMETERS: |
| 276 reason_string = "incompatible-parameters"; |
| 277 break; |
| 278 default: |
| 279 DLOG(FATAL) << "Invalid reason: " << reason; |
| 280 reason_string = "success"; |
| 281 } |
| 282 reason_tag->AddElement(new XmlElement( |
| 283 QName(kJingleNamespace, reason_string))); |
| 284 } |
| 256 | 285 |
| 257 reason_tag->AddElement(new XmlElement(termination_reason)); | 286 if (action != SESSION_TERMINATE) { |
| 258 } else { | |
| 259 XmlElement* content_tag = | 287 XmlElement* content_tag = |
| 260 new XmlElement(QName(kJingleNamespace, "content")); | 288 new XmlElement(QName(kJingleNamespace, "content")); |
| 261 jingle_tag->AddElement(content_tag); | 289 jingle_tag->AddElement(content_tag); |
| 262 | 290 |
| 263 content_tag->AddAttr(QName(kEmptyNamespace, "name"), | 291 content_tag->AddAttr(QName(kEmptyNamespace, "name"), |
| 264 ContentDescription::kChromotingContentName); | 292 ContentDescription::kChromotingContentName); |
| 265 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator"); | 293 content_tag->AddAttr(QName(kEmptyNamespace, "creator"), "initiator"); |
| 266 | 294 |
| 267 if (description.get()) | 295 if (description.get()) |
| 268 content_tag->AddElement(description->ToXml()); | 296 content_tag->AddElement(description->ToXml()); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en"); | 398 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en"); |
| 371 text_elem->SetBodyText(error_text); | 399 text_elem->SetBodyText(error_text); |
| 372 error->AddElement(text_elem); | 400 error->AddElement(text_elem); |
| 373 } | 401 } |
| 374 | 402 |
| 375 return iq; | 403 return iq; |
| 376 } | 404 } |
| 377 | 405 |
| 378 } // namespace protocol | 406 } // namespace protocol |
| 379 } // namespace remoting | 407 } // namespace remoting |
| OLD | NEW |