socks5bytestreammanager.h

00001 /*
00002   Copyright (c) 2007 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
00011 */
00012 
00013 
00014 #ifndef SOCKS5BYTESTREAMMANAGER_H__
00015 #define SOCKS5BYTESTREAMMANAGER_H__
00016 
00017 #include "iqhandler.h"
00018 #include "jid.h"
00019 
00020 namespace gloox
00021 {
00022 
00023   class SOCKS5BytestreamHandler;
00024   class SOCKS5BytestreamServer;
00025   class SOCKS5Bytestream;
00026   class ClientBase;
00027 
00031   struct StreamHost
00032   {
00033     JID jid;                    
00034     std::string host;           
00035     int port;                   
00036 //         std::string zeroconf;       /**< A zeroconf identifier. */
00037   };
00038 
00042   typedef std::list<StreamHost> StreamHostList;
00043 
00050   class GLOOX_API SOCKS5BytestreamManager : public IqHandler
00051   {
00052 
00053     friend class SOCKS5Bytestream;
00054 
00055     public:
00056 
00060       enum S5BMode
00061       {
00062         S5BTCP/*,*/                     
00063         /*S5BUDP*/                      
00064       };
00065 
00072       SOCKS5BytestreamManager( ClientBase *parent, SOCKS5BytestreamHandler* s5bh );
00073 
00077       virtual ~SOCKS5BytestreamManager();
00078 
00084       void setStreamHosts( StreamHostList hosts ) { m_hosts = hosts; }
00085 
00092       void addStreamHost( const JID& jid, const std::string& host, int port );
00093 
00107       bool requestSOCKS5Bytestream( const JID& to, S5BMode mode, const std::string& sid = "" );
00108 
00115       bool dispose( SOCKS5Bytestream *s5b );
00116 
00121       void acceptSOCKS5Bytestream( const std::string& sid );
00122 
00127       void rejectSOCKS5Bytestream( const std::string& sid );
00128 
00135       void registerSOCKS5BytestreamHandler( SOCKS5BytestreamHandler *s5bh )
00136         { m_socks5BytestreamHandler = s5bh; }
00137 
00141       void removeSOCKS5BytestreamHandler()
00142         { m_socks5BytestreamHandler = 0; }
00143 
00149       void registerSOCKS5BytestreamServer( SOCKS5BytestreamServer* server ) { m_server = server; }
00150 
00154       void removeSOCKS5BytestreamServer() { m_server = 0; }
00155 
00156       // reimplemented from IqHandler
00157       virtual bool handleIq( Stanza *stanza );
00158 
00159       // reimplemented from IqHandler
00160       virtual bool handleIqID( Stanza *stanza, int context );
00161 
00162     private:
00163       void rejectSOCKS5Bytestream( const JID& from, const std::string& id, StanzaError reason );
00164       bool haveStream( const JID& from );
00165       const StreamHost* findProxy( const JID& from, const std::string& hostjid, const std::string& sid );
00166 
00167       void acknowledgeStreamHost( bool success, const JID& jid, const std::string& sid );
00168 
00169       enum IBBActionType
00170       {
00171         S5BOpenStream,
00172         S5BCloseStream,
00173         S5BActivateStream
00174       };
00175 
00176       typedef std::map<std::string, SOCKS5Bytestream*> S5BMap;
00177       S5BMap m_s5bMap;
00178 
00179       struct AsyncS5BItem
00180       {
00181         JID from;
00182         std::string id;
00183         StreamHostList sHosts;
00184         bool incoming;
00185       };
00186       typedef std::map<std::string, AsyncS5BItem> AsyncTrackMap;
00187       AsyncTrackMap m_asyncTrackMap;
00188 
00189       ClientBase *m_parent;
00190       SOCKS5BytestreamHandler* m_socks5BytestreamHandler;
00191       SOCKS5BytestreamServer* m_server;
00192       StreamHostList m_hosts;
00193       StringMap m_trackMap;
00194 
00195   };
00196 
00197 }
00198 
00199 #endif // SOCKS5BYTESTREAMMANAGER_H__

Generated on Sat Nov 10 08:50:27 2007 for gloox by  doxygen 1.5.3-20071008