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();
924 #ifdef CLIENTBASE_TEST
948 virtual const std::string& filterString()
const;
958 virtual Tag* tag()
const
979 virtual void handleStartNode(
const Tag* start ) = 0;
987 virtual bool handleNormalNode(
Tag* tag ) = 0;
988 virtual void rosterFilled() = 0;
989 virtual void cleanup() {}
990 virtual void handleIqIDForward(
const IQ& iq,
int context ) { (void) iq; (void) context; }
991 void send( Tag* tag,
bool queue,
bool del );
992 std::string hmac(
const std::string& str,
const std::string& key );
993 std::string hi(
const std::string& str,
const std::string& key,
int iter );
995 void parse(
const std::string& data );
997 void handleStreamError( Tag* tag );
998 TLSBase* getDefaultEncryption();
999 CompressionBase* getDefaultCompression();
1001 void notifyIqHandlers( IQ& iq );
1002 void notifyMessageHandlers( Message& msg );
1003 void notifyPresenceHandlers( Presence& presence );
1004 void notifySubscriptionHandlers( Subscription& s10n );
1005 void notifyTagHandlers( Tag* tag );
1007 void addFrom( Tag* tag );
1008 void addNamespace( Tag* tag );
1011 virtual bool handleIq(
const IQ& iq );
1014 virtual void handleIqID(
const IQ& iq,
int context );
1023 struct TagHandlerStruct
1030 struct JidPresHandlerStruct
1033 PresenceHandler* ph;
1041 typedef std::list<ConnectionListener*> ConnectionListenerList;
1042 typedef std::multimap<const std::string, IqHandler*> IqHandlerMapXmlns;
1043 typedef std::multimap<const int, IqHandler*> IqHandlerMap;
1044 typedef std::map<const std::string, TrackStruct> IqTrackMap;
1045 typedef std::map<const std::string, MessageHandler*> MessageHandlerMap;
1046 typedef std::map<int, Tag*> SMQueueMap;
1047 typedef std::list<MessageSession*> MessageSessionList;
1048 typedef std::list<MessageHandler*> MessageHandlerList;
1049 typedef std::list<PresenceHandler*> PresenceHandlerList;
1050 typedef std::list<JidPresHandlerStruct> PresenceJidHandlerList;
1051 typedef std::list<SubscriptionHandler*> SubscriptionHandlerList;
1052 typedef std::list<TagHandlerStruct> TagHandlerList;
1054 ConnectionListenerList m_connectionListeners;
1055 IqHandlerMapXmlns m_iqNSHandlers;
1056 IqHandlerMap m_iqExtHandlers;
1057 IqTrackMap m_iqIDHandlers;
1058 SMQueueMap m_smQueue;
1059 MessageSessionList m_messageSessions;
1060 MessageHandlerList m_messageHandlers;
1061 PresenceHandlerList m_presenceHandlers;
1062 PresenceJidHandlerList m_presenceJidHandlers;
1063 SubscriptionHandlerList m_subscriptionHandlers;
1064 TagHandlerList m_tagHandlers;
1066 StatisticsHandler * m_statisticsHandler;
1067 MUCInvitationHandler * m_mucInvitationHandler;
1068 MessageSessionHandler * m_messageSessionHandlerChat;
1069 MessageSessionHandler * m_messageSessionHandlerGroupchat;
1070 MessageSessionHandler * m_messageSessionHandlerHeadline;
1071 MessageSessionHandler * m_messageSessionHandlerNormal;
1073 util::Mutex m_iqHandlerMapMutex;
1074 util::Mutex m_iqExtHandlerMapMutex;
1075 util::Mutex m_queueMutex;
1078 LogSink m_logInstance;
1079 StanzaExtensionFactory* m_seFactory;
1080 EventDispatcher m_dispatcher;
1085 std::string m_streamErrorCData;
1086 Tag* m_streamErrorAppCondition;
1088 StatisticsStruct m_stats;
1092 std::string m_clientFirstMessageBare;
1093 std::string m_serverSignature;
1094 std::string m_gs2Header;
1095 std::string m_ntlmDomain;
1096 bool m_customConnection;
1099 util::AtomicRefCount m_nextId;
1103 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
1104 CredHandle m_credHandle;
1105 CtxtHandle m_ctxtHandle;
1112 #endif // CLIENTBASE_H__
An abstract base class for a connection.
AuthenticationError authError() const
const std::string & server() const
std::list< const StanzaExtension * > StanzaExtensionList
ConnectionBase * m_connection
An abstraction of a message session between any two entities.
TLSBase * encryptionImpl() const
A virtual interface which can be reimplemented to receive incoming subscription stanzas.
std::list< std::string > StringList
const std::string XMLNS_XMPP_PING
An base class for event handlers.
An abstraction of an IQ stanza.
This is an abstract base class for stream compression implementations.
virtual const std::string & username() const
void setAuthzid(const JID &authzid)
std::list< Tag * > TagList
GLOOX_DEPRECATED std::string m_selectedResource
A virtual interface which can be reimplemented to receive incoming message sessions.
A stanza error abstraction implemented as a StanzaExtension.
An abstraction of a presence stanza.
This is an abstract base class to receive events from a ConnectionBase-derived object.
void setCACerts(const StringList &cacerts)
An abstraction of a message stanza.
const std::string & streamErrorCData() const
const Tag * streamErrorAppCondition() const
const std::string & xmlLang() const
void setAuthFailure(AuthenticationError e)
The namespace for the gloox library.
A virtual interface which can be reimplemented to receive incoming message stanzas.
void setPassword(const std::string &password)
This class abstracts a stanza extension, which is usually an element in a specific namespace...
StanzaExtensionList m_presenceExtensions
A virtual interface which can be reimplemented to receive non-XMPP Core stanzas.
virtual Disco * disco() const
CompressionBase * m_compression
This class implements Jabber/XMPP roster handling in the jabber:iq:roster namespace.
A virtual interface which can be reimplemented to receive presence stanzas.
void setXmlLang(const std::string &xmllang)
std::map< std::string, std::string > StringMap
void setSASLMechanisms(int mechanisms)
std::string m_clientCerts
A virtual interface which can be reimplemented to receive IQ stanzas.
A handler that can be used to receive invitations to MUC rooms.
This class implements XEP-0030 (Service Discovery) and XEP-0092 (Software Version).
void setNTLMDomain(const std::string &domain)
void setCompression(bool compression)
An abstraction of a subscription stanza.
void setTls(TLSPolicy tls)
void setAuthed(bool authed)
StreamError streamError() const
virtual const std::string & password() const
An abstract base class for TLS implementations.
void setAuthcid(const std::string &authcid)
An implementation of log sink and source.
Derived classes can be registered as ConnectionListeners with the Client.
const StanzaExtensionList & presenceExtensions() const
An interface that allows for interacting with TLS implementations derived from TLSBase.
An abstract base class used to receive de/compressed data from a CompressionBase-derived object...
ConnectionBase * connectionImpl() const
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
This is an abstraction of an XML element.
CompressionBase * compressionImpl() const
A virtual interface which can be reimplemented to receive connection statistics.