gloox  1.0.20
socks5bytestreamserver.h
1 /*
2  Copyright (c) 2007-2017 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef SOCKS5BYTESTREAMSERVER_H__
15 #define SOCKS5BYTESTREAMSERVER_H__
16 
17 #include "macros.h"
18 #include "connectionhandler.h"
19 #include "connectiontcpserver.h"
20 #include "logsink.h"
21 #include "mutex.h"
22 
23 namespace gloox
24 {
25 
37  {
38 
39  friend class SOCKS5BytestreamManager;
40 
41  public:
48  SOCKS5BytestreamServer( const LogSink& logInstance, int port, const std::string& ip = EmptyString );
49 
54 
60  ConnectionError listen();
61 
68  ConnectionError recv( int timeout );
69 
73  void stop();
74 
80  int localPort() const;
81 
87  const std::string localInterface() const;
88 
93  int serverSocket() const { return m_tcpServer->socket(); }
94 
95  // reimplemented from ConnectionHandler
96  virtual void handleIncomingConnection( ConnectionBase* server, ConnectionBase* connection );
97 
98  // reimplemented from ConnectionDataHandler
99  virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
100 
101  // reimplemented from ConnectionDataHandler
102  virtual void handleConnect( const ConnectionBase* connection );
103 
104  // reimplemented from ConnectionDataHandler
105  virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
106 
107  private:
108  SOCKS5BytestreamServer& operator=( const SOCKS5BytestreamServer& );
109  void registerHash( const std::string& hash );
110  void removeHash( const std::string& hash );
111  ConnectionBase* getConnection( const std::string& hash );
112 
113  enum NegotiationState
114  {
116  StateUnnegotiated,
117  StateAuthmethodAccepted,
118  StateAuthAccepted,
119  StateDestinationAccepted,
120  StateActive
121  };
122 
123  struct ConnectionInfo
124  {
125  NegotiationState state;
126  std::string hash;
127  };
128 
129  typedef std::map<ConnectionBase*, ConnectionInfo> ConnectionMap;
130  ConnectionMap m_connections;
131 
132  typedef std::list<const ConnectionBase*> ConnectionList;
133  ConnectionList m_oldConnections;
134 
135  typedef std::list<std::string> HashMap;
136  HashMap m_hashes;
137 
138  ConnectionTCPServer* m_tcpServer;
139 
140  util::Mutex m_mutex;
141  const LogSink& m_logInstance;
142  std::string m_ip;
143  int m_port;
144 
145  };
146 
147 }
148 
149 #endif // SOCKS5BYTESTREAMSERVER_H__
An abstract base class for a connection.
This is an implementation of a simple listening TCP connection.
A server listening for SOCKS5 bytestreams.
A simple implementation of mutex as a wrapper around a pthread mutex or a win32 critical section...
Definition: mutex.h:33
ConnectionError
Definition: gloox.h:683
An SOCKS5BytestreamManager dispatches SOCKS5 Bytestreams.
This is an abstract base class to receive events from a ConnectionBase-derived object.
This is an abstract base class to receive incoming connection attempts. Do not confuse this with Conn...
The namespace for the gloox library.
Definition: adhoc.cpp:27
An implementation of log sink and source.
Definition: logsink.h:38
const std::string EmptyString
Definition: gloox.cpp:124