Table of Contents
List of Examples
Purple module is a multi-protocol instant-messaging gateway module which use libpurple, the library on bottom of Pidgin (ex-gaim).
This plugin was wrote in order to proof the concept of gateway between SIP and MSN/Live networks. As libpurple is written to code multi-protocol graphic IM clients, it provides a high level API in order to manipulate accounts, contacts, contacts lists, conversations and more.
So this module provides a multi-protocol IM/Presence client running inside Kamailio with an account for each protocols used by each SIP user whereas libpurple is designed for a graphic client for only one user.
It's no really adapted to a production environment with a huge user count but can be used in order to demonstrate the concept or to use it in SOHO environment.
By default, there's some undefined symbol errors with libpurple shared object when using inside Kamailio. To solve it, you have to force preload of the library by setting up LD_PRELOAD environment variable.
Before starting Kamailio use (adapt the path to your environment):
export LD_PRELOAD=$LD_PRELOAD:/usr/local/lib/libpurple.so
Limitations: doesn't implement authorization requests from external accounts to SIP.
The following modules must be loaded before this module:
presence*.
pua.
database driver module (db_mysql, ...).
The database is used to map SIP URIs with external accounts (eg. MSN).
Example 1.1. Database table description
... +----------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | sip_user | varchar(128) | NO | | NULL | | | ext_user | varchar(128) | NO | | NULL | | | ext_prot | varchar(16) | NO | | NULL | | | ext_pass | varchar(64) | YES | | NULL | | +----------+------------------+------+-----+---------+----------------+ ...
The meaning of columns:
sip_user user's SIP URI.
ext_user user's external account login.
ext_prot purple plugin id to use, except for gtalk.
ext_pass user's external account password.
Example 1.2. Database sample records
... +----+------------------+-----------------+----------------+----------+ | id | sip_user | ext_user | ext_prot | ext_pass | +----+------------------+-----------------+----------------+----------+ | 1 | sip:alice@domain | alice@live.com | prpl-msn-pecan | password | | 2 | sip:bob@domain | bob@live.com | prpl-msn-pecan | password | | 3 | sip:alice@domain | alice@gmail.com | gtalk | password | | 4 | sip:bob@domain | bob@gmail.com | gtalk | password | +----+------------------+-----------------+----------------+----------+ ...
Example 1.3. MySQL create script
... CREATE TABLE purplemap ( id INT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT, sip_user VARCHAR(128) NOT NULL, ext_user VARCHAR(128) NOT NULL, ext_prot VARCHAR(16) NOT NULL, ext_pass VARCHAR(64) ); ...
The URL to connect to database.
Default value is “mysql://openserro:openserro@localhost/openser”.
Example 1.4. Set db_url
parameter
... modparam("purple", "db_url", "dbdriver://username:password@dbhost/dbname") ...
Database table name.
Default value is purplemap.
Send message to a purple destination.
This function can be used from REQUEST_ROUTE.
Example 1.8. purple_send_message
usage
... if (is_method("MESSAGE")) { xlog("MESSAGE $ru from [$fu] to [$tu]\n"); if (uri !~ "sip:.+@.+;proto=.+") { purple_send_message(); sl_send_reply("202", "Accepted"); } } ...
Handle PUBLISH to a purple destination.
This function can be used from REQUEST_ROUTE.
Example 1.9. purple_handle_publish
usage
... if(is_method("PUBLISH")) { xlog("PUBLISH $ru from [$fu] to [$tu]\n"); if (uri !~ "sip:.+@.+;proto=.+") purple_handle_publish(); } ...