Blocking vs. Non-blocking Connections
Sending and Receiving of Chat Messages
Protocol Extensions (XEPs)
HTTP and SOCKS5 Proxy support
Upgrading from earlier versions
The design of gloox follows the so-called observer pattern, which basically means that everything is event-driven. There are two ways you can connect to the Jabber/XMPP network using gloox, either as client or as component. For a C++ XMPP server library see http://camaya.net/glooxd.
The most important tools of gloox are the event handlers. Currently, there exist 4 handlers for the basic protocol as defined in the RFCs, as well as numerous handlers for events generated by the included XEP-implementations and for additional functionality. Additionally, a log handler, a generic tag handler and a handler for connection events are available.
Basically these handlers are virtual interfaces from which you derive a class and implement a few virtual functions. Then you register such an object with the respective protocol implementation. A short example:
Somewhere else you do something like this:
Now, every time a presence stanza (not subscription stanza) is received, handlePresence() is called with the current stanza as argument. You can then use the extensive getters of the Stanza class to extract stanza data.
This works similar for all the other event handlers. Another example, this time using the connection event handler (class ConnectionListener ):
A component in the Jabber/XMPP network is an add-on to a server which runs externally to the actual server software, but can have similar privileges. Components use a protocol described in XEP-0114 to connect and authenticate to a server.
The Component class supports this protocol and can be used to create a new Jabber component. It's as simple as:
A client can be an end-user's chat client, a bot, or a similar entity not tied to a particular server. The Client class implements the necessary functionality to connect to an XMPP server. Usage is, again, pretty simple:
For some kind of bots a blocking connection (the default behaviour) is ideal. All the bot does is react to events coming from the server. However, for end user clients or anything with a GUI this is far from perfect.
In these cases non-blocking connections can be used. If ClientBase::connect( false ) is called, the function returnes immediately after the connection has been established. It is then the resposibility of the programmer to initiate receiving of data from the socket.
The easiest way is to call ClientBase::recv() periodically with the desired timeout (in microseconds) as parameter. The default value of -1 means the call blocks until any data was received, which is then parsed automatically.
As an alternative to periodic polling you can get a hold of the raw file descriptor used for the connection. You can then use select() on it and use ClientBase::recv() when select indicates that data is available. You should not recv() any data from the file descriptor directly as there is no way to feed that back into the parser.
To get the file descriptor you'll need to set a connection class (e.g. an instance of ConnectionTCPClient ) manually, like so:
It would also be possible to fetch the fd like this:
Obviously this will only work as long as you haven't set a different type of connection using setConnectionImpl().
Among others, RFC 3921 defines the protocol to manage one's contact list (roster). In gloox, the RosterManager class implements this functionality. A few easy-to-use functions are available to subscribe to or unsubscribe from the presence of remote entities. It is also possible to add a contact to a roster without actually subscribing to the contacts presence. Additionally, the interface RosterListener offers many callbacks for various roster-related events.
If you create a Client object as shown above, you also get a RosterManager for free. Client::rosterManager() returns a pointer to the object.
Also defined in RFC 3921: Privacy Lists. A Privacy List can be used to explicitely block or allow sending of stanzas from and to contacts, respectively. You can define rules based on JID, stanza type, etc. The PrivacyManager class and the PrivacyListHandler virtual interface allow for full flexibility in Privacy List handling.
For Messaging it is recommended to use the MessageSession interface. It handles sending and receiving of messages as well as message events and chat states (such as typing notifications, etc.). See MessageSession for more details.
The XMPP Standards Foundation has published a number of extensions to the core protocols, called XMPP Extension Protocols (XEPs). A couple of these XEPs are implemented in gloox:
Further extensions can easily be implemented using StanzaExtensions .
For file transfer, gloox implements XEP-0095 (Stream Initiation) as well XEP-0096 (File Transfer) for the signalling, and XEP-0065 (SOCKS5 Bytestreams) as well as XEP-0047 (In-Band Bytestreams) for the transport. See SIProfileFT .