<?xml version="1.0" encoding='ISO-8859-1'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [

<!-- Include general documentation entities -->
<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
%docentities;

]>
<!-- Module User's Guide -->

<chapter xmlns:xi="http://www.w3.org/2001/XInclude">

	<title>&adminguide;</title>

	<section>
	<title>Overview</title>
	<para>
		This module provides offline message storage for &kamailioname;. It
		stores received messages for an offline user and sends them when the
		user comes back online. It can also send reminders and auto-expire
		messages.
	</para>
	<para>
		For each message, the module stores <quote>Request-URI</quote>
		(<quote>R-URI</quote>) only if it is a complete address of record
		(<quote>username@hostname</quote>), &uri; from <quote>To</quote>
		header, &uri; from <quote>From</quote> header, incoming time,
		expiration time, content type and body of the message. If
		<quote>R-URI</quote> is not an address of record (it might be the
		contact address for current &sip; session) the &uri;
		from <quote>To</quote> header will be used as <abbrev>R-URI</abbrev>.
	</para>
	<para>
		When the expiration time is passed, the message is discarded from
		database.  Expiration time is computed based on incoming time and
		one of the module's parameters.
	</para>
	<para>
		Every time when a user registers with &kamailio;, 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 and then be deleted.
	</para>
	<para>
		It may happen that the &sip; user registering use a &sip; User Agent
		that has no support for MESSAGE requests. In this case the <quote>failure_route</quote>
		should be used to re-store the undelivered requests.
	</para>
	<para>
		Another functionality provided by the MSILO module is to send messages at
		a certain time -- the reminder functionality. Using config logic, a
		received message can be stored and delivered at a time specified while
		storing with the 'snd_time_avp'.
	</para>
	</section>
	<section>
	<title>Dependencies</title>
	<section>
		<title>&kamailio; modules</title>
		<para>
		The following modules must be loaded before this module:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>database module</emphasis> - mysql, dbtext or other
				module that implements the <quote>db</quote> interface and
				provides support for storing/receiving data to/from a
				database system.
			</para>
			</listitem>
			<listitem>
			<para>
				<emphasis>TM</emphasis>--transaction module-- used to
				send &sip; requests.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	<section>
		<title>External libraries or applications</title>
		<para>
		The following libraries or applications must be installed before
		running &kamailio; with this module:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>none</emphasis>.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	</section>
	<section>
	<title>Parameters</title>
	<section id="msilo.p.db_url">
		<title><varname>db_url</varname> (string)</title>
		<para>
		Database &url;.
		</para>
		<para>
		<emphasis>
			Default value is
			<quote>&defaultdb;</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>db_url</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "db_url", "&exampledb;")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.db_table">
		<title><varname>db_table</varname> (string)</title>
		<para>
		The name of table where to store the messages.
		</para>
		<para>
		<emphasis>
			Default value is <quote>silo</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>db_table</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "db_table", "silo")
...
</programlisting>
		</example>
	</section>

	<section id="msilo.p.sc_mid">
		<title><varname>sc_mid</varname> (string)</title>
		<para>
		The name of the column in silo table used to store the message id.
		</para>
		<para>Default value is <quote>mid</quote>.</para>
		<example>
		<title>Set the <quote>sc_mid</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "sc_mid", "other_mid")
