All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
xmpp_c2s.h
Go to the documentation of this file.
/*
* xmpp_c2s.h
*
* Extensible Messaging and Presence Protocol (XMPP) Core
* Client to Server communication classes
*
* Portable Windows Library
*
* Copyright (c) 2004 Reitek S.p.A.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Post Increment
*
* Contributor(s): ______________________________________.
*
* $Revision: 24875 $
* $Author: rjongbloed $
* $Date: 2010-11-12 02:03:15 -0600 (Fri, 12 Nov 2010) $
*/
#ifndef PTLIB_XMPP_C2S_H
#define PTLIB_XMPP_C2S_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptclib/xmpp.h>
#if P_EXPAT
#include <ptclib/psasl.h>
#include <ptlib/sockets.h>
namespace XMPP
{
namespace C2S
{
class TCPTransport : public Transport
{
PCLASSINFO(TCPTransport, Transport);
public:
TCPTransport(const PString& hostname);
TCPTransport(const PString& hostname, WORD port);
~TCPTransport();
const PString& GetServerHost() const { return m_Hostname; }
WORD GetServerPort() const { return m_Port; }
virtual PBoolean Open();
virtual PBoolean Close();
protected:
PString m_Hostname;
WORD m_Port;
PTCPSocket * m_Socket;
};
class StreamHandler : public BaseStreamHandler
{
PCLASSINFO(StreamHandler, BaseStreamHandler);
public:
StreamHandler(const JID& jid, const PString& pwd, PBoolean newAccount = false);
~StreamHandler();
virtual PBoolean IsEstablished() const { return m_State == Established; }
virtual PBoolean Start(Transport * transport = 0);
PBoolean Send(Stanza * stanza);
void SetVersion(WORD major, WORD minor);
void GetVersion(WORD& major, WORD& minor) const;
const JID& GetJID() const { return m_JID; }
PNotifierList& SessionEstablishedHandlers() { return m_SessionEstablishedHandlers; }
PNotifierList& SessionReleasedHandlers() { return m_SessionReleasedHandlers; }
PNotifierList& ErrorHandlers() { return m_ErrorHandlers; }
PNotifierList& MessageHandlers() { return m_MessageHandlers; }
PNotifierList& PresenceHandlers() { return m_PresenceHandlers; }
PNotifierList& IQHandlers() { return m_IQHandlers; }
PNotifierList& IQNamespaceHandlers(const PString& xml_namespace);
PNotifierList& MessageSenderHandlers(const JID& from);
virtual PBoolean DiscoverItems(
const PString& jid,
PNotifier * responseHandler,
const PString& node = PString::Empty()
);
virtual PBoolean DiscoverInfo(
const PString& jid,
PNotifier * responseHandler,
const PString& node = PString::Empty()
);
protected:
virtual void OnOpen(Stream& stream, INT);
virtual void OnClose(Stream& stream, INT);
virtual void StartRegistration();
virtual void StartAuthNegotiation();
virtual void OnSessionEstablished();
virtual void OnSessionReleased();
virtual void OnElement(PXML& pdu);
virtual void OnError(PXML& pdu);
virtual void OnMessage(XMPP::Message& pdu);
virtual void OnPresence(XMPP::Presence& pdu);
virtual void OnIQ(XMPP::IQ& pdu);
// State handlers
virtual void HandleNullState(PXML& pdu);
virtual void HandleRegStartedState(PXML& pdu);
virtual void HandleTLSStartedState(PXML& pdu);
#if P_SASL
virtual void HandleSASLStartedState(PXML& pdu);
#endif
virtual void HandleNonSASLStartedState(PXML& pdu);
virtual void HandleStreamSentState(PXML& pdu);
virtual void HandleBindSentState(PXML& pdu);
virtual void HandleSessionSentState(PXML& pdu);
virtual void HandleEstablishedState(PXML& pdu);
virtual PBoolean Discover(const PString& xmlns,
const PString& jid,
PNotifier * responseHandler,
const PString& node);
WORD m_VersionMajor;
WORD m_VersionMinor;
PString m_StreamID;
PBoolean m_NewAccount;
JID m_JID;
const PString m_Password;
#if P_SASL
PSASLClient m_SASL;
PString m_Mechanism;
#endif
PBoolean m_HasBind;
PBoolean m_HasSession;
PNotifierList m_SessionEstablishedHandlers;
PNotifierList m_SessionReleasedHandlers;
PNotifierList m_ErrorHandlers;
PNotifierList m_MessageHandlers;
PNotifierList m_PresenceHandlers;
PNotifierList m_IQHandlers;
PDictionary<PString, PNotifierList> m_IQNamespaceHandlers;
PDictionary<JID, PNotifierList> m_MessageSenderHandlers;
PMutex m_PendingIQsLock;
StanzaList m_PendingIQs;
enum StreamState
{
Null,
RegStarted,
TLSStarted,
SASLStarted,
NonSASLStarted,
StreamSent,
BindSent,
SessionSent,
Established
};
virtual void SetState(StreamState s);
StreamState m_State;
};
} // namespace C2S
} // namespace XMPP
#endif // P_EXPAT
#endif // PTLIB_XMPP_C2S_H
// End of File ///////////////////////////////////////////////////////////////
XMPP::C2S::TCPTransport::m_Port
WORD m_Port
Definition: xmpp_c2s.h:73
XMPP::C2S::StreamHandler::IQNamespaceHandlers
PNotifierList & IQNamespaceHandlers(const PString &xml_namespace)
A notifier list for a specific namespace.
XMPP::C2S::StreamHandler::IQHandlers
PNotifierList & IQHandlers()
Definition: xmpp_c2s.h:123
XMPP::C2S::TCPTransport::GetServerHost
const PString & GetServerHost() const
Definition: xmpp_c2s.h:65
XMPP::C2S::StreamHandler::~StreamHandler
~StreamHandler()
XMPP::C2S::StreamHandler::OnSessionReleased
virtual void OnSessionReleased()
XMPP::C2S::StreamHandler::OnClose
virtual void OnClose(Stream &stream, INT)
XMPP::C2S::StreamHandler::m_PendingIQsLock
PMutex m_PendingIQsLock
Definition: xmpp_c2s.h:208
XMPP::C2S::StreamHandler::IsEstablished
virtual PBoolean IsEstablished() const
Definition: xmpp_c2s.h:89
XMPP::C2S::StreamHandler::HandleTLSStartedState
virtual void HandleTLSStartedState(PXML &pdu)
XMPP::C2S::StreamHandler::OnMessage
virtual void OnMessage(XMPP::Message &pdu)
XMPP::C2S::StreamHandler::m_StreamID
PString m_StreamID
Definition: xmpp_c2s.h:188
PNotifier
Class specialisation for PNotifierTemplate<INT>
XMPP::C2S::StreamHandler::OnIQ
virtual void OnIQ(XMPP::IQ &pdu)
XMPP::C2S::StreamHandler::m_VersionMinor
WORD m_VersionMinor
Definition: xmpp_c2s.h:187
XMPP::C2S::StreamHandler::SASLStarted
Definition: xmpp_c2s.h:216
XMPP::C2S::StreamHandler::ErrorHandlers
PNotifierList & ErrorHandlers()
These notifier lists are fired when a XMPP stanza or a stream error is received.
Definition: xmpp_c2s.h:120
XMPP::C2S::TCPTransport::GetServerPort
WORD GetServerPort() const
Definition: xmpp_c2s.h:66
PDictionary< PString, PNotifierList >
XMPP::Stream
This class represents a XMPP stream, i.e.
Definition: xmpp.h:147
XMPP::C2S::StreamHandler::BindSent
Definition: xmpp_c2s.h:219
XMPP::C2S::StreamHandler::m_SessionEstablishedHandlers
PNotifierList m_SessionEstablishedHandlers
Definition: xmpp_c2s.h:199
XMPP::C2S::StreamHandler::m_HasSession
PBoolean m_HasSession
Definition: xmpp_c2s.h:197
XMPP::C2S::StreamHandler::m_NewAccount
PBoolean m_NewAccount
Definition: xmpp_c2s.h:189
XMPP::IQ
Definition: xmpp.h:379
XMPP::C2S::StreamHandler::OnElement
virtual void OnElement(PXML &pdu)
XMPP::C2S::StreamHandler::NonSASLStarted
non SASL authentication (JEP-0078)
Definition: xmpp_c2s.h:217
XMPP::C2S::StreamHandler::OnOpen
virtual void OnOpen(Stream &stream, INT)
XMPP::C2S::StreamHandler::SetState
virtual void SetState(StreamState s)
psasl.h
XMPP::C2S::StreamHandler::Established
Definition: xmpp_c2s.h:221
XMPP::C2S::StreamHandler::m_SessionReleasedHandlers
PNotifierList m_SessionReleasedHandlers
Definition: xmpp_c2s.h:200
XMPP::C2S::StreamHandler::HandleNonSASLStartedState
virtual void HandleNonSASLStartedState(PXML &pdu)
XMPP::C2S::TCPTransport::TCPTransport
TCPTransport(const PString &hostname)
XMPP::C2S::StreamHandler::Null
Definition: xmpp_c2s.h:213
XMPP::C2S::StreamHandler::StartAuthNegotiation
virtual void StartAuthNegotiation()
XMPP::C2S::StreamHandler::m_PresenceHandlers
PNotifierList m_PresenceHandlers
Definition: xmpp_c2s.h:203
XMPP::C2S::StreamHandler::OnSessionEstablished
virtual void OnSessionEstablished()
XMPP::C2S::StreamHandler::PresenceHandlers
PNotifierList & PresenceHandlers()
Definition: xmpp_c2s.h:122
XMPP::C2S::TCPTransport
XMPP client to server TCP transport.
Definition: xmpp_c2s.h:56
XMPP::C2S::StreamHandler::m_ErrorHandlers
PNotifierList m_ErrorHandlers
Definition: xmpp_c2s.h:201
XMPP::C2S::StreamHandler::StreamState
StreamState
Definition: xmpp_c2s.h:211
XMPP::JID
Definition: xmpp.h:59
PXML
Definition: pxml.h:114
XMPP::C2S::StreamHandler::SessionEstablishedHandlers
PNotifierList & SessionEstablishedHandlers()
These notifier lists after when a client session is established (i.e.
Definition: xmpp_c2s.h:111
XMPP::C2S::StreamHandler::DiscoverItems
virtual PBoolean DiscoverItems(const PString &jid, PNotifier *responseHandler, const PString &node=PString::Empty())
JEP-0030 Service Discovery access methods.
XMPP::C2S::StreamHandler::SessionSent
Definition: xmpp_c2s.h:220
PBoolean
BOOL PBoolean
Definition: object.h:102
xmpp.h
XMPP::C2S::StreamHandler::GetVersion
void GetVersion(WORD &major, WORD &minor) const
XMPP::C2S::StreamHandler::SessionReleasedHandlers
PNotifierList & SessionReleasedHandlers()
Definition: xmpp_c2s.h:112
XMPP::C2S::StreamHandler::HandleEstablishedState
virtual void HandleEstablishedState(PXML &pdu)
XMPP::C2S::StreamHandler::m_IQNamespaceHandlers
PDictionary< PString, PNotifierList > m_IQNamespaceHandlers
Definition: xmpp_c2s.h:205
XMPP::C2S::StreamHandler::m_HasBind
PBoolean m_HasBind
Definition: xmpp_c2s.h:196
XMPP::C2S::StreamHandler::DiscoverInfo
virtual PBoolean DiscoverInfo(const PString &jid, PNotifier *responseHandler, const PString &node=PString::Empty())
XMPP::C2S::StreamHandler::m_MessageHandlers
PNotifierList m_MessageHandlers
Definition: xmpp_c2s.h:202
XMPP::C2S::StreamHandler::Start
virtual PBoolean Start(Transport *transport=0)
XMPP::C2S::StreamHandler::GetJID
const JID & GetJID() const
Definition: xmpp_c2s.h:104
XMPP::C2S::StreamHandler::OnError
virtual void OnError(PXML &pdu)
XMPP::C2S::StreamHandler::HandleSessionSentState
virtual void HandleSessionSentState(PXML &pdu)
PString
The character string class.
Definition: pstring.h:108
XMPP::C2S::StreamHandler::Discover
virtual PBoolean Discover(const PString &xmlns, const PString &jid, PNotifier *responseHandler, const PString &node)
XMPP::C2S::StreamHandler::m_PendingIQs
StanzaList m_PendingIQs
Definition: xmpp_c2s.h:209
PTCPSocket
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:44
XMPP::Presence
Definition: xmpp.h:311
XMPP::C2S::StreamHandler::HandleRegStartedState
virtual void HandleRegStartedState(PXML &pdu)
PString::Empty
static PString Empty()
Return an empty string.
XMPP::C2S::StreamHandler::HandleStreamSentState
virtual void HandleStreamSentState(PXML &pdu)
XMPP::C2S::StreamHandler::m_VersionMajor
WORD m_VersionMajor
Definition: xmpp_c2s.h:186
XMPP::C2S::StreamHandler::m_MessageSenderHandlers
PDictionary< JID, PNotifierList > m_MessageSenderHandlers
Definition: xmpp_c2s.h:206
XMPP::C2S::StreamHandler::StartRegistration
virtual void StartRegistration()
XMPP::C2S::StreamHandler::MessageSenderHandlers
PNotifierList & MessageSenderHandlers(const JID &from)
A notifier list for a particular message originator.
XMPP::C2S::StreamHandler
This class handles the client side of a C2S (Client to Server) XMPP stream.
Definition: xmpp_c2s.h:81
XMPP::C2S::StreamHandler::HandleNullState
virtual void HandleNullState(PXML &pdu)
XMPP::C2S::StreamHandler::StreamSent
Definition: xmpp_c2s.h:218
XMPP::C2S::StreamHandler::SetVersion
void SetVersion(WORD major, WORD minor)
XMPP::C2S::TCPTransport::~TCPTransport
~TCPTransport()
XMPP::C2S::StreamHandler::MessageHandlers
PNotifierList & MessageHandlers()
Definition: xmpp_c2s.h:121
XMPP::C2S::StreamHandler::RegStarted
Definition: xmpp_c2s.h:214
XMPP::C2S::StreamHandler::HandleBindSentState
virtual void HandleBindSentState(PXML &pdu)
XMPP::C2S::TCPTransport::m_Hostname
PString m_Hostname
Definition: xmpp_c2s.h:72
XMPP::Stanza
XMPP stanzas: the following classes represent the three stanzas (PDUs) defined by the xmpp protocol...
Definition: xmpp.h:222
XMPP::C2S::StreamHandler::StreamHandler
StreamHandler(const JID &jid, const PString &pwd, PBoolean newAccount=false)
XMPP::Transport
This interface is the base class of each XMPP transport class.
Definition: xmpp.h:134
XMPP::C2S::StreamHandler::m_State
StreamState m_State
Definition: xmpp_c2s.h:226
XMPP::C2S::StreamHandler::Send
PBoolean Send(Stanza *stanza)
Request the delivery of the specified stanza NOTE: the StreamHandler takes ownership of the stanza an...
sockets.h
PMutex
Synonym for PTimedMutex.
XMPP::C2S::TCPTransport::m_Socket
PTCPSocket * m_Socket
Definition: xmpp_c2s.h:74
XMPP::BaseStreamHandler
Definition: xmpp.h:183
XMPP::C2S::StreamHandler::TLSStarted
Definition: xmpp_c2s.h:215
XMPP::C2S::StreamHandler::m_IQHandlers
PNotifierList m_IQHandlers
Definition: xmpp_c2s.h:204
PNotifierList
Definition: notifier_ext.h:102
XMPP::C2S::StreamHandler::OnPresence
virtual void OnPresence(XMPP::Presence &pdu)
XMPP::C2S::StreamHandler::m_JID
JID m_JID
Definition: xmpp_c2s.h:190
XMPP::Message
Definition: xmpp.h:252
XMPP::C2S::TCPTransport::Open
virtual PBoolean Open()
XMPP::C2S::StreamHandler::m_Password
const PString m_Password
Definition: xmpp_c2s.h:191
XMPP::C2S::TCPTransport::Close
virtual PBoolean Close()
Close the channel.