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 );
683 virtual void handleTag(
Tag* tag );
686 virtual void handleCompressedData(
const std::string& data );
689 virtual void handleDecompressedData(
const std::string& data );
692 virtual void handleReceivedData(
const ConnectionBase* connection,
const std::string& data );
701 virtual void handleEncryptedData(
const TLSBase* base,
const std::string& data );
704 virtual void handleDecryptedData(
const TLSBase* base,
const std::string& data );
707 virtual void handleHandshakeResult(
const TLSBase* base,
bool success,
CertInfo &certinfo );
715 void notifyOnResourceBindError(
const Error* error );
721 void notifyOnResourceBind(
const std::string& resource );
728 void notifyOnSessionCreateError(
const Error* error );
737 bool notifyOnTLSConnect(
const CertInfo& info );
742 void notifyOnConnect();
781 virtual bool checkStreamVersion(
const std::string& version );
792 void processSASLSuccess();
798 void processSASLChallenge(
const std::string& challenge );
804 void processSASLError(
Tag* tag );
828 void send(
const std::string& xml );
841 GLOOX_DEPRECATED std::string m_selectedResource;
850 std::string m_server;
853 bool m_compressionActive;
855 bool m_encryptionActive;
869 #ifdef CLIENTBASE_TEST
893 virtual const std::string& filterString()
const;
903 virtual Tag* tag()
const
924 virtual void handleStartNode(
const Tag* start ) = 0;
931 virtual bool handleNormalNode(
Tag* tag ) = 0;
932 virtual void rosterFilled() = 0;
933 virtual void cleanup() {}
934 virtual void handleIqIDForward(
const IQ& iq,
int context ) { (void) iq; (void) context; }
936 void parse(
const std::string& data );
938 void handleStreamError( Tag* tag );
939 TLSBase* getDefaultEncryption();
940 CompressionBase* getDefaultCompression();
942 void notifyIqHandlers( IQ& iq );
943 void notifyMessageHandlers( Message& msg );
944 void notifyPresenceHandlers( Presence& presence );
945 void notifySubscriptionHandlers( Subscription& s10n );
946 void notifyTagHandlers( Tag* tag );
948 void addFrom( Tag* tag );
949 void addNamespace( Tag* tag );
952 virtual bool handleIq(
const IQ& iq );
955 virtual void handleIqID(
const IQ& iq,
int context );
964 struct TagHandlerStruct
971 struct JidPresHandlerStruct
982 typedef std::list<ConnectionListener*> ConnectionListenerList;
983 typedef std::multimap<const std::string, IqHandler*> IqHandlerMapXmlns;
984 typedef std::multimap<const int, IqHandler*> IqHandlerMap;
985 typedef std::map<const std::string, TrackStruct> IqTrackMap;
986 typedef std::map<const std::string, MessageHandler*> MessageHandlerMap;
987 typedef std::list<MessageSession*> MessageSessionList;
988 typedef std::list<MessageHandler*> MessageHandlerList;
989 typedef std::list<PresenceHandler*> PresenceHandlerList;
990 typedef std::list<JidPresHandlerStruct> PresenceJidHandlerList;
991 typedef std::list<SubscriptionHandler*> SubscriptionHandlerList;
992 typedef std::list<TagHandlerStruct> TagHandlerList;
994 ConnectionListenerList m_connectionListeners;
995 IqHandlerMapXmlns m_iqNSHandlers;
996 IqHandlerMap m_iqExtHandlers;
997 IqTrackMap m_iqIDHandlers;
998 MessageSessionList m_messageSessions;
999 MessageHandlerList m_messageHandlers;
1000 PresenceHandlerList m_presenceHandlers;
1001 PresenceJidHandlerList m_presenceJidHandlers;
1002 SubscriptionHandlerList m_subscriptionHandlers;
1003 TagHandlerList m_tagHandlers;
1005 StatisticsHandler * m_statisticsHandler;
1006 MUCInvitationHandler * m_mucInvitationHandler;
1007 MessageSessionHandler * m_messageSessionHandlerChat;
1008 MessageSessionHandler * m_messageSessionHandlerGroupchat;
1009 MessageSessionHandler * m_messageSessionHandlerHeadline;
1010 MessageSessionHandler * m_messageSessionHandlerNormal;
1012 util::Mutex m_iqHandlerMapMutex;
1013 util::Mutex m_iqExtHandlerMapMutex;
1016 LogSink m_logInstance;
1017 StanzaExtensionFactory* m_seFactory;
1018 EventDispatcher m_dispatcher;
1023 std::string m_streamErrorCData;
1024 Tag* m_streamErrorAppCondition;
1026 StatisticsStruct m_stats;
1030 std::string m_ntlmDomain;
1031 bool m_autoMessageSession;
1032 bool m_customConnection;
1035 util::AtomicRefCount m_nextId;
1037 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
1038 CredHandle m_credHandle;
1039 CtxtHandle m_ctxtHandle;
1046 #endif // CLIENTBASE_H__