PTLib  Version 2.18.8
 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 
28 #ifndef PTLIB_XMPP_C2S_H
29 #define PTLIB_XMPP_C2S_H
30 
31 #ifdef P_USE_PRAGMA
32 #pragma interface
33 #endif
34 
35 #include <ptclib/xmpp.h>
36 
37 #if P_EXPAT
38 
39 #include <ptclib/psasl.h>
40 #include <ptlib/sockets.h>
41 
42 
44 
45 namespace XMPP
46 {
47  namespace C2S
48  {
49 
52  class TCPTransport : public Transport
53  {
54  PCLASSINFO(TCPTransport, Transport);
55 
56  public:
57  TCPTransport(const PString& hostname);
58  TCPTransport(const PString& hostname, WORD port);
59  ~TCPTransport();
60 
61  const PString& GetServerHost() const { return m_Hostname; }
62  WORD GetServerPort() const { return m_Port; }
63 
64  virtual PBoolean Open();
65  virtual PBoolean Close();
66 
67  protected:
69  WORD m_Port;
71  };
72 
73 
78  {
79  PCLASSINFO(StreamHandler, BaseStreamHandler);
80 
81  public:
82  StreamHandler(const JID& jid, const PString& pwd, PBoolean newAccount = false);
84 
85  virtual PBoolean IsEstablished() const { return m_State == Established; }
86 
87  virtual PBoolean Start(Transport * transport = 0);
88 
95  PBoolean Send(Stanza * stanza);
96 
97  void SetVersion(WORD major, WORD minor);
98  void GetVersion(WORD& major, WORD& minor) const;
99 
100  const JID& GetJID() const { return m_JID; }
101 
109 
120 
125  PNotifierList& IQNamespaceHandlers(const PString& xml_namespace);
126 
133 
138  virtual PBoolean DiscoverItems(
139  const PString& jid,
140  const PNotifier & responseHandler,
141  const PString& node = PString::Empty()
142  );
143  virtual PBoolean DiscoverInfo(
144  const PString& jid,
145  const PNotifier & responseHandler,
146  const PString& node = PString::Empty()
147  );
148 
149  protected:
150  virtual void OnOpen(Stream& stream, INT);
151  virtual void OnClose(Stream& stream, INT);
152  virtual void StartRegistration();
153  virtual void StartAuthNegotiation();
154 
155  virtual void OnSessionEstablished();
156  virtual void OnSessionReleased();
157  virtual void OnElement(PXMLElement & pdu);
158  virtual void OnError(PXMLElement & pdu);
159 
160  virtual void OnMessage(XMPP::Message& pdu);
161  virtual void OnPresence(XMPP::Presence& pdu);
162  virtual void OnIQ(XMPP::IQ& pdu);
163 
164  // State handlers
165  virtual void HandleNullState(PXMLElement & pdu);
166  virtual void HandleRegStartedState(PXMLElement & pdu);
167  virtual void HandleTLSStartedState(PXMLElement & pdu);
168 #if P_SASL
169  virtual void HandleSASLStartedState(PXMLElement & pdu);
170 #endif
171  virtual void HandleNonSASLStartedState(PXMLElement & pdu);
172  virtual void HandleStreamSentState(PXMLElement & pdu);
173  virtual void HandleBindSentState(PXMLElement & pdu);
174  virtual void HandleSessionSentState(PXMLElement & pdu);
175  virtual void HandleEstablishedState(PXMLElement& pdu);
176 
177  virtual PBoolean Discover(const PString& xmlns,
178  const PString& jid,
179  const PNotifier & responseHandler,
180  const PString& node);
181 
188 #if P_SASL
191 #endif
194 
203 
204  PDECLARE_MUTEX( m_PendingIQsLock);
205  StanzaList m_PendingIQs;
206 
208  {
218  };
219 
220  virtual void SetState(StreamState s);
221 
223  };
224 
225  } // namespace C2S
226 } // namespace XMPP
227 
228 
229 #endif // P_EXPAT
230 
231 #endif // PTLIB_XMPP_C2S_H
232 
233 // End of File ///////////////////////////////////////////////////////////////
WORD m_Port
Definition: xmpp_c2s.h:69
PNotifierList & IQNamespaceHandlers(const PString &xml_namespace)
A notifier list for a specific namespace.
PNotifierList & IQHandlers()
Definition: xmpp_c2s.h:119
const PString & GetServerHost() const
Definition: xmpp_c2s.h:61
virtual void OnSessionReleased()
virtual void OnClose(Stream &stream, INT)
virtual void HandleSASLStartedState(PXMLElement &pdu)
virtual void HandleEstablishedState(PXMLElement &pdu)
virtual void OnElement(PXMLElement &pdu)
virtual PBoolean IsEstablished() const
Definition: xmpp_c2s.h:85
virtual void OnMessage(XMPP::Message &pdu)
PString m_StreamID
Definition: xmpp_c2s.h:184
Class specialisation for PNotifierTemplate&lt;P_INT_PTR&gt;
virtual void OnIQ(XMPP::IQ &pdu)
WORD m_VersionMinor
Definition: xmpp_c2s.h:183
Definition: xmpp_c2s.h:212
PNotifierList & ErrorHandlers()
These notifier lists are fired when a XMPP stanza or a stream error is received. ...
Definition: xmpp_c2s.h:116
WORD GetServerPort() const
Definition: xmpp_c2s.h:62
This template class maps the PAbstractDictionary to a specific key and data types.
Definition: dict.h:978
This class represents a XMPP stream, i.e.
Definition: xmpp.h:143
Definition: xmpp_c2s.h:215
PNotifierList m_SessionEstablishedHandlers
Definition: xmpp_c2s.h:195
PBoolean m_HasSession
Definition: xmpp_c2s.h:193
PBoolean m_NewAccount
Definition: xmpp_c2s.h:185
PSASLClient m_SASL
Definition: xmpp_c2s.h:189
Definition: xmpp.h:373
virtual void HandleStreamSentState(PXMLElement &pdu)
non SASL authentication (JEP-0078)
Definition: xmpp_c2s.h:213
virtual void OnOpen(Stream &stream, INT)
virtual void SetState(StreamState s)
Definition: xmpp_c2s.h:217
virtual void HandleRegStartedState(PXMLElement &pdu)
PNotifierList m_SessionReleasedHandlers
Definition: xmpp_c2s.h:196
virtual void HandleSessionSentState(PXMLElement &pdu)
TCPTransport(const PString &hostname)
Definition: xmpp_c2s.h:209
virtual void StartAuthNegotiation()
PNotifierList m_PresenceHandlers
Definition: xmpp_c2s.h:199
virtual void HandleNullState(PXMLElement &pdu)
virtual void HandleBindSentState(PXMLElement &pdu)
virtual void OnSessionEstablished()
PNotifierList & PresenceHandlers()
Definition: xmpp_c2s.h:118
XMPP client to server TCP transport.
Definition: xmpp_c2s.h:52
virtual PBoolean DiscoverItems(const PString &jid, const PNotifier &responseHandler, const PString &node=PString::Empty())
JEP-0030 Service Discovery access methods.
PNotifierList m_ErrorHandlers
Definition: xmpp_c2s.h:197
PDECLARE_MUTEX(m_PendingIQsLock)
StreamState
Definition: xmpp_c2s.h:207
Definition: xmpp.h:55
PNotifierList & SessionEstablishedHandlers()
These notifier lists after when a client session is established (i.e.
Definition: xmpp_c2s.h:107
Definition: xmpp_c2s.h:216
void GetVersion(WORD &major, WORD &minor) const
PNotifierList & SessionReleasedHandlers()
Definition: xmpp_c2s.h:108
PDictionary< PString, PNotifierList > m_IQNamespaceHandlers
Definition: xmpp_c2s.h:201
virtual PBoolean DiscoverInfo(const PString &jid, const PNotifier &responseHandler, const PString &node=PString::Empty())
PBoolean m_HasBind
Definition: xmpp_c2s.h:192
virtual void OnError(PXMLElement &pdu)
PNotifierList m_MessageHandlers
Definition: xmpp_c2s.h:198
virtual PBoolean Discover(const PString &xmlns, const PString &jid, const PNotifier &responseHandler, const PString &node)
virtual PBoolean Start(Transport *transport=0)
virtual void HandleNonSASLStartedState(PXMLElement &pdu)
bool PBoolean
Definition: object.h:174
const JID & GetJID() const
Definition: xmpp_c2s.h:100
The character string class.
Definition: pstring.h:108
StanzaList m_PendingIQs
Definition: xmpp_c2s.h:205
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:40
Definition: xmpp.h:307
Definition: pxml.h:398
WORD m_VersionMajor
Definition: xmpp_c2s.h:182
PDictionary< JID, PNotifierList > m_MessageSenderHandlers
Definition: xmpp_c2s.h:202
virtual void StartRegistration()
PNotifierList & MessageSenderHandlers(const JID &from)
A notifier list for a particular message originator.
virtual void HandleTLSStartedState(PXMLElement &pdu)
Definition: psasl.h:38
This class handles the client side of a C2S (Client to Server) XMPP stream.
Definition: xmpp_c2s.h:77
Definition: xmpp_c2s.h:214
static const PString & Empty()
Return an empty string.
void SetVersion(WORD major, WORD minor)
PNotifierList & MessageHandlers()
Definition: xmpp_c2s.h:117
Definition: xmpp_c2s.h:210
PString m_Hostname
Definition: xmpp_c2s.h:68
XMPP stanzas: the following classes represent the three stanzas (PDUs) defined by the xmpp protocol...
Definition: xmpp.h:221
StreamHandler(const JID &jid, const PString &pwd, PBoolean newAccount=false)
This interface is the base class of each XMPP transport class.
Definition: xmpp.h:130
StreamState m_State
Definition: xmpp_c2s.h:222
PBoolean Send(Stanza *stanza)
Request the delivery of the specified stanza NOTE: the StreamHandler takes ownership of the stanza a...
PTCPSocket * m_Socket
Definition: xmpp_c2s.h:70
Definition: xmpp.h:181
Definition: xmpp_c2s.h:211
PNotifierList m_IQHandlers
Definition: xmpp_c2s.h:200
virtual void OnPresence(XMPP::Presence &pdu)
JID m_JID
Definition: xmpp_c2s.h:186
Definition: xmpp.h:250
PString m_Mechanism
Definition: xmpp_c2s.h:190
virtual PBoolean Open()
const PString m_Password
Definition: xmpp_c2s.h:187
virtual PBoolean Close()
Close the channel.