Ejabberd hooks with twisted

2009-01-05 00:46:10 by Fabio Forno

Few days ago I've found on Launchpad an interesting project by Thomas Hervé, the twisted interface to OTP, which allows to connect to erlang nodes using Twisted Matrix. The idea is incredibily powerful because it allows to easily build mixed-distributed applications using both erlang and python/twisted where they are best. So I gave it a try with ejabberd which has hooks for adding callbacks to its internal components (i.e. it's possible to intercept and modify packets). Unfortunately I've discovered that the present implementation of ejabberd hooks allows to connect only callbacks from the same node of ejabberd, i.e. as an extension module, but ejabberd folks have been incredibily quick in releasing a patch which allows distributed hooks, by adding the "CallNode" atom as parameter. The patch may be not stable yet, but it works perfectly with the last release of ejabberd (2.0.2), and here is an example of a twisted node which intercepts and logs all packets sent and received by any user (here is the full code, change the node names accordingly to your setup).

It works very simply. The hooks are written as methods of a regular python class with the "remote_" prefix:

class UserMonitor(object):
    
    def remote_receive_packet(self, jid, frm, to, packet):
        print ">>",  to_domish(packet).toXml()
    
    def remote_send_packet(self, frm, to, packet):
        print "<<",  to_domish(packet).toXml()

which is published by using a PersistentPortMapper:

nodeName = buildNodeName("uccaro@olindo.bluendo.priv")
epmd = PersistentPortMapperFactory(nodeName, cookie, "olindo.bluendo.priv")
epmd.publish(proxy = UserMonitor())

After this it's possible to call the methods proxy:receive_packtes and proxy:send_packet from any erlang node.

Then we register with ejabberd using a second node which calls the register methods, using the ejabberd api:

@defer.inlineCallbacks
def register_hook(epmd):
    # connect to the ejabberd node
    inst = yield epmd.connectToNode("ejabberd")
   
    # register hooks
    r = yield inst.factory.callRemote(
            inst,
            "ejabberd_hooks",
            "add_dist",
            Atom("user_receive_packet"), # hook name
            "olindo.bluendo.priv", # virtual host
            Atom("uccaro@olindo.bluendo.priv"), # hook node
            Atom("proxy"), # hook module
            Atom("receive_packet"), # hook method
            10
    )

And bingo, after this ejabberd happily starts calling our hooks!

As bonus in the code you find also a function which translates from the ejabberd xml representation to twisted domish nodes, which is far more usable.

Lampiro bug fixes and improvements

2008-12-18 01:03:51 by Fabio Forno

One of the great advantages of free and open source projects is the feedback you receive from users. So few days after the release we've been able to fix many quirks while casting the roadmap for the  next major release. In particular:

  • fixed "user add" in the menu, which was not working
  • improved the usability in roster navigation
  • adjusted the "ok" and "cancel" buttons in the composition forms, which were creating some troubles in some phone models

Lampiro 8.11.2 is out, go and get it.

Proxy65 1.2 released

2008-12-15 00:17:32 by Fabio Forno

After almost one year I've made a new version of Proxy 65 in order to make it work with twisted 8.x

Before upgrading you must:

  • install twisted 8.x
  • remove old proxy65.* files in the twisted/plugins directory

And then follow instructions in the README, which are slightly changed

The package is available here.

Let me know (xmpp: ff at jabber.bluendo.com) if you find any issue

Update on the Lampiro release

2008-12-05 16:38:19 by Fabio Forno

Differently from what written yesterday, TLS and compression weren't enabled in the build since it was meant to be just a preview release (the official "stable" one will be announced here http://lampiro.bluendo.com). Now we provide these three different builds:

  • Light, with no TLS and compression
  • With compression only
  • With TLS and compression (side note: if you use TLS compression doesn't work since there is no purpose in compressing an already encrypted stream, and Bouncy Castle doesn't support compression in the mobile version yet)

You may download them from the usual address.

 And, finally, for any discussion about the client you can find us in this chatroom lampiro@conference.jabber.bluendo.com (if we don't sleep ;) )

Hooray!

2008-12-04 23:10:37 by Fabio Forno

Christmas is approaching and it's bringing you a gift: after a very long and hard work Lampiro, our mobile XMPP client, has been completely rewritten with the addition of many many features:

  • Compression
  • TLS
  • Groupchats
  • Gateway support
  • Improved dataforms
  • New graphical UI with many tweaks for improving usability
  • Support for touch screens

 But there are two more technical "features" which make us even more excited:

  • the new graphical UI with the support of layouts is just the first enabling step in our vision of an XMPP client as the preferred developement platforms for mobiles; yes we strongly believe that the right choice for delivering applications to mobiles is not the browser, but a rich IM client, supplying asynchronous messaging and presence (more on this in the next days)
  • and last but not least, now the code is completely opensourced under GPL, so you can get and hack it, contributing to build the best IM client!

 And before closing the link where you can download both the compiled jar and the source code: http://code.google.com/p/lampiro/

Happy messaging!