15 #ifndef CLIENTBASE_H__
16 #define CLIENTBASE_H__
20 #include "eventdispatcher.h"
21 #include "iqhandler.h"
25 #include "taghandler.h"
26 #include "statisticshandler.h"
27 #include "tlshandler.h"
28 #include "compressiondatahandler.h"
29 #include "connectiondatahandler.h"
31 #include "atomicrefcount.h"
37 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
39 #define SECURITY_WIN32
54 class MessageSessionHandler;
55 class ConnectionListener;
58 class PresenceHandler;
59 class SubscriptionHandler;
60 class MUCInvitationHandler;
64 class CompressionBase;
65 class StanzaExtensionFactory;
92 ClientBase(
const std::string& ns,
const std::string& server,
int port = -1 );
103 ClientBase(
const std::string& ns,
const std::string& password,
104 const std::string& server,
int port = -1 );
123 bool connect(
bool block =
true );
138 virtual const std::string&
username()
const {
return m_jid.username(); }
147 const JID&
jid() {
return m_authzid ? m_authzid : m_jid; }
184 void setServer(
const std::string &server );
190 void setPassword(
const std::string &password ) { m_password = password; }
196 const std::string&
server()
const {
return m_server; }
202 bool sasl()
const {
return m_sasl; }
221 int port()
const {
return m_port; }
227 virtual const std::string&
password()
const {
return m_password; }
240 const std::string getID();
249 void send(
Tag* tag );
260 void send(
IQ& iq,
IqHandler* ih,
int context,
bool del =
false );
266 void send(
const IQ& iq );
272 void send(
const Message& msg );
302 const std::string&
xmlLang()
const {
return m_xmllang; }
310 void setXmlLang(
const std::string& xmllang ) { m_xmllang = xmllang; }
342 void setEncryptionImpl(
TLSBase* tb );
364 void whitespacePing();
391 void setAuthcid(
const std::string& authcid ) { m_authcid = authcid; }
416 bool removeStanzaExtension(
int ext );
433 void registerIqHandler(
IqHandler* ih,
int exttype );
503 void registerTagHandler(
TagHandler* th,
const std::string& tag,
504 const std::string& xmlns );
527 void removeIqHandler(
IqHandler* ih,
int exttype );
555 void removeTagHandler(
TagHandler* th,
const std::string& tag,
556 const std::string& xmlns );
561 void removeStatisticsHandler();
581 void setClientCert(
const std::string& clientKey,
const std::string& clientCerts );
618 const std::string& streamErrorText(
const std::string& lang =
"default" )
const;
658 void removeMUCInvitationHandler();
674 bool removePresenceExtension(
int type );
692 virtual void handleTag(
Tag* tag );
695 virtual void handleCompressedData(
const std::string& data );
698 virtual void handleDecompressedData(
const std::string& data );
701 virtual void handleReceivedData(
const ConnectionBase* connection,
const std::string& data );
710 virtual void handleEncryptedData(
const TLSBase* base,
const std::string& data );
713 virtual void handleDecryptedData(
const TLSBase* base,
const std::string& data );
716 virtual void handleHandshakeResult(
const TLSBase* base,
bool success,
CertInfo &certinfo );
719 #ifdef CLIENTBASE_TEST
727 void notifyOnResourceBindError(
const Error* error );
733 void notifyOnResourceBind(
const std::string& resource );
740 void notifyOnSessionCreateError(
const Error* error );
749 bool notifyOnTLSConnect(
const CertInfo& info );
754 void notifyOnConnect();
793 virtual bool checkStreamVersion(
const std::string& version );
808 bool processSASLSuccess(
const std::string& payload );
814 void processSASLChallenge(
const std::string& challenge );
820 void processSASLError(
Tag* tag );
844 void send(
const std::string& xml );
854 void checkQueue(
int handled,
bool resend );
866 std::string getRandom();
925 #ifdef CLIENTBASE_TEST
949 virtual const std::string& filterString()
const;
959 virtual Tag* tag()
const
980 virtual void handleStartNode(
const Tag* start ) = 0;
988 virtual bool handleNormalNode(
Tag* tag ) = 0;
989 virtual void rosterFilled() = 0;
990 virtual void cleanup() {}
991 virtual void handleIqIDForward(
const IQ& iq,
int context ) { (void) iq; (void) context; }
992 void send( Tag* tag,
bool queue,
bool del );
993 std::string hmac(
const std::string& str,
const std::string& key );
994 std::string hi(
const std::string& str,
const std::string& key,
int iter );
996 void parse(
const std::string& data );
998 void handleStreamError( Tag* tag );
999 TLSBase* getDefaultEncryption();
1000 CompressionBase* getDefaultCompression();
1002 void notifyIqHandlers( IQ& iq );
1003 void notifyMessageHandlers( Message& msg );
1004 void notifyPresenceHandlers( Presence& presence );
1005 void notifySubscriptionHandlers( Subscription& s10n );
1006 void notifyTagHandlers( Tag* tag );
1008 void addFrom( Tag* tag );
1009 void addNamespace( Tag* tag );
1012 virtual bool handleIq(
const IQ& iq );
1015 virtual void handleIqID(
const IQ& iq,
int context );
1024 struct TagHandlerStruct
1031 struct JidPresHandlerStruct
1034 PresenceHandler* ph;
1042 typedef std::list<ConnectionListener*> ConnectionListenerList;
1043 typedef std::multimap<const std::string, IqHandler*> IqHandlerMapXmlns;
1044 typedef std::multimap<const int, IqHandler*> IqHandlerMap;
1045 typedef std::map<const std::string, TrackStruct> IqTrackMap;
1046 typedef std::map<const std::string, MessageHandler*> MessageHandlerMap;
1047 typedef std::map<int, Tag*> SMQueueMap;
1048 typedef std::list<MessageSession*> MessageSessionList;
1049 typedef std::list<MessageHandler*> MessageHandlerList;
1050 typedef std::list<PresenceHandler*> PresenceHandlerList;
1051 typedef std::list<JidPresHandlerStruct> PresenceJidHandlerList;
1052 typedef std::list<SubscriptionHandler*> SubscriptionHandlerList;
1053 typedef std::list<TagHandlerStruct> TagHandlerList;
1055 ConnectionListenerList m_connectionListeners;
1056 IqHandlerMapXmlns m_iqNSHandlers;
1057 IqHandlerMap m_iqExtHandlers;
1058 IqTrackMap m_iqIDHandlers;
1059 SMQueueMap m_smQueue;
1060 MessageSessionList m_messageSessions;
1061 MessageHandlerList m_messageHandlers;
1062 PresenceHandlerList m_presenceHandlers;
1063 PresenceJidHandlerList m_presenceJidHandlers;
1064 SubscriptionHandlerList m_subscriptionHandlers;
1065 TagHandlerList m_tagHandlers;
1067 StatisticsHandler * m_statisticsHandler;
1068 MUCInvitationHandler * m_mucInvitationHandler;
1069 MessageSessionHandler * m_messageSessionHandlerChat;
1070 MessageSessionHandler * m_messageSessionHandlerGroupchat;
1071 MessageSessionHandler * m_messageSessionHandlerHeadline;
1072 MessageSessionHandler * m_messageSessionHandlerNormal;
1074 util::Mutex m_iqHandlerMapMutex;
1075 util::Mutex m_iqExtHandlerMapMutex;
1076 util::Mutex m_queueMutex;
1079 LogSink m_logInstance;
1080 StanzaExtensionFactory* m_seFactory;
1081 EventDispatcher m_dispatcher;
1086 std::string m_streamErrorCData;
1087 Tag* m_streamErrorAppCondition;
1089 StatisticsStruct m_stats;
1093 std::string m_clientFirstMessageBare;
1094 std::string m_serverSignature;
1095 std::string m_gs2Header;
1096 std::string m_ntlmDomain;
1097 bool m_customConnection;
1099 std::string m_uniqueBaseId;
1100 util::AtomicRefCount m_nextId;
1104 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
1105 CredHandle m_credHandle;
1106 CtxtHandle m_ctxtHandle;
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
const Tag * streamErrorAppCondition() const
const std::string & server() const
void setCompression(bool compression)
std::string m_clientCerts
CompressionBase * compressionImpl() const
void setAuthFailure(AuthenticationError e)
void setAuthed(bool authed)
void setCACerts(const StringList &cacerts)
void setAuthcid(const std::string &authcid)
virtual Disco * disco() const
virtual const std::string & username() const
StanzaExtensionList m_presenceExtensions
void setPassword(const std::string &password)
const std::string & xmlLang() const
CompressionBase * m_compression
AuthenticationError authError() const
const StanzaExtensionList & presenceExtensions() const
GLOOX_DEPRECATED std::string m_selectedResource
virtual const std::string & password() const
void setSASLMechanisms(int mechanisms)
ConnectionBase * connectionImpl() const
void setNTLMDomain(const std::string &domain)
void setAuthzid(const JID &authzid)
void setXmlLang(const std::string &xmllang)
const std::string & streamErrorCData() const
ConnectionBase * m_connection
void setTls(TLSPolicy tls)
TLSBase * encryptionImpl() const
StreamError streamError() const
This is an abstract base class for stream compression implementations.
An abstract base class used to receive de/compressed data from a CompressionBase-derived object.
An abstract base class for a connection.
This is an abstract base class to receive events from a ConnectionBase-derived object.
Derived classes can be registered as ConnectionListeners with the Client.
This class implements XEP-0030 (Service Discovery) and XEP-0092 (Software Version).
A stanza error abstraction implemented as a StanzaExtension.
An base class for event handlers.
An abstraction of an IQ stanza.
A virtual interface which can be reimplemented to receive IQ stanzas.
An implementation of log sink and source.
A handler that can be used to receive invitations to MUC rooms.
A virtual interface which can be reimplemented to receive incoming message stanzas.
A virtual interface which can be reimplemented to receive incoming message sessions.
An abstraction of a message session between any two entities.
An abstraction of a message stanza.
A virtual interface which can be reimplemented to receive presence stanzas.
An abstraction of a presence stanza.
This class implements Jabber/XMPP roster handling in the jabber:iq:roster namespace.
This class abstracts a stanza extension, which is usually an XML child element in a specific namespac...
A virtual interface which can be reimplemented to receive connection statistics.
A virtual interface which can be reimplemented to receive incoming subscription stanzas.
An abstraction of a subscription stanza.
An abstract base class for TLS implementations.
An interface that allows for interacting with TLS implementations derived from TLSBase.
A virtual interface which can be reimplemented to receive non-XMPP Core stanzas.
This is an abstraction of an XML element.
The namespace for the gloox library.
std::list< Tag * > TagList
const std::string XMLNS_XMPP_PING
std::list< const StanzaExtension * > StanzaExtensionList
std::list< std::string > StringList
std::map< std::string, std::string > StringMap