Registration Class Reference

This class is an implementation of JEP-0077 (In-Band Registration). More...

#include <registration.h>

Inherits IqHandler.

Inheritance diagram for Registration:

Inheritance graph
[legend]
Collaboration diagram for Registration:

Collaboration graph
[legend]
List of all members.

Public Types

enum  fieldEnum

Public Member Functions

 Registration (ClientBase *parent)
virtual ~Registration ()
void fetchRegistrationFields ()
void createAccount (int fields, fieldStruct values)
void removeAccount ()
void changePassword (const std::string &password)
void registerRegistrationHandler (RegistrationHandler *rh)
void removeRegistrationHandler ()
virtual bool handleIq (Stanza *stanza)
virtual bool handleIqID (Stanza *stanza, int context)

Classes

struct  fieldStruct

Detailed Description

This class is an implementation of JEP-0077 (In-Band Registration).

Derive your object from RegistrationHandler and implement the virtual functions offered by that interface. Then use it like this:

 Client *c = new Client( "example.org" );
 c->disableRoster(); // not needed
 c->disableDisco(); // not needed

 Registration* r = new Registration( c );
 r->registerRegistrationHandler( this );
 r->fetchRegistrationFields();

 c->connect();
In RegistrationHandler::handleRegistrationFields() you should check which information the server requires to open a new account. You might not always get away with just username and password. Then call createAccount() with a filled-in fieldStruct and an int representing the bit-wise ORed fields you want to have included in the registration attempt. For your convenience you can use the 'fields' argument of handleRegistrationFields(). ;) It's your responsibility to make sure at least those fields the server requested are filled in.

Check tests/register_test.cpp for an example.

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

Definition at line 56 of file registration.h.


Member Enumeration Documentation

enum fieldEnum
 

The possible fields of a JEP-0077 account registration.

Definition at line 87 of file registration.h.


Constructor & Destructor Documentation

Registration ClientBase parent  ) 
 

Constructor.

Parameters:
parent The ClientBase which is used for establishing a connection.

Definition at line 23 of file registration.cpp.

References ClientBase::registerIqHandler().

~Registration  )  [virtual]
 

Virtual destructor.

Definition at line 30 of file registration.cpp.

References ClientBase::removeIqHandler().


Member Function Documentation

void changePassword const std::string &  password  ) 
 

Tells the server to change the password for the current account.

Parameters:
password The new password.

Definition at line 125 of file registration.cpp.

References Tag::addAttrib(), Tag::addChild(), ClientBase::authed(), ClientBase::getID(), ClientBase::send(), ClientBase::server(), ClientBase::trackID(), and ClientBase::username().

void createAccount int  fields,
fieldStruct  values
 

Attempts to register an account with the given credentials. Only the fields OR'ed in fields will be sent. This can only be called with an unauthenticated parent (Client).

Note:
It is recommended to use fetchRegistrationFields to find out which fields the server requires.
Parameters:
fields The fields to use to generate the registration request. OR'ed fieldEnum values.
values The struct contains the values which shall be used for the registration.

Definition at line 54 of file registration.cpp.

References Tag::addAttrib(), Tag::addChild(), Registration::fieldStruct::address, Registration::fieldStruct::city, Registration::fieldStruct::date, Registration::fieldStruct::email, Registration::fieldStruct::first, ClientBase::getID(), Registration::fieldStruct::last, Registration::fieldStruct::misc, Registration::fieldStruct::name, Registration::fieldStruct::nick, Prep::nodeprep(), Registration::fieldStruct::password, Registration::fieldStruct::phone, ClientBase::send(), Registration::fieldStruct::state, Registration::fieldStruct::text, ClientBase::trackID(), Registration::fieldStruct::url, Registration::fieldStruct::username, and Registration::fieldStruct::zip.

void fetchRegistrationFields  ) 
 

Use this function to request the registration fields the server requires. The required fields are returned asynchronously to the object registered as RegistrationHandler by calling RegistrationHandler::handleRegistrationFields().

Definition at line 36 of file registration.cpp.

References Tag::addAttrib(), Tag::addChild(), ClientBase::getID(), ClientBase::send(), ClientBase::state(), gloox::STATE_CONNECTED, and ClientBase::trackID().

bool handleIq Stanza stanza  )  [virtual]
 

Reimplement this function if you want to be notified about incoming IQs.

Parameters:
stanza The complete Stanza.
Returns:
Indicates whether a request of type 'get' or 'set' has been handled. This includes the obligatory 'result' answer. If you return false, a 'error' will be sent.

Implements IqHandler.

Definition at line 156 of file registration.cpp.

References Tag::findChild(), RegistrationHandler::handleRegistrationResult(), RegistrationHandler::REGISTRATION_BAD_REQUEST, RegistrationHandler::REGISTRATION_CONFLICT, RegistrationHandler::REGISTRATION_FORBIDDEN, RegistrationHandler::REGISTRATION_NOT_ACCEPTABLE, RegistrationHandler::REGISTRATION_NOT_ALLOWED, RegistrationHandler::REGISTRATION_NOT_AUTHORIZED, RegistrationHandler::REGISTRATION_REGISTRATION_REQUIRED, RegistrationHandler::REGISTRATION_UNEXPECTED_REQUEST, gloox::STANZA_IQ_ERROR, and Stanza::subtype().

bool handleIqID Stanza stanza,
int  context
[virtual]
 

Reimplement this function if you want to be notified about incoming IQs with a specific value of the id attribute. You have to enable tracking of those IDs using Client::trackID(). This is usually useful for IDs that generate a positive reply, i.e. <iq type='result' id='reg'/> where a namespace filter wouldn't work.

Parameters:
stanza The complete Stanza.
context A value to restore context, stored with ClientBase::trackID().
Returns:
Indicates whether a request of type 'get' or 'set' has been handled. This includes the obligatory 'result' answer. If you return false, a 'error' will be sent.

Implements IqHandler.

Definition at line 187 of file registration.cpp.

References Tag::findChild(), RegistrationHandler::handleAlreadyRegistered(), RegistrationHandler::handleRegistrationFields(), RegistrationHandler::handleRegistrationResult(), Tag::hasChild(), RegistrationHandler::REGISTRATION_SUCCESS, gloox::STANZA_IQ_RESULT, and Stanza::subtype().

void registerRegistrationHandler RegistrationHandler rh  ) 
 

Registers the given rh as RegistrationHandler. Only one handler is possible at a time.

Parameters:
rh The RegistrationHandler to register.

Definition at line 146 of file registration.cpp.

void removeAccount  ) 
 

Tells the server to remove the currently authenticated account from the server.

Definition at line 105 of file registration.cpp.

References Tag::addAttrib(), Tag::addChild(), ClientBase::authed(), JID::full(), ClientBase::getID(), ClientBase::jid(), ClientBase::send(), and ClientBase::trackID().

void removeRegistrationHandler  ) 
 

Un-registers the current RegistrationHandler.

Definition at line 151 of file registration.cpp.


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