socks5bytestreammanager.h
/*
Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#ifndef SOCKS5BYTESTREAMMANAGER_H__
#define SOCKS5BYTESTREAMMANAGER_H__
#include "iqhandler.h"
#include "jid.h"
#include "stanzaextension.h"
namespace gloox
{
class BytestreamHandler;
class SOCKS5BytestreamServer;
class SOCKS5Bytestream;
class ClientBase;
struct StreamHost
{
JID jid;
std::string host;
int port;
// std::string zeroconf; /**< A zeroconf identifier. */
};
typedef std::list<StreamHost> StreamHostList;
class GLOOX_API SOCKS5BytestreamManager : public IqHandler
{
friend class SOCKS5Bytestream;
public:
enum S5BMode
{
S5BTCP,
S5BUDP,
S5BInvalid
};
SOCKS5BytestreamManager( ClientBase* parent, BytestreamHandler* s5bh );
virtual ~SOCKS5BytestreamManager();
void setStreamHosts( StreamHostList hosts ) { m_hosts = hosts; }
void addStreamHost( const JID& jid, const std::string& host, int port );
bool requestSOCKS5Bytestream( const JID& to, S5BMode mode, const std::string& sid = EmptyString,
const JID& from = JID() );
bool dispose( SOCKS5Bytestream* s5b );
void acceptSOCKS5Bytestream( const std::string& sid );
void rejectSOCKS5Bytestream( const std::string& sid, StanzaError reason = StanzaErrorNotAcceptable );
void registerBytestreamHandler( BytestreamHandler* s5bh )
{ m_socks5BytestreamHandler = s5bh; }
void removeBytestreamHandler()
{ m_socks5BytestreamHandler = 0; }
void registerSOCKS5BytestreamServer( SOCKS5BytestreamServer* server ) { m_server = server; }
void removeSOCKS5BytestreamServer() { m_server = 0; }
// reimplemented from IqHandler.
virtual bool handleIq( const IQ& iq );
// reimplemented from IqHandler.
virtual void handleIqID( const IQ& iq, int context );
private:
#ifdef SOCKS5BYTESTREAMMANAGER_TEST
public:
#endif
class Query : public StanzaExtension
{
public:
Query();
Query( const std::string& sid, S5BMode mode,
const StreamHostList& hosts );
Query( const JID& jid, const std::string& sid, bool activate );
Query( const Tag* tag );
virtual ~Query();
const std::string& sid() const { return m_sid; }
const JID& jid() const { return m_jid; }
S5BMode mode() const { return m_mode; }
const StreamHostList& hosts() const { return m_hosts; }
// reimplemented from StanzaExtension
virtual const std::string& filterString() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* newInstance( const Tag* tag ) const
{
return new Query( tag );
}
// reimplemented from StanzaExtension
virtual Tag* tag() const;
// reimplemented from StanzaExtension
virtual StanzaExtension* clone() const
{
return new Query( *this );
}
private:
enum QueryType
{
TypeSH,
TypeSHU,
TypeA,
TypeInvalid
};
std::string m_sid;
JID m_jid;
SOCKS5BytestreamManager::S5BMode m_mode;
StreamHostList m_hosts;
QueryType m_type;
};
SOCKS5BytestreamManager& operator=( const SOCKS5BytestreamManager&);
void rejectSOCKS5Bytestream( const JID& from, const std::string& id, StanzaError reason = StanzaErrorNotAcceptable );
bool haveStream( const JID& from );
const StreamHost* findProxy( const JID& from, const std::string& hostjid, const std::string& sid );
void acknowledgeStreamHost( bool success, const JID& jid, const std::string& sid );
enum IBBActionType
{
S5BOpenStream,
S5BCloseStream,
S5BActivateStream
};
typedef std::map<std::string, SOCKS5Bytestream*> S5BMap;
S5BMap m_s5bMap;
struct AsyncS5BItem
{
JID from;
JID to;
std::string id;
StreamHostList sHosts;
bool incoming;
};
typedef std::map<std::string, AsyncS5BItem> AsyncTrackMap;
AsyncTrackMap m_asyncTrackMap;
ClientBase* m_parent;
BytestreamHandler* m_socks5BytestreamHandler;
SOCKS5BytestreamServer* m_server;
StreamHostList m_hosts;
StringMap m_trackMap;
};
}
#endif // SOCKS5BYTESTREAMMANAGER_H__
gloox::BytestreamHandler
A virtual interface that allows to receive new incoming Bytestream requests from remote entities.
Definition bytestreamhandler.h:37
gloox::ClientBase
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
Definition clientbase.h:79
gloox::IQ
An abstraction of an IQ stanza.
Definition iq.h:34
gloox::IqHandler
A virtual interface which can be reimplemented to receive IQ stanzas.
Definition iqhandler.h:32
gloox::JID
An abstraction of a JID.
Definition jid.h:31
gloox::SOCKS5BytestreamManager
An SOCKS5BytestreamManager dispatches SOCKS5 Bytestreams.
Definition socks5bytestreammanager.h:52
gloox::SOCKS5BytestreamManager::removeBytestreamHandler
void removeBytestreamHandler()
Definition socks5bytestreammanager.h:147
gloox::SOCKS5BytestreamManager::setStreamHosts
void setStreamHosts(StreamHostList hosts)
Definition socks5bytestreammanager.h:86
gloox::SOCKS5BytestreamManager::SOCKS5BytestreamManager
SOCKS5BytestreamManager(ClientBase *parent, BytestreamHandler *s5bh)
Definition socks5bytestreammanager.cpp:148
gloox::SOCKS5BytestreamManager::S5BMode
S5BMode
Definition socks5bytestreammanager.h:62
gloox::SOCKS5BytestreamManager::S5BTCP
@ S5BTCP
Definition socks5bytestreammanager.h:63
gloox::SOCKS5BytestreamManager::S5BUDP
@ S5BUDP
Definition socks5bytestreammanager.h:64
gloox::SOCKS5BytestreamManager::S5BInvalid
@ S5BInvalid
Definition socks5bytestreammanager.h:65
gloox::SOCKS5BytestreamManager::registerSOCKS5BytestreamServer
void registerSOCKS5BytestreamServer(SOCKS5BytestreamServer *server)
Definition socks5bytestreammanager.h:155
gloox::SOCKS5BytestreamManager::registerBytestreamHandler
void registerBytestreamHandler(BytestreamHandler *s5bh)
Definition socks5bytestreammanager.h:141
gloox::SOCKS5BytestreamManager::removeSOCKS5BytestreamServer
void removeSOCKS5BytestreamServer()
Definition socks5bytestreammanager.h:160
gloox::SOCKS5BytestreamServer
A server listening for SOCKS5 bytestreams.
Definition socks5bytestreamserver.h:37
gloox::SOCKS5Bytestream
An implementation of a single SOCKS5 Bytestream (XEP-0065).
Definition socks5bytestream.h:43
gloox::StanzaExtension
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
Definition stanzaextension.h:204
gloox::Tag
This is an abstraction of an XML element.
Definition tag.h:47
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::EmptyString
const std::string EmptyString
Definition gloox.cpp:124
gloox::StanzaError
StanzaError
Definition gloox.h:872
gloox::StanzaErrorNotAcceptable
@ StanzaErrorNotAcceptable
Definition gloox.h:900
gloox::TypeInvalid
@ TypeInvalid
Definition dataform.h:44
gloox::StreamHostList
std::list< StreamHost > StreamHostList
Definition socks5bytestreammanager.h:43
gloox::StringMap
std::map< std::string, std::string > StringMap
Definition gloox.h:1261
gloox::StreamHost
Definition socks5bytestreammanager.h:33
gloox::StreamHost::port
int port
Definition socks5bytestreammanager.h:36
gloox::StreamHost::host
std::string host
Definition socks5bytestreammanager.h:35
gloox::StreamHost::jid
JID jid
Definition socks5bytestreammanager.h:34