Stolen from git://gitorious.org/sofia-sip/sofia-sip