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="0" rem:exit-code="100" xmlns:rem="google:remoting"> | |
36 // <rem:signature rem:time="1372878097">.signature.</rem:signature> | |
37 // <rem:host-version>30.0.1554.0</rem:host-version> | |
38 // </rem:host-status> | |
39 // </cli:iq> | |
40 // | |
41 // The signature is a base-64 encoded SHA-1 hash, signed with the host's | |
42 // private RSA key. The message being signed is the full Jid, e.g. | |
43 // "user@gmail.com/chromoting123123". | |
rmsousa
2013/07/04 01:20:14
Nit: please update
weitao
2013/07/09 00:37:40
Done.
| |
44 class HostStatusSender : SignalStrategy::Listener { | |
45 public: | |
46 | |
47 enum HostStatus { | |
48 OFFLINE = 0, | |
49 ONLINE = 1, | |
50 }; | |
51 | |
52 HostStatusSender(const std::string& host_id, | |
53 SignalStrategy* signal_strategy, | |
54 scoped_refptr<RsaKeyPair> key_pair, | |
55 const std::string& directory_bot_jid); | |
56 virtual ~HostStatusSender(); | |
57 | |
58 // SignalStrategy::Listener interface. | |
59 virtual void OnSignalStrategyStateChange( | |
60 SignalStrategy::State state) OVERRIDE; | |
61 virtual bool OnSignalStrategyIncomingStanza( | |
62 const buzz::XmlElement* stanza) OVERRIDE; | |
63 | |
64 // APIs for sending host status XMPP messages to the chromoting bot. | |
65 // status: the reason (exit code) why the host is offline. | |
66 void SendOnlineStatus(); | |
67 void SendOfflineStatus(int exit_code); | |
68 | |
69 private: | |
70 // Helper method for sending either an online or an offline status message. | |
71 void SendHostStatus(HostStatus status, int exit_code); | |
72 | |
73 // Helper method to compose host status stanzas. | |
74 scoped_ptr<buzz::XmlElement> CreateHostStatusMessage( | |
75 HostStatus status, int exit_code); | |
76 | |
77 // Helper method to create the signature blob used in the host status stanza. | |
78 scoped_ptr<buzz::XmlElement> CreateSignature( | |
79 HostStatus status, int exit_code); | |
80 | |
81 std::string host_id_; | |
82 SignalStrategy* signal_strategy_; | |
83 scoped_refptr<RsaKeyPair> key_pair_; | |
84 std::string directory_bot_jid_; | |
85 scoped_ptr<IqSender> iq_sender_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(HostStatusSender); | |
88 }; | |
89 | |
90 } // namespace remoting | |
91 | |
92 #endif // REMOTING_HOST_STATUS_SENDER_H_ | |
OLD | NEW |