| 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/host/register_support_host_request.h" | 5 #include "remoting/host/register_support_host_request.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringize_macros.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "remoting/base/constants.h" | 16 #include "remoting/base/constants.h" |
| 16 #include "remoting/host/host_config.h" | 17 #include "remoting/host/host_config.h" |
| 18 #include "remoting/host/host_details.h" |
| 17 #include "remoting/signaling/iq_sender.h" | 19 #include "remoting/signaling/iq_sender.h" |
| 18 #include "remoting/signaling/jid_util.h" | 20 #include "remoting/signaling/jid_util.h" |
| 19 #include "remoting/signaling/signal_strategy.h" | 21 #include "remoting/signaling/signal_strategy.h" |
| 20 #include "remoting/signaling/signaling_address.h" | 22 #include "remoting/signaling/signaling_address.h" |
| 21 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" | 23 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h" |
| 22 #include "third_party/libjingle_xmpp/xmpp/constants.h" | 24 #include "third_party/libjingle_xmpp/xmpp/constants.h" |
| 23 | 25 |
| 24 using buzz::QName; | 26 using buzz::QName; |
| 25 using buzz::XmlElement; | 27 using buzz::XmlElement; |
| 26 | 28 |
| 27 namespace remoting { | 29 namespace remoting { |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 30 // Strings used in the request message we send to the bot. | 32 // Strings used in the request message we send to the bot. |
| 31 const char kRegisterQueryTag[] = "register-support-host"; | 33 const char kRegisterQueryTag[] = "register-support-host"; |
| 32 const char kPublicKeyTag[] = "public-key"; | 34 const char kPublicKeyTag[] = "public-key"; |
| 33 const char kSignatureTag[] = "signature"; | 35 const char kSignatureTag[] = "signature"; |
| 34 const char kSignatureTimeAttr[] = "time"; | 36 const char kSignatureTimeAttr[] = "time"; |
| 37 const char kHostVersionTag[] = "host-version"; |
| 38 const char kHostOsNameTag[] = "host-os-name"; |
| 39 const char kHostOsVersionTag[] = "host-os-version"; |
| 35 | 40 |
| 36 // Strings used to parse responses received from the bot. | 41 // Strings used to parse responses received from the bot. |
| 37 const char kRegisterQueryResultTag[] = "register-support-host-result"; | 42 const char kRegisterQueryResultTag[] = "register-support-host-result"; |
| 38 const char kSupportIdTag[] = "support-id"; | 43 const char kSupportIdTag[] = "support-id"; |
| 39 const char kSupportIdLifetimeTag[] = "support-id-lifetime"; | 44 const char kSupportIdLifetimeTag[] = "support-id-lifetime"; |
| 40 } | 45 } |
| 41 | 46 |
| 42 RegisterSupportHostRequest::RegisterSupportHostRequest( | 47 RegisterSupportHostRequest::RegisterSupportHostRequest( |
| 43 SignalStrategy* signal_strategy, | 48 SignalStrategy* signal_strategy, |
| 44 scoped_refptr<RsaKeyPair> key_pair, | 49 scoped_refptr<RsaKeyPair> key_pair, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 82 } |
| 78 } | 83 } |
| 79 | 84 |
| 80 bool RegisterSupportHostRequest::OnSignalStrategyIncomingStanza( | 85 bool RegisterSupportHostRequest::OnSignalStrategyIncomingStanza( |
| 81 const buzz::XmlElement* stanza) { | 86 const buzz::XmlElement* stanza) { |
| 82 return false; | 87 return false; |
| 83 } | 88 } |
| 84 | 89 |
| 85 std::unique_ptr<XmlElement> | 90 std::unique_ptr<XmlElement> |
| 86 RegisterSupportHostRequest::CreateRegistrationRequest(const std::string& jid) { | 91 RegisterSupportHostRequest::CreateRegistrationRequest(const std::string& jid) { |
| 87 std::unique_ptr<XmlElement> query( | 92 auto query = base::MakeUnique<XmlElement>( |
| 88 new XmlElement(QName(kChromotingXmlNamespace, kRegisterQueryTag))); | 93 QName(kChromotingXmlNamespace, kRegisterQueryTag)); |
| 89 XmlElement* public_key = new XmlElement( | 94 |
| 95 auto public_key = base::MakeUnique<XmlElement>( |
| 90 QName(kChromotingXmlNamespace, kPublicKeyTag)); | 96 QName(kChromotingXmlNamespace, kPublicKeyTag)); |
| 91 public_key->AddText(key_pair_->GetPublicKey()); | 97 public_key->AddText(key_pair_->GetPublicKey()); |
| 92 query->AddElement(public_key); | 98 query->AddElement(public_key.release()); |
| 99 |
| 93 query->AddElement(CreateSignature(jid).release()); | 100 query->AddElement(CreateSignature(jid).release()); |
| 101 |
| 102 // Add host version. |
| 103 auto host_version = base::MakeUnique<XmlElement>( |
| 104 QName(kChromotingXmlNamespace, kHostVersionTag)); |
| 105 host_version->AddText(STRINGIZE(VERSION)); |
| 106 query->AddElement(host_version.release()); |
| 107 |
| 108 // Add host os name. |
| 109 auto host_os_name = base::MakeUnique<XmlElement>( |
| 110 QName(kChromotingXmlNamespace, kHostOsNameTag)); |
| 111 host_os_name->AddText(GetHostOperatingSystemName()); |
| 112 query->AddElement(host_os_name.release()); |
| 113 |
| 114 // Add host os version. |
| 115 auto host_os_version = base::MakeUnique<XmlElement>( |
| 116 QName(kChromotingXmlNamespace, kHostOsVersionTag)); |
| 117 host_os_version->AddText(GetHostOperatingSystemVersion()); |
| 118 query->AddElement(host_os_version.release()); |
| 119 |
| 94 return query; | 120 return query; |
| 95 } | 121 } |
| 96 | 122 |
| 97 std::unique_ptr<XmlElement> RegisterSupportHostRequest::CreateSignature( | 123 std::unique_ptr<XmlElement> RegisterSupportHostRequest::CreateSignature( |
| 98 const std::string& jid) { | 124 const std::string& jid) { |
| 99 std::unique_ptr<XmlElement> signature_tag( | 125 std::unique_ptr<XmlElement> signature_tag( |
| 100 new XmlElement(QName(kChromotingXmlNamespace, kSignatureTag))); | 126 new XmlElement(QName(kChromotingXmlNamespace, kSignatureTag))); |
| 101 | 127 |
| 102 int64_t time = static_cast<int64_t>(base::Time::Now().ToDoubleT()); | 128 int64_t time = static_cast<int64_t>(base::Time::Now().ToDoubleT()); |
| 103 std::string time_str(base::Int64ToString(time)); | 129 std::string time_str(base::Int64ToString(time)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // Cleanup state before calling the callback. | 225 // Cleanup state before calling the callback. |
| 200 request_.reset(); | 226 request_.reset(); |
| 201 iq_sender_.reset(); | 227 iq_sender_.reset(); |
| 202 signal_strategy_->RemoveListener(this); | 228 signal_strategy_->RemoveListener(this); |
| 203 signal_strategy_ = nullptr; | 229 signal_strategy_ = nullptr; |
| 204 | 230 |
| 205 base::ResetAndReturn(&callback_).Run(support_id, lifetime, error_message); | 231 base::ResetAndReturn(&callback_).Run(support_id, lifetime, error_message); |
| 206 } | 232 } |
| 207 | 233 |
| 208 } // namespace remoting | 234 } // namespace remoting |
| OLD | NEW |