
MSILO Module

Daniel-Constantin Mierla

   voice-system.ro

Edited by

Daniel-Constantin Mierla

   Copyright © 2003 FhG FOKUS
     _________________________________________________________

   Table of Contents
   1. User's Guide

        1.1. Overview
        1.2. Dependencies

              1.2.1. OpenSER modules
              1.2.2. External libraries or applications

        1.3. Exported Parameters

              1.3.1. db_url (string)
              1.3.2. db_table (string)
              1.3.3. registrar (string)
              1.3.4. reminder (string)
              1.3.5. expire_time (int)
              1.3.6. check_time (int)
              1.3.7. send_time (int)
              1.3.8. clean_period (int)
              1.3.9. use_contact (int)
              1.3.10. sc_mid (string)
              1.3.11. sc_from (string)
              1.3.12. sc_to (string)
              1.3.13. sc_uri_user (string)
              1.3.14. sc_uri_host (string)
              1.3.15. sc_body (string)
              1.3.16. sc_ctype (string)
              1.3.17. sc_exp_time (string)
              1.3.18. sc_inc_time (string)
              1.3.19. sc_snd_time (string)
              1.3.20. snd_time_avp (str)
              1.3.21. add_date (int)
              1.3.22. max_messages (int)

        1.4. Exported Functions

              1.4.1. m_store([owner])
              1.4.2. m_dump([owner])

        1.5. Exported Statistics

              1.5.1. stored_messages
              1.5.2. dumped_messages
              1.5.3. failed_messages
              1.5.4. dumped_reminders
              1.5.5. failed_reminders

        1.6. Installation & Running

              1.6.1. OpenSER config file

   2. Developer's Guide
   3. Frequently Asked Questions

   List of Examples
   1-1. Set the "db_url" parameter
   1-2. Set the "db_table" parameter
   1-3. Set the "registrar" parameter
   1-4. Set the "reminder" parameter
   1-5. Set the "expire_time" parameter
   1-6. Set the "check_time" parameter
   1-7. Set the "send_time" parameter
   1-8. Set the "clean_period" parameter
   1-9. Set the "use_contact" parameter
   1-10. Set the "sc_mid" parameter
   1-11. Set the "sc_from" parameter
   1-12. Set the "sc_to" parameter
   1-13. Set the "sc_uri_user" parameter
   1-14. Set the "sc_uri_host" parameter
   1-15. Set the "sc_body" parameter
   1-16. Set the "sc_ctype" parameter
   1-17. Set the "sc_exp_time" parameter
   1-18. Set the "sc_inc_time" parameter
   1-19. Set the "sc_snd_time" parameter
   1-20. Set the "snd_time_avp" parameter
   1-21. Set the "add_date" parameter
   1-22. Set the "max_messages" parameter
   1-23. m_store usage
   1-24. m_dump usage
   1-25. OpenSER config script - sample msilo usage
     _________________________________________________________

Chapter 1. User's Guide

1.1. Overview

   This modules provides offline message storage for the Open SIP
   Express Router. It stores received messages for an offline
   user and sends them when the user becomes online.

   For each message, the modules stores "Request-URI" ("R-URI")
   only if it is a complete address of record
   ("username@hostname"), URI from "To" header, URI from "From"
   header, incoming time, expiration time, content type and body
   of the message. If "R-URI" is not an address of record (it
   might be the contact address for current SIP session) the URI
   from "To" header will be used as R-URI.

   When the expiration time passed, the message is discarded from
   database. Expiration time is computed based on incoming time
   and one of the module's parameters.

   Every time when a user registers with OpenSER, the module is
   looking in database for offline messages intended for that
   user. All of them will be sent to contact address provided in
   REGISTER request.

   It may happen the SIP user to be registered but his SIP User
   Agent to have no support for MESSAGE request. In this case it
   should be used the "failure_route" to store the undelivered
   requests.
     _________________________________________________________

1.2. Dependencies

1.2.1. OpenSER modules

   The following modules must be loaded before this module:

     * database module - mysql, dbtext or other module that
       implements the "db" interface and provides support for
       storing/receiving data to/from a database system.
     * TM--transaction module--is used to send SIP requests.
     _________________________________________________________

1.2.2. External libraries or applications

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

     * none.
     _________________________________________________________

1.3. Exported Parameters

1.3.1. db_url (string)

   Database URL.

   Default value is
   "mysql://openser:openserrw@localhost/openser". 

   Example 1-1. Set the "db_url" parameter
