ClientBase Class Reference

This is the common base class for a jabber Client and a jabber Component. More...

#include <clientbase.h>

Inherited by Client, and Component.

Inheritance diagram for ClientBase:

Inheritance graph
[legend]
Collaboration diagram for ClientBase:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ClientBase (const std::string &ns, const std::string &server, int port=-1)
 ClientBase (const std::string &ns, const std::string &password, const std::string &server, int port=-1)
virtual ~ClientBase ()
bool connect (bool block=true)
ConnectionError recv (int timeout=-1)
void disconnect ()
virtual const std::string username () const =0
JIDjid ()
void setSasl (bool sasl)
void setTls (bool tls)
void setPort (int port)
void setServer (const std::string &server)
void setPassword (const std::string &password)
const std::string server () const
bool sasl () const
bool tls () const
int port () const
virtual const std::string password () const
const std::string getID ()
virtual void send (Tag *tag)
bool authed () const
ConnectionState state () const
const std::string & xmlLang () const
void setXmlLang (const std::string &xmllang)
int fileDescriptor () const
void registerConnectionListener (ConnectionListener *cl)
void registerIqHandler (IqHandler *ih, const std::string &xmlns)
void trackID (IqHandler *ih, const std::string &id, int context)
void registerMessageHandler (MessageHandler *mh)
void registerPresenceHandler (PresenceHandler *ph)
void registerSubscriptionHandler (SubscriptionHandler *sh)
void registerLogHandler (LogHandler *lh)
void registerTagHandler (TagHandler *th, const std::string &tag, const std::string &xmlns)
void removeConnectionListener (ConnectionListener *cl)
void removeIqHandler (const std::string &xmlns)
void removeMessageHandler (MessageHandler *mh)
void removePresenceHandler (PresenceHandler *ph)
void removeSubscriptionHandler (SubscriptionHandler *sh)
void removeTagHandler (TagHandler *th, const std::string &tag, const std::string &xmlns)
void removeLogHandler (LogHandler *lh)
void setCACerts (const StringList &cacerts)
StreamError streamError () const
const std::string streamErrorText (const std::string &lang="default") const
const std::string streamErrorCData () const
const TagstreamErrorAppCondition () const
AuthenticationError authError () const

Protected Types

enum  SaslMechanisms { SASL_DIGEST_MD5, SASL_PLAIN, SASL_ANONYMOUS }

Protected Member Functions

void notifyOnResourceBindError (ConnectionListener::ResourceBindError error)
void notifyOnSessionCreateError (ConnectionListener::SessionCreateError error)
bool notifyOnTLSConnect (const CertInfo &info)
void log (const std::string &xml, bool incoming)
void notifyOnConnect ()
void disconnect (ConnectionError reason)
void header ()
void setAuthed (bool authed)
void setAuthFailure (AuthenticationError e)
virtual bool checkStreamVersion (const std::string &version)
void startSASL (SaslMechanisms type)
void processSASLChallenge (const std::string &challenge)
void processSASLError (Stanza *stanza)
void startTls ()
bool hasTls ()

Protected Attributes

JID m_jid
Connectionm_connection
std::string m_namespace
std::string m_password
std::string m_xmllang
std::string m_server
std::string m_sid
bool m_authed
bool m_sasl
bool m_tls
int m_port

Friends

class Parser

Detailed Description

This is the common base class for a jabber Client and a jabber Component.

It manages connection establishing, authentication, filter registrationa and invocation.

Author:
Jakob Schroeter <js@camaya.net>
Since:
0.3

Definition at line 50 of file clientbase.h.


Member Enumeration Documentation

enum SaslMechanisms [protected]
 

Enumerator:
SASL_DIGEST_MD5  SASL Digest-MD5 according to RFC 2831.
SASL_PLAIN  SASL PLAIN according to RFC 2595 Section 6.
SASL_ANONYMOUS  SASL ANONYMOUS according to draft-ietf-sasl-anon-05.txt/ RFC 2245 Section 6.

Definition at line 385 of file clientbase.h.


Constructor & Destructor Documentation

