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

Generated on Fri Mar 7 06:25:03 2008 for PTLib by  doxygen 1.5.1