gloox 1.0.28
StanzaExtension Class Referenceabstract

#include <stanzaextension.h>

Inheritance diagram for StanzaExtension:

Public Member Functions

 StanzaExtension (int type)
virtual ~StanzaExtension ()
virtual StanzaembeddedStanza () const
virtual TagembeddedTag () const
virtual const std::string & filterString () const =0
virtual StanzaExtensionnewInstance (const Tag *tag) const =0
virtual Tagtag () const =0
virtual StanzaExtensionclone () const =0
int extensionType () const

Detailed Description

This class abstracts a stanza extension, which is usually an XML child element in a specific namespace inside an XMPP stanza.

This class is the base class for almost all protocol extensions in gloox. As such, it should be used whenever an add-on to the core XMPP spec needs to be made. For simple protocols it may suffice to create a sub-class of StanzaExtension. For protocols which require keeping of state, an additional persistent object acting like a manager may be needed.

A Stanza can be extended by additional namespaced child elements. Obviously, it is not viable to include all the kinds of extensions possible. To avoid hard-coding of such extensions into gloox, StanzaExtension can be used to inform the core of gloox about additional supported extensions without it needing to know about the exact implementation.

Note that a StanzaExtension can be used for both sending and receiving of custom protocols. When receiving, gloox requires an appropriate implementation of the pure virtuals filterString() and newInstance(). To be able to properly use the encapsulation, some getters may be necessary. Note that the object you will be dealing with usually is const.

For sending StanzaExtensions, a custom constructor (as well as some setters, possibly) is needed. Additionally, an implementation of tag() is required.

  • Sub-class StanzaExtension and add at least a constructor that accepots a Tag* (so it can parse an incoming extension in XML format), as well as one accepting whatever data you need to construct outgoing extension XML. Alternatively to the latter (or in addition) you can also add setters, of course. One of the constructors should be able to create an empty instance so it can be passed to ClientBase when registering your extension type. This empty instance will only be used to create another new instance using the Tag* constructor when matching extension XML comes in.
  • Re-implement filterString(). filterString() is supposed to return an XPath expression that matches the child element of a stanza that the protocol-to-implement uses. For example, consider this hypothetical XML format: The protocol is encapsulated inside a <stats> element in the 'ext:stats' namespace. It uses IQ stanzas for transmission.
    <iq from='...' to='...' id='id1' type='get'>
    <stats xmlns='ext:stats'/>
    </iq>
    <iq from='...' to='...' id='id1' type='result'>
    <stats xmlns='ext:stats'>
    <users>10</users>
    </stats>
    </iq>
    The idea of filterString() and its XPath expression is to match the <stats> element such that it can be fed to your StanzaExtension-derived class' constructor when creating a new instance of it. For our stats protocol, filterString() would return something like: /iq/stats[@xmlns='ext:stats']
  • When subclassing StanzaExtension, you have to initialize it with an int, the extension's type. You should choose a value that is not yet used in gloox, and unique to the given extension you implement. In general, you are free to use values above ExtUser , e.g ExtUser+1, etc. See StanzaExtensionType for existing values.
  • Finally, gloox must be able to serialize the StanzaExtension back into string'ified XML. This is done by means of the tag() function which must be reimplemented. The output Tag should – like the input Tag – be embeddable into the respective stanza.
Author
Jakob Schröter js@ca.nosp@m.maya.nosp@m..net
Since
0.9

Definition at line 203 of file stanzaextension.h.

Constructor & Destructor Documentation

◆ StanzaExtension()

StanzaExtension ( int type)
inline

Constructs an empty StanzaExtension.

Parameters
typeDesignates the extension's type. It should be one of StanzaExtensionType for built-in extensions, and it should be higher than ExtUser for custom types.

Definition at line 211 of file stanzaextension.h.

◆ ~StanzaExtension()

virtual ~StanzaExtension ( )
inlinevirtual

Virtual destructor.

Definition at line 216 of file stanzaextension.h.

Member Function Documentation

◆ clone()

◆ embeddedStanza()

virtual Stanza * embeddedStanza ( ) const
inlinevirtual

This function returns the embedded Stanza, if any. You only have to reimplement it if your protocol flow contains embedded Stanzas.

Returns
The embedded Stanza. May be 0.

Reimplemented in Carbons, and Forward.

Definition at line 224 of file stanzaextension.h.

◆ embeddedTag()

virtual Tag * embeddedTag ( ) const
inlinevirtual

This function returns the embedded Tag that the embedded Stanza is based on, if any. You only have to reimplement it if your protocol flow contains embedded Stanzas.

Returns
The embedded Tag. May be 0.

Reimplemented in Carbons, Forward, and Session::Jingle.

Definition at line 232 of file stanzaextension.h.

◆ extensionType()

int extensionType ( ) const
inline

Returns the extension's type.

Returns
The extension's type.

Definition at line 271 of file stanzaextension.h.

◆ filterString()

virtual const std::string & filterString ( ) const
pure virtual

Returns an XPath expression that describes a path to child elements of a stanza that an extension handles.

Returns
The extension's filter string.

Implemented in Adhoc::Command, AMP, Attention, Capabilities, Carbons, ChatState, DataForm, DelayedDelivery, Disco::Info, Disco::Items, Error, FeatureNeg, Forward, GPGEncrypted, GPGSigned, IOData, Session::Jingle, LastActivity::Query, MessageEvent, MUCRoom::MUC, MUCRoom::MUCUser, Nickname, OOB, Event, Receipt, Registration::Query, SHIM, SoftwareVersion, VCard, VCardUpdate, and XHtmlIM.

◆ newInstance()

virtual StanzaExtension * newInstance ( const Tag * tag) const
pure virtual

Returns a new Instance of the derived type. Usually, for a derived class FooExtension, the implementation of this function looks like:

StanzaExtension* FooExtension::newInstance( const Tag* tag ) const
{
return new FooExtension( tag );
}
Returns
The derived extension's new instance.

Implemented in Adhoc::Command, AMP, Attention, Capabilities, Carbons, ChatState, DataForm, DelayedDelivery, Disco::Info, Disco::Items, Error, FeatureNeg, Forward, GPGEncrypted, GPGSigned, IOData, Session::Jingle, LastActivity::Query, MessageEvent, MUCRoom::MUC, MUCRoom::MUCUser, Nickname, OOB, Event, Receipt, Registration::Query, SHIM, SoftwareVersion, VCard, VCardUpdate, and XHtmlIM.

◆ tag()


The documentation for this class was generated from the following file: