gloox  1.0.1
siprofileft.h
1 /*
2  Copyright (c) 2007-2012 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 SIPROFILEFT_H__
15 #define SIPROFILEFT_H__
16 
17 #include "iqhandler.h"
18 #include "socks5bytestreammanager.h"
19 #include "siprofilehandler.h"
20 #include "sihandler.h"
21 #include "simanager.h"
22 #include "bytestreamhandler.h"
23 
24 #include <string>
25 #include <map>
26 
27 namespace gloox
28 {
29 
30  class ClientBase;
31  class InBandBytestream;
32  class IQ;
33  class JID;
34  class SIProfileFTHandler;
35  class SOCKS5Bytestream;
36 
150  class GLOOX_API SIProfileFT : public SIProfileHandler, public SIHandler,
151  public BytestreamHandler, public IqHandler
152  {
153  public:
158  {
159  FTTypeS5B = 1,
160  FTTypeIBB = 2,
161  FTTypeOOB = 4,
162  FTTypeAll = 0xFF
163  };
164 
178  SIProfileFT( ClientBase* parent, SIProfileFTHandler* sipfth, SIManager* manager = 0,
179  SOCKS5BytestreamManager* s5Manager = 0 );
180 
184  virtual ~SIProfileFT();
185 
202  const std::string requestFT( const JID& to, const std::string& name, long size,
203  const std::string& hash = EmptyString,
204  const std::string& desc = EmptyString,
205  const std::string& date = EmptyString,
206  const std::string& mimetype = EmptyString,
207  int streamTypes = FTTypeAll,
208  const JID& from = JID(),
209  const std::string& sid = EmptyString );
210 
221  void acceptFT( const JID& to, const std::string& sid,
222  StreamType type = FTTypeS5B, const JID& from = JID() );
223 
232  void declineFT( const JID& to, const std::string& sid, SIManager::SIError reason,
233  const std::string& text = EmptyString );
234 
241  void cancel( Bytestream* bs );
242 
248  void dispose( Bytestream* bs );
249 
256  void registerSIProfileFTHandler( SIProfileFTHandler* sipfth ) { m_handler = sipfth; }
257 
261  void removeSIProfileFTHandler() { m_handler = 0; }
262 
268  void setStreamHosts( StreamHostList hosts );
269 
276  void addStreamHost( const JID& jid, const std::string& host, int port );
277 
283  void registerSOCKS5BytestreamServer( SOCKS5BytestreamServer* server )
284  { if( m_socks5Manager ) m_socks5Manager->registerSOCKS5BytestreamServer( server ); }
285 
289  void removeSOCKS5BytestreamServer()
290  { if( m_socks5Manager ) m_socks5Manager->removeSOCKS5BytestreamServer(); }
291 
292  // reimplemented from SIProfileHandler
293  virtual void handleSIRequest( const JID& from, const JID& to, const std::string& id,
294  const SIManager::SI& si );
295 
296  // reimplemented from SIHandler
297  virtual void handleSIRequestResult( const JID& from, const JID& to, const std::string& sid,
298  const SIManager::SI& si );
299 
300  // reimplemented from SIHandler
301  virtual void handleSIRequestError( const IQ& iq, const std::string& sid );
302 
303  // reimplemented from BytestreamHandler
304  virtual void handleIncomingBytestreamRequest( const std::string& sid, const JID& from );
305 
306  // reimplemented from BytestreamHandler
307  virtual void handleIncomingBytestream( Bytestream* bs );
308 
309  // reimplemented from BytestreamHandler
310  virtual void handleOutgoingBytestream( Bytestream* bs );
311 
312  // reimplemented from BytestreamHandler
313  virtual void handleBytestreamError( const IQ& iq, const std::string& sid );
314 
315  // reimplemented from IqHandler.
316  virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
317 
318  // reimplemented from IqHandler.
319  virtual void handleIqID( const IQ& iq, int context );
320 
321  private:
322 
323  enum TrackEnum
324  {
325  OOBSent
326  };
327 
328  ClientBase* m_parent;
329  SIManager* m_manager;
330  SIProfileFTHandler* m_handler;
331  SOCKS5BytestreamManager* m_socks5Manager;
332  StreamHostList m_hosts;
333  StringMap m_id2sid;
334  bool m_delManager;
335  bool m_delS5Manager;
336 
337  };
338 
339 }
340 
341 #endif // SIPROFILEFT_H__