ClientBase const std::string &  ns,
const std::string &  server,
int  port = -1
 

Constructs a new ClientBase. You should not need to use this class directly. Use Client or Component instead.

Parameters:
ns The namespace which qualifies the stream. Either jabber:client or jabber:component:*
server The server to connect to.
port The port to connect to. The default of -1 means to look up the port via DNS SRV or to use a default port of 5222 as defined in XMPP: Core.

Definition at line 37 of file clientbase.cpp.

ClientBase const std::string &  ns,
const std::string &  password,
const std::string &  server,
int  port = -1
 

Constructs a new ClientBase. You should not need to use this class directly. Use Client or Component instead.

Parameters:
ns The namespace which qualifies the stream. Either jabber:client or jabber:component:*
password The password to use for further authentication.
server The server to connect to.
port The port to connect to. The default of -1 means to look up the port via DNS SRV or to use a default port of 5222 as defined in XMPP: Core.

Definition at line 45 of file clientbase.cpp.

~ClientBase  )  [virtual]
 

Virtual destrcuctor.

Definition at line 54 of file clientbase.cpp.

References ClientBase::m_connection.


Member Function Documentation

bool authed  )  const [inline]
 

Returns whether authentication has taken place and was successful.

Returns:
True if authentication has been carried out and was successful, false otherwise.

Definition at line 204 of file clientbase.h.

Referenced by Registration::changePassword(), and Registration::removeAccount().

AuthenticationError authError  )  const [inline]
 

Use this function to retrieve the type of the authentication error after it occurs and you received a ConnectionError of type CONN_AUTHENTICATION_FAILED from the ConnectionListener.

Returns:
The type of the authentication, if any, AUTH_ERROR_UNDEFINED otherwise.

Definition at line 382 of file clientbase.h.

bool connect bool  block = true  ) 
 

Initiates the connection to a server. This function blocks as long as a connection is established. You can have the connection block 'til the end of the connection, or you can have it return immediately. If you choose the latter, its your responsibility to call recv() every now and then to actually receive data from the socket and to feed the parser.

Parameters:
block True for blocking, false for non-blocking connect. Defaults to true.
Returns:
False if prerequisits are not met (server not set) or if the connection was refused, true otherwise.

Definition at line 68 of file clientbase.cpp.

References Connection::connect(), ClientBase::header(), ClientBase::m_connection, ClientBase::m_port, ClientBase::m_server, ClientBase::Parser, Connection::receive(), Connection::setCACerts(), and gloox::STATE_CONNECTED.

void disconnect  ) 
 

Disconnects from the server.

Definition at line 159 of file clientbase.cpp.

References gloox::CONN_USER_DISCONNECTED.

Referenced by NonSaslAuth::handleIqID().

int fileDescriptor  )  const
 

Gives access to the raw file descriptor of the current connection. Use it wisely. Especially, you should not recv() any data from it. There is no way to feed that back into the parser. You can use select() on it and use Connection::recv( -1 ) to fetch the data.

Returns:
The file descriptor of the active connection, or -1 if no connection is established.

Definition at line 515 of file clientbase.cpp.

References Connection::fileDescriptor(), and ClientBase::m_connection.

const std::string getID  ) 
 

Creates a string which is unique in the current instance and can be used as an ID for queries.

Returns:
A unique string suitable for query IDs.

Definition at line 388 of file clientbase.cpp.

Referenced by RosterManager::add(), Registration::changePassword(), Registration::createAccount(), NonSaslAuth::doAuth(), FlexibleOffline::fetchMessages(), Registration::fetchRegistrationFields(), RosterManager::fill(), Disco::getDiscoInfo(), Disco::getDiscoItems(), LastActivity::query(), Registration::removeAccount(), PrivacyManager::removeList(), FlexibleOffline::removeMessages(), PrivacyManager::requestList(), PrivacyManager::requestListNames(), PrivateXML::requestXML(), PrivacyManager::setActive(), PrivacyManager::setDefault(), ClientBase::startSASL(), PrivacyManager::store(), PrivateXML::storeXML(), RosterManager::synchronize(), PrivacyManager::unsetActive(), PrivacyManager::unsetDefault(), and RosterManager::unsubscribe().

