Author: Peter Saint-Andre
License: This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at <http://www.opencontent.org/openpub/>).
Acknowledgement: An earlier version of this article was published at O'Reilly Network (<http://www.oreillynet.com/>) in October 2000.
Discussions of XML can often seem dry, abstract, and even hopelessly arcane (have you read the XML Schema spec lately?). So it can be refreshing to look at a powerful (even fun) application that's built on XML. One such application is Jabber, an open-source instant messaging and presence system that is beginning to garner a lot of attention from the open-source community and large corporations alike.
Eric S. Raymond's first lesson of open-source software development declares that "Every good work of software starts by scratching a developer's personal itch." That was certainly the case with Jabber. Jeremie Miller, the founder of the Jabber.org Project, got sick of using four or five applications to keep in touch with friends on different instant messaging (IM) systems and to monitor various IRC channels. So he started to think about building a cross-platform, open-source IM system that would speak to all the other messaging systems.
From the beginning of the project in early 1998, Jeremie resolved that Jabber would stand apart from existing IM systems by being based on a foundation of XML. Indeed, XML is not an afterthought or a cool buzzword in the Jabber world, but simply the way things are done.
The basic architecture of Jabber is extremely similar to that of email. Jabber consists of a network of distributed servers, each associated with a distinct Internet domain. In order to communicate with other people, you first create an account on a server and then log in. You may then send messages and exchange presence with other users. These users can be on your own server or in other domains. If you send a message to someone in another domain, your server connects to the destination server and "hands off" the message to that server, which delivers it to the intended recipient. A further similarity with email is that Jabber IDs look just like email addresses (e.g., stpeter@jabber.org).
The server perspective is somewhat more complicated. In fact, this is intentional, because the complexity of the server makes it easy to write Jabber clients (there are clients for everything from Windows, Linux, and MacOS to BeOS, Amiga, even Newton!). In essence, however, the server is made of two basic components: the core Jabber router and optional components such as groupchat services and "gateways" to non-Jabber IM networks.
The core router handles communications within the Jabber system. An example is when I send a message from my Jabber account to a friend who is also using Jabber. In this case, all the messaging occurs in the format of Jabber's open XML protocol, so the communications are "native" to Jabber. Although there is a lot of code that makes this happen, in a way it is relatively simple.
The gateways translate Jabber XML into and out of what we might think of as "foreign" protocols. An example is when I chat with a friend who's using another instant messaging system (such as AIM, ICQ, or MSN). It's in the world of gateways that some of the "black magic" of Jabber comes into play, especially when the foreign protocol is not well-documented. When you use Jabber to connect to non-Jabber systems, it is as if the relevant gateway is "masquerading" as you on the foreign system. When you register with the gateway, you tell it about your user information on the foreign system and in the future it acts on your behalf with that system, sending and receiving messages and presence information in that foreign protocol. The result is that your friends on (let's say) ICQ think they're communicating with you on ICQ when in fact you are using Jabber, and specifically Jabber's ICQ gateway, to speak the language of ICQ. In this way Jabber is somewhat like a universal translator, although at present Jabber is not "universal" since gateways do not yet exist for all messaging systems. (And no, we won't get into the politics of interoperability in this article!)
As noted, within the Jabber system itself, all communications take place in XML. Specifically, communications between the client and the server occur over persistent TCP connections using XML Streams that go through port 5222 (or 5223 when using SSL). Here is what the XML might look like (you'll notice that there are actually two streams: one from the client to the server and one from the server to the client):
SEND: <stream:stream
SEND: to='jabber.org'
SEND: xmlns='jabber:client'
SEND: xmlns:stream='http://etherx.jabber.org/streams'>
RECV: <stream:stream
RECV: from='jabber.org'
RECV: xmlns='jabber:client'
RECV: xmlns:stream='http://etherx.jabber.org/streams'
RECV: id='123456789'>
(XML for user session goes here)
SEND: </stream:stream>
RECV: </stream:stream>
All of the user session data transferred between client and server is contained within three basic Jabber XML elements:
Here is what a simple presence element looks like:
<presence
from='juliet@shakespeare.lit/balcony'
to='romeo@shakespeare.lit/pda'>
<status>Online</status>
</presence>
And here is what a simple message element looks like:
<message
from='juliet@shakespeare.lit/balcony'
to='romeo@shakespeare.lit/pda'>
type='chat'>
<body>Wherefore art thou, Romeo?</body>
</message>
In addition to these basic elements (which themselves support a wide range of information exchange), Jabber XML is highly extensible and it is easy to add new namespaces for things like vCard XML, RSS for headlines, stock tickers, or structured data for custom applications that run on top of Jabber. In essence, Jabber can function as something approaching a generalized XML router, sending any XML from one point to another, instantly.
"Well that's interesting," I hear you saying, "But what kind of fun stuff can Jabber do for me now?" The existing applications of Jabber are mostly centered around basic messaging: one-to-one chat, groupchat, connecting to other IM systems (currently AIM, ICQ, MSN, and Yahoo!), and so on. However, Jabber also supports handy functionality like receiving news headlines and transferring files. In addition, the Jabber Software Foundation is designing protocols for more advanced features such as calendaring, whiteboarding, user avatars, and generic publish-subscribe functionality (for things like user avatars, auction systems, and weblog integration).
The Jabber developers definitely have issues of privacy and security at the top of their minds. For instance, your presence on Jabber is available only to those whose subscriptions you approve. In addition, Jabber supports SSL in communications between clients and servers, PGP/GnuPG has been implemented in several Jabber clients, and the Jabber community is working to add robust, "next-generation" security mechanisms such as SASL and XML encryption.
Finally, the ability to run your own Jabber server (and even change the source code if you want to) separates Jabber from all of the proprietary IM systems in existence. This is a big selling point with security-conscious individuals and organizations across the Internet, and is one reason why there are tens of thousands of Jabber servers running throughout the world, with more coming online every day.
In sum, Jabber is the open alternative, which is why it's often described as "the Linux of instant messaging". And like most open-source software, it is spreading like wildfire. To download Jabber-based software or just find out more about Jabber, visit jabber.org today!