...
modparam("msilo", "db_url", "mysql://user:passwd@host.com/dbname")
...
     _________________________________________________________

1.3.2. db_table (string)

   The name of table where to store the messages.

   Default value is "silo". 

   Example 1-2. Set the "db_table" parameter
...
modparam("msilo", "db_table", "silo")
...
     _________________________________________________________

1.3.3. registrar (string)

   The SIP address used to inform users that destination of their
   message is not online and the message will be delivered next
   time when that user goes online. If the parameter is not set,
   the module will not send any notification. All requests
   intended for this SIP address will not be stored for lately
   delivery.

   Default value is "NULL". 

   Example 1-3. Set the "registrar" parameter
...
modparam("msilo", "registrar", "sip:registrar@example.org")
...
     _________________________________________________________

1.3.4. reminder (string)

   The SIP address used to send reminder messages. If this value
   is not set, the reminder feature is disabled.

   Default value is "NULL". 

   Example 1-4. Set the "reminder" parameter
...
modparam("msilo", "reminder", "sip:registrar@example.org")
...
     _________________________________________________________

1.3.5. expire_time (int)

   Expire time of stored messages - seconds. When this time
   passed, the message is silently discarded from database.

   Default value is "259200 (72 hours = 3 days)". 

   Example 1-5. Set the "expire_time" parameter
...
modparam("msilo", "expire_time", 36000)
...
     _________________________________________________________

1.3.6. check_time (int)

   Timer interval to check if dumped messages are sent OK -
   seconds. The module keeps each request send by itself for a
   new online user and if the reply is 2xx then the message is
   deleted from database.

   Default value is "30". 

   Example 1-6. Set the "check_time" parameter
...
modparam("msilo", "check_time", 10)
...
     _________________________________________________________

1.3.7. send_time (int)

   Timer interval in seconds to check if there are reminder
   messages. The module takes all reminder messages that must be
   sent at that moment or before that moment.

   If the value is 0, the reminder feature is disabled.

   Default value is "0". 

   Example 1-7. Set the "send_time" parameter
...
modparam("msilo", "send_time", 60)
...
     _________________________________________________________

1.3.8. clean_period (int)

   Number of "check_time" cycles when to check if there are
   expired messages in database.

   Default value is "5". 

   Example 1-8. Set the "clean_period" parameter
...
modparam("msilo", "clean_period", "3")
...
     _________________________________________________________

1.3.9. use_contact (int)

   Turns on/off the usage of the Contact address to send
   notification back to sender whose message is stored by MSILO.

   Default value is "1 (0 = off, 1 = on)". 

   Example 1-9. Set the "use_contact" parameter
...
modparam("msilo", "use_contact", 0)
...
     _________________________________________________________

1.3.10. sc_mid (string)

   The name of the column in silo table, storing message id.

   Default value is "mid".

   Example 1-10. Set the "sc_mid" parameter
...
modparam("msilo", "sc_mid", "other_mid")
...
     _________________________________________________________

1.3.11. sc_from (string)

   The name of the column in silo table, storing the source
   address.

   Default value is "src_addr".

   Example 1-11. Set the "sc_from" parameter
...
modparam("msilo", "sc_from", "source_address")
...
     _________________________________________________________

1.3.12. sc_to (string)

   The name of the column in silo table, storing the destination
   address.

   Default value is "dst_addr".

   Example 1-12. Set the "sc_to" parameter
...
modparam("msilo", "sc_to", "destination_address")
...
     _________________________________________________________

1.3.13. sc_uri_user (string)

   The name of the column in silo table, storing the user name.

   Default value is "username".

   Example 1-13. Set the "sc_uri_user" parameter
...
modparam("msilo", "sc_uri_user", "user")
...
     _________________________________________________________

1.3.14. sc_uri_host (string)

   The name of the column in silo table, storing the domain.

   Default value is "domain".

   Example 1-14. Set the "sc_uri_host" parameter
         ...
         modparam("msilo", "sc_uri_host", "domain")
         ...

     _________________________________________________________

1.3.15. sc_body (string)

   The name of the column storing the message body in silo table.

   Default value is "body".

   Example 1-15. Set the "sc_body" parameter
        ...
        modparam("msilo", "sc_body", "message_body")
        ...

     _________________________________________________________

