OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef REMOTING_HOST_GNUBBY_AUTH_HANDLER_POSIX_H_ | 5 #ifndef REMOTING_HOST_GNUBBY_AUTH_HANDLER_POSIX_H_ |
6 #define REMOTING_HOST_GNUBBY_AUTH_HANDLER_POSIX_H_ | 6 #define REMOTING_HOST_GNUBBY_AUTH_HANDLER_POSIX_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | |
11 | 10 |
12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
13 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
14 #include "net/socket/stream_listen_socket.h" | 13 #include "net/socket/stream_listen_socket.h" |
15 #include "remoting/host/gnubby_auth_handler.h" | 14 #include "remoting/host/gnubby_auth_handler.h" |
16 | 15 |
| 16 namespace base { |
| 17 class DictionaryValue; |
| 18 } // namespace base |
| 19 |
17 namespace remoting { | 20 namespace remoting { |
18 | 21 |
19 namespace protocol { | 22 namespace protocol { |
20 class ClientStub; | 23 class ClientStub; |
21 } // namespace protocol | 24 } // namespace protocol |
22 | 25 |
| 26 class GnubbySocket; |
| 27 |
23 class GnubbyAuthHandlerPosix : public GnubbyAuthHandler, | 28 class GnubbyAuthHandlerPosix : public GnubbyAuthHandler, |
24 public base::NonThreadSafe, | 29 public base::NonThreadSafe, |
25 public net::StreamListenSocket::Delegate { | 30 public net::StreamListenSocket::Delegate { |
26 public: | 31 public: |
27 explicit GnubbyAuthHandlerPosix(protocol::ClientStub* client_stub); | 32 explicit GnubbyAuthHandlerPosix(protocol::ClientStub* client_stub); |
28 virtual ~GnubbyAuthHandlerPosix(); | 33 virtual ~GnubbyAuthHandlerPosix(); |
29 | 34 |
30 bool HasActiveSocketForTesting(net::StreamListenSocket* socket) const; | 35 bool HasActiveSocketForTesting(net::StreamListenSocket* socket) const; |
| 36 int GetConnectionIdForTesting(net::StreamListenSocket* socket) const; |
| 37 GnubbySocket* GetGnubbySocketForTesting( |
| 38 net::StreamListenSocket* socket) const; |
31 | 39 |
32 private: | 40 private: |
| 41 typedef std::map<int, GnubbySocket*> ActiveSockets; |
| 42 |
33 // GnubbyAuthHandler interface. | 43 // GnubbyAuthHandler interface. |
34 virtual void DeliverClientMessage(const std::string& message) OVERRIDE; | 44 virtual void DeliverClientMessage(const std::string& message) OVERRIDE; |
35 virtual void DeliverHostDataMessage(int connection_id, | 45 virtual void DeliverHostDataMessage(int connection_id, |
36 const std::string& data) const OVERRIDE; | 46 const std::string& data) const OVERRIDE; |
37 | 47 |
38 // StreamListenSocket::Delegate interface. | 48 // StreamListenSocket::Delegate interface. |
39 virtual void DidAccept(net::StreamListenSocket* server, | 49 virtual void DidAccept(net::StreamListenSocket* server, |
40 scoped_ptr<net::StreamListenSocket> socket) OVERRIDE; | 50 scoped_ptr<net::StreamListenSocket> socket) OVERRIDE; |
41 virtual void DidRead(net::StreamListenSocket* socket, | 51 virtual void DidRead(net::StreamListenSocket* socket, |
42 const char* data, | 52 const char* data, |
43 int len) OVERRIDE; | 53 int len) OVERRIDE; |
44 virtual void DidClose(net::StreamListenSocket* socket) OVERRIDE; | 54 virtual void DidClose(net::StreamListenSocket* socket) OVERRIDE; |
45 | 55 |
46 // Create socket for authorization. | 56 // Create socket for authorization. |
47 void CreateAuthorizationSocket(); | 57 void CreateAuthorizationSocket(); |
48 | 58 |
49 // Process a gnubby request. | 59 // Process a gnubby request. |
50 void ProcessGnubbyRequest(int connection_id, const char* data, int data_len); | 60 void ProcessGnubbyRequest(int connection_id, const std::string& request_data); |
| 61 |
| 62 // Gets an active socket iterator for the connection id in |message|. |
| 63 ActiveSockets::iterator GetSocketForMessage(base::DictionaryValue* message); |
| 64 |
| 65 // Send an error and close an active socket. |
| 66 void SendErrorAndCloseActiveSocket(const ActiveSockets::iterator& iter); |
| 67 |
| 68 // A request timed out. |
| 69 void RequestTimedOut(int connection_id); |
51 | 70 |
52 // Interface through which communication with the client occurs. | 71 // Interface through which communication with the client occurs. |
53 protocol::ClientStub* client_stub_; | 72 protocol::ClientStub* client_stub_; |
54 | 73 |
55 // Socket used to listen for authorization requests. | 74 // Socket used to listen for authorization requests. |
56 scoped_ptr<net::StreamListenSocket> auth_socket_; | 75 scoped_ptr<net::StreamListenSocket> auth_socket_; |
57 | 76 |
58 // The last assigned gnubby connection id. | 77 // The last assigned gnubby connection id. |
59 int last_connection_id_; | 78 int last_connection_id_; |
60 | 79 |
61 // Sockets by connection id used to process gnubbyd requests. | 80 // Sockets by connection id used to process gnubbyd requests. |
62 typedef std::map<int, net::StreamListenSocket*> ActiveSockets; | |
63 ActiveSockets active_sockets_; | 81 ActiveSockets active_sockets_; |
64 | 82 |
65 // Partial gnubbyd request data by connection id. | |
66 typedef std::map<int, std::vector<char> > ActiveRequests; | |
67 ActiveRequests active_requests_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerPosix); | 83 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerPosix); |
70 }; | 84 }; |
71 | 85 |
72 } // namespace remoting | 86 } // namespace remoting |
73 | 87 |
74 #endif // REMOTING_HOST_GNUBBY_AUTH_HANDLER_POSIX_H_ | 88 #endif // REMOTING_HOST_GNUBBY_AUTH_HANDLER_POSIX_H_ |
OLD | NEW |