gloox  1.0.9
connectionsocks5proxy.h
1 /*
2  Copyright (c) 2007-2013 by Jakob Schroeter <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 CONNECTIONSOCKS5PROXY_H__
15 #define CONNECTIONSOCKS5PROXY_H__
16 
17 #include "gloox.h"
18 #include "connectionbase.h"
19 #include "logsink.h"
20 
21 #include <string>
22 
23 namespace gloox
24 {
25 
54  {
55  public:
70  ConnectionSOCKS5Proxy( ConnectionBase* connection, const LogSink& logInstance,
71  const std::string& server, int port = -1, bool ip = false );
72 
86  const LogSink& logInstance,
87  const std::string& server, int port = -1, bool ip = false );
88 
92  virtual ~ConnectionSOCKS5Proxy();
93 
94  // reimplemented from ConnectionBase
95  virtual ConnectionError connect();
96 
97  // reimplemented from ConnectionBase
98  virtual ConnectionError recv( int timeout = -1 );
99 
100  // reimplemented from ConnectionBase
101  virtual bool send( const std::string& data );
102 
103  // reimplemented from ConnectionBase
104  virtual ConnectionError receive();
105 
106  // reimplemented from ConnectionBase
107  virtual void disconnect();
108 
109  // reimplemented from ConnectionBase
110  virtual void cleanup();
111 
112  // reimplemented from ConnectionBase
113  virtual void getStatistics( long int &totalIn, long int &totalOut );
114 
115  // reimplemented from ConnectionDataHandler
116  virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
117 
118  // reimplemented from ConnectionDataHandler
119  virtual void handleConnect( const ConnectionBase* connection );
120 
121  // reimplemented from ConnectionDataHandler
122  virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
123 
124  // reimplemented from ConnectionDataHandler
125  virtual ConnectionBase* newInstance() const;
126 
134  void setServer( const std::string& host, int port = -1, bool ip = false )
135  { m_server = host; m_port = port; m_ip = ip; }
136 
142  void setProxyAuth( const std::string& user, const std::string& password )
143  { m_proxyUser = user; m_proxyPwd = password; }
144 
149  void setConnectionImpl( ConnectionBase* connection );
150 
151  private:
152  enum Socks5State
153  {
154  S5StateDisconnected,
155  S5StateConnecting,
156  S5StateNegotiating,
157  S5StateAuthenticating,
158  S5StateConnected
159  };
160 
161  ConnectionSOCKS5Proxy &operator=( const ConnectionSOCKS5Proxy& );
162  void negotiate();
163 
164  ConnectionBase* m_connection;
165  const LogSink& m_logInstance;
166 
167  Socks5State m_s5state;
168 
169  std::string m_proxyUser;
170  std::string m_proxyPwd;
171  std::string m_proxyHandshakeBuffer;
172  bool m_ip;
173 
174  };
175 
176 }
177 
178 #endif // CONNECTIONSOCKS5PROXY_H__