...
</programlisting>
		</example>
	</section>

	<section id="msilo.p.sc_from">
		<title><varname>sc_from</varname> (string)</title>
		<para>
		The name of the column in silo table, storing the source address.
		</para>
		<para>Default value is <quote>src_addr</quote>.</para>
		<example>
		<title>Set the <quote>sc_from</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "sc_from", "source_address")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.sc_to">
		<title><varname>sc_to</varname> (string)</title>
		<para>
		The name of the column in silo table, storing the destination address.
		</para>
		<para>Default value is <quote>dst_addr</quote>.</para>
		<example>
		<title>Set the <quote>sc_to</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "sc_to", "destination_address")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.sc_uri_user">
		<title><varname>sc_uri_user</varname> (string)</title>
		<para>
		The name of the column in silo table, storing the user name.
		</para>
		<para>Default value is <quote>username</quote>.</para>
		<example>
		<title>Set the <quote>sc_uri_user</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "sc_uri_user", "user")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.sc_uri_host">
		<title><varname>sc_uri_host</varname> (string)</title>
		<para>
		The name of the column in silo table, storing the domain.
		</para>
		<para>Default value is <quote>domain</quote>.</para>
		<example>
		<title>Set the <quote>sc_uri_host</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "sc_uri_host", "domain")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.sc_body">
		<title><varname>sc_body</varname> (string)</title>
		<para>
		The name of the column storing the message body in silo table.
		</para>
		<para>Default value is <quote>body</quote>.</para>
		<example>
		<title>Set the <quote>sc_body</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "sc_body", "message_body")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.sc_ctype">
		<title><varname>sc_ctype</varname> (string)</title>
		<para>
		The name of the column in silo table, storing content type.
		</para>
		<para>Default value is <quote>ctype</quote>.</para>
		<example>
		<title>Set the <quote>sc_ctype</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "sc_ctype", "content_type")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.sc_exp_time">
		<title><varname>sc_exp_time</varname> (string)</title>
		<para>
		The name of the column in silo table, storing the expire time of the message.
		</para>
		<para>Default value is <quote>exp_time</quote>.</para>
		<example>
		<title>Set the <quote>sc_exp_time</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "sc_exp_time", "expire_time")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.sc_inc_time">
		<title><varname>sc_inc_time</varname> (string)</title>
		<para>
		The name of the column in silo table, storing the incoming time of the message.
		</para>
		<para>Default value is <quote>inc_time</quote>.</para>
		<example>
		<title>Set the <quote>sc_inc_time</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "sc_inc_time", "incoming_time")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.sc_snd_time">
		<title><varname>sc_snd_time</varname> (string)</title>
		<para>
		The name of the column in silo table, storing the send time for the reminder.
		</para>
		<para>Default value is <quote>snd_time</quote>.</para>
		<example>
		<title>Set the <quote>sc_snd_time</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "sc_snd_time", "send_reminder_time")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.sc_stored_hdrs">
		<title><varname>sc_stored_hdrs</varname> (string)</title>
		<para>
		The name of the column in silo table, storing the extra headers.
		</para>
		<para>Default value is <quote>extra_hdrs</quote>.</para>
		<example>
		<title>Set the <quote>sc_stored_hdrs</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "sc_stored_hdrs", "extra_headers")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.from_address">
		<title><varname>from_address</varname> (string)</title>
		<para>
		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. This parameter may contain pseudo-variables.
		</para>
		<para>
		<emphasis>
			Default value is <quote>NULL</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>from_address</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "from_address", "sip:registrar@example.org")
modparam("msilo", "from_address", "sip:$rU@example.org")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.contact_hdr">
		<title><varname>contact_hdr</varname> (string)</title>
		<para>
		The value of the <quote>Contact</quote> header (including header name and ending
		\r\n) to be added in notification messages.
		It can contain pseudo-variables.
		</para>
		<para>
		<emphasis>
			Default value is <quote>NULL</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>contact_hdr</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "contact_hdr", "Contact: &lt;sip:null@example.com&gt;\r\n")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.extra_hdrs">
		<title><varname>extra_hdrs</varname> (string)</title>
		<para>
		Extra headers (each ending with	\r\n) to be added in
		messages sent from silo by m_dump.
		It can contain pseudo-variables.
		</para>
		<para>
		<emphasis>
			Default value is <quote>NULL</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>extra_hdrs</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "extra_hdrs", "X-Extra: $tu\r\nY-Extra: foo\r\n")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.offline_message">
		<title><varname>offline_message</varname> (string)</title>
		<para>
		The body of the notification message.
		It can contain pseudo-variables.
		</para>
		<para>
		<emphasis>
			Default value is <quote>NULL</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>offline_message</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "offline_message", "*** User $rU is offline!")
