Sunday, November 14, 2010

Rescoping XMPP stanza's


An interesting aspect of XMPP is 're-scoping' of XML stanza's between client and server namespace. To elaborate briefly : xmpp clients send xml stanza's namespace'd by 'jabber:client', while stanza's are namespace'd by 'jabber:server' between servers.
So if user1 on server1 needs to send a xml stanza to user2 on server2, server1 will need to 're-scope' the stanza from "jabber:client" namespace to "jabber:server" namespace before transmitting it to server2, and server2 will need to re-scope it back to "jabber:client".

The interesting thing here is, re-scoping xml snippets in a general case, is quite tricky unless it is fully specified : and while going over the xmpp-bis spec for 3920 rfc, I found the description insufficiently robust. Dont get me wrong, it does describe what is required : but there seems to be a lot of loose ends.


As part of hacking up a new xml streaming parser, I was struck by the ambiguity regarding this aspect in XMPP spec.


To give a few examples, consider the following xml stanza's, how are they to be 're-scoped'.


  1. <message  to="user2@server2" xml:lang="en"><body>Test 0</body></message>
  2. <ns:message  to="user2@server2" xml:lang="en" xmlns:ns="jabber:client"><body>Test 1</body></ns:message>
  3. <ns:message  to="user2@server2" xml:lang="en" xmlns:ns="jabber:client"><ns1:body xmlns:ns1="jabber:client" >Test 2</ns1: body></ns:message>

Actually, all three of them are exactly equivalent from client's xml parser point of view. There are, definitely, many more variants of the above : I am just restricting to some simple examples.
If you think this is an elaborate stretch, let me assure you it is not : a simple example of xmpp client which is aggregating xml snippets from various producers and sending it out : so the content (like body here) is not too much in its control.
Not to mention, the XMPP spec is defining xml streams, so definitely needs to be as robust as possible in terms of defining what this means.



There are, ofcourse, other variations of this - like explicitly namespaced attributes, etc. I will post some experimental results later on.





No comments:

Post a Comment