connectionsocks5proxy.h

00001 /*
00002   Copyright (c) 2007-2008 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 CONNECTIONSOCKS5PROXY_H__
00015 #define CONNECTIONSOCKS5PROXY_H__
00016 
00017 #include "gloox.h"
00018 #include "connectionbase.h"
00019 #include "logsink.h"
00020 
00021 #include <string>
00022 
00023 namespace gloox
00024 {
00025 
00053   class GLOOX_API ConnectionSOCKS5Proxy : public ConnectionBase, public ConnectionDataHandler
00054   {
00055     public:
00070       ConnectionSOCKS5Proxy( ConnectionBase *connection, const LogSink& logInstance,
00071                              const std::string& server, int port = -1, bool ip = false );
00072 
00085       ConnectionSOCKS5Proxy( ConnectionDataHandler *cdh, ConnectionBase *connection,
00086                              const LogSink& logInstance,
00087                              const std::string& server, int port = -1, bool ip = false );
00088 
00092       virtual ~ConnectionSOCKS5Proxy();
00093 
00094       // reimplemented from ConnectionBase
00095       virtual ConnectionError connect();
00096 
00097       // reimplemented from ConnectionBase
00098       virtual ConnectionError recv( int timeout = -1 );
00099 
00100       // reimplemented from ConnectionBase
00101       virtual bool send( const std::string& data );
00102 
00103       // reimplemented from ConnectionBase
00104       virtual ConnectionError receive();
00105 
00106       // reimplemented from ConnectionBase
00107       virtual void disconnect();
00108 
00109       // reimplemented from ConnectionBase
00110       virtual void cleanup();
00111 
00112       // reimplemented from ConnectionBase
00113       virtual void getStatistics( int &totalIn, int &totalOut );
00114 
00115       // reimplemented from ConnectionDataHandler
00116       virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
00117 
00118       // reimplemented from ConnectionDataHandler
00119       virtual void handleConnect( const ConnectionBase* connection );
00120 
00121       // reimplemented from ConnectionDataHandler
00122       virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
00123 
00124       // reimplemented from ConnectionDataHandler
00125       virtual ConnectionBase* newInstance() const;
00126 
00134       void setServer( const std::string& host, int port = -1, bool ip = false )
00135         { m_server = host; m_port = port; m_ip = ip; }
00136 
00142       void setProxyAuth( const std::string& user, const std::string& password )
00143         { m_proxyUser = user; m_proxyPassword = password; }
00144 
00149       void setConnectionImpl( ConnectionBase* connection );
00150 
00151    private:
00152      enum Socks5State
00153      {
00154        S5StateDisconnected,
00155        S5StateConnecting,
00156        S5StateNegotiating,
00157        S5StateAuthenticating,
00158        S5StateConnected
00159      };
00160 
00161       ConnectionSOCKS5Proxy &operator=( const ConnectionSOCKS5Proxy& );
00162       void negotiate();
00163 
00164       ConnectionBase* m_connection;
00165       const LogSink& m_logInstance;
00166 
00167       Socks5State m_s5state;
00168 
00169       std::string m_proxyUser;
00170       std::string m_proxyPassword;
00171       std::string m_proxyHandshakeBuffer;
00172       bool m_ip;
00173 
00174   };
00175 
00176 }
00177 
00178 #endif // CONNECTIONSOCKS5PROXY_H__

Generated on Fri Oct 10 15:26:11 2008 for gloox by  doxygen 1.5.6