OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_HOST_STATUS_SENDER_H_ |
| 6 #define REMOTING_HOST_STATUS_SENDER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "remoting/base/rsa_key_pair.h" |
| 14 #include "remoting/jingle_glue/signal_strategy.h" |
| 15 |
| 16 namespace base { |
| 17 class MessageLoopProxy; |
| 18 } // namespace base |
| 19 |
| 20 namespace buzz { |
| 21 class XmlElement; |
| 22 } // namespace buzz |
| 23 |
| 24 namespace remoting { |
| 25 |
| 26 class RsaKeyPair; |
| 27 class IqSender; |
| 28 |
| 29 // HostStatusSender sends the host status to the Chromoting Bot. |
| 30 // Each host status stanza looks as follows: |
| 31 // |
| 32 // <cli:iq type="set" to="user@gmail.com/chromoting123123" |
| 33 // id="123" xmlns:cli="jabber:client"> |
| 34 // <rem:host-status rem:hostid="0" |
| 35 // rem:status="OFFLINE" rem:exit-code="INVALID_HOST_CONFIGURATION" |
| 36 // xmlns:rem="google:remoting"> |
| 37 // <rem:signature rem:time="1372878097">.signature.</rem:signature> |
| 38 // <rem:host-version>30.0.1554.0</rem:host-version> |
| 39 // <rem:log><rem:entry cpu="x86_64" event-name="host-status" |
| 40 // host-version="30.0.1560.0" os-name="Linux" role="host"/> |
| 41 // </rem:log> |
| 42 // </rem:host-status> |
| 43 // </cli:iq> |
| 44 // |
| 45 // The signature is a base-64 encoded SHA-1 hash, signed with the host's |
| 46 // private RSA key. The message being signed contains the full Jid (e.g. |
| 47 // "user@gmail.com/chromoting123123"), the timestamp, the host status, |
| 48 // and the exit code. |
| 49 class HostStatusSender : SignalStrategy::Listener { |
| 50 public: |
| 51 |
| 52 enum HostStatus { |
| 53 OFFLINE = 0, |
| 54 ONLINE = 1 |
| 55 }; |
| 56 |
| 57 HostStatusSender(const std::string& host_id, |
| 58 SignalStrategy* signal_strategy, |
| 59 scoped_refptr<RsaKeyPair> key_pair, |
| 60 const std::string& directory_bot_jid); |
| 61 virtual ~HostStatusSender(); |
| 62 |
| 63 // SignalStrategy::Listener interface. |
| 64 virtual void OnSignalStrategyStateChange( |
| 65 SignalStrategy::State state) OVERRIDE; |
| 66 virtual bool OnSignalStrategyIncomingStanza( |
| 67 const buzz::XmlElement* stanza) OVERRIDE; |
| 68 |
| 69 // APIs for sending host status XMPP messages to the chromoting bot. |
| 70 // status: the reason (exit code) why the host is offline. |
| 71 void SendOnlineStatus(); |
| 72 void SendOfflineStatus(int exit_code); |
| 73 |
| 74 private: |
| 75 // Helper method for sending either an online or an offline status message. |
| 76 void SendHostStatus(HostStatus status, int exit_code); |
| 77 |
| 78 // Helper method to compose host status stanzas. |
| 79 scoped_ptr<buzz::XmlElement> CreateHostStatusMessage( |
| 80 HostStatus status, int exit_code); |
| 81 |
| 82 // Helper method to create the signature blob used in the host status stanza. |
| 83 scoped_ptr<buzz::XmlElement> CreateSignature( |
| 84 HostStatus status, int exit_code); |
| 85 |
| 86 std::string host_id_; |
| 87 SignalStrategy* signal_strategy_; |
| 88 scoped_refptr<RsaKeyPair> key_pair_; |
| 89 std::string directory_bot_jid_; |
| 90 scoped_ptr<IqSender> iq_sender_; |
| 91 |
| 92 // The string representation of the HostStatus values. |
| 93 static std::string host_status_strings_[2]; |
| 94 |
| 95 inline static std::string HostStatusToString(HostStatus host_status) { |
| 96 return host_status_strings_[host_status]; |
| 97 } |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(HostStatusSender); |
| 100 }; |
| 101 |
| 102 } // namespace remoting |
| 103 |
| 104 #endif // REMOTING_HOST_STATUS_SENDER_H_ |
OLD | NEW |