| 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/content_description.h" | 5 #include "remoting/protocol/content_description.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/authenticator.h" | 10 #include "remoting/protocol/authenticator.h" | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 56 // e.g. for video channel: | 56 // e.g. for video channel: | 
| 57 //    <video transport="stream" version="1" codec="vp8" /> | 57 //    <video transport="stream" version="1" codec="vp8" /> | 
| 58 XmlElement* FormatChannelConfig(const ChannelConfig& config, | 58 XmlElement* FormatChannelConfig(const ChannelConfig& config, | 
| 59                                 const std::string& tag_name) { | 59                                 const std::string& tag_name) { | 
| 60   XmlElement* result = new XmlElement( | 60   XmlElement* result = new XmlElement( | 
| 61       QName(kChromotingXmlNamespace, tag_name)); | 61       QName(kChromotingXmlNamespace, tag_name)); | 
| 62 | 62 | 
| 63   result->AddAttr(QName(kDefaultNs, kTransportAttr), | 63   result->AddAttr(QName(kDefaultNs, kTransportAttr), | 
| 64                   ValueToName(kTransports, config.transport)); | 64                   ValueToName(kTransports, config.transport)); | 
| 65 | 65 | 
| 66   result->AddAttr(QName(kDefaultNs, kVersionAttr), | 66   if (config.transport != ChannelConfig::TRANSPORT_NONE) { | 
| 67                   base::IntToString(config.version)); | 67     result->AddAttr(QName(kDefaultNs, kVersionAttr), | 
|  | 68                     base::IntToString(config.version)); | 
| 68 | 69 | 
| 69   if (config.codec != ChannelConfig::CODEC_UNDEFINED) { | 70     if (config.codec != ChannelConfig::CODEC_UNDEFINED) { | 
| 70     result->AddAttr(QName(kDefaultNs, kCodecAttr), | 71       result->AddAttr(QName(kDefaultNs, kCodecAttr), | 
| 71                     ValueToName(kCodecs, config.codec)); | 72                       ValueToName(kCodecs, config.codec)); | 
|  | 73     } | 
| 72   } | 74   } | 
| 73 | 75 | 
| 74   return result; | 76   return result; | 
| 75 } | 77 } | 
| 76 | 78 | 
| 77 // Returns false if the element is invalid. | 79 // Returns false if the element is invalid. | 
| 78 bool ParseChannelConfig(const XmlElement* element, bool codec_required, | 80 bool ParseChannelConfig(const XmlElement* element, bool codec_required, | 
| 79                         ChannelConfig* config) { | 81                         ChannelConfig* config) { | 
| 80   if (!NameToValue( | 82   if (!NameToValue( | 
| 81           kTransports, element->Attr(QName(kDefaultNs, kTransportAttr)), | 83           kTransports, element->Attr(QName(kDefaultNs, kTransportAttr)), | 
| 82           &config->transport) || | 84           &config->transport)) { | 
| 83       !base::StringToInt(element->Attr(QName(kDefaultNs, kVersionAttr)), |  | 
| 84                          &config->version)) { |  | 
| 85     return false; | 85     return false; | 
| 86   } | 86   } | 
| 87 | 87 | 
| 88   if (codec_required) { | 88   // Version is not required when transport="none". | 
| 89     if (!NameToValue(kCodecs, element->Attr(QName(kDefaultNs, kCodecAttr)), | 89   if (config->transport != ChannelConfig::TRANSPORT_NONE) { | 
| 90                      &config->codec)) { | 90     if (!base::StringToInt(element->Attr(QName(kDefaultNs, kVersionAttr)), | 
|  | 91                            &config->version)) { | 
| 91       return false; | 92       return false; | 
| 92     } | 93     } | 
|  | 94 | 
|  | 95     // Codec is not required when transport="none". | 
|  | 96     if (codec_required) { | 
|  | 97       if (!NameToValue(kCodecs, element->Attr(QName(kDefaultNs, kCodecAttr)), | 
|  | 98                        &config->codec)) { | 
|  | 99         return false; | 
|  | 100       } | 
|  | 101     } else { | 
|  | 102       config->codec = ChannelConfig::CODEC_UNDEFINED; | 
|  | 103     } | 
| 93   } else { | 104   } else { | 
|  | 105     config->version = 0; | 
| 94     config->codec = ChannelConfig::CODEC_UNDEFINED; | 106     config->codec = ChannelConfig::CODEC_UNDEFINED; | 
| 95   } | 107   } | 
| 96 | 108 | 
| 97   return true; | 109   return true; | 
| 98 } | 110 } | 
| 99 | 111 | 
| 100 }  // namespace | 112 }  // namespace | 
| 101 | 113 | 
| 102 ContentDescription::ContentDescription( | 114 ContentDescription::ContentDescription( | 
| 103     scoped_ptr<CandidateSessionConfig> config, | 115     scoped_ptr<CandidateSessionConfig> config, | 
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 184   while (child) { | 196   while (child) { | 
| 185     ChannelConfig channel_config; | 197     ChannelConfig channel_config; | 
| 186     if (ParseChannelConfig(child, codec_required, &channel_config)) { | 198     if (ParseChannelConfig(child, codec_required, &channel_config)) { | 
| 187       configs->push_back(channel_config); | 199       configs->push_back(channel_config); | 
| 188     } | 200     } | 
| 189     child = child->NextNamed(tag); | 201     child = child->NextNamed(tag); | 
| 190   } | 202   } | 
| 191   if (optional && configs->empty()) { | 203   if (optional && configs->empty()) { | 
| 192       // If there's no mention of the tag, implicitly assume | 204       // If there's no mention of the tag, implicitly assume | 
| 193       // TRANSPORT_NONE for the channel. | 205       // TRANSPORT_NONE for the channel. | 
| 194       configs->push_back(ChannelConfig(ChannelConfig::TRANSPORT_NONE, | 206       configs->push_back(ChannelConfig()); | 
| 195                                        kDefaultStreamVersion, |  | 
| 196                                        ChannelConfig::CODEC_VERBATIM)); |  | 
| 197   } | 207   } | 
| 198   return true; | 208   return true; | 
| 199 } | 209 } | 
| 200 | 210 | 
| 201 // static | 211 // static | 
| 202 scoped_ptr<ContentDescription> ContentDescription::ParseXml( | 212 scoped_ptr<ContentDescription> ContentDescription::ParseXml( | 
| 203     const XmlElement* element) { | 213     const XmlElement* element) { | 
| 204   if (element->Name() != QName(kChromotingXmlNamespace, kDescriptionTag)) { | 214   if (element->Name() != QName(kChromotingXmlNamespace, kDescriptionTag)) { | 
| 205     LOG(ERROR) << "Invalid description: " << element->Str(); | 215     LOG(ERROR) << "Invalid description: " << element->Str(); | 
| 206     return scoped_ptr<ContentDescription>(); | 216     return scoped_ptr<ContentDescription>(); | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 222   const XmlElement* child = Authenticator::FindAuthenticatorMessage(element); | 232   const XmlElement* child = Authenticator::FindAuthenticatorMessage(element); | 
| 223   if (child) | 233   if (child) | 
| 224     authenticator_message.reset(new XmlElement(*child)); | 234     authenticator_message.reset(new XmlElement(*child)); | 
| 225 | 235 | 
| 226   return scoped_ptr<ContentDescription>( | 236   return scoped_ptr<ContentDescription>( | 
| 227       new ContentDescription(config.Pass(), authenticator_message.Pass())); | 237       new ContentDescription(config.Pass(), authenticator_message.Pass())); | 
| 228 } | 238 } | 
| 229 | 239 | 
| 230 }  // namespace protocol | 240 }  // namespace protocol | 
| 231 }  // namespace remoting | 241 }  // namespace remoting | 
| OLD | NEW | 
|---|