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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 buzz::XmlElement* text_elem = | 615 buzz::XmlElement* text_elem = |
622 new buzz::XmlElement(QName(kJabberNamespace, "text")); | 616 new buzz::XmlElement(QName(kJabberNamespace, "text")); |
623 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en"); | 617 text_elem->SetAttr(QName(kXmlNamespace, "lang"), "en"); |
624 text_elem->SetBodyText(error_text); | 618 text_elem->SetBodyText(error_text); |
625 error->AddElement(text_elem); | 619 error->AddElement(text_elem); |
626 } | 620 } |
627 | 621 |
628 return iq; | 622 return iq; |
629 } | 623 } |
630 | 624 |
| 625 IceTransportInfo::NamedCandidate::NamedCandidate( |
| 626 const std::string& name, |
| 627 const cricket::Candidate& candidate) |
| 628 : name(name), candidate(candidate) {} |
| 629 |
| 630 IceTransportInfo::IceCredentials::IceCredentials(std::string channel, |
| 631 std::string ufrag, |
| 632 std::string password) |
| 633 : channel(channel), ufrag(ufrag), password(password) {} |
| 634 |
631 IceTransportInfo::IceTransportInfo() {} | 635 IceTransportInfo::IceTransportInfo() {} |
632 IceTransportInfo::~IceTransportInfo() {} | 636 IceTransportInfo::~IceTransportInfo() {} |
633 | 637 |
634 bool IceTransportInfo::ParseXml( | 638 bool IceTransportInfo::ParseXml( |
635 const buzz::XmlElement* element) { | 639 const buzz::XmlElement* element) { |
636 if (element->Name() != QName(kIceTransportNamespace, "transport")) { | 640 if (element->Name() != QName(kIceTransportNamespace, "transport")) { |
637 return false; | 641 return false; |
638 } | 642 } |
639 | 643 |
640 ice_credentials.clear(); | 644 ice_credentials.clear(); |
(...skipping 30 matching lines...) Expand all Loading... |
671 result->AddElement(FormatIceCredentials(credentials)); | 675 result->AddElement(FormatIceCredentials(credentials)); |
672 } | 676 } |
673 for (const NamedCandidate& candidate : candidates) { | 677 for (const NamedCandidate& candidate : candidates) { |
674 result->AddElement(FormatIceCandidate(candidate)); | 678 result->AddElement(FormatIceCandidate(candidate)); |
675 } | 679 } |
676 return result; | 680 return result; |
677 } | 681 } |
678 | 682 |
679 } // namespace protocol | 683 } // namespace protocol |
680 } // namespace remoting | 684 } // namespace remoting |
OLD | NEW |