gloox  1.0.16
socks5bytestreammanager.h
1 /*
2  Copyright (c) 2007-2015 by Jakob Schröter <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 SOCKS5BYTESTREAMMANAGER_H__
15 #define SOCKS5BYTESTREAMMANAGER_H__
16 
17 #include "iqhandler.h"
18 #include "jid.h"
19 #include "stanzaextension.h"
20 
21 namespace gloox
22 {
23 
24  class BytestreamHandler;
25  class SOCKS5BytestreamServer;
26  class SOCKS5Bytestream;
27  class ClientBase;
28 
32  struct StreamHost
33  {
34  JID jid;
35  std::string host;
36  int port;
37 // std::string zeroconf; /**< A zeroconf identifier. */
38  };
39 
43  typedef std::list<StreamHost> StreamHostList;
44 
51  class GLOOX_API SOCKS5BytestreamManager : public IqHandler
52  {
53 
54  friend class SOCKS5Bytestream;
55 
56  public:
57 
61  enum S5BMode
62  {
65  S5BInvalid
66  };
67 
75 
79  virtual ~SOCKS5BytestreamManager();
80 
86  void setStreamHosts( StreamHostList hosts ) { m_hosts = hosts; }
87 
94  void addStreamHost( const JID& jid, const std::string& host, int port );
95 
111  bool requestSOCKS5Bytestream( const JID& to, S5BMode mode, const std::string& sid = EmptyString,
112  const JID& from = JID() );
113 
120  bool dispose( SOCKS5Bytestream* s5b );
121 
126  void acceptSOCKS5Bytestream( const std::string& sid );
127 
133  void rejectSOCKS5Bytestream( const std::string& sid, StanzaError reason = StanzaErrorNotAcceptable );
134 
142  { m_socks5BytestreamHandler = s5bh; }
143 
148  { m_socks5BytestreamHandler = 0; }
149 
155  void registerSOCKS5BytestreamServer( SOCKS5BytestreamServer* server ) { m_server = server; }
156 
160  void removeSOCKS5BytestreamServer() { m_server = 0; }
161 
162  // reimplemented from IqHandler.
163  virtual bool handleIq( const IQ& iq );
164 
165  // reimplemented from IqHandler.
166  virtual void handleIqID( const IQ& iq, int context );
167 
168  private:
169 #ifdef SOCKS5BYTESTREAMMANAGER_TEST
170  public:
171 #endif
172 
173  class Query : public StanzaExtension
174  {
175  public:
179  Query();
180 
187  Query( const std::string& sid, S5BMode mode,
188  const StreamHostList& hosts );
189 
197  Query( const JID& jid, const std::string& sid, bool activate );
198 
203  Query( const Tag* tag );
204 
208  virtual ~Query();
209 
214  const std::string& sid() const { return m_sid; }
215 
220  const JID& jid() const { return m_jid; }
221 
226  S5BMode mode() const { return m_mode; }
227 
232  const StreamHostList& hosts() const { return m_hosts; }
233 
234  // reimplemented from StanzaExtension
235  virtual const std::string& filterString() const;
236 
237  // reimplemented from StanzaExtension
238  virtual StanzaExtension* newInstance( const Tag* tag ) const
239  {
240  return new Query( tag );
241  }
242 
243  // reimplemented from StanzaExtension
244  virtual Tag* tag() const;
245 
246  // reimplemented from StanzaExtension
247  virtual StanzaExtension* clone() const
248  {
249  return new Query( *this );
250  }
251 
252  private:
253  enum QueryType
254  {
255  TypeSH,
256  TypeSHU,
257  TypeA,
259  };
260 
261  std::string m_sid;
262  JID m_jid;
264  StreamHostList m_hosts;
265  QueryType m_type;
266 
267  };
268 
269  SOCKS5BytestreamManager& operator=( const SOCKS5BytestreamManager&);
270  void rejectSOCKS5Bytestream( const JID& from, const std::string& id, StanzaError reason = StanzaErrorNotAcceptable );
271  bool haveStream( const JID& from );
272  const StreamHost* findProxy( const JID& from, const std::string& hostjid, const std::string& sid );
273 
274  void acknowledgeStreamHost( bool success, const JID& jid, const std::string& sid );
275 
276  enum IBBActionType
277  {
278  S5BOpenStream,
279  S5BCloseStream,
280  S5BActivateStream
281  };
282 
283  typedef std::map<std::string, SOCKS5Bytestream*> S5BMap;
284  S5BMap m_s5bMap;
285 
286  struct AsyncS5BItem
287  {
288  JID from;
289  JID to;
290  std::string id;
291  StreamHostList sHosts;
292  bool incoming;
293  };
294  typedef std::map<std::string, AsyncS5BItem> AsyncTrackMap;
295  AsyncTrackMap m_asyncTrackMap;
296 
297  ClientBase* m_parent;
298  BytestreamHandler* m_socks5BytestreamHandler;
299  SOCKS5BytestreamServer* m_server;
300  StreamHostList m_hosts;
301  StringMap m_trackMap;
302 
303  };
304 
305 }
306 
307 #endif // SOCKS5BYTESTREAMMANAGER_H__
void setStreamHosts(StreamHostList hosts)
A server listening for SOCKS5 bytestreams.
An abstraction of an IQ stanza.
Definition: iq.h:33
An SOCKS5BytestreamManager dispatches SOCKS5 Bytestreams.
std::list< StreamHost > StreamHostList
StanzaError
Definition: gloox.h:866
The namespace for the gloox library.
Definition: adhoc.cpp:27
This class abstracts a stanza extension, which is usually an element in a specific namespace...
std::map< std::string, std::string > StringMap
Definition: gloox.h:1254
An abstraction of a JID.
Definition: jid.h:30
void registerSOCKS5BytestreamServer(SOCKS5BytestreamServer *server)
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition: iqhandler.h:31
An implementation of a single SOCKS5 Bytestream (XEP-0065).
void registerBytestreamHandler(BytestreamHandler *s5bh)
A virtual interface that allows to receive new incoming Bytestream requests from remote entities...
const std::string EmptyString
Definition: gloox.cpp:123
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition: clientbase.h:76
This is an abstraction of an XML element.
Definition: tag.h:46