socks5bytestreamserver.h

00001 /*
00002   Copyright (c) 2007-2009 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
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 = EmptyString );
00050 
00054       ~SOCKS5BytestreamServer();
00055 
00061       ConnectionError listen();
00062 
00069       ConnectionError recv( int timeout );
00070 
00074       void stop();
00075 
00081       int localPort() const;
00082 
00088       const std::string localInterface() const;
00089 
00090       // reimplemented from ConnectionHandler
00091       virtual void handleIncomingConnection( ConnectionBase* server, ConnectionBase* connection );
00092 
00093       // reimplemented from ConnectionDataHandler
00094       virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
00095 
00096       // reimplemented from ConnectionDataHandler
00097       virtual void handleConnect( const ConnectionBase* connection );
00098 
00099       // reimplemented from ConnectionDataHandler
00100       virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
00101 
00102     private:
00103       SOCKS5BytestreamServer& operator=( const SOCKS5BytestreamServer& );
00104       void registerHash( const std::string& hash );
00105       void removeHash( const std::string& hash );
00106       ConnectionBase* getConnection( const std::string& hash );
00107 
00108       enum NegotiationState
00109       {
00110         StateDisconnected,
00111         StateUnnegotiated,
00112         StateAuthmethodAccepted,
00113         StateAuthAccepted,
00114         StateDestinationAccepted,
00115         StateActive
00116       };
00117 
00118       struct ConnectionInfo
00119       {
00120         NegotiationState state;
00121         std::string hash;
00122       };
00123 
00124       typedef std::map<ConnectionBase*, ConnectionInfo> ConnectionMap;
00125       ConnectionMap m_connections;
00126 
00127       typedef std::list<const ConnectionBase*> ConnectionList;
00128       ConnectionList m_oldConnections;
00129 
00130       typedef std::list<std::string> HashMap;
00131       HashMap m_hashes;
00132 
00133       ConnectionTCPServer* m_tcpServer;
00134 
00135       util::Mutex m_mutex;
00136       const LogSink& m_logInstance;
00137       std::string m_ip;
00138       int m_port;
00139 
00140   };
00141 
00142 }
00143 
00144 #endif // SOCKS5BYTESTREAMSERVER_H__
Generated on Tue Jun 8 23:37:54 2010 for gloox by  doxygen 1.6.3