PTLib  Version 2.10.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
xmpp_c2s.h
Go to the documentation of this file.
1 /*
2  * xmpp_c2s.h
3  *
4  * Extensible Messaging and Presence Protocol (XMPP) Core
5  * Client to Server communication classes
6  *
7  * Portable Windows Library
8  *
9  * Copyright (c) 2004 Reitek S.p.A.
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Portable Windows Library.
22  *
23  * The Initial Developer of the Original Code is Post Increment
24  *
25  * Contributor(s): ______________________________________.
26  *
27  * $Revision: 24875 $
28  * $Author: rjongbloed $
29  * $Date: 2010-11-12 02:03:15 -0600 (Fri, 12 Nov 2010) $
30  */
31 
32 #ifndef PTLIB_XMPP_C2S_H
33 #define PTLIB_XMPP_C2S_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 #include <ptclib/xmpp.h>
40 
41 #if P_EXPAT
42 
43 #include <ptclib/psasl.h>
44 #include <ptlib/sockets.h>
45 
46 
48 
49 namespace XMPP
50 {
51  namespace C2S
52  {
53 
56  class TCPTransport : public Transport
57  {
58  PCLASSINFO(TCPTransport, Transport);
59 
60  public:
61  TCPTransport(const PString& hostname);
62  TCPTransport(const PString& hostname, WORD port);
63  ~TCPTransport();
64 
65  const PString& GetServerHost() const { return m_Hostname; }
66  WORD GetServerPort() const { return m_Port; }
67 
68  virtual PBoolean Open();
69  virtual PBoolean Close();
70 
71  protected:
73  WORD m_Port;
75  };
76 
77 
82  {
83  PCLASSINFO(StreamHandler, BaseStreamHandler);
84 
85  public:
86  StreamHandler(const JID& jid, const PString& pwd, PBoolean newAccount = false);
88 
89  virtual PBoolean IsEstablished() const { return m_State == Established; }
90 
91  virtual PBoolean Start(Transport * transport = 0);
92 
99  PBoolean Send(Stanza * stanza);
100 
101  void SetVersion(WORD major, WORD minor);
102  void GetVersion(WORD& major, WORD& minor) const;
103 
104  const JID& GetJID() const { return m_JID; }
105 
113 
124 
129  PNotifierList& IQNamespaceHandlers(const PString& xml_namespace);
130 
137 
142  virtual PBoolean DiscoverItems(
143  const PString& jid,
144  PNotifier * responseHandler,
145  const PString& node = PString::Empty()
146  );
147  virtual PBoolean DiscoverInfo(
148  const PString& jid,
149  PNotifier * responseHandler,
150  const PString& node = PString::Empty()
151  );
152 
153  protected:
154  virtual void OnOpen(Stream& stream, INT);
155  virtual void OnClose(Stream& stream, INT);
156  virtual void StartRegistration();
157  virtual void StartAuthNegotiation();
158 
159  virtual void OnSessionEstablished();
160  virtual void OnSessionReleased();
161  virtual void OnElement(PXML& pdu);
162  virtual void OnError(PXML& pdu);
163 
164  virtual void OnMessage(XMPP::Message& pdu);
165  virtual void OnPresence(XMPP::Presence& pdu);
166  virtual void OnIQ(XMPP::IQ& pdu);
167 
168  // State handlers
169  virtual void HandleNullState(PXML& pdu);
170  virtual void HandleRegStartedState(PXML& pdu);
171  virtual void HandleTLSStartedState(PXML& pdu);
172 #if P_SASL
173  virtual void HandleSASLStartedState(PXML& pdu);
174 #endif
175  virtual void HandleNonSASLStartedState(PXML& pdu);
176  virtual void HandleStreamSentState(PXML& pdu);
177  virtual void HandleBindSentState(PXML& pdu);
178  virtual void HandleSessionSentState(PXML& pdu);
179  virtual void HandleEstablishedState(PXML& pdu);
180 
181  virtual PBoolean Discover(const PString& xmlns,
182  const PString& jid,
183  PNotifier * responseHandler,
184  const PString& node);
185 
192 #if P_SASL
193  PSASLClient m_SASL;
194  PString m_Mechanism;
195 #endif
198 
207 
209  StanzaList m_PendingIQs;
210 
212  {
222  };
223 
224  virtual void SetState(StreamState s);
225 
227  };
228 
229  } // namespace C2S
230 } // namespace XMPP
231 
232 
233 #endif // P_EXPAT
234 
235 #endif // PTLIB_XMPP_C2S_H
236 
237 // End of File ///////////////////////////////////////////////////////////////
WORD m_Port
Definition: xmpp_c2s.h:73
PNotifierList & IQNamespaceHandlers(const PString &xml_namespace)
A notifier list for a specific namespace.
PNotifierList & IQHandlers()
Definition: xmpp_c2s.h:123
const PString & GetServerHost() const
Definition: xmpp_c2s.h:65
virtual void OnSessionReleased()
virtual void OnClose(Stream &stream, INT)
PMutex m_PendingIQsLock
Definition: xmpp_c2s.h:208
virtual PBoolean IsEstablished() const
Definition: xmpp_c2s.h:89
virtual void HandleTLSStartedState(PXML &pdu)
virtual void OnMessage(XMPP::Message &pdu)
PString m_StreamID
Definition: xmpp_c2s.h:188
Class specialisation for PNotifierTemplate&lt;INT&gt;
virtual void OnIQ(XMPP::IQ &pdu)
WORD m_VersionMinor
Definition: xmpp_c2s.h:187
Definition: xmpp_c2s.h:216
PNotifierList & ErrorHandlers()
These notifier lists are fired when a XMPP stanza or a stream error is received. ...
Definition: xmpp_c2s.h:120
WORD GetServerPort() const
Definition: xmpp_c2s.h:66
This class represents a XMPP stream, i.e.
Definition: xmpp.h:147
Definition: xmpp_c2s.h:219
PNotifierList m_SessionEstablishedHandlers
Definition: xmpp_c2s.h:199
PBoolean m_HasSession
Definition: xmpp_c2s.h:197
PBoolean m_NewAccount
Definition: xmpp_c2s.h:189
Definition: xmpp.h:379
virtual void OnElement(PXML &pdu)
non SASL authentication (JEP-0078)
Definition: xmpp_c2s.h:217
virtual void OnOpen(Stream &stream, INT)
virtual void SetState(StreamState s)
Definition: xmpp_c2s.h:221
PNotifierList m_SessionReleasedHandlers
Definition: xmpp_c2s.h:200
virtual void HandleNonSASLStartedState(PXML &pdu)
TCPTransport(const PString &hostname)
Definition: xmpp_c2s.h:213
virtual void StartAuthNegotiation()
PNotifierList m_PresenceHandlers
Definition: xmpp_c2s.h:203
virtual void OnSessionEstablished()
PNotifierList & PresenceHandlers()
Definition: xmpp_c2s.h:122
XMPP client to server TCP transport.
Definition: xmpp_c2s.h:56
PNotifierList m_ErrorHandlers
Definition: xmpp_c2s.h:201
StreamState
Definition: xmpp_c2s.h:211
Definition: xmpp.h:59
Definition: pxml.h:114
PNotifierList & SessionEstablishedHandlers()
These notifier lists after when a client session is established (i.e.
Definition: xmpp_c2s.h:111
virtual PBoolean DiscoverItems(const PString &jid, PNotifier *responseHandler, const PString &node=PString::Empty())
JEP-0030 Service Discovery access methods.
Definition: xmpp_c2s.h:220
BOOL PBoolean
Definition: object.h:102
void GetVersion(WORD &major, WORD &minor) const
PNotifierList & SessionReleasedHandlers()
Definition: xmpp_c2s.h:112
virtual void HandleEstablishedState(PXML &pdu)
PDictionary< PString, PNotifierList > m_IQNamespaceHandlers
Definition: xmpp_c2s.h:205
PBoolean m_HasBind
Definition: xmpp_c2s.h:196
virtual PBoolean DiscoverInfo(const PString &jid, PNotifier *responseHandler, const PString &node=PString::Empty())
PNotifierList m_MessageHandlers
Definition: xmpp_c2s.h:202
virtual PBoolean Start(Transport *transport=0)
const JID & GetJID() const
Definition: xmpp_c2s.h:104
virtual void OnError(PXML &pdu)
virtual void HandleSessionSentState(PXML &pdu)
The character string class.
Definition: pstring.h:108
virtual PBoolean Discover(const PString &xmlns, const PString &jid, PNotifier *responseHandler, const PString &node)
StanzaList m_PendingIQs
Definition: xmpp_c2s.h:209
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:44
Definition: xmpp.h:311
virtual void HandleRegStartedState(PXML &pdu)
static PString Empty()
Return an empty string.
virtual void HandleStreamSentState(PXML &pdu)
WORD m_VersionMajor
Definition: xmpp_c2s.h:186
PDictionary< JID, PNotifierList > m_MessageSenderHandlers
Definition: xmpp_c2s.h:206
virtual void StartRegistration()
PNotifierList & MessageSenderHandlers(const JID &from)
A notifier list for a particular message originator.
This class handles the client side of a C2S (Client to Server) XMPP stream.
Definition: xmpp_c2s.h:81
virtual void HandleNullState(PXML &pdu)
Definition: xmpp_c2s.h:218
void SetVersion(WORD major, WORD minor)
PNotifierList & MessageHandlers()
Definition: xmpp_c2s.h:121
Definition: xmpp_c2s.h:214
virtual void HandleBindSentState(PXML &pdu)
PString m_Hostname
Definition: xmpp_c2s.h:72
XMPP stanzas: the following classes represent the three stanzas (PDUs) defined by the xmpp protocol...
Definition: xmpp.h:222
StreamHandler(const JID &jid, const PString &pwd, PBoolean newAccount=false)
This interface is the base class of each XMPP transport class.
Definition: xmpp.h:134
StreamState m_State
Definition: xmpp_c2s.h:226
PBoolean Send(Stanza *stanza)
Request the delivery of the specified stanza NOTE: the StreamHandler takes ownership of the stanza a...
Synonym for PTimedMutex.
PTCPSocket * m_Socket
Definition: xmpp_c2s.h:74
Definition: xmpp.h:183
Definition: xmpp_c2s.h:215
PNotifierList m_IQHandlers
Definition: xmpp_c2s.h:204
Definition: notifier_ext.h:102
virtual void OnPresence(XMPP::Presence &pdu)
JID m_JID
Definition: xmpp_c2s.h:190
Definition: xmpp.h:252
virtual PBoolean Open()
const PString m_Password
Definition: xmpp_c2s.h:191
virtual PBoolean Close()
Close the channel.