gloox  0.9.9.12
socks5bytestream.h
1 /*
2  Copyright (c) 2006-2008 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 SOCKS5BYTESTREAM_H__
15 #define SOCKS5BYTESTREAM_H__
16 
17 #include "messagefilter.h"
18 #include "iqhandler.h"
19 #include "gloox.h"
20 #include "socks5bytestreammanager.h"
21 #include "connectiondatahandler.h"
22 
23 #include <string>
24 
25 namespace gloox
26 {
27 
28  class ClientBase;
29  class SOCKS5BytestreamDataHandler;
30  class ConnectionBase;
31  class LogSink;
32 
44  class GLOOX_API SOCKS5Bytestream : public ConnectionDataHandler
45  {
46  friend class SOCKS5BytestreamManager;
47 
48  public:
52  virtual ~SOCKS5Bytestream();
53 
58  bool isOpen() const { return m_open; }
59 
71  bool connect();
72 
76  void close();
77 
87  bool send( const std::string& data );
88 
95  ConnectionError recv( int timeout = -1 );
96 
101  const std::string& sid() const { return m_sid; }
102 
108  const JID& target() const { return m_target; }
109 
115  const JID& initiator() const { return m_initiator; }
116 
122  void setConnectionImpl( ConnectionBase* connection );
123 
129  ConnectionBase* connectionImpl( ) { return m_connection; }
130 
135  void setStreamHosts( const StreamHostList& hosts ) { m_hosts = hosts; }
136 
143  void registerSOCKS5BytestreamDataHandler( SOCKS5BytestreamDataHandler *s5bdh )
144  { m_socks5BytestreamDataHandler = s5bdh; }
145 
149  void removeSOCKS5BytestreamDataHandler()
150  { m_socks5BytestreamDataHandler = 0; }
151 
152  // re-implemented from ConnectionDataHandler
153  virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
154 
155  // re-implemented from ConnectionDataHandler
156  virtual void handleConnect( const ConnectionBase* connection );
157 
158  // re-implemented from ConnectionDataHandler
159  virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
160 
161  private:
163  LogSink& logInstance, const JID& initiator, const JID& target,
164  const std::string& sid );
165  void activate();
166 
167  SOCKS5BytestreamManager *m_manager;
168  ConnectionBase* m_connection;
169  ConnectionBase* m_socks5;
170  const LogSink& m_logInstance;
171  SOCKS5BytestreamDataHandler *m_socks5BytestreamDataHandler;
172  const JID m_initiator;
173  const JID m_target;
174  std::string m_sid;
175  bool m_open;
176  JID m_proxy;
177 
178  StreamHostList m_hosts;
179 
180  };
181 
182 }
183 
184 #endif // SOCKS5BYTESTREAM_H__