180 likes | 519 Views
Mrinal Kalakrishnan PES Institute of Technology. Programming and Extending Jabber/XMPP. Jabber and XMPP. Open XML-based protocol Exchange messages and presence between any two points on the internet Instant messaging, and much more Decentralized – like email
E N D
Mrinal Kalakrishnan PES Institute of Technology Programming and Extending Jabber/XMPP
Jabber and XMPP • Open XML-based protocol • Exchange messages and presence between any two points on the internet • Instant messaging, and much more • Decentralized – like email • XMPP = eXtensible Messaging and Presence Protocol, standardized by the IETF
Decentralization C1 C2 S1.com C7 S2.net S3.org C3 S2S C8 C4 C2S C5 C9 C6
JIDs, Resources, Priorities • JID – Jabber ID • username@servername.com • username2@servername.com • Multiple connections allowed from the same JID • Each connection has a unique “Resource” name • username@servername.com/home • username@servername.com/work • Each connection/resource also has a priority • Higher priority resource gets all messages
XML Protocol Basics • Client to Server connection – TCP port 5222 • XML Streams • One XML document in each direction <?xml version=”1.0”?> <roottag> <fragment1/> <fragment2/> <fragment3/> </roottag>
The Building Blocks • <message/> • <presence/> • <iq/>
<message/> • Send messages from one Jabber entity to another • Example: <message from='me@myserver.com/home' to='you@yourserver.com' type='chat'> <subject>Time to meet?</subject> <body>When do you want to meet?</body> </message>
<presence/> • Used to indicate availability (or unavailability) of a Jabber entity • Example: <presence from='me@myserver.com/home' to='you@yourserver.com'> <show>away</show> <status>Stepped out for a while</status> <priority>5</priority> </presence>
<iq/> • Iq = Info/Query • Any kind of structured (XML) conversation between two entities • Example (logging on to the server): <iq type=”set”> <query xmlns=”jabber:iq:auth”> <username>myname</username> <resource>Home</resource> <digest>b495d84ca048ef01508503dba94e</digest> </query> </iq>
The Roster and Presence Subscription • Roster (contact list) is stored on the server • Retrieved after logging on using an <iq/> query • Adding another Jabber user to the roster is termed “presence subscription” • To add a user: <presence to='you@yourserver.com' type='subscribe'> • Response: <presence from='you@yourserver.com' type='subscribed'>
More than just Instant Messaging • Collaboration tools • File sharing • Gaming • Remote systems monitoring • Network management • Content syndication
Tcl Objective-C PHP Ruby Flash Delphi Jabber Code Libraries • C • C++ • Java • Perl • Python • C# / .NET http://www.jabber.org/developer/librarylist.php
Basic Jabber Application Programming • Connect to port 5222 of the server • Open XML stream, and authenticate with the server • Send initial presence, and request roster • Register callback functions for incoming <message/>, <presence/> and <iq/> packets • Respond appropriately to the incoming packets in the callback functions • Send out <message/>, <presence/> and <iq/> packets when needed
Example Application – Webber • A Jabber presence indicator for a webpage • Uses the jabber.py Python library • Implementation consists of two distinct sections: • A 'bot' program continuously running as a Jabber client, gathering presence information and updating a database • The webpage, a PHP script which reads the database and displays the presence status
Webberbot • A daemon program running as a Jabber client • Processes incoming <presence/> packets: • If presence type is “available” or “unavailable”, update the presence information in a table with the full JID as the key • If presence type is “subscribe” or “unsubscribe”, send the appropriate reply <presence/> packets. • Ignore <message/> and <iq/> packets.
Webber: The PHP Script • Read the presence entries from the database • If there are multiple resources listed for the same JID, return the status of the highest priority • Display the status on the page!
Example 2 – SMS Interfacing • Jabber ICQ gateway (JIT - http://jit.jabberstudio.org/) provides a bidirectional interface between Jabber and SMS • Build a client that responds to message events from the JID of the mobile phone (eg: 919845012345@sms.myjabberserver.com) and performs actions based on the message contents • Simple to program, and the possibilities are endless!
Resources and URLs • http://www.jabber.org/ - Home of the Jabber Software Foundation • http://www.jabberstudio.org/ - Development hub for the Jabber community • http://mrinal.net/webber/ - The example application Contact me at mail@mrinal.net