Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

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  * $Log: xmpp_c2s.h,v $
00028  * Revision 1.6  2004/05/09 07:23:46  rjongbloed
00029  * More work on XMPP, thanks Federico Pinna and Reitek S.p.A.
00030  *
00031  * Revision 1.5  2004/04/28 11:26:42  csoutheren
00032  * Hopefully fixed SASL and SASL2 problems
00033  *
00034  * Revision 1.4  2004/04/26 19:44:30  dsandras
00035  * Fixes compilation with P_SASL = 0.
00036  *
00037  * Revision 1.3  2004/04/26 01:51:57  rjongbloed
00038  * More implementation of XMPP, thanks a lot to Federico Pinna & Reitek S.p.A.
00039  *
00040  * Revision 1.2  2004/04/23 06:07:24  csoutheren
00041  * Added #if P_SASL to allow operation without SASL
00042  *
00043  * Revision 1.1  2004/04/22 12:31:00  rjongbloed
00044  * Added PNotifier extensions and XMPP (Jabber) support,
00045  *   thanks to Federico Pinna and Reitek S.p.A.
00046  *
00047  *
00048  */
00049 
00050 #ifndef _XMPP_C2S
00051 #define _XMPP_C2S
00052 
00053 #ifdef P_USE_PRAGMA
00054 #pragma interface
00055 #endif
00056 
00057 #include <ptclib/xmpp.h>
00058 
00059 #if P_EXPAT
00060 
00061 #include <ptclib/psasl.h>
00062 #include <ptlib/sockets.h>
00063 
00064 
00066 
00067 namespace XMPP
00068 {
00069   namespace C2S
00070   {
00071 
00074     class TCPTransport : public Transport
00075     {
00076       PCLASSINFO(TCPTransport, Transport);
00077 
00078     public:
00079       TCPTransport(const PString& hostname);
00080       TCPTransport(const PString& hostname, WORD port);
00081       ~TCPTransport();
00082 
00083       const PString&  GetServerHost() const   { return m_Hostname; }
00084       WORD            GetServerPort() const   { return m_Port; }
00085 
00086       virtual BOOL Open();
00087       virtual BOOL Close();
00088 
00089     protected:
00090       PString         m_Hostname;
00091       WORD            m_Port;
00092       PTCPSocket *    m_Socket;
00093     };
00094   
00095 
00099     class StreamHandler : public BaseStreamHandler
00100     {
00101       PCLASSINFO(StreamHandler, BaseStreamHandler);
00102 
00103     public:
00104       StreamHandler(const JID& jid, const PString& pwd, BOOL newAccount = FALSE);
00105       ~StreamHandler();
00106 
00107       virtual BOOL IsEstablished() const        { return m_State == Established; }
00108 
00109       virtual BOOL Start(Transport * transport = 0);
00110 
00117       BOOL    Send(Stanza * stanza);
00118 
00119       void    SetVersion(WORD major, WORD minor);
00120       void    GetVersion(WORD& major, WORD& minor) const;
00121 
00122       const JID&  GetJID() const  { return m_JID; }
00123 
00129       PNotifierList&  SessionEstablishedHandlers()  { return m_SessionEstablishedHandlers; }
00130       PNotifierList&  SessionReleasedHandlers()     { return m_SessionReleasedHandlers; }
00131 
00138       PNotifierList&  ErrorHandlers()     { return m_ErrorHandlers; }
00139       PNotifierList&  MessageHandlers()   { return m_MessageHandlers; }
00140       PNotifierList&  PresenceHandlers()  { return m_PresenceHandlers; }
00141       PNotifierList&  IQHandlers()        { return m_IQHandlers; }
00142 
00147       PNotifierList&  IQNamespaceHandlers(const PString& xml_namespace);
00148 
00154       PNotifierList&  MessageSenderHandlers(const JID& from);
00155 
00160       virtual BOOL DiscoverItems(
00161                     const PString& jid,           // JID to which a query will be send
00162                     PNotifier * responseHandler,
00163                     const PString& node = PString::Empty()); // Optional node
00164 
00165       virtual BOOL DiscoverInfo(
00166                     const PString& jid,           // JID to which a query will be send
00167                     PNotifier * responseHandler,
00168                     const PString& node = PString::Empty()); // Optional node
00169 
00170     protected:
00171       virtual void    OnOpen(Stream& stream, INT);
00172       virtual void    OnClose(Stream& stream, INT);
00173       virtual void    StartRegistration();
00174       virtual void    StartAuthNegotiation();
00175 
00176       virtual void    OnSessionEstablished();
00177       virtual void    OnSessionReleased();
00178       virtual void    OnElement(PXML& pdu);
00179       virtual void    OnError(PXML& pdu);
00180 
00181       virtual void    OnMessage(XMPP::Message& pdu);
00182       virtual void    OnPresence(XMPP::Presence& pdu);
00183       virtual void    OnIQ(XMPP::IQ& pdu);
00184 
00185       // State handlers
00186       virtual void    HandleNullState(PXML& pdu);
00187       virtual void    HandleRegStartedState(PXML& pdu);
00188       virtual void    HandleTLSStartedState(PXML& pdu);
00189 #if P_SASL2
00190       virtual void    HandleSASLStartedState(PXML& pdu);
00191 #endif
00192       virtual void    HandleNonSASLStartedState(PXML& pdu);
00193       virtual void    HandleStreamSentState(PXML& pdu);
00194       virtual void    HandleBindSentState(PXML& pdu);
00195       virtual void    HandleSessionSentState(PXML& pdu);
00196       virtual void    HandleEstablishedState(PXML& pdu);
00197 
00198       virtual BOOL    Discover(const PString& xmlns,
00199                                const PString& jid,
00200                                PNotifier * responseHandler,
00201                                const PString& node);
00202 
00203       WORD                m_VersionMajor;
00204       WORD                m_VersionMinor;
00205       PString             m_StreamID;
00206       BOOL                m_NewAccount;
00207       JID                 m_JID;
00208       const PString       m_Password;
00209 #if P_SASL2
00210       PSASLClient         m_SASL;
00211       PString             m_Mechanism;
00212 #endif
00213       BOOL                m_HasBind;
00214       BOOL                m_HasSession;
00215 
00216       PNotifierList       m_SessionEstablishedHandlers;
00217       PNotifierList       m_SessionReleasedHandlers;
00218       PNotifierList       m_ErrorHandlers;
00219       PNotifierList       m_MessageHandlers;
00220       PNotifierList       m_PresenceHandlers;
00221       PNotifierList       m_IQHandlers;
00222       PDictionary<PString, PNotifierList> m_IQNamespaceHandlers;
00223       PDictionary<JID, PNotifierList> m_MessageSenderHandlers;
00224 
00225       PMutex              m_PendingIQsLock;
00226       StanzaList          m_PendingIQs;
00227 
00228       enum StreamState
00229       {
00230         Null,
00231         RegStarted,
00232         TLSStarted,
00233         SASLStarted,
00234         NonSASLStarted, // non SASL authentication (JEP-0078)
00235         StreamSent,
00236         BindSent,
00237         SessionSent,
00238         Established
00239       };
00240 
00241       virtual void SetState(StreamState s);
00242 
00243       StreamState m_State;
00244     };
00245 
00246   }  // namespace C2S
00247 } // namespace XMPP
00248 
00249 
00250 #endif  // P_EXPAT
00251 
00252 #endif  // _XMPP_C2S
00253 
00254 // End of File ///////////////////////////////////////////////////////////////
00255 
00256 
00257 

Generated on Wed Sep 28 10:27:34 2005 for PWLib by  doxygen 1.4.4