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" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 signal_strategy_->RemoveListener(this); | 58 signal_strategy_->RemoveListener(this); |
59 } | 59 } |
60 | 60 |
61 void RegisterSupportHostRequest::OnSignalStrategyStateChange( | 61 void RegisterSupportHostRequest::OnSignalStrategyStateChange( |
62 SignalStrategy::State state) { | 62 SignalStrategy::State state) { |
63 if (state == SignalStrategy::CONNECTED) { | 63 if (state == SignalStrategy::CONNECTED) { |
64 DCHECK(!callback_.is_null()); | 64 DCHECK(!callback_.is_null()); |
65 | 65 |
66 request_ = iq_sender_->SendIq( | 66 request_ = iq_sender_->SendIq( |
67 buzz::STR_SET, directory_bot_jid_, | 67 buzz::STR_SET, directory_bot_jid_, |
68 CreateRegistrationRequest(signal_strategy_->GetLocalJid()).Pass(), | 68 CreateRegistrationRequest(signal_strategy_->GetLocalJid()), |
69 base::Bind(&RegisterSupportHostRequest::ProcessResponse, | 69 base::Bind(&RegisterSupportHostRequest::ProcessResponse, |
70 base::Unretained(this))); | 70 base::Unretained(this))); |
71 } else if (state == SignalStrategy::DISCONNECTED) { | 71 } else if (state == SignalStrategy::DISCONNECTED) { |
72 // We will reach here if signaling fails to connect. | 72 // We will reach here if signaling fails to connect. |
73 std::string error_message = "Signal strategy disconnected."; | 73 std::string error_message = "Signal strategy disconnected."; |
74 LOG(ERROR) << error_message; | 74 LOG(ERROR) << error_message; |
75 CallCallback(std::string(), base::TimeDelta(), error_message); | 75 CallCallback(std::string(), base::TimeDelta(), error_message); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 bool RegisterSupportHostRequest::OnSignalStrategyIncomingStanza( | 79 bool RegisterSupportHostRequest::OnSignalStrategyIncomingStanza( |
80 const buzz::XmlElement* stanza) { | 80 const buzz::XmlElement* stanza) { |
81 return false; | 81 return false; |
82 } | 82 } |
83 | 83 |
84 scoped_ptr<XmlElement> RegisterSupportHostRequest::CreateRegistrationRequest( | 84 scoped_ptr<XmlElement> RegisterSupportHostRequest::CreateRegistrationRequest( |
85 const std::string& jid) { | 85 const std::string& jid) { |
86 scoped_ptr<XmlElement> query(new XmlElement( | 86 scoped_ptr<XmlElement> query(new XmlElement( |
87 QName(kChromotingXmlNamespace, kRegisterQueryTag))); | 87 QName(kChromotingXmlNamespace, kRegisterQueryTag))); |
88 XmlElement* public_key = new XmlElement( | 88 XmlElement* public_key = new XmlElement( |
89 QName(kChromotingXmlNamespace, kPublicKeyTag)); | 89 QName(kChromotingXmlNamespace, kPublicKeyTag)); |
90 public_key->AddText(key_pair_->GetPublicKey()); | 90 public_key->AddText(key_pair_->GetPublicKey()); |
91 query->AddElement(public_key); | 91 query->AddElement(public_key); |
92 query->AddElement(CreateSignature(jid).release()); | 92 query->AddElement(CreateSignature(jid).release()); |
93 return query.Pass(); | 93 return query; |
94 } | 94 } |
95 | 95 |
96 scoped_ptr<XmlElement> RegisterSupportHostRequest::CreateSignature( | 96 scoped_ptr<XmlElement> RegisterSupportHostRequest::CreateSignature( |
97 const std::string& jid) { | 97 const std::string& jid) { |
98 scoped_ptr<XmlElement> signature_tag(new XmlElement( | 98 scoped_ptr<XmlElement> signature_tag(new XmlElement( |
99 QName(kChromotingXmlNamespace, kSignatureTag))); | 99 QName(kChromotingXmlNamespace, kSignatureTag))); |
100 | 100 |
101 int64_t time = static_cast<int64_t>(base::Time::Now().ToDoubleT()); | 101 int64_t time = static_cast<int64_t>(base::Time::Now().ToDoubleT()); |
102 std::string time_str(base::Int64ToString(time)); | 102 std::string time_str(base::Int64ToString(time)); |
103 signature_tag->AddAttr( | 103 signature_tag->AddAttr( |
104 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); | 104 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); |
105 | 105 |
106 std::string message = NormalizeJid(jid) + ' ' + time_str; | 106 std::string message = NormalizeJid(jid) + ' ' + time_str; |
107 std::string signature(key_pair_->SignMessage(message)); | 107 std::string signature(key_pair_->SignMessage(message)); |
108 signature_tag->AddText(signature); | 108 signature_tag->AddText(signature); |
109 | 109 |
110 return signature_tag.Pass(); | 110 return signature_tag; |
111 } | 111 } |
112 | 112 |
113 void RegisterSupportHostRequest::ParseResponse(const XmlElement* response, | 113 void RegisterSupportHostRequest::ParseResponse(const XmlElement* response, |
114 std::string* support_id, | 114 std::string* support_id, |
115 base::TimeDelta* lifetime, | 115 base::TimeDelta* lifetime, |
116 std::string* error_message) { | 116 std::string* error_message) { |
117 std::ostringstream error; | 117 std::ostringstream error; |
118 | 118 |
119 std::string type = response->Attr(buzz::QN_TYPE); | 119 std::string type = response->Attr(buzz::QN_TYPE); |
120 if (type == buzz::STR_ERROR) { | 120 if (type == buzz::STR_ERROR) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 // Cleanup state before calling the callback. | 198 // Cleanup state before calling the callback. |
199 request_.reset(); | 199 request_.reset(); |
200 iq_sender_.reset(); | 200 iq_sender_.reset(); |
201 signal_strategy_->RemoveListener(this); | 201 signal_strategy_->RemoveListener(this); |
202 signal_strategy_ = nullptr; | 202 signal_strategy_ = nullptr; |
203 | 203 |
204 base::ResetAndReturn(&callback_).Run(support_id, lifetime, error_message); | 204 base::ResetAndReturn(&callback_).Run(support_id, lifetime, error_message); |
205 } | 205 } |
206 | 206 |
207 } // namespace remoting | 207 } // namespace remoting |
OLD | NEW |