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"
36 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
38 #define SECURITY_WIN32
53 class MessageSessionHandler;
54 class ConnectionListener;
57 class PresenceHandler;
58 class SubscriptionHandler;
59 class MUCInvitationHandler;
63 class CompressionBase;
64 class StanzaExtensionFactory;
91 ClientBase(
const std::string& ns,
const std::string& server,
int port = -1 );
102 ClientBase(
const std::string& ns,
const std::string& password,
103 const std::string& server,
int port = -1 );
122 bool connect(
bool block =
true );
137 virtual const std::string&
username()
const {
return m_jid.username(); }
146 const JID&
jid() {
return m_authzid ? m_authzid : m_jid; }
183 void setServer(
const std::string &server );
189 void setPassword(
const std::string &password ) { m_password = password; }
195 const std::string&
server()
const {
return m_server; }
201 bool sasl()
const {
return m_sasl; }
220 int port()
const {
return m_port; }
226 virtual const std::string&
password()
const {
return m_password; }
239 const std::string getID();
248 void send(
Tag* tag );
259 void send(
IQ& iq,
IqHandler* ih,
int context,
bool del =
false );
265 void send(
const IQ& iq );
271 void send(
const Message& msg );
301 const std::string&
xmlLang()
const {
return m_xmllang; }
309 void setXmlLang(
const std::string& xmllang ) { m_xmllang = xmllang; }
341 void setEncryptionImpl(
TLSBase* tb );
363 void whitespacePing();
390 void setAuthcid(
const std::string& authcid ) { m_authcid = authcid; }
415 bool removeStanzaExtension(
int ext );
432 void registerIqHandler(
IqHandler* ih,
int exttype );
502 void registerTagHandler(
TagHandler* th,
const std::string& tag,
503 const std::string& xmlns );
526 void removeIqHandler(
IqHandler* ih,
int exttype );
554 void removeTagHandler(
TagHandler* th,
const std::string& tag,
555 const std::string& xmlns );
560 void removeStatisticsHandler();
580 void setClientCert(
const std::string& clientKey,
const std::string& clientCerts );
617 const std::string& streamErrorText(
const std::string& lang =
"default" )
const;
657 void removeMUCInvitationHandler();
673 bool removePresenceExtension(
int type );
682 virtual void handleTag(
Tag* tag );
685 virtual void handleCompressedData(
const std::string& data );
688 virtual void handleDecompressedData(
const std::string& data );
691 virtual void handleReceivedData(
const ConnectionBase* connection,
const std::string& data );
700 virtual void handleEncryptedData(
const TLSBase* base,
const std::string& data );
703 virtual void handleDecryptedData(
const TLSBase* base,
const std::string& data );
706 virtual void handleHandshakeResult(
const TLSBase* base,
bool success,
CertInfo &certinfo );
714 void notifyOnResourceBindError(
const Error* error );
720 void notifyOnResourceBind(
const std::string& resource );
727 void notifyOnSessionCreateError(
const Error* error );
736 bool notifyOnTLSConnect(
const CertInfo& info );
741 void notifyOnConnect();
780 virtual bool checkStreamVersion(
const std::string& version );
791 void processSASLSuccess();
797 void processSASLChallenge(
const std::string& challenge );
803 void processSASLError(
Tag* tag );
833 std::string m_selectedResource;
840 std::string m_server;
843 bool m_compressionActive;
845 bool m_encryptionActive;
859 #ifdef CLIENTBASE_TEST
883 virtual const std::string& filterString()
const;
893 virtual Tag* tag()
const
912 virtual void handleStartNode() = 0;
919 virtual bool handleNormalNode(
Tag* tag ) = 0;
920 virtual void rosterFilled() = 0;
921 virtual void cleanup() {}
922 virtual void handleIqIDForward(
const IQ& iq,
int context ) { (void) iq; (void) context; }
924 void parse(
const std::string& data );
926 void handleStreamError( Tag* tag );
927 TLSBase* getDefaultEncryption();
928 CompressionBase* getDefaultCompression();
930 void notifyIqHandlers( IQ& iq );
931 void notifyMessageHandlers( Message& msg );
932 void notifyPresenceHandlers( Presence& presence );
933 void notifySubscriptionHandlers( Subscription& s10n );
934 void notifyTagHandlers( Tag* tag );
936 void send(
const std::string& xml );
937 void addFrom( Tag* tag );
938 void addNamespace( Tag* tag );
941 virtual bool handleIq(
const IQ& iq );
944 virtual void handleIqID(
const IQ& iq,
int context );
953 struct TagHandlerStruct
960 struct JidPresHandlerStruct
971 typedef std::list<ConnectionListener*> ConnectionListenerList;
972 typedef std::multimap<const std::string, IqHandler*> IqHandlerMapXmlns;
973 typedef std::multimap<const int, IqHandler*> IqHandlerMap;
974 typedef std::map<const std::string, TrackStruct> IqTrackMap;
975 typedef std::map<const std::string, MessageHandler*> MessageHandlerMap;
976 typedef std::list<MessageSession*> MessageSessionList;
977 typedef std::list<MessageHandler*> MessageHandlerList;
978 typedef std::list<PresenceHandler*> PresenceHandlerList;
979 typedef std::list<JidPresHandlerStruct> PresenceJidHandlerList;
980 typedef std::list<SubscriptionHandler*> SubscriptionHandlerList;
981 typedef std::list<TagHandlerStruct> TagHandlerList;
983 ConnectionListenerList m_connectionListeners;
984 IqHandlerMapXmlns m_iqNSHandlers;
985 IqHandlerMap m_iqExtHandlers;
986 IqTrackMap m_iqIDHandlers;
987 MessageSessionList m_messageSessions;
988 MessageHandlerList m_messageHandlers;
989 PresenceHandlerList m_presenceHandlers;
990 PresenceJidHandlerList m_presenceJidHandlers;
991 SubscriptionHandlerList m_subscriptionHandlers;
992 TagHandlerList m_tagHandlers;
994 StatisticsHandler * m_statisticsHandler;
995 MUCInvitationHandler * m_mucInvitationHandler;
996 MessageSessionHandler * m_messageSessionHandlerChat;
997 MessageSessionHandler * m_messageSessionHandlerGroupchat;
998 MessageSessionHandler * m_messageSessionHandlerHeadline;
999 MessageSessionHandler * m_messageSessionHandlerNormal;
1001 util::Mutex m_iqHandlerMapMutex;
1004 LogSink m_logInstance;
1005 StanzaExtensionFactory* m_seFactory;
1006 EventDispatcher m_dispatcher;
1011 std::string m_streamErrorCData;
1012 Tag* m_streamErrorAppCondition;
1014 StatisticsStruct m_stats;
1018 std::string m_ntlmDomain;
1019 bool m_autoMessageSession;
1021 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
1022 CredHandle m_credHandle;
1023 CtxtHandle m_ctxtHandle;
1030 #endif // CLIENTBASE_H__