JID& jid  )  [inline]
 

Returns the current jabber id.

Returns:
The Jabber ID.
Note:
I you change the server part of the JID, the server of the connection is not synced. You have to do that manually using setServer().

Definition at line 121 of file clientbase.h.

Referenced by RosterManager::ackSubscriptionRequest(), FlexibleOffline::checkSupport(), Client::Client(), NonSaslAuth::doAuth(), FlexibleOffline::fetchHeaders(), Disco::getDiscoInfo(), Disco::getDiscoItems(), FlexibleOffline::getMsgCount(), Disco::handleIq(), Registration::removeAccount(), RosterManager::RosterManager(), RosterManager::subscribe(), and RosterManager::unsubscribe().

virtual const std::string password  )  const [inline, virtual]
 

Returns the current password.

Returns:
The password used to connect.

Reimplemented in Component.

Definition at line 185 of file clientbase.h.

int port  )  const [inline]
 

Returns the port. The default of -1 means that the actual port will be looked up using SRV records, or the XMPP default port of 5222 will be used.

Returns:
The port used to connect.

Definition at line 179 of file clientbase.h.

ConnectionError recv int  timeout = -1  ) 
 

Use this periodically to receive data from the socket and to feed the parser. You need to use this only if you chose to connect in non-blocking mode.

Parameters:
timeout The timeout to use for select. Default of -1 means blocking until data was available.
Returns:
The state of the connection.

Definition at line 60 of file clientbase.cpp.

References gloox::CONN_OK, ClientBase::m_connection, and Connection::recv().

void registerConnectionListener ConnectionListener cl  ) 
 

Registers cl as object that receives connection notifications.

Parameters:
cl The object to receive connection notifications.

Definition at line 604 of file clientbase.cpp.

void registerIqHandler IqHandler ih,
const std::string &  xmlns
 

Registers ih as object that receives Iq stanza notifications for namespace xmlns. Only one handler per namespace is possible.

Parameters:
ih The object to receive Iq stanza notifications.
xmlns The namespace the object handles.

Definition at line 545 of file clientbase.cpp.

Referenced by Adhoc::Adhoc(), Disco::Disco(), NonSaslAuth::NonSaslAuth(), PrivacyManager::PrivacyManager(), PrivateXML::PrivateXML(), Registration::Registration(), and RosterManager::RosterManager().

void registerLogHandler LogHandler lh  ) 
 

Registers lh as object that receives all XML sent back and forth on the connection. Suitable for logging to a file, etc.

Parameters:
lh The object to receive exchanged data.

Definition at line 535 of file clientbase.cpp.

void registerMessageHandler MessageHandler mh  ) 
 

Registers mh as object that receives Message stanza notifications.

Parameters:
mh The object to receive Message stanza notifications.

Definition at line 568 of file clientbase.cpp.

void registerPresenceHandler PresenceHandler ph  ) 
 

Registers ph as object that receives Presence stanza notifications.

Parameters:
ph The object to receive Presence stanza notifications.

Definition at line 523 of file clientbase.cpp.

Referenced by RosterManager::RosterManager().

void registerSubscriptionHandler SubscriptionHandler sh  ) 
 

Registers sh as object that receives Subscription stanza notifications.

Parameters:
sh The object to receive Subscription stanza notifications.

Definition at line 580 of file clientbase.cpp.

Referenced by RosterManager::RosterManager().

void registerTagHandler TagHandler th,
const std::string &  tag,
const std::string &  xmlns
 

Registers th as object that receives incoming packts with a given root tag qualified by the given namespace.

Parameters:
th The object to receive Subscription packet notifications.
tag The element's name.
xmlns The element's namespace.

Definition at line 586 of file clientbase.cpp.

void removeConnectionListener ConnectionListener cl  ) 
 

Removes the given object from the list of connection listeners.

Parameters:
cl The object to remove from the list.

Definition at line 610 of file clientbase.cpp.

