xmpp_c2s.h

Go to the documentation of this file.
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: 20385 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 2008) $
00030  */
00031 
00032 #ifndef _XMPP_C2S
00033 #define _XMPP_C2S
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 = PFalse);
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     protected:
00153       virtual void    OnOpen(Stream& stream, INT);
00154       virtual void    OnClose(Stream& stream, INT);
00155       virtual void    StartRegistration();
00156       virtual void    StartAuthNegotiation();
00157 
00158       virtual void    OnSessionEstablished();
00159       virtual void    OnSessionReleased();
00160       virtual void    OnElement(PXML& pdu);
00161       virtual void    OnError(PXML& pdu);
00162 
00163       virtual void    OnMessage(XMPP::Message& pdu);
00164       virtual void    OnPresence(XMPP::Presence& pdu);
00165       virtual void    OnIQ(XMPP::IQ& pdu);
00166 
00167       // State handlers
00168       virtual void    HandleNullState(PXML& pdu);
00169       virtual void    HandleRegStartedState(PXML& pdu);
00170       virtual void    HandleTLSStartedState(PXML& pdu);
00171 #if P_SASL2
00172       virtual void    HandleSASLStartedState(PXML& pdu);
00173 #endif
00174       virtual void    HandleNonSASLStartedState(PXML& pdu);
00175       virtual void    HandleStreamSentState(PXML& pdu);
00176       virtual void    HandleBindSentState(PXML& pdu);
00177       virtual void    HandleSessionSentState(PXML& pdu);
00178       virtual void    HandleEstablishedState(PXML& pdu);
00179 
00180       virtual PBoolean    Discover(const PString& xmlns,
00181                                const PString& jid,
00182                                PNotifier * responseHandler,
00183                                const PString& node);
00184 
00185       WORD                m_VersionMajor;
00186       WORD                m_VersionMinor;
00187       PString             m_StreamID;
00188       PBoolean                m_NewAccount;
00189       JID                 m_JID;
00190       const PString       m_Password;
00191 #if P_SASL2
00192       PSASLClient         m_SASL;
00193       PString             m_Mechanism;
00194 #endif
00195       PBoolean                m_HasBind;
00196       PBoolean                m_HasSession;
00197 
00198       PNotifierList       m_SessionEstablishedHandlers;
00199       PNotifierList       m_SessionReleasedHandlers;
00200       PNotifierList       m_ErrorHandlers;
00201       PNotifierList       m_MessageHandlers;
00202       PNotifierList       m_PresenceHandlers;
00203       PNotifierList       m_IQHandlers;
00204       PDictionary<PString, PNotifierList> m_IQNamespaceHandlers;
00205       PDictionary<JID, PNotifierList> m_MessageSenderHandlers;
00206 
00207       PMutex              m_PendingIQsLock;
00208       StanzaList          m_PendingIQs;
00209 
00210       enum StreamState
00211       {
00212         Null,
00213         RegStarted,
00214         TLSStarted,
00215         SASLStarted,
00216         NonSASLStarted, 
00217         StreamSent,
00218         BindSent,
00219         SessionSent,
00220         Established
00221       };
00222 
00223       virtual void SetState(StreamState s);
00224 
00225       StreamState m_State;
00226     };
00227 
00228   }  // namespace C2S
00229 } // namespace XMPP
00230 
00231 
00232 #endif  // P_EXPAT
00233 
00234 #endif  // _XMPP_C2S
00235 
00236 // End of File ///////////////////////////////////////////////////////////////
00237 
00238 
00239 

Generated on Mon Sep 15 01:21:35 2008 for PTLib by  doxygen 1.5.1