PTLib
Version 2.10.4
|
00001 /* 00002 * xmpp_c2s.h 00003 * 00004 * Extensible Messaging and Presence Protocol (XMPP) Core 00005 * Client to Server communication classes 00006 * 00007 * Portable Windows Library 00008 * 00009 * Copyright (c) 2004 Reitek S.p.A. 00010 * 00011 * The contents of this file are subject to the Mozilla Public License 00012 * Version 1.0 (the "License"); you may not use this file except in 00013 * compliance with the License. You may obtain a copy of the License at 00014 * http://www.mozilla.org/MPL/ 00015 * 00016 * Software distributed under the License is distributed on an "AS IS" 00017 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00018 * the License for the specific language governing rights and limitations 00019 * under the License. 00020 * 00021 * The Original Code is Portable Windows Library. 00022 * 00023 * The Initial Developer of the Original Code is Post Increment 00024 * 00025 * Contributor(s): ______________________________________. 00026 * 00027 * $Revision: 24875 $ 00028 * $Author: rjongbloed $ 00029 * $Date: 2010-11-12 02:03:15 -0600 (Fri, 12 Nov 2010) $ 00030 */ 00031 00032 #ifndef PTLIB_XMPP_C2S_H 00033 #define PTLIB_XMPP_C2S_H 00034 00035 #ifdef P_USE_PRAGMA 00036 #pragma interface 00037 #endif 00038 00039 #include <ptclib/xmpp.h> 00040 00041 #if P_EXPAT 00042 00043 #include <ptclib/psasl.h> 00044 #include <ptlib/sockets.h> 00045 00046 00048 00049 namespace XMPP 00050 { 00051 namespace C2S 00052 { 00053 00056 class TCPTransport : public Transport 00057 { 00058 PCLASSINFO(TCPTransport, Transport); 00059 00060 public: 00061 TCPTransport(const PString& hostname); 00062 TCPTransport(const PString& hostname, WORD port); 00063 ~TCPTransport(); 00064 00065 const PString& GetServerHost() const { return m_Hostname; } 00066 WORD GetServerPort() const { return m_Port; } 00067 00068 virtual PBoolean Open(); 00069 virtual PBoolean Close(); 00070 00071 protected: 00072 PString m_Hostname; 00073 WORD m_Port; 00074 PTCPSocket * m_Socket; 00075 }; 00076 00077 00081 class StreamHandler : public BaseStreamHandler 00082 { 00083 PCLASSINFO(StreamHandler, BaseStreamHandler); 00084 00085 public: 00086 StreamHandler(const JID& jid, const PString& pwd, PBoolean newAccount = false); 00087 ~StreamHandler(); 00088 00089 virtual PBoolean IsEstablished() const { return m_State == Established; } 00090 00091 virtual PBoolean Start(Transport * transport = 0); 00092 00099 PBoolean Send(Stanza * stanza); 00100 00101 void SetVersion(WORD major, WORD minor); 00102 void GetVersion(WORD& major, WORD& minor) const; 00103 00104 const JID& GetJID() const { return m_JID; } 00105 00111 PNotifierList& SessionEstablishedHandlers() { return m_SessionEstablishedHandlers; } 00112 PNotifierList& SessionReleasedHandlers() { return m_SessionReleasedHandlers; } 00113 00120 PNotifierList& ErrorHandlers() { return m_ErrorHandlers; } 00121 PNotifierList& MessageHandlers() { return m_MessageHandlers; } 00122 PNotifierList& PresenceHandlers() { return m_PresenceHandlers; } 00123 PNotifierList& IQHandlers() { return m_IQHandlers; } 00124 00129 PNotifierList& IQNamespaceHandlers(const PString& xml_namespace); 00130 00136 PNotifierList& MessageSenderHandlers(const JID& from); 00137 00142 virtual PBoolean DiscoverItems( 00143 const PString& jid, 00144 PNotifier * responseHandler, 00145 const PString& node = PString::Empty() 00146 ); 00147 virtual PBoolean DiscoverInfo( 00148 const PString& jid, 00149 PNotifier * responseHandler, 00150 const PString& node = PString::Empty() 00151 ); 00152 00153 protected: 00154 virtual void OnOpen(Stream& stream, INT); 00155 virtual void OnClose(Stream& stream, INT); 00156 virtual void StartRegistration(); 00157 virtual void StartAuthNegotiation(); 00158 00159 virtual void OnSessionEstablished(); 00160 virtual void OnSessionReleased(); 00161 virtual void OnElement(PXML& pdu); 00162 virtual void OnError(PXML& pdu); 00163 00164 virtual void OnMessage(XMPP::Message& pdu); 00165 virtual void OnPresence(XMPP::Presence& pdu); 00166 virtual void OnIQ(XMPP::IQ& pdu); 00167 00168 // State handlers 00169 virtual void HandleNullState(PXML& pdu); 00170 virtual void HandleRegStartedState(PXML& pdu); 00171 virtual void HandleTLSStartedState(PXML& pdu); 00172 #if P_SASL 00173 virtual void HandleSASLStartedState(PXML& pdu); 00174 #endif 00175 virtual void HandleNonSASLStartedState(PXML& pdu); 00176 virtual void HandleStreamSentState(PXML& pdu); 00177 virtual void HandleBindSentState(PXML& pdu); 00178 virtual void HandleSessionSentState(PXML& pdu); 00179 virtual void HandleEstablishedState(PXML& pdu); 00180 00181 virtual PBoolean Discover(const PString& xmlns, 00182 const PString& jid, 00183 PNotifier * responseHandler, 00184 const PString& node); 00185 00186 WORD m_VersionMajor; 00187 WORD m_VersionMinor; 00188 PString m_StreamID; 00189 PBoolean m_NewAccount; 00190 JID m_JID; 00191 const PString m_Password; 00192 #if P_SASL 00193 PSASLClient m_SASL; 00194 PString m_Mechanism; 00195 #endif 00196 PBoolean m_HasBind; 00197 PBoolean m_HasSession; 00198 00199 PNotifierList m_SessionEstablishedHandlers; 00200 PNotifierList m_SessionReleasedHandlers; 00201 PNotifierList m_ErrorHandlers; 00202 PNotifierList m_MessageHandlers; 00203 PNotifierList m_PresenceHandlers; 00204 PNotifierList m_IQHandlers; 00205 PDictionary<PString, PNotifierList> m_IQNamespaceHandlers; 00206 PDictionary<JID, PNotifierList> m_MessageSenderHandlers; 00207 00208 PMutex m_PendingIQsLock; 00209 StanzaList m_PendingIQs; 00210 00211 enum StreamState 00212 { 00213 Null, 00214 RegStarted, 00215 TLSStarted, 00216 SASLStarted, 00217 NonSASLStarted, 00218 StreamSent, 00219 BindSent, 00220 SessionSent, 00221 Established 00222 }; 00223 00224 virtual void SetState(StreamState s); 00225 00226 StreamState m_State; 00227 }; 00228 00229 } // namespace C2S 00230 } // namespace XMPP 00231 00232 00233 #endif // P_EXPAT 00234 00235 #endif // PTLIB_XMPP_C2S_H 00236 00237 // End of File ///////////////////////////////////////////////////////////////