void removeIqHandler const std::string &  xmlns  ) 
 

Removes the handler for the given namespace from the list of Iq handlers.

Parameters:
xmlns The namespace to remove from the list.

Definition at line 562 of file clientbase.cpp.

Referenced by Adhoc::~Adhoc(), Disco::~Disco(), NonSaslAuth::~NonSaslAuth(), PrivacyManager::~PrivacyManager(), PrivateXML::~PrivateXML(), Registration::~Registration(), and RosterManager::~RosterManager().

void removeLogHandler LogHandler lh  ) 
 

Removes the given object from the list of log handlers.

Parameters:
lh The object to remove from the list.

Definition at line 540 of file clientbase.cpp.

void removeMessageHandler MessageHandler mh  ) 
 

Removes the given object from the list of message handlers.

Parameters:
mh The object to remove from the list.

Definition at line 574 of file clientbase.cpp.

void removePresenceHandler PresenceHandler ph  ) 
 

Removes the given object from the list of presence handlers.

Parameters:
ph The object to remove from the list.

Definition at line 529 of file clientbase.cpp.

Referenced by RosterManager::~RosterManager().

void removeSubscriptionHandler SubscriptionHandler sh  ) 
 

Removes the given object from the list of subscription handlers.

Parameters:
sh The object to remove from the list.

Definition at line 598 of file clientbase.cpp.

Referenced by RosterManager::~RosterManager().

void removeTagHandler TagHandler th,
const std::string &  tag,
const std::string &  xmlns
 

Removes the given object from the list of tag handlers for the given element and namespace.

Parameters:
th The object to remove from the list.
tag The element to remove the handler for.
xmlns The namespace qualifying the element.

Definition at line 616 of file clientbase.cpp.

bool sasl  )  const [inline]
 

Returns the current SASL status.

Returns:
The current SASL status.

Definition at line 166 of file clientbase.h.

void send Tag tag  )  [virtual]
 

Sends a given Tag over an established connection.

Parameters:
tag The Tag to send.

Definition at line 357 of file clientbase.cpp.

References gloox::STANZA_UNDEFINED, Tag::type(), and Tag::xml().

Referenced by RosterManager::ackSubscriptionRequest(), Client::bindResource(), Registration::changePassword(), Registration::createAccount(), NonSaslAuth::doAuth(), Registration::fetchRegistrationFields(), RosterManager::fill(), Disco::getDiscoInfo(), Disco::getDiscoItems(), PrivacyManager::handleIq(), LastActivity::handleIq(), Disco::handleIq(), Component::handleStartNode(), ClientBase::header(), LastActivity::query(), Registration::removeAccount(), PrivacyManager::removeList(), PrivacyManager::requestList(), PrivacyManager::requestListNames(), PrivateXML::requestXML(), PrivacyManager::setActive(), PrivacyManager::setDefault(), ClientBase::startSASL(), ClientBase::startTls(), PrivateXML::storeXML(), RosterManager::subscribe(), PrivacyManager::unsetActive(), PrivacyManager::unsetDefault(), and RosterManager::unsubscribe().

const std::string server  )  const [inline]
 

Returns the current prepped server.

Returns:
The server used to connect.

Definition at line 160 of file clientbase.h.

Referenced by Registration::changePassword().

void setCACerts const StringList cacerts  )  [inline]
 

Use this function to set a number of trusted root CA certificates. which shall be used to verify a servers certificate.

Parameters:
cacerts A list of absolute paths to CA root certificate files in PEM format.

Definition at line 343 of file clientbase.h.

void setPassword const std::string &  password  )  [inline]
 

Sets the password to use to connect to the XMPP server.

Parameters:
password The password to use for authentication.

Definition at line 154 of file clientbase.h.

void setPort int  port  )  [inline]
 

Sets the port to connect to. This is not necessary if either the default port (5222) is used or SRV records exist which will be resolved.

Parameters:
port The port to connect to.

Definition at line 140 of file clientbase.h.

void setSasl bool  sasl  )  [inline]
 

Switches usage of SASL on/off. Default: on

