Chromium Code Reviews| 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/content_description.h" | 5 #include "remoting/protocol/content_description.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | |
| 8 #include "base/logging.h" | 7 #include "base/logging.h" |
| 9 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 10 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
| 11 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 10 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 12 | 11 |
| 13 using buzz::QName; | 12 using buzz::QName; |
| 14 using buzz::XmlElement; | 13 using buzz::XmlElement; |
| 15 | 14 |
| 16 namespace remoting { | 15 namespace remoting { |
| 17 namespace protocol { | 16 namespace protocol { |
| 18 | 17 |
| 19 const char ContentDescription::kChromotingContentName[] = "chromoting"; | 18 const char ContentDescription::kChromotingContentName[] = "chromoting"; |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 const char kDefaultNs[] = ""; | 22 const char kDefaultNs[] = ""; |
| 24 | 23 |
| 25 // Following constants are used to format session description in XML. | 24 // Following constants are used to format session description in XML. |
| 26 const char kDescriptionTag[] = "description"; | 25 const char kDescriptionTag[] = "description"; |
| 27 const char kControlTag[] = "control"; | 26 const char kControlTag[] = "control"; |
| 28 const char kEventTag[] = "event"; | 27 const char kEventTag[] = "event"; |
| 29 const char kVideoTag[] = "video"; | 28 const char kVideoTag[] = "video"; |
| 30 const char kResolutionTag[] = "initial-resolution"; | 29 const char kResolutionTag[] = "initial-resolution"; |
| 31 const char kAuthenticationTag[] = "authentication"; | 30 const char kAuthenticationTag[] = "authentication"; |
| 32 const char kCertificateTag[] = "certificate"; | |
| 33 const char kAuthTokenTag[] = "auth-token"; | |
| 34 | 31 |
| 35 const char kTransportAttr[] = "transport"; | 32 const char kTransportAttr[] = "transport"; |
| 36 const char kVersionAttr[] = "version"; | 33 const char kVersionAttr[] = "version"; |
| 37 const char kCodecAttr[] = "codec"; | 34 const char kCodecAttr[] = "codec"; |
| 38 const char kWidthAttr[] = "width"; | 35 const char kWidthAttr[] = "width"; |
| 39 const char kHeightAttr[] = "height"; | 36 const char kHeightAttr[] = "height"; |
| 40 | 37 |
| 41 const char kStreamTransport[] = "stream"; | 38 const char kStreamTransport[] = "stream"; |
| 42 const char kDatagramTransport[] = "datagram"; | 39 const char kDatagramTransport[] = "datagram"; |
| 43 const char kSrtpTransport[] = "srtp"; | 40 const char kSrtpTransport[] = "srtp"; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 config->codec = ChannelConfig::CODEC_UNDEFINED; | 140 config->codec = ChannelConfig::CODEC_UNDEFINED; |
| 144 } | 141 } |
| 145 | 142 |
| 146 return true; | 143 return true; |
| 147 } | 144 } |
| 148 | 145 |
| 149 } // namespace | 146 } // namespace |
| 150 | 147 |
| 151 ContentDescription::ContentDescription( | 148 ContentDescription::ContentDescription( |
| 152 const CandidateSessionConfig* candidate_config, | 149 const CandidateSessionConfig* candidate_config, |
| 153 const std::string& auth_token, | 150 const buzz::XmlElement* authenticator_message) |
| 154 const std::string& certificate) | |
| 155 : candidate_config_(candidate_config), | 151 : candidate_config_(candidate_config), |
| 156 auth_token_(auth_token), | 152 authenticator_message_(authenticator_message) { |
| 157 certificate_(certificate) { | |
| 158 } | 153 } |
| 159 | 154 |
| 160 ContentDescription::~ContentDescription() { } | 155 ContentDescription::~ContentDescription() { } |
| 161 | 156 |
| 162 // ToXml() creates content description for chromoting session. The | 157 // ToXml() creates content description for chromoting session. The |
| 163 // description looks as follows: | 158 // description looks as follows: |
| 164 // <description xmlns="google:remoting"> | 159 // <description xmlns="google:remoting"> |
| 165 // <control transport="stream" version="1" /> | 160 // <control transport="stream" version="1" /> |
| 166 // <event transport="datagram" version="1" /> | 161 // <event transport="datagram" version="1" /> |
| 167 // <video transport="srtp" codec="vp8" version="1" /> | 162 // <video transport="srtp" codec="vp8" version="1" /> |
| 168 // <initial-resolution width="800" height="600" /> | 163 // <initial-resolution width="800" height="600" /> |
| 169 // <authentication> | 164 // <authentication> |
| 170 // <certificate>[BASE64 Encoded Certificate]</certificate> | 165 // Authentication message created by Authenticator implementation. |
|
Wez
2011/11/25 06:54:11
nit: The word "authentication" seems superfluous h
Sergey Ulanov
2011/11/28 18:55:16
Done.
| |
| 171 // <auth-token>...</auth-token> // IT2Me only. | |
| 172 // </authentication> | 166 // </authentication> |
| 173 // </description> | 167 // </description> |
| 174 // | 168 // |
| 175 XmlElement* ContentDescription::ToXml() const { | 169 XmlElement* ContentDescription::ToXml() const { |
| 176 XmlElement* root = new XmlElement( | 170 XmlElement* root = new XmlElement( |
| 177 QName(kChromotingXmlNamespace, kDescriptionTag), true); | 171 QName(kChromotingXmlNamespace, kDescriptionTag), true); |
| 178 | 172 |
| 179 std::vector<ChannelConfig>::const_iterator it; | 173 std::vector<ChannelConfig>::const_iterator it; |
| 180 | 174 |
| 181 for (it = config()->control_configs().begin(); | 175 for (it = config()->control_configs().begin(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 196 XmlElement* resolution_tag = new XmlElement( | 190 XmlElement* resolution_tag = new XmlElement( |
| 197 QName(kChromotingXmlNamespace, kResolutionTag)); | 191 QName(kChromotingXmlNamespace, kResolutionTag)); |
| 198 resolution_tag->AddAttr(QName(kDefaultNs, kWidthAttr), | 192 resolution_tag->AddAttr(QName(kDefaultNs, kWidthAttr), |
| 199 base::IntToString( | 193 base::IntToString( |
| 200 config()->initial_resolution().width)); | 194 config()->initial_resolution().width)); |
| 201 resolution_tag->AddAttr(QName(kDefaultNs, kHeightAttr), | 195 resolution_tag->AddAttr(QName(kDefaultNs, kHeightAttr), |
| 202 base::IntToString( | 196 base::IntToString( |
| 203 config()->initial_resolution().height)); | 197 config()->initial_resolution().height)); |
| 204 root->AddElement(resolution_tag); | 198 root->AddElement(resolution_tag); |
| 205 | 199 |
| 206 if (!certificate().empty() || !auth_token().empty()) { | 200 if (authenticator_message_.get()) { |
| 207 XmlElement* authentication_tag = new XmlElement( | 201 DCHECK(authenticator_message_->Name() == |
| 208 QName(kChromotingXmlNamespace, kAuthenticationTag)); | 202 QName(kChromotingXmlNamespace, kAuthenticationTag)); |
| 209 | 203 root->AddElement(new XmlElement(*authenticator_message_)); |
| 210 if (!certificate().empty()) { | |
| 211 XmlElement* certificate_tag = new XmlElement( | |
| 212 QName(kChromotingXmlNamespace, kCertificateTag)); | |
| 213 | |
| 214 std::string base64_cert; | |
| 215 if (!base::Base64Encode(certificate(), &base64_cert)) { | |
| 216 LOG(DFATAL) << "Cannot perform base64 encode on certificate"; | |
| 217 } | |
| 218 | |
| 219 certificate_tag->SetBodyText(base64_cert); | |
| 220 authentication_tag->AddElement(certificate_tag); | |
| 221 } | |
| 222 | |
| 223 if (!auth_token().empty()) { | |
| 224 XmlElement* auth_token_tag = new XmlElement( | |
| 225 QName(kChromotingXmlNamespace, kAuthTokenTag)); | |
| 226 auth_token_tag->SetBodyText(auth_token()); | |
| 227 authentication_tag->AddElement(auth_token_tag); | |
| 228 } | |
| 229 | |
| 230 root->AddElement(authentication_tag); | |
| 231 } | 204 } |
| 232 | 205 |
| 233 return root; | 206 return root; |
| 234 } | 207 } |
| 235 | 208 |
| 236 // static | 209 // static |
| 237 ContentDescription* ContentDescription::ParseXml( | 210 ContentDescription* ContentDescription::ParseXml( |
| 238 const XmlElement* element) { | 211 const XmlElement* element) { |
| 239 if (element->Name() == QName(kChromotingXmlNamespace, kDescriptionTag)) { | 212 if (element->Name() == QName(kChromotingXmlNamespace, kDescriptionTag)) { |
| 240 scoped_ptr<CandidateSessionConfig> config( | 213 scoped_ptr<CandidateSessionConfig> config( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 return NULL; // Resolution must always be specified. | 253 return NULL; // Resolution must always be specified. |
| 281 int width; | 254 int width; |
| 282 int height; | 255 int height; |
| 283 if (!base::StringToInt(child->Attr(QName(kDefaultNs, kWidthAttr)), | 256 if (!base::StringToInt(child->Attr(QName(kDefaultNs, kWidthAttr)), |
| 284 &width) || | 257 &width) || |
| 285 !base::StringToInt(child->Attr(QName(kDefaultNs, kHeightAttr)), | 258 !base::StringToInt(child->Attr(QName(kDefaultNs, kHeightAttr)), |
| 286 &height)) { | 259 &height)) { |
| 287 return NULL; | 260 return NULL; |
| 288 } | 261 } |
| 289 ScreenResolution resolution(width, height); | 262 ScreenResolution resolution(width, height); |
| 290 if (!resolution.IsValid()) { | 263 if (!resolution.IsValid()) |
| 291 return NULL; | 264 return NULL; |
| 292 } | |
| 293 | 265 |
| 294 *config->mutable_initial_resolution() = resolution; | 266 *config->mutable_initial_resolution() = resolution; |
| 295 | 267 |
| 296 // Parse authentication information. | 268 scoped_ptr<XmlElement> authenticator_message; |
| 297 std::string certificate; | |
| 298 std::string auth_token; | |
| 299 child = element->FirstNamed(QName(kChromotingXmlNamespace, | 269 child = element->FirstNamed(QName(kChromotingXmlNamespace, |
| 300 kAuthenticationTag)); | 270 kAuthenticationTag)); |
| 301 if (child) { | 271 if (child) |
| 302 // Parse the certificate. | 272 authenticator_message.reset(new XmlElement(*child)); |
| 303 const XmlElement* cert_tag = | |
| 304 child->FirstNamed(QName(kChromotingXmlNamespace, kCertificateTag)); | |
| 305 if (cert_tag) { | |
| 306 std::string base64_cert = cert_tag->BodyText(); | |
| 307 if (!base::Base64Decode(base64_cert, &certificate)) { | |
| 308 LOG(ERROR) << "Failed to decode certificate received from the peer."; | |
| 309 return NULL; | |
| 310 } | |
| 311 } | |
| 312 | 273 |
| 313 // Parse auth-token. | 274 return new ContentDescription( |
| 314 const XmlElement* auth_token_tag = | 275 config.release(), authenticator_message.release()); |
| 315 child->FirstNamed(QName(kChromotingXmlNamespace, kAuthTokenTag)); | |
| 316 if (auth_token_tag) { | |
| 317 auth_token = auth_token_tag->BodyText(); | |
| 318 } | |
| 319 } | |
| 320 | |
| 321 return new ContentDescription(config.release(), auth_token, certificate); | |
| 322 } | 276 } |
| 323 LOG(ERROR) << "Invalid description: " << element->Str(); | 277 LOG(ERROR) << "Invalid description: " << element->Str(); |
| 324 return NULL; | 278 return NULL; |
| 325 } | 279 } |
| 326 | 280 |
| 327 } // namespace protocol | 281 } // namespace protocol |
| 328 } // namespace remoting | 282 } // namespace remoting |
| OLD | NEW |