1.3.16. sc_ctype (string)

   The name of the column in silo table, storing content type.

   Default value is "ctype".

   Example 1-16. Set the "sc_ctype" parameter
         ...
         modparam("msilo", "sc_body", "content_type")
         ...

     _________________________________________________________

1.3.17. sc_exp_time (string)

   The name of the column in silo table, storing the expire time
   of the message.

   Default value is "exp_time".

   Example 1-17. Set the "sc_exp_time" parameter
         ...
         modparam("msilo", "sc_exp_time", "expire_time")
         ...

     _________________________________________________________

1.3.18. sc_inc_time (string)

   The name of the column in silo table, storing the incoming
   time of the message.

   Default value is "inc_time".

   Example 1-18. Set the "sc_inc_time" parameter
         ...
         modparam("msilo", "sc_inc_time", "incoming_time")
         ...

     _________________________________________________________

1.3.19. sc_snd_time (string)

   The name of the column in silo table, storing the send time
   for the reminder.

   Default value is "snd_time".

   Example 1-19. Set the "sc_snd_time" parameter
         ...
         modparam("msilo", "sc_inc_time", "send_reminder_time")
         ...

     _________________________________________________________

1.3.20. snd_time_avp (str)

   The name of an AVP which may contain the time when to sent the
   received message as reminder.The AVP is used ony by m_store().

   If the parameter is not set, the module does not look for this
   AVP. If the value is set to a valid AVP name, then the module
   expects in the AVP to be a time value in format YYYYMMDDHHMMSS
   (e.g., 20060101201500).

   Default value is "null". 

   Example 1-20. Set the "snd_time_avp" parameter
...
modparam("msilo", "snd_time_avp", "$avp(i:123)")
...
     _________________________________________________________

1.3.21. add_date (int)

   Wheter to add as prefix the date when the message was stored.

   Default value is "1" (1==on/0==off). 

   Example 1-21. Set the "add_date" parameter
...
modparam("msilo", "add_date", "0")
...
     _________________________________________________________

1.3.22. max_messages (int)

   Maximum number of stored message for an AoR. Value 0 equals to
   no limit.

   Default value is 0. 

   Example 1-22. Set the "max_messages" parameter
...
modparam("msilo", "max_messages", 0)
...
     _________________________________________________________

1.4. Exported Functions

1.4.1. m_store([owner])

   The method stores certain parts of the current SIP request (it
   should be called when the request type is MESSAGE and the
   destination user is offline or his UA does not support MESSAGE
   requests). If the user is registered with a UA which does not
   support MESSAGE requests you should not use mode="0" if you
   have changed the request uri with the contact address of
   user's UA.

   Meaning of the parameters is as follows:

     * owner - is a string that must contain a SIP URI in whose
       inbox the message will be stored. It can have any pseudo
       variable. If "owner" is missing, the SIP address is taken
       from R-URI.

   This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.

   Example 1-23. m_store usage
...
m_store();
m_store("$tu");
...
     _________________________________________________________

1.4.2. m_dump([owner])

   The method sends stored messages for the SIP user that is
   going to register to his actual contact address. The method
   should be called when a REGISTER request is received and the
   "Expire" header has a value greater than zero.

   Meaning of the parameters is as follows:

     * owner - is a string that must contain a SIP URI whose
       inbox will be dumped. It can have any pseudo variable. If
       "owner" is missing, the SIP address is taken from To URI.

   This function can be used from REQUEST_ROUTE.

   Example 1-24. m_dump usage
...
m_store();
m_store("$fu");
...
     _________________________________________________________

1.5. Exported Statistics

1.5.1. stored_messages

   The number of messages stored by msilo.
     _________________________________________________________

1.5.2. dumped_messages

   The number of dumped messages.
     _________________________________________________________

1.5.3. failed_messages

   The number of failed dumped messages.
     _________________________________________________________

1.5.4. dumped_reminders

   The number of dumped reminder messages.
     _________________________________________________________

1.5.5. failed_reminders

   The number of failed reminder messages.
     _________________________________________________________

1.6. Installation & Running

1.6.1. OpenSER config file

   Next picture displays a sample usage of msilo.

   Example 1-25. OpenSER config script - sample msilo usage
...
# $Id: README 1800 2007-03-10 16:12:47Z bogdan_iancu $
#
# MSILO usage example
#
#


debug=9           # debug level (cmd line: -dddddddddd)
fork=no           # don't fork
log_stderror=yes  # log to stderr (cmd line: -E)


