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

<chapter>
	<chapterinfo>
	<revhistory>
		<revision>
		<revnumber>$Revision: 1827 $</revnumber>
		<date>$Date: 2007-03-12 17:22:53 +0200 (Mon, 12 Mar 2007) $</date>
		</revision>
	</revhistory>
	</chapterinfo>
	<title>User's Guide</title>
	
	<section>
	<title>Overview</title>
	<para>
		Offer a possibility to store incoming/outgoing SIP messages in database.
	</para>
	<para>
	There are two ways of storing information.
		<itemizedlist>
		<listitem>
		<para>
		by calling explicitely the sip_trace() method in OpenSER configuration
		file. In this case the original message is processed.
		</para>
		</listitem>
		<listitem>
		<para>
		by setting the flag equal with the value of 'trace_flag' (e.g.,
		setflag(__trace_flag__)) parameter of the module. In this case, the\
		message sent forward is processed. The logging mechanism is based on
		TM/SL callbacks, so only messages processed with TM/SL are logged.
		</para>
		</listitem>
		</itemizedlist>
	</para>

	<para>
	The tracing can be turned on/off using fifo commad.
	</para>
	<para>
	openserctl fifo sip_trace on
	</para>
	<para>
	openserctl fifo sip_trace off
	</para>
	</section>
	<section>
	<title>Dependencies</title>
	<section>
		<title>&ser; Modules</title>
		<para>
		The following modules must be loaded before this module:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>database module</emphasis> - mysql, postrgress,
				dbtext, unixodbc...
			</para>
			</listitem>
			<listitem>
			<para>
				<emphasis>tm and sl modules</emphasis> - optional, only if
				you want to trace messages forwarded by these modules.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	<section>
		<title>External Libraries or Applications</title>
		<para>
		The following libraries or applications must be installed before running
		&ser; with this module loaded:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>None</emphasis>.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	</section>
	<section>
	<title>Exported Parameters</title>
	<section>
		<title><varname>db_url</varname> (str)</title>
		<para>
		Database URL.
		</para>
		<para>
		<emphasis>
			Default value is "".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>db_url</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("siptrace", "db_url", "mysql://user:passwd@host/dbname")
...
</programlisting>
		</example>
	</section>
	<section>
		<title><varname>table</varname> (str)</title>
		<para>
		Name of the table where to store the SIP messages.
		</para>
		<para>
		<emphasis>
			Default value is "sip_trace".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>sip_trace</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("siptrace", "table", "strace")
...
</programlisting>
		</example>
	</section>
	<section>
		<title><varname>trace_flag</varname> (integer)</title>
		<para>
		Which flag is used to mark messages to trace
		</para>
		<para>
		<emphasis>
			Default value is "0".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>trace_flag</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("siptrace", "trace_flag", 22)
...
</programlisting>
		</example>
	</section>
	<section>
		<title><varname>trace_on</varname> (integer)</title>
		<para>
		Parameter to enable/disable trace (on(1)/off(0))
		</para>
		<para>
		<emphasis>
			Default value is "0".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>trace_on</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("siptrace", "trace_on", 1)
...
</programlisting>
		</example>
	</section>
	<section>
		<title><varname>traced_user_avp</varname> (str)</title>
		<para>
		The name of the AVP storing the SIP URI of the traced user. If
		the AVP is set, messages are stored in database table and
		'traced_user' column is filled with AVP's value. You can store
		the message many times for many users by having multiple values
		for this AVP.
		</para>
		<para>
		<emphasis>
			Default value is "NULL" (feature disabled).
		</emphasis>
		</para>
		<example>
		<title>Set <varname>trace_on</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("siptrace", "traced_user_avp", "$avp(i:123)")