modparam("msilo", "offline_message", "&lt;em&gt;I am offline!&lt;/em&gt;")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.content_type_hdr">
		<title><varname>content_type_hdr</varname> (string)</title>
		<para>
		The value of the Content-Type header (including header name and ending
		\r\n) to be added in notification messages. It must reflect what the
		'offline_message' contains.
		It can contain pseudo-variables.
		</para>
		<para>
		<emphasis>
			Default value is <quote>NULL</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>content_type_hdr</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "content_type_hdr", "Content-Type: text/plain\r\n")
modparam("msilo", "content_type_hdr", "Content-Type: text/html\r\n")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.reminder">
		<title><varname>reminder</varname> (string)</title>
		<para>
		The &sip; address used to send reminder messages. If this value
		is not set, the reminder feature is disabled.
		</para>
		<para>
		<emphasis>
			Default value is <quote>NULL</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>reminder</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "reminder", "sip:registrar@example.org")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.outbound_proxy">
		<title><varname>outbound_proxy</varname> (string)</title>
		<para>
		The &sip; address used as next hop when sending the message. Very
		useful when using &kamailio; with a domain name not in <acronym>DNS</acronym>, or when
		using a separate &kamailio; instance for msilo processing. If not set,
		the message will be sent to the address in destination URI.
		</para>
		<para>
		<emphasis>
			Default value is <quote>NULL</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>outbound_proxy</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "outbound_proxy", "sip:kamailio.org;transport=tcp")
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.expire_time">
		<title><varname>expire_time</varname> (int)</title>
		<para>
		Expire time of stored messages - seconds. When this time passed, the message is
		silently discarded from database.
		</para>
		<para>
		<emphasis>
			Default value is <quote>259200 (72 hours = 3 days)</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>expire_time</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "expire_time", 36000)
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.check_time">
		<title><varname>check_time</varname> (int)</title>
		<para>
		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.
		</para>
		<para>
		<emphasis>
			Default value is <quote>60</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>check_time</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "check_time", 10)
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.send_time">
		<title><varname>send_time</varname> (int)</title>
		<para>
		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.
		</para>
		<para>
		If the value is 0, the reminder feature is disabled.
		</para>
		<para>
		<emphasis>
			Default value is <quote>0</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>send_time</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "send_time", 60)
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.clean_period">
		<title><varname>clean_period</varname> (int)</title>
		<para>
		Number of <quote>check_time</quote> cycles when to check if
		there are expired messages in database.
		</para>
		<para>
		<emphasis>
			Default value is <quote>10</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>clean_period</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "clean_period", 3)
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.use_contact">
		<title><varname>use_contact</varname> (int)</title>
		<para>
		Turns on/off the usage of the <quote>Contact</quote> address to send notification
		back to sender whose message is stored by <acronym>MSILO</acronym>.
		</para>
		<para>
		<emphasis>
			Default value is <quote>1 (0 = off, 1 = on)</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>use_contact</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "use_contact", 0)
...
</programlisting>
		</example>
	</section>

	<section id="msilo.p.snd_time_avp">
		<title><varname>snd_time_avp</varname> (str)</title>
		<para>
		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().
		</para>
		<para>
		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 <quote>YYYYMMDDHHMMSS</quote> (e.g., 20060101201500).
		</para>
		<para>
		<emphasis>
			Default value is <quote>null</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>snd_time_avp</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "snd_time_avp", "$avp(i:123)")
...
</programlisting>
		</example>
	</section>

	<section id="msilo.p.add_date">
		<title><varname>add_date</varname> (int)</title>
		<para>
		Whether to add as prefix the date when the message was stored.
		</para>
		<para>
		<emphasis>
			Default value is <quote>1</quote> (1==on/0==off).
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>add_date</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "add_date", 0)
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.max_messages">
		<title><varname>max_messages</varname> (int)</title>
		<para>
		Maximum number of stored message for an AoR.  Value 0
		equals to no limit.
		</para>
		<para>
		<emphasis>
			Default value is 0.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>max_messages</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "max_messages", 0)
