| 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" |
| 11 #include "remoting/protocol/name_value_map.h" | 11 #include "remoting/protocol/name_value_map.h" |
| 12 #include "remoting/signaling/jid_util.h" |
| 12 #include "remoting/signaling/remoting_bot.h" | 13 #include "remoting/signaling/remoting_bot.h" |
| 13 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 14 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 14 | 15 |
| 15 using buzz::QName; | 16 using buzz::QName; |
| 16 using buzz::XmlElement; | 17 using buzz::XmlElement; |
| 17 | 18 |
| 18 namespace remoting { | 19 namespace remoting { |
| 19 namespace protocol { | 20 namespace protocol { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 attribute_name = (from) ? "from-channel" : "to-channel"; | 167 attribute_name = (from) ? "from-channel" : "to-channel"; |
| 167 break; | 168 break; |
| 168 default: | 169 default: |
| 169 NOTREACHED(); | 170 NOTREACHED(); |
| 170 } | 171 } |
| 171 return QName(kEmptyNamespace, attribute_name); | 172 return QName(kEmptyNamespace, attribute_name); |
| 172 } | 173 } |
| 173 | 174 |
| 174 SignalingAddress ParseAddress( | 175 SignalingAddress ParseAddress( |
| 175 const buzz::XmlElement* iq, bool from, std::string* error) { | 176 const buzz::XmlElement* iq, bool from, std::string* error) { |
| 176 SignalingAddress empty_instance; | |
| 177 | |
| 178 std::string jid(iq->Attr(GetQNameByField(Field::JID, from))); | 177 std::string jid(iq->Attr(GetQNameByField(Field::JID, from))); |
| 178 if (jid.empty()) { |
| 179 return SignalingAddress(); |
| 180 } |
| 179 | 181 |
| 180 const XmlElement* jingle = iq->FirstNamed(QName(kJingleNamespace, "jingle")); | 182 const XmlElement* jingle = iq->FirstNamed(QName(kJingleNamespace, "jingle")); |
| 181 | 183 |
| 182 if (!jingle) { | 184 if (!jingle) { |
| 183 return SignalingAddress(jid); | 185 return SignalingAddress(jid); |
| 184 } | 186 } |
| 185 | 187 |
| 186 std::string type(iq->Attr(QName(std::string(), "type"))); | 188 std::string type(iq->Attr(QName(std::string(), "type"))); |
| 187 // For error IQs, flips the |from| flag as the jingle node represents the | 189 // For error IQs, flips the |from| flag as the jingle node represents the |
| 188 // original request. | 190 // original request. |
| 189 if (type == "error") { | 191 if (type == "error") { |
| 190 from = !from; | 192 from = !from; |
| 191 } | 193 } |
| 192 | 194 |
| 193 std::string endpoint_id( | 195 std::string endpoint_id( |
| 194 jingle->Attr(GetQNameByField(Field::ENDPOINT_ID, from))); | 196 jingle->Attr(GetQNameByField(Field::ENDPOINT_ID, from))); |
| 195 std::string channel_str(jingle->Attr(GetQNameByField(Field::CHANNEL, from))); | 197 std::string channel_str(jingle->Attr(GetQNameByField(Field::CHANNEL, from))); |
| 196 SignalingAddress::Channel channel; | 198 SignalingAddress::Channel channel; |
| 197 | 199 |
| 198 if (channel_str.empty()) { | 200 if (channel_str.empty()) { |
| 199 channel = SignalingAddress::Channel::XMPP; | 201 channel = SignalingAddress::Channel::XMPP; |
| 200 } else if (!NameToValue(kChannelTypes, channel_str, &channel)) { | 202 } else if (!NameToValue(kChannelTypes, channel_str, &channel)) { |
| 201 *error = "Unknown channel: " + channel_str; | 203 *error = "Unknown channel: " + channel_str; |
| 202 return empty_instance; | 204 return SignalingAddress(); |
| 203 } | 205 } |
| 204 | 206 |
| 205 bool is_lcs = (channel == SignalingAddress::Channel::LCS); | 207 bool is_lcs = (channel == SignalingAddress::Channel::LCS); |
| 206 | 208 |
| 207 if (is_lcs == endpoint_id.empty()) { | 209 if (is_lcs == endpoint_id.empty()) { |
| 208 *error = (is_lcs ? "Missing |endpoint-id| for LCS channel" | 210 *error = (is_lcs ? "Missing |endpoint-id| for LCS channel" |
| 209 : "|endpoint_id| should be empty for XMPP channel"); | 211 : "|endpoint_id| should be empty for XMPP channel"); |
| 210 return empty_instance; | 212 return SignalingAddress(); |
| 211 } | 213 } |
| 212 | 214 |
| 213 if (from && is_lcs && !IsValidBotJid(jid)) { | 215 if (from && is_lcs && !IsValidBotJid(jid)) { |
| 214 *error = "Reject LCS message from untrusted sender: " + jid; | 216 *error = "Reject LCS message from untrusted sender: " + jid; |
| 215 return empty_instance; | 217 return SignalingAddress(); |
| 216 } | 218 } |
| 217 | 219 |
| 218 return SignalingAddress(jid, endpoint_id, channel); | 220 return SignalingAddress(jid, endpoint_id, channel); |
| 219 } | 221 } |
| 220 | 222 |
| 221 void SetAddress(buzz::XmlElement* iq, | 223 void SetAddress(buzz::XmlElement* iq, |
| 222 buzz::XmlElement* jingle, | 224 buzz::XmlElement* jingle, |
| 223 const SignalingAddress& address, | 225 const SignalingAddress& address, |
| 224 bool from) { | 226 bool from) { |
| 225 if (address.empty()) { | 227 if (address.empty()) { |
| 226 return; | 228 return; |
| 227 } | 229 } |
| 228 | 230 |
| 229 // Always set the JID. | 231 // Always set the JID. |
| 230 iq->SetAttr(GetQNameByField(Field::JID, from), address.jid); | 232 iq->SetAttr(GetQNameByField(Field::JID, from), address.jid()); |
| 231 | 233 |
| 232 // Do not tamper the routing-info in the jingle tag for error IQ's, as | 234 // Do not tamper the routing-info in the jingle tag for error IQ's, as |
| 233 // it corresponds to the original message. | 235 // it corresponds to the original message. |
| 234 std::string type(iq->Attr(QName(std::string(), "type"))); | 236 std::string type(iq->Attr(QName(std::string(), "type"))); |
| 235 if (type == "error") { | 237 if (type == "error") { |
| 236 return; | 238 return; |
| 237 } | 239 } |
| 238 | 240 |
| 239 // Start from a fresh slate regardless of the previous address format. | 241 // Start from a fresh slate regardless of the previous address format. |
| 240 jingle->ClearAttr(GetQNameByField(Field::CHANNEL, from)); | 242 jingle->ClearAttr(GetQNameByField(Field::CHANNEL, from)); |
| 241 jingle->ClearAttr(GetQNameByField(Field::ENDPOINT_ID, from)); | 243 jingle->ClearAttr(GetQNameByField(Field::ENDPOINT_ID, from)); |
| 242 | 244 |
| 243 // Only set the channel and endpoint_id in the LCS channel. | 245 // Only set the channel and endpoint_id in the LCS channel. |
| 244 if (address.channel == SignalingAddress::Channel::LCS) { | 246 if (address.channel() == SignalingAddress::Channel::LCS) { |
| 245 jingle->AddAttr( | 247 jingle->AddAttr(GetQNameByField(Field::ENDPOINT_ID, from), |
| 246 GetQNameByField(Field::ENDPOINT_ID, from), address.endpoint_id); | 248 address.endpoint_id()); |
| 247 jingle->AddAttr( | 249 jingle->AddAttr(GetQNameByField(Field::CHANNEL, from), |
| 248 GetQNameByField(Field::CHANNEL, from), | 250 ValueToName(kChannelTypes, address.channel())); |
| 249 ValueToName(kChannelTypes, address.channel)); | |
| 250 } | 251 } |
| 251 } | 252 } |
| 252 | 253 |
| 253 } // namespace | 254 } // namespace |
| 254 | 255 |
| 255 IceTransportInfo::NamedCandidate::NamedCandidate( | |
| 256 const std::string& name, | |
| 257 const cricket::Candidate& candidate) | |
| 258 : name(name), | |
| 259 candidate(candidate) { | |
| 260 } | |
| 261 | |
| 262 IceTransportInfo::IceCredentials::IceCredentials(std::string channel, | |
| 263 std::string ufrag, | |
| 264 std::string password) | |
| 265 : channel(channel), ufrag(ufrag), password(password) { | |
| 266 } | |
| 267 | |
| 268 SignalingAddress::SignalingAddress() | 256 SignalingAddress::SignalingAddress() |
| 269 : channel(SignalingAddress::Channel::XMPP) {} | 257 : channel_(SignalingAddress::Channel::XMPP) {} |
| 270 | 258 |
| 271 SignalingAddress::SignalingAddress(const std::string& jid) | 259 SignalingAddress::SignalingAddress(const std::string& jid) |
| 272 : jid(jid), channel(SignalingAddress::Channel::XMPP) {} | 260 : jid_(NormalizeJid(jid)), channel_(SignalingAddress::Channel::XMPP) { |
| 261 DCHECK(!jid.empty()); |
| 262 } |
| 273 | 263 |
| 274 SignalingAddress::SignalingAddress(const std::string& jid, | 264 SignalingAddress::SignalingAddress(const std::string& jid, |
| 275 const std::string& endpoint_id, | 265 const std::string& endpoint_id, |
| 276 Channel channel) | 266 Channel channel) |
| 277 : jid(jid), endpoint_id(endpoint_id), channel(channel) {} | 267 : jid_(NormalizeJid(jid)), |
| 278 | 268 endpoint_id_(NormalizeJid(endpoint_id)), |
| 279 bool SignalingAddress::operator==(const SignalingAddress& other) { | 269 channel_(channel) { |
| 280 return (other.endpoint_id == endpoint_id) && (other.jid == jid) && | 270 DCHECK(!jid.empty()); |
| 281 (other.channel == channel); | |
| 282 } | 271 } |
| 283 | 272 |
| 284 bool SignalingAddress::operator!=(const SignalingAddress& other) { | 273 bool SignalingAddress::operator==(const SignalingAddress& other) const { |
| 274 return (other.jid_ == jid_) && (other.endpoint_id_ == endpoint_id_) && |
| 275 (other.channel_ == channel_); |
| 276 } |
| 277 |
| 278 bool SignalingAddress::operator!=(const SignalingAddress& other) const { |
| 285 return !(*this == other); | 279 return !(*this == other); |
| 286 } | 280 } |
| 287 | 281 |
| 288 // static | 282 // static |
| 289 bool JingleMessage::IsJingleMessage(const buzz::XmlElement* stanza) { | 283 bool JingleMessage::IsJingleMessage(const buzz::XmlElement* stanza) { |
| 290 return stanza->Name() == QName(kJabberNamespace, "iq") && | 284 return stanza->Name() == QName(kJabberNamespace, "iq") && |
| 291 stanza->Attr(QName(std::string(), "type")) == "set" && | 285 stanza->Attr(QName(std::string(), "type")) == "set" && |
| 292 stanza->FirstNamed(QName(kJingleNamespace, "jingle")) != nullptr; | 286 stanza->FirstNamed(QName(kJingleNamespace, "jingle")) != nullptr; |
| 293 } | 287 } |
| 294 | 288 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 buzz::XmlElement* text_elem = | 592 buzz::XmlElement* text_elem = |
| 599 new buzz::XmlElement(QName(kJabberNamespace, "text")); | 593 new buzz::XmlElement(QName(kJabberNamespace, "text")); |
| 600 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en"); | 594 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en"); |
| 601 text_elem->SetBodyText(error_text); | 595 text_elem->SetBodyText(error_text); |
| 602 error->AddElement(text_elem); | 596 error->AddElement(text_elem); |
| 603 } | 597 } |
| 604 | 598 |
| 605 return iq; | 599 return iq; |
| 606 } | 600 } |
| 607 | 601 |
| 602 IceTransportInfo::NamedCandidate::NamedCandidate( |
| 603 const std::string& name, |
| 604 const cricket::Candidate& candidate) |
| 605 : name(name), candidate(candidate) {} |
| 606 |
| 607 IceTransportInfo::IceCredentials::IceCredentials(std::string channel, |
| 608 std::string ufrag, |
| 609 std::string password) |
| 610 : channel(channel), ufrag(ufrag), password(password) {} |
| 611 |
| 608 IceTransportInfo::IceTransportInfo() {} | 612 IceTransportInfo::IceTransportInfo() {} |
| 609 IceTransportInfo::~IceTransportInfo() {} | 613 IceTransportInfo::~IceTransportInfo() {} |
| 610 | 614 |
| 611 bool IceTransportInfo::ParseXml( | 615 bool IceTransportInfo::ParseXml( |
| 612 const buzz::XmlElement* element) { | 616 const buzz::XmlElement* element) { |
| 613 if (element->Name() != QName(kIceTransportNamespace, "transport")) | 617 if (element->Name() != QName(kIceTransportNamespace, "transport")) |
| 614 return false; | 618 return false; |
| 615 | 619 |
| 616 ice_credentials.clear(); | 620 ice_credentials.clear(); |
| 617 candidates.clear(); | 621 candidates.clear(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 645 result->AddElement(FormatIceCredentials(credentials)); | 649 result->AddElement(FormatIceCredentials(credentials)); |
| 646 } | 650 } |
| 647 for (const NamedCandidate& candidate : candidates) { | 651 for (const NamedCandidate& candidate : candidates) { |
| 648 result->AddElement(FormatIceCandidate(candidate)); | 652 result->AddElement(FormatIceCandidate(candidate)); |
| 649 } | 653 } |
| 650 return result; | 654 return result; |
| 651 } | 655 } |
| 652 | 656 |
| 653 } // namespace protocol | 657 } // namespace protocol |
| 654 } // namespace remoting | 658 } // namespace remoting |
| OLD | NEW |