Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

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 "connectiontcpserver.h"
00020 #include "logsink.h"
00021 #include "mutex.h"
00022 
00023 namespace gloox
00024 {
00025 
00036   class GLOOX_API SOCKS5BytestreamServer : public ConnectionHandler, public ConnectionDataHandler
00037   {
00038 
00039     friend class SOCKS5BytestreamManager;
00040 
00041     public:
00048       SOCKS5BytestreamServer( const LogSink& logInstance, int port, const std::string& ip = EmptyString );
00049 
00053       ~SOCKS5BytestreamServer();
00054 
00060       void setServerImpl( ConnectionBase *server );
00061 
00065       void removeServerImpl();
00066 
00072       ConnectionError listen();
00073 
00080       ConnectionError recv( int timeout );
00081 
00085       void stop();
00086 
00092       int localPort() const;
00093 
00099       const std::string localInterface() const;
00100 
00105       ConnectionBase* server() const { return m_server; }
00106 
00107       // reimplemented from ConnectionHandler
00108       virtual void handleIncomingConnection( ConnectionBase* server, ConnectionBase* connection );
00109 
00110       // reimplemented from ConnectionDataHandler
00111       virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
00112 
00113       // reimplemented from ConnectionDataHandler
00114       virtual void handleConnect( const ConnectionBase* connection );
00115 
00116       // reimplemented from ConnectionDataHandler
00117       virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
00118 
00119     private:
00120       SOCKS5BytestreamServer& operator=( const SOCKS5BytestreamServer& );
00121       void registerHash( const std::string& hash );
00122       void removeHash( const std::string& hash );
00123       ConnectionBase* getConnection( const std::string& hash );
00124 
00125       enum NegotiationState
00126       {
00127         StateDisconnected,
00128         StateUnnegotiated,
00129         StateAuthmethodAccepted,
00130         StateAuthAccepted,
00131         StateDestinationAccepted,
00132         StateActive
00133       };
00134 
00135       struct ConnectionInfo
00136       {
00137         NegotiationState state;
00138         std::string hash;
00139       };
00140 
00141       typedef std::map<ConnectionBase*, ConnectionInfo> ConnectionMap;
00142       ConnectionMap m_connections;
00143 
00144       typedef std::list<const ConnectionBase*> ConnectionList;
00145       ConnectionList m_oldConnections;
00146 
00147       typedef std::list<std::string> HashMap;
00148       HashMap m_hashes;
00149 
00150       ConnectionBase* m_server;
00151 
00152       util::Mutex m_mutex;
00153       const LogSink& m_logInstance;
00154       std::string m_ip;
00155       int m_port;
00156 
00157   };
00158 
00159 }
00160 
00161 #endif // SOCKS5BYTESTREAMSERVER_H__

Generated on Tue May 4 16:35:13 2010 for gloox by  doxygen 1.4.1