modparam("siptrace", "traced_user_avp", "$avp(s:user)")
...
</programlisting>
		</example>
	</section>
	<section>
		<title><varname>trace_table_avp</varname> (str)</title>
		<para>
		The name of the AVP storing the name of the table where to
		store the SIP messages. If it is not set, the value of
		'table' parameter is used. In this way one can select
		dynamically where to store the traced messages. The table
		must exists, and must have the same structure as 'sip_trace'
		table.
		</para>
		<para>
		<emphasis>
			Default value is "NULL" (feature disabled).
		</emphasis>
		</para>
		<example>
		<title>Set <varname>trace_on</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("siptrace", "trace_table_avp", "$avp(i:345)")
modparam("siptrace", "trace_table_avp", "$avp(s:siptrace_table)")
...
</programlisting>
		</example>
	</section>
	<section>
		<title><varname>duplicate_uri</varname> (str)</title>
		<para>
		The address in form of SIP uri where to send a duplicate
		of traced message. It uses UDP all the time.
		</para>
		<para>
		<emphasis>
			Default value is "NULL".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>duplicate_uri</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("siptrace", "duplicate_uri", "sip:10.1.1.1:5888")
...
</programlisting>
		</example>
	</section>
	<section>
		<title><varname>trace_local_ip</varname> (str)</title>
		<para>
		The address to be used in fromip field for local generated
		messages. If not set, the module sets it to the address
		of the socket that will be used to send the message.
		</para>
		<para>
		<emphasis>
			Default value is "NULL".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>trace_local_ip</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("siptrace", "trace_local_ip", "10.1.1.1:5064")
...
</programlisting>
		</example>
	</section>
	</section>
	
	<section>
	<title>Exported Functions</title>
	<section>
		<title>
		<function moreinfo="none">sip_trace()</function>
		</title>
		<para>
		Store current processed SIP message in database. It is stored in the
		form prior applying chages made to it.
		</para>
		<para>
		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE.
		</para>
		<example>
		<title><function>sip_trace()</function> usage</title>
		<programlisting format="linespecific">
...
sip_trace();
...
</programlisting>
		</example>
	</section>

	</section>

    <section>
	<title>Exported MI Functions</title>
	<section>
		<title>
		<function moreinfo="none">sip_trace</function>
		</title>
		<para>

		</para>
		<para>
		Name: <emphasis>sip_trace</emphasis>
		</para>
		<para>Parameters: </para>
		<itemizedlist>
            <listitem><para>trace_mode : turns on/off SIP message tracing. Possible values are:</para>
			      <itemizedlist>
	                 <listitem><para> on </para></listitem> 
			         <listitem><para> off </para></listitem>	
				  </itemizedlist>
			</listitem>	  
		</itemizedlist>

 		<para>
		MI FIFO Command Format:
		</para>
        <programlisting  format="linespecific">
		:sip_trace:_reply_fifo_file_
		trace_mode
		_empty_line_
		</programlisting>
	</section>
	</section>
	
	<section>
	<title>sip_trace table definition</title>
	<para>
	Next is presented the definition of sip_trace table
	</para>
		<example>
		<title>sip_trace sql</title>
		<programlisting format="linespecific">
CREATE TABLE `sip_trace` (
  `id` int(10) NOT NULL auto_increment,
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  `callid` varchar(254) NOT NULL default '',
  `traced_user` varchar(128) NOT NULL default '',
  `msg` text NOT NULL,
  `method` varchar(50) NOT NULL default '',
  `status` varchar(254) NOT NULL default '',
  `fromip` varchar(50) NOT NULL default '',
  `toip` varchar(50) NOT NULL default '',
  `fromtag` varchar(64) NOT NULL default '',
  `direction` varchar(4) NOT NULL default '',
  INDEX user_idx (traced_user),
  INDEX date_id (date),
  INDEX ip_idx (fromip),
  KEY `call_id` (`callid`),
  PRIMARY KEY  (`id`)
);
</programlisting>
		</example>
	</section>

	<section>
	<title>Known issues</title>
	<para>
	Stateless forwarded messages (forward()) are not logged if you set the
	flag, use sip_trace().
	</para>
	</section>
	
</chapter>

<!-- Keep this element at the end of the file
Local Variables:
sgml-parent-document: ("siptrace.sgml" "Book" "chapter")
End:
-->
