Client Class Reference

This class implements a basic Jabber Client. More...

#include <client.h>

Inherits ClientBase.

Inheritance diagram for Client:

Inheritance graph
[legend]
Collaboration diagram for Client:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Client (const std::string &server)
 Client (const JID &jid, const std::string &password, int port=-1)
 Client (const std::string &username, const std::string &password, const std::string &server, const std::string &resource, int port=-1)
virtual ~Client ()
void bindResource ()
virtual const std::string username () const
std::string const resource () const
int priority () const
void setUsername (const std::string &username)
void setResource (const std::string &resource)
void setInitialPriority (int priority)
void setAutoPresence (bool autoPresence)
GLOOX_DEPRECATED void setForceNonSasl (bool force=true)
void disableDisco ()
void disableRoster ()
RosterManagerrosterManager ()
Discodisco ()
void disconnect ()

Protected Member Functions

void nonSaslLogin ()

Friends

class NonSaslAuth
class Parser

Detailed Description

This class implements a basic Jabber Client.

It supports SASL Authentication as well as TLS (Encryption), which can be switched on/off separately. They are used automatically if the server supports them.

To use, create a new Client instance and feed it connection credentials, either in the Constructor or afterwards using the setters. You should then register packet handlers implementing the corresponding Interfaces (ConnectionListener, PresenceHandler, MessageHandler, IqHandler, SubscriptionHandler), and call connect() to establish the connection to the server.

Note:
While the MessageHandler interface is still available (and will be in future versions) it is now recommended to use the new MessageSession for any serious messaging.
Simple usage example:
 using namespace gloox;

 void TestProg::doIt()
 {
   Client* j = new Client( "user@server/resource", "password" );
   j->registerPresenceHandler( this );
   j->disco()->setVersion( "TestProg", "1.0" );
   j->disco()->setIdentity( "client", "bot" );
   j->setAutoPresence( true );
   j->setInitialPriority( 5 );
   j->connect();
 }

 virtual void TestProg::presenceHandler( Stanza *stanza )
 {
   // handle incoming presence packets here
 }

However, you can skip the presence handling stuff if you make use of the RosterManager.

By default, the library handles a few (incoming) IQ namespaces on the application's behalf. These include:

SASL Authentication

Besides the simple, IQ-based authentication (JEP-0078), gloox supports several SASL (Simple Authentication and Security Layer, RFC 2222) authentication mechanisms. Of course, all these mechanisms are not tried unless the server offers them.

Author:
Jakob Schroeter <js@camaya.net>

Definition at line 101 of file client.h.


Constructor & Destructor Documentation

Client ( const std::string &  server  ) 

Constructs a new Client which can be used for account registration only. SASL and TLS are on by default. The port will be determined by looking up SRV records. Alternatively, you can set the port explicitly by calling setPort().

Parameters:
server The server to connect to.

Definition at line 38 of file client.cpp.

Client ( const JID jid,
const std::string &  password,
int  port = -1 
)

Constructs a new Client. SASL and TLS are on by default. This should be the default constructor for most use cases. The server address will be taken from the JID. The actual host will be resolved using SRV records. The domain part of the JID is used as a fallback in case no SRV record is found, or you can set the server address separately by calling setServer().

Parameters:
jid A full Jabber ID used for connecting to the server.
password The password used for authentication.
port The port to connect to. The default of -1 means to look up the port via DNS SRV.

Definition at line 49 of file client.cpp.

Client ( const std::string &  username,
const std::string &  password,
const std::string &  server,
const std::string &  resource,
int  port = -1 
)

Constructs a new Client. SASL and TLS are on by default. The actual host will be resolved using SRV records. The server value is used as a fallback in case no SRV record is found.

Parameters:
username The username/local part of the JID.
resource The resource part of the JID.
password The password to use for authentication.
server The Jabber ID'S server part and the host name to connect to. If those are different for your setup, use the second constructor instead.
port The port to connect to. The default of -1 means to look up the port via DNS SRV.

Definition at line 61 of file client.cpp.

~Client (  )  [virtual]

Virtual destructor.

Definition at line 76 of file client.cpp.


Member Function Documentation

void bindResource (  ) 

Use this function to re-try to bind a resource only in case you were notified about an error by means of ConnectionListener::onResourceBindError(). You may (or should) use setResource() before.

Definition at line 332 of file client.cpp.

virtual const std::string username (  )  const [inline, virtual]

Returns the current prepped username.

Returns:
The username used to connect.

Implements ClientBase.

Definition at line 159 of file client.h.

Referenced by NonSaslAuth::doAuth().

std::string const resource (  )  const [inline]

Returns the current prepped resource.

Returns:
The resource used to connect.

Definition at line 165 of file client.h.

Referenced by Client::bindResource().

int priority (  )  const [inline]

Returns the current priority.

Returns:
The priority of the current resource.

Definition at line 171 of file client.h.

void setUsername ( const std::string &  username  ) 

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

Parameters:
username The username to authenticate with.

Definition at line 91 of file client.cpp.

void setResource ( const std::string &  resource  )  [inline]

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

Parameters:
resource The resource to use to log into the server.

Definition at line 183 of file client.h.

void setInitialPriority ( int  priority  ) 

Set initial priority. Legal values: -128 <= priority <= 127

Parameters:
priority The initial priority value.

Definition at line 483 of file client.cpp.

void setAutoPresence ( bool  autoPresence  )  [inline]

Enables/disables the automatic sending of a presence packet upon successful authentication before the ConnectionListeners are notified. Default: off

Parameters:
autoPresence Whether to switch AutoPresence on or off.

Definition at line 197 of file client.h.

GLOOX_DEPRECATED void setForceNonSasl ( bool  force = true  )  [inline]

This is a temporary hack to enforce Non-SASL login. You should not need to use it.

Parameters:
force Whether to force non-SASL auth. Default true.
Deprecated:

Definition at line 204 of file client.h.

void disableDisco (  ) 

Disables automatic handling of disco queries. There is currently no way to re-enable disco query-handling.

Note:
This disables the browsing capabilities because both use the same Disco object.

Definition at line 452 of file client.cpp.

void disableRoster (  ) 

Disables the automatic roster management. You have to keep track of incoming presence yourself if you want to have a roster.

Definition at line 459 of file client.cpp.

RosterManager * rosterManager (  ) 

This function gives access to the RosterManager object.

Returns:
A pointer to the RosterManager.

Definition at line 493 of file client.cpp.

Disco * disco (  ) 

This function gives access to the Disco object.

Returns:
A pointer to the Disco object.

Definition at line 498 of file client.cpp.

void disconnect (  ) 

Disconnects from the server.

Definition at line 522 of file client.cpp.

Referenced by NonSaslAuth::handleIqID().

void nonSaslLogin (  )  [protected]

Initiates non-SASL login.

Definition at line 466 of file client.cpp.


The documentation for this class was generated from the following files:
Generated on Tue May 1 14:20:22 2007 for gloox by  doxygen 1.5.1