children=2        # number of children
check_via=no      # (cmd. line: -v)
dns=off           # (cmd. line: -r)
rev_dns=off       # (cmd. line: -R)
port=5060

listen=10.0.0.2   # listen address

# ------------------ module loading ----------------------------------

loadmodule "modules/print/print.so"
loadmodule "modules/textops/textops.so"

loadmodule "modules/sl/sl.so"
loadmodule "modules/mysql/mysql.so"
loadmodule "modules/maxfwd/maxfwd.so"
loadmodule "modules/msilo/msilo.so"
loadmodule "modules/tm/tm.so"
loadmodule "modules/registrar/registrar.so"
loadmodule "modules/usrloc/usrloc.so"

# ----------------- setting module-specific parameters ---------------

# -- registrar params --

modparam("registrar", "default_expires", 120)

# -- registrar params --

modparam("usrloc", "db_mode", 0)

# -- msilo params --

modparam("msilo","db_url","mysql://user:xxx@127.0.0.1/msilo")
modparam("msilo","registrar","sip:registrar@mydomain.com")

# -- tm params --

modparam("tm", "fr_timer", 10 )
modparam("tm", "fr_inv_timer", 15 )
modparam("tm", "wt_timer", 10 )


route{
    if ( !mf_process_maxfwd_header("10") )
    {
        sl_send_reply("483","To Many Hops");
        drop();
    };


    if (uri==myself) {
    {
        # for testing purposes, simply okay all REGISTERs
        if (method=="REGISTER")
        {
            save("location");
            log("REGISTER received -> dumping messages with MSILO\n");

            # MSILO - dumping user's offline messages
            if (m_dump())
            {
                log("MSILO: offline messages dumped - if they were\n");
            }else{
                log("MSILO: no offline messages dumped\n");
            };
            break;
        };

        # domestic SIP destinations are handled using our USRLOC DB

        if(!lookup("location"))
        {
            if (! t_newtran())
               {
                sl_reply_error();
                break;
               };
            # we do not care about anything else but MESSAGEs
            if (!method=="MESSAGE")
            {
                if (!t_reply("404", "Not found"))
                {
                    sl_reply_error();
                };
                break;
            };
            log("MESSAGE received -> storing using MSILO\n");
            # MSILO - storing as offline message
            if (m_store("$ru"))
            {
                log("MSILO: offline message stored\n");
                if (!t_reply("202", "Accepted"))
                {
                    sl_reply_error();
                };
            }else{
                log("MSILO: offline message NOT stored\n");
                if (!t_reply("503", "Service Unavailable"))
                {
                    sl_reply_error();
                };
            };
            break;
        };
        # if the downstream UA does not support MESSAGE requests
        # go to failure_route[1]
        t_on_failure("1");
        t_relay();
        break;
    };

    # forward anything else
    t_relay();
}

failure_route[1] {
    # forwarding failed -- check if the request was a MESSAGE
    if (!method=="MESSAGE")
    {
        break;
    };

    log(1,"MSILO:the downstream UA doesn't support MESSAGEs\n");
    # we have changed the R-URI with the contact address, ignore it now
    if (m_store("$ou"))
    {
        log("MSILO: offline message stored\n");
        t_reply("202", "Accepted");
    }else{
        log("MSILO: offline message NOT stored\n");
        t_reply("503", "Service Unavailable");
    };
}



...
     _________________________________________________________

Chapter 2. Developer's Guide

   The module does not provide any API to use in other OpenSER
   modules.
     _________________________________________________________

Chapter 3. Frequently Asked Questions

   3.1. Where can I find more about OpenSER?
   3.2. Where can I post a question about this module?
   3.3. How can I report a bug?

   3.1. Where can I find more about OpenSER?

   Take a look at http://openser.org/.

   3.2. Where can I post a question about this module?

   First at all check if your question was already answered on
   one of our mailing lists:

     * User Mailing List -
       http://openser.org/cgi-bin/mailman/listinfo/users
     * Developer Mailing List -
       http://openser.org/cgi-bin/mailman/listinfo/devel

   E-mails regarding any stable OpenSER release should be sent to
   <users@openser.org> and e-mails regarding development versions
   should be sent to <devel@openser.org>.

   If you want to keep the mail private, send it to
   <team@openser.org>.

   3.3. How can I report a bug?

   Please follow the guidelines provided at:
   http://sourceforge.net/tracker/?group_id=139143.