Parameters:
sasl Whether to switch SASL usage on or off.

Definition at line 127 of file clientbase.h.

void setServer const std::string &  server  )  [inline]
 

Sets the XMPP server to connect to.

Parameters:
server The server to connect to. Either IP or fully qualified domain name.
Note:
If you change the server, the server part of the JID is not synced. You have to do that manually using jid() and JID::setServer().

Definition at line 148 of file clientbase.h.

void setTls bool  tls  )  [inline]
 

Switches usage of TLS on/off (if available). Default: on

Parameters:
tls Whether to switch TLS usage on or off.

Definition at line 133 of file clientbase.h.

void setXmlLang const std::string &  xmllang  )  [inline]
 

Sets the value for the xml:lang attribute of the initial stream.

Parameters:
xmllang The language identifier for the stream. It must conform to section 2.12 of the XML specification and RFC 3066. Default is 'en'.

Definition at line 224 of file clientbase.h.

ConnectionState state  )  const
 

Returns the current connection status.

Returns:
The status of the connection.

Definition at line 381 of file clientbase.cpp.

References ClientBase::m_connection, Connection::state(), and gloox::STATE_DISCONNECTED.

Referenced by Registration::fetchRegistrationFields().

StreamError streamError  )  const [inline]
 

Use this function to retrieve the type of the stream error after it occurs and you received a ConnectionError of type CONN_STREAM_ERROR from the ConnectionListener.

Definition at line 349 of file clientbase.h.

const Tag* streamErrorAppCondition  )  const [inline]
 

This function can be used to retrieve the application-specific error condition of a stream error.

Returns:
The application-specific error element of a stream error. 0 if no respective element was found or no error occured.

Definition at line 375 of file clientbase.h.

const std::string streamErrorCData  )  const [inline]
 

In case the defined-condition element of an stream error contains XML character data you can use this function to retrieve it. RFC 3920 only defines one condition (see-other-host)where this is possible.

Returns:
The cdata of the stream error's text element (only for see-other-host).

Definition at line 368 of file clientbase.h.

const std::string streamErrorText const std::string &  lang = "default"  )  const
 

Returns the text of a stream error for the given language if available. If the requested language is not available, the default text (without a xml:lang attribute) will be returned.

Parameters:
lang The language identifier for the desired language. It must conform to section 2.12 of the XML specification and RFC 3066. If empty, the default body will be returned, if any.
Returns:
The describing text of a stream error. Empty if no stream error occured.

Definition at line 488 of file clientbase.cpp.

bool tls  )  const [inline]
 

Returns the current TLS status.

Returns:
The current TLS status.

Definition at line 172 of file clientbase.h.

void trackID IqHandler ih,
const std::string &  id,
int  context
 

Use this function to be notified of incoming IQ stanzas with the given value of the id attribute. Since IDs are supposed to be unique, this notification works only once.

Parameters:
ih The IqHandler to receive notifications.
id The id to track.
context A value that allows for restoring context.

Definition at line 551 of file clientbase.cpp.

Referenced by Registration::changePassword(), Registration::createAccount(), NonSaslAuth::doAuth(), Registration::fetchRegistrationFields(), Disco::getDiscoInfo(), Disco::getDiscoItems(), LastActivity::query(), Registration::removeAccount(), PrivacyManager::removeList(), PrivacyManager::requestList(), PrivacyManager::requestListNames(), PrivateXML::requestXML(), PrivacyManager::setActive(), PrivacyManager::setDefault(), PrivateXML::storeXML(), PrivacyManager::unsetActive(), and PrivacyManager::unsetDefault().

virtual const std::string username  )  const [pure virtual]
 

Reimplement this function to provide a username for connection purposes.

Returns:
The username.

Implemented in Client, and Component.

Referenced by Registration::changePassword().

const std::string& xmlLang  )  const [inline]
 

Retrieves the value of the xml:lang attribute of the initial stream. Default is 'en', i.e. if not changed by a call to setXmlLang().

Definition at line 216 of file clientbase.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 16 16:19:56 2006 for gloox by  doxygen 1.4.6