gloox  0.9.9.12
socks5bytestreammanager.h
1 /*
2  Copyright (c) 2007-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 SOCKS5BYTESTREAMMANAGER_H__
15 #define SOCKS5BYTESTREAMMANAGER_H__
16 
17 #include "iqhandler.h"
18 #include "jid.h"
19 
20 namespace gloox
21 {
22 
23  class SOCKS5BytestreamHandler;
24  class SOCKS5BytestreamServer;
25  class SOCKS5Bytestream;
26  class ClientBase;
27 
31  struct StreamHost
32  {
33  JID jid;
34  std::string host;
35  int port;
36 // std::string zeroconf; /**< A zeroconf identifier. */
37  };
38 
42  typedef std::list<StreamHost> StreamHostList;
43 
50  class GLOOX_API SOCKS5BytestreamManager : public IqHandler
51  {
52 
53  friend class SOCKS5Bytestream;
54 
55  public:
56 
60  enum S5BMode
61  {
62  S5BTCP/*,*/
63  /*S5BUDP*/
64  };
65 
73 
77  virtual ~SOCKS5BytestreamManager();
78 
84  void setStreamHosts( StreamHostList hosts ) { m_hosts = hosts; }
85 
92  void addStreamHost( const JID& jid, const std::string& host, int port );
93 
107  bool requestSOCKS5Bytestream( const JID& to, S5BMode mode, const std::string& sid = "" );
108 
115  bool dispose( SOCKS5Bytestream *s5b );
116 
121  void acceptSOCKS5Bytestream( const std::string& sid );
122 
127  void rejectSOCKS5Bytestream( const std::string& sid );
128 
135  void registerSOCKS5BytestreamHandler( SOCKS5BytestreamHandler *s5bh )
136  { m_socks5BytestreamHandler = s5bh; }
137 
141  void removeSOCKS5BytestreamHandler()
142  { m_socks5BytestreamHandler = 0; }
143 
149  void registerSOCKS5BytestreamServer( SOCKS5BytestreamServer* server ) { m_server = server; }
150 
154  void removeSOCKS5BytestreamServer() { m_server = 0; }
155 
156  // reimplemented from IqHandler
157  virtual bool handleIq( Stanza *stanza );
158 
159  // reimplemented from IqHandler
160  virtual bool handleIqID( Stanza *stanza, int context );
161 
162  private:
163  void rejectSOCKS5Bytestream( const JID& from, const std::string& id, StanzaError reason );
164  bool haveStream( const JID& from );
165  const StreamHost* findProxy( const JID& from, const std::string& hostjid, const std::string& sid );
166 
167  void acknowledgeStreamHost( bool success, const JID& jid, const std::string& sid );
168 
169  enum IBBActionType
170  {
171  S5BOpenStream,
172  S5BCloseStream,
173  S5BActivateStream
174  };
175 
176  typedef std::map<std::string, SOCKS5Bytestream*> S5BMap;
177  S5BMap m_s5bMap;
178 
179  struct AsyncS5BItem
180  {
181  JID from;
182  std::string id;
183  StreamHostList sHosts;
184  bool incoming;
185  };
186  typedef std::map<std::string, AsyncS5BItem> AsyncTrackMap;
187  AsyncTrackMap m_asyncTrackMap;
188 
189  ClientBase *m_parent;
190  SOCKS5BytestreamHandler* m_socks5BytestreamHandler;
191  SOCKS5BytestreamServer* m_server;
192  StreamHostList m_hosts;
193  StringMap m_trackMap;
194 
195  };
196 
197 }
198 
199 #endif // SOCKS5BYTESTREAMMANAGER_H__