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();
879 GLOOX_DEPRECATED std::string m_selectedResource;
888 std::string m_server;
891 bool m_compressionActive;
893 bool m_encryptionActive;
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__