вторник, 28 сентября 2010 г.

Relay auth to an XMPP component

Standard ejabberd auth modules include odbc, ldap, external (with script). Also there is original module "internal" which hosts users data in Mnesia. But sometimes these modules are not enough.

Writing a custom auth module for ejabberd is easy. Copy, for example, ejabberd_auth_internal.erl and replace its interface methods with your own.

Recently I needed to relay auth to an XMPP component. I have to make an IQ inside check_password method. The problem is that check_password is called in user session process and routing for the session does not work yet. This means, you wont receive XMPP stanzas in this method by calling receive.

Take a look at the working snippet:


check_password(User, Server, Password) ->
    SelfJid = jlib:string_to_jid(Server),
    AuthJid = jlib:string_to_jid("profile1." ++ Server),
    IQGet = #iq{
      type = get,
      sub_el = [{xmlelement, "query", [{"xmlns", ?NS_SUP_AUTH}, {"user", User}, {"password", Password}], []}]
     },
    Pid = self(),

    F = fun(IQReply) ->
                Pid ! IQReply
        end,

    ejabberd_local:route_iq(SelfJid, AuthJid, IQGet, F),

    receive #iq{type = result} ->
            true;
    Other ->
            ?INFO_MSG("Auth IQ for ~s failed: ~p", [User, Other]),
            false
    end.


profile1.server.com is a JID of the auth component. The component receives an IQ with user id and password and returns "result" IQ if auth is fine, "error" otherwise.

The trick here is to use ejabberd_local:route_iq. But then we need to block the call flow of check_password until the auth component returns us the result. route_iq takes a function parameter which is called in local router process. It routes the reply back to a function basing on its own IQ id -> function map. Another trick is to make our original (client) process pid to reside in function's closure. Then we can safely block with receive and wait for a message from the function.

пятница, 10 сентября 2010 г.

Thinkpad T61 warranty repair

I've been using T61 for about two years and a half.
Recently the screen flashed and turned off while I was working. It didnt turn on any more.

I had checked my serial number at Lenovo site and happily discovered that few months of warranty left.

It took almost three weeks to fix. They changed LCD display (this was expected), then motherboard and the panel with touchpad. Seems motherboard had burnt out together with LCD. And plastic panel was a bit damaged - they replaced it too :)

понедельник, 26 июля 2010 г.

Why my Android sucks

I've been using HTC Legend with Android 2.1 for about two months. There are few major things that make the experience much worser than it could be:

  • The device is unable to play popular video formats (divx, xvid, etc) out of the box. The only usable video format is H264 - you have to convert video to it.
  • Android Market does not work for Russia - what a crap? There are alternatives, but anyways. Apple AppStore is already here, btw.
  • I cannot send files via Bluetooth from device to PC and vice versa. At the same time SE z530i <-> Legend works fine, PC <-> SE z530i both work fine. Maybe Ubuntu at my PC lacks some BT profiles (Bluetooth FTP, I guess). But it is a problem of device, not Ubuntu, because HTC Legend is a consumer product, and it should support everything.
  • I cannot create complex Wi-Fi connections with fixed IP and VPN. iPod can do it easily.
  • It has annoying glitches in base preinstalled software, for example Weather Widget.

воскресенье, 13 июня 2010 г.

Advance Wars for Android

As always, my dream project was already implemented by someone else.

Advance Wars, my favourite game for Game Boy Advance was reinvented for Android.

Battle for Mars is a remake of original game, leaving most of tactics gameplay fun but with different storyline and graphics.

Actually there is zero storyline, comparing to original game. And wholly, it is actually worser than original game :) But I like it anyways.

вторник, 20 апреля 2010 г.

Bitbucket

Last month I've been using Bitbucket for hosting my company's Mercurial repository.

I am admire of SaaS approach, but Bitbucket has succeeded proving me the opposite.
My repository is unavailable right now. And this happens much more offen than I expected from service dedicated for code hosting. pull/push operations take long time (up to 5-10 seconds). I have no idea how to make Mercurial so slow.

Maybe I'll give Assembla a try. But more probable, I'll rent a small VDS at Gandi and deploy my own Mercurial installation there.

среда, 23 декабря 2009 г.

flashpolicytwistd Ubuntu package

I've created an Ubuntu DEB package for flashpolicytwistd - a simple Flash Policy Server written in Python/Twisted. This simplifies installation process a lot.

Find the deb at project's download page.

понедельник, 21 декабря 2009 г.

CPU benchmark

I wrote a simple Python program, which builds R-Tree index for 100k nodes.

The program runs single thread and this means that only a single core of a CPU is working.

3m 31.322s Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz
3m 2.835s Quad-Core AMD Opteron(tm) Processor 2372 HE @ 2.1Ghz
1m 31.393s Intel(R) Core(TM) i7 CPU 975 @ 3.33GHz