Purple Module

Eric Ptak

Atos Worldline

Edited by

Eric Ptak


Table of Contents

1. Admin Guide
1. Overview
2. Known limitations
3. Dependencies
3.1. Kamailio Modules
3.2. External Libraries or Applications
4. Database
5. Parameters
5.1. db_url (str)
5.2. db_table (str)
5.3. httpProxy_host (str)
5.4. httpProxy_port (int)
6. Functions
6.1. purple_send_message()
6.2. purple_handle_publish()
6.3. purple_handle_subscribe()

List of Examples

1.1. Database table description
1.2. Database sample records
1.3. MySQL create script
1.4. Set db_url parameter
1.5. Set db_table parameter
1.6. Set httpProxy_host parameter
1.7. Set httpProxy_port parameter
1.8. purple_send_message usage
1.9. purple_handle_publish usage
1.10. purple_handle_subscribe usage

Chapter 1. Admin Guide

1. Overview

Note: the module is not actively maintained and may be deprecated in the near future.

Purple module is a multi-protocol instant-messaging gateway module which use libpurple, the library that Pidgin (ex-gaim) is based on.

This plugin was written as a proof of concept 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.

This module provides a multi-protocol IM/Presence client running inside Kamailio with an account for each protocol used by each SIP user. 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 in a SOHO environment.

By default, there's some undefined symbol errors with libpurple shared object when using it 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

2. Known limitations

Doesn't implement authorization requests from external accounts to SIP.

3. Dependencies

3.1. Kamailio Modules

The following modules must be loaded before this module:

  • presence*.

  • pua.

  • database driver module (db_mysql, ...).

3.2. External Libraries or Applications

The following libraries or applications must be installed before running Kamailio with this module loaded:

  • libpurple, e.g. from pidgin 2.5.2.

4. Database

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)
);
...

5. Parameters

5.1. db_url (str)

The URL to connect to database.

Default value is mysql://kamailioro:kamailioro@localhost/kamailio.

Example 1.4. Set db_url parameter

...
modparam("purple", "db_url", "dbdriver://username:password@dbhost/dbname")
...

5.2. db_table (str)

Database table name.

Default value is purplemap.

Example 1.5. Set db_table parameter

...
modparam("purple", "db_table", "purplemap")
...

5.3. httpProxy_host (str)

Address of HTTP proxy.

Default value is NULL.

Example 1.6. Set httpProxy_host parameter

...
modparam("purple", "httpProxy_host", "10.26.52.12")
...

5.4. httpProxy_port (int)

Port of HTTP proxy.

Default value is 0.

Example 1.7. Set httpProxy_port parameter

...
modparam("purple", "httpProxy_port", 3128)
...

6. Functions

6.1.  purple_send_message()

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");
    }
}
...

6.2.  purple_handle_publish()

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();
}
...

6.3.  purple_handle_subscribe()

Handle SUBSCRIBE to a purple destination.

This function can be used from REQUEST_ROUTE.

Example 1.10. purple_handle_subscribe usage

...
if(is_method("SUBSCRIBE")) {
    xlog("SUBSCRIBE $ru from [$fu] to [$tu]\n");
    if ($hdr(Event) == "presence")
        purple_handle_subscribe("$ruri", "$hdr(Expires)");
}
...