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