00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef SOCKS5BYTESTREAMSERVER_H__
00015 #define SOCKS5BYTESTREAMSERVER_H__
00016
00017 #include "macros.h"
00018 #include "connectionhandler.h"
00019 #include "logsink.h"
00020 #include "mutex.h"
00021
00022 namespace gloox
00023 {
00024
00025 class ConnectionTCPServer;
00026
00037 class GLOOX_API SOCKS5BytestreamServer : public ConnectionHandler, public ConnectionDataHandler
00038 {
00039
00040 friend class SOCKS5BytestreamManager;
00041
00042 public:
00049 SOCKS5BytestreamServer( const LogSink& logInstance, int port, const std::string& ip = "" );
00050
00054 ~SOCKS5BytestreamServer();
00055
00061 ConnectionError listen();
00062
00069 ConnectionError recv( int timeout );
00070
00074 void stop();
00075
00076
00077 virtual void handleIncomingConnection( ConnectionBase* connection );
00078
00079
00080 virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
00081
00082
00083 virtual void handleConnect( const ConnectionBase* connection );
00084
00085
00086 virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
00087
00088 private:
00089 SOCKS5BytestreamServer& operator=( const SOCKS5BytestreamServer& );
00090 void registerHash( const std::string& hash );
00091 void removeHash( const std::string& hash );
00092 ConnectionBase* getConnection( const std::string& hash );
00093
00094 enum NegotiationState
00095 {
00096 StateDisconnected,
00097 StateUnnegotiated,
00098 StateAuthmethodAccepted,
00099 StateAuthAccepted,
00100 StateDestinationAccepted,
00101 StateActive
00102 };
00103
00104 struct ConnectionInfo
00105 {
00106 NegotiationState state;
00107 std::string hash;
00108 };
00109
00110 typedef std::map<ConnectionBase*, ConnectionInfo> ConnectionMap;
00111 ConnectionMap m_connections;
00112
00113 typedef std::list<const ConnectionBase*> ConnectionList;
00114 ConnectionList m_oldConnections;
00115
00116 typedef std::list<std::string> HashMap;
00117 HashMap m_hashes;
00118
00119 ConnectionTCPServer* m_tcpServer;
00120
00121 Mutex m_mutex;
00122 const LogSink& m_logInstance;
00123 std::string m_ip;
00124 int m_port;
00125
00126 };
00127
00128 }
00129
00130 #endif // SOCKS5BYTESTREAMSERVER_H__