gloox was born as part of a university project (XMPPGrid: A Grid Framework) that used Jabber/XMPP as a transport protocol. Because, at that time, there were no C++ XMPP libraries available that suited my needs, I decided to roll my own.
gloox (http://camaya.net/gloox) heavily uses the Observer Pattern. There are listeners ("handlers" in gloox-speak) for almost every imaginable event that can occur, from connection establishment to error conditions. After a connection has been established, everything is event driven, and simple applications, such as bots, can easily do without a mainloop or threads. On the other hand, gloox exposes the necessary interface to manually initiate fetching of data from the socket.
Right after the XML parser receives a complete stanza, it is parsed into a Stanza object that offers a convenient interface to take apart such an XML element. The respective handlers are then called based on the stanza's type.
The library offers classes to create regular clients as well as components. These only offer basic functionality, but can be extended with several included implementations of so-called Jabber Enhancement Proposals (JEPs) to create a full-featured client/component.
In general, using the library is as simple as:
- • Creating a new Client or Component object.
- • Creating and registering the desired handlers.
- • Calling connect().
Most protocol enhancements follow a similar approach: They simply register as handlers for one of the Stanza types. For example, the Info/Query (IQ) mechanism of the XMPP spec is an important tool to control various aspects of a session. The basic syntax of IQ packets is always the same and different protocols are distinguished based on the payload of an IQ packet: The child element and its namespace. gloox offers a handler for these namespaces, which makes it extremely easy to implement every IQ-based protocol.
Additionally, handlers for the remaining XMPP packet types (called "stanzas" in XMPP) are included, along with a generic tag handler for protocols not using these defined stanza types.
While using these interfaces, the higher level layers offer handlers themselves, with data types tailored to their needs. This minimizes the need to know the XMPP protocol by heart if the included classes are used.
Even though it is defined in the XMPP IM spec, Roster Management is an example for such a higher level protocol. The RosterManager registers itself as a handler for IQ stanzas carrying "query" elements qualified by the jabber:iq:roster namespace. It can then add or remove items from a user's contact list, and react to incoming so-called roster pushes, an updated contact list item sent by the server.
The RosterManager offers clients a rich interface to be notified about any changes happening to the contact list. Events exist for adding and removing contacts, as well as for changes in subscription states.
The decision of using/activating one (or more) of the protocol enhancements is with the user of the library. The modular structure allows addition and removal of those enhancements at runtime. More JEPs can easily be implemented, usually by creating handlers for the respective XML namespaces a JEP uses. gloox is licensed under the GPL and commercial licenses are available.
DDJ