...
</programlisting>
		</example>
	</section>
	<section id="msilo.p.add_contact">
		<title><varname>add_contact</varname> (int)</title>
		<para>
		Whether to add contact header to generated messages. The
		contact address is the From URI.
		</para>
		<para>
		<emphasis>
			Default value is <quote>0</quote> (1==on; 0==off as
			per RFC3428).
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>add_contact</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "add_contact", 1)
...
</programlisting>
		</example>
	</section>

	<section id="msilo.p.extra_hdrs_avp">
		<title><varname>extra_hdrs_avp</varname> (str)</title>
		<para>
		Name of an AVP which may contain extra headers that are
		stored with the message when m_store() is called.  These extra
		headers (if any) are then included in MESSAGE request
		generated by m_dump().
		</para>
		<para>
		If the parameter is not set, m_store() does not look
		for extra headers from any AVP.
		</para>
		<para>
		<emphasis>
			Default value is <quote>null</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>extra_hdrs_avp</quote> parameter</title>
<programlisting format="linespecific">
...
modparam("msilo", "extra_hdrs_avp", "$avp(msilo_extra_hdrs)")
...
</programlisting>
		</example>
	</section>

	<section id="msilo.p.skip_notification_flag">
		<title><varname>skip_notification_flag</varname> (int)</title>
		<para>
			Flag to mark the message for which no notification should be
			sent back to sender when storing in msilo. Valid value is in
			between 0 and 31.
		</para>
		<para>
		<emphasis>
			Default value is <quote>-1</quote> (feature disabled).
		</emphasis>
		</para>
		<example>
		<title>Set the <quote>skip_notification_flag</quote> parameter</title>
		<programlisting format="linespecific">
...
modparam("msilo", "skip_notification_flag", 18)
...
setflag(18);
m_store(...);
...
</programlisting>
		</example>
	</section>

	</section>

	<section>
	<title>Functions</title>
	<section id="msilo.f.m_store">
		<title><function moreinfo="none">m_store([owner])</function></title>
		<para>
		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=<quote>0</quote> if you have
		changed the request uri with the contact address of user's &ua;.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para>
			<emphasis>owner</emphasis> - 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.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
		</para>
		<example>
		<title><function>m_store</function> usage</title>
		<programlisting format="linespecific">
...
m_store();
m_store("$tu");
...
</programlisting>
		</example>
	</section>
	<section id="msilo.f.m_dump">
		<title><function moreinfo="none">m_dump([owner])</function></title>
		<para>
		The method sends stored messages for the &sip; user that has
		registered to the contact address in the registration.
		The method should be called when a REGISTER request is received
		and the <quote>Expire</quote> header has a value greater than zero.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para>
			<emphasis>owner</emphasis> - 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.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from REQUEST_ROUTE.
		</para>
		<example>
		<title><function>m_dump</function> usage</title>
		<programlisting format="linespecific">
...
m_dump();
m_dump("$fu");
...
</programlisting>
		</example>
	</section>
	</section>

	<section>
	<title>Statistics</title>
	<section>
		<title>stored_messages</title>
		<para>
		The number of messages stored by msilo.
		</para>
	</section>
	<section>
		<title>dumped_messages</title>
		<para>
		The number of dumped messages.
		</para>
	</section>
	<section>
		<title>failed_messages</title>
		<para>
		The number of failed dumped messages.
		</para>
	</section>
	<section>
		<title>dumped_reminders</title>
		<para>
		The number of dumped reminder messages.
		</para>
	</section>
	<section>
		<title>failed_reminders</title>
		<para>
		The number of failed reminder messages.
		</para>
	</section>
	</section>

	<section>
	<title>Installation and Running</title>
		<section>
		<title>&kamailio; config file</title>
		<para>
		Next picture displays a sample usage of msilo.
		</para>
		<example>
		<title>&kamailio; config script - sample msilo usage</title>
		<programlisting format="linespecific">
...
<xi:include href="msilo.cfg" parse="text"/>
...
		</programlisting>
		</example>
	</section>
	</section>
</chapter>
