<?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 "../../../docbook/entities.xml">
%docentities;

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

<chapter>
	
	<title>&adminguide;</title>
	
	<section>
	<title>Overview</title>
	<para>
	The dialog module provides dialog awareness to the &kamailio; proxy. Its 
	functionality is to keep track of the current dialogs, to offer information
	about them (like how many dialogs are active) or to manage them. The module
	exports several functions that could be used directly from scripts.
	</para>
	<para>
	The module, via an internal API, also provide the foundation to build on 
	top of it more complex dialog-based functionalities via other &kamailio; 
	modules.
	</para>
	</section>

	<section>
	<title>How it works</title>
	<para>
	To create the dialog associated to an initial request, the flag 
	<quote>dlg_flag</quote> (<xref linkend="dlg-flag-id"/>) must be set before
	creating the corresponding transaction.
	</para>
	<para>
	The dialog is automatically destroyed when a <quote>BYE</quote> is 
	received. In case of no <quote>BYE</quote>, the dialog lifetime is 
	controlled via the default timeout (see <quote>default_timeout</quote>
	- <xref linkend="default-timeout-id"/>) and custom timeout (see 
	<quote>timeout_avp</quote> - <xref linkend="timeout-avp-id"/>). The 
	dialog timeout is reset each time a sequential request passes.
	</para>
	</section>

	<section>
	<title>Dialog profiling</title>
	<para>
	Dialog profiling is a mechanism that helps in classifying, sorting and
	keeping trace of certain types of dialogs, using whatever properties of
	the dialog (like caller, destination, type of calls, etc).
	Dialogs can be dynamically added in different (and several) profile 
	tables - logically, each profile table can have a special meaning (like 
	dialogs outside the domain, dialogs terminated to PSTN, etc).
	</para>
	<para>
	There are two types of profiles:
	<itemizedlist>
		<listitem>
		<para>
			<emphasis>with no value</emphasis> - a dialog simply belongs 
			to a profile. (like outbound calls profile). There is no other 
			additional information to describe the dialog's belonging to the
			profile;
		</para>
		</listitem>
		<listitem>
		<para>
			<emphasis>with value</emphasis> - a dialog belongs to a profile 
			having a certain value (like in caller profile, where the value 
			is the caller ID). The belonging of the dialog to the profile is
			strictly related to the value.
		</para>
		</listitem>
	</itemizedlist>
	</para>
	<para>
	A dialog can be added to multiple profiles in the same time.
	</para>
	<para>
	Profiles are visible (at the moment) in the request route (for initial 
	and sequential requests) and in the branch, failure and reply routes of 
	the original request.
	</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>TM</emphasis> - Transaction module
			</para>
			</listitem>
			<listitem>
			<para>
				<emphasis>RR</emphasis> - Record-Route module
			</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 loaded:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>None</emphasis>.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	</section>


	<section>
	<title>Exported Parameters</title>
	<section>
		<title><varname>enable_stats</varname> (integer)</title>
		<para>
		If the statistics support should be enabled or not. Via statistic 
		variables, the module provide information about the dialog processing.
		Set it to zero to disable or to non-zero to enable it.
		</para>
		<para>
		<emphasis>
			Default value is <quote>1 (enabled)</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>enable_stats</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "enable_stats", 0)
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>hash_size</varname> (integer)</title>
		<para>
		The size of the hash table internally used to keep the dialogs. A 
		larger table is much faster but consumes more memory. The hash size
		must be a power of two number.
		</para>
		<para>
		IMPORTANT: If dialogs' information should be stored in a database, 
		a constant hash_size should be used, otherwise the restoring process 
		will not take place. If you really want to modify the hash_size you 
		must delete all table's rows before restarting the server.
		</para>
		<para>
		<emphasis>
			Default value is <quote>4096</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>hash_size</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "hash_size", 1024)
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>rr_param</varname> (string)</title>
		<para>
		Name of the Record-Route parameter to be added with the dialog cookie.
		It is used for the fast dialog matching of sequential requests.
		</para>
		<para>
		<emphasis>
			Default value is <quote>did</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>rr_param</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "rr_param", "xyz")
...
</programlisting>
		</example>
	</section>

	<section id="dlg-flag-id">
		<title><varname>dlg_flag</varname> (integer)</title>
		<para>
		Flag to be used for marking if a dialog should be constructed for the
		current request (this make sense only for initial requests).
		</para>
		<para>
		<emphasis>
			Default value is <quote>none</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>dlg_flag</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "dlg_flag", 4)
...
</programlisting>
		</example>
	</section>

	<section id="timeout-avp-id">
		<title><varname>timeout_avp</varname> (string)</title>
		<para>
		The specification of an AVP that contain a custom timeout (in seconds)
		for the dialog. It may be used only in a request (initial or sequential)
		context 
		</para>
		<para>
		<emphasis>
			Default value is <quote>none</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>timeout_avp</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "timeout_avp", "$avp(i:10)")
...
</programlisting>
		</example>
	</section>

	<section id="default-timeout-id">
		<title><varname>default_timeout</varname> (integer)</title>
		<para>
		The default dialog timeout (in seconds) if no custom one is set.
		</para>
		<para>
		<emphasis>
			Default value is <quote>43200 (12 hours)</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>default_timeout</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "default_timeout", 21600)
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>dlg_extra_hdrs</varname> (string)</title>
		<para>
		A string containing the extra headers (full format, with EOH)
		to be added in the requests generated by the module (like BYEs).
		</para>
		<para>
		<emphasis>
			Default value is <quote>NULL</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>dlf_extra_hdrs</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "dlg_extra_hdrs", "Hint: credit expired\r\n")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>dlg_match_mode</varname> (integer)</title>
		<para>
		How the sequential requests should be matched against the known dialogs.
		The modes are a combination between matching based on a cookie (DID)
		stored as cookie in Record-Route header and the matching based on SIP 
		elements (as in RFC3261).
		</para>
		<para>
		The supported modes are:
		</para>
		<itemizedlist>
			<listitem><para>
				<emphasis>0 - DID_ONLY</emphasis> - the match is done 
				exclusively based on DID;
			</para></listitem>
			<listitem><para>
				<emphasis>1 - DID_FALLBACK</emphasis> - the match is first 
				tried based on DID and if not present, it will fallback to
				SIP matching;
			</para></listitem>
			<listitem><para>
				<emphasis>2 - DID_NONE</emphasis> - the match is done 
				exclusively based on SIP elements; no DID information is added 
				in RR.
			</para></listitem>
		</itemizedlist>
		<para>
		<emphasis>
			Default value is <quote>0 (DID_ONLY)</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>dlg_match_mode</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "dlg_match_mode", 1)
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>db_url</varname> (string)</title>
		<para>
		If you want to store the information about the dialogs in a database 
		a database url must be specified.
		</para>
		<para>
		<emphasis>
			Default value is <quote>&defaultdb;</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>db_url</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "db_url", "&exampledb;")
...
</programlisting>
		</example>
	</section>

<section>
		<title><varname>db_mode</varname> (integer)</title>
		<para>
		Describe how to push into the DB the dialogs' information from memory.
		</para>
		<para>
		The supported modes are:
		</para>
		<itemizedlist>
			<listitem><para>
				<emphasis>0 - NO_DB</emphasis> - the memory content is not
				flushed into DB;
			</para></listitem>
			<listitem><para>
				<emphasis>1 - REALTIME</emphasis> - any dialog information 
				changes will be reflected into the database immediatly.
			</para></listitem>
			<listitem><para>
				<emphasis>2 - DELAYED</emphasis> - the dialog information 
				changes will be flushed into DB periodically, based on a
				timer routine.
			</para></listitem>
			<listitem><para>
				<emphasis>3 - SHUTDOWN</emphasis> - the dialog information 
				will be flushed into DB only at shutdown - no runtime updates.
			</para></listitem>
		</itemizedlist>
		<para>
		<emphasis>
			Default value is <quote>0</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>db_mode</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "db_mode", 1)
...
</programlisting>
		</example>
	</section>

<section>
		<title><varname>db_update_period</varname> (integer)</title>
		<para>
			The interval (seconds) at which to update dialogs' information if you chose to store the dialogs' info at a given interval.
			A too short interval will generate intensive database operations, a too large one will not notice short dialogs.
		</para>
		<para>
		<emphasis>
			Default value is <quote>60</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>db_update_period</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "db_update_period", 120)
...
</programlisting>
		</example>
	</section>

<section>
		<title><varname>db_fetch_rows</varname> (integer)</title>
		<para>
			The number of the rows to be fetched at once from database when loading the dialog records at startup from the database.
			This value can be used to tune the load time at startup. For 1MB of private memory (default) it should be below 400.
			The database driver must support fetch_result() capability. A value of 0 means the functionality is disabled.
		</para>
		<para>
		<emphasis>
			Default value is <quote>200</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>db_fetch_rows</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "db_fetch_rows", 500)
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>table_name</varname> (string)</title>
		<para>
		If you want to store the information about the dialogs in a 
		database a table name must be specified.
		</para>
		<para>
		<emphasis>
			Default value is <quote>dialog</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>table_name</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "table_name", "my_dialog")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>callid_column</varname> (string)</title>
		<para>
			The column name in the database to store the dialogs' callid.
		</para>
		<para>
		<emphasis>
			Default value is <quote>callid</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>callid_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "callid_column", "callid_c_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>from_uri_column</varname> (string)</title>
		<para>
			The column name in the database to store the caller's 
			sip address.
		</para>
		<para>
		<emphasis>
			Default value is <quote>from_uri</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>from_uri_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "from_uri_column", "from_uri_c_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>from_tag_column</varname> (string)</title>
		<para>
			The column name in the database to store the From tag from 
			the INVITE request.
		</para>
		<para>
		<emphasis>
			Default value is <quote>from_tag</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>from_tag_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "from_tag_column", "from_tag_c_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>to_uri_column</varname> (string)</title>
		<para>
			The column name in the database to store the callee's sip address.
		</para>
		<para>
		<emphasis>
			Default value is <quote>to_uri</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>to_uri_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "to_uri_column", "to_uri_c_name")
...
</programlisting>
		</example>
	</section>


	<section>
		<title><varname>to_tag_column</varname> (string)</title>
		<para>
			The column name in the database to store the To tag from 
			the 200 OK response to the INVITE request, if present.
		</para>
		<para>
		<emphasis>
			Default value is <quote>to_tag</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>to_tag_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "to_tag_column", "to_tag_c_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>caller_cseq_column</varname> (string)</title>
		<para>
			The column name in the database to store the cseq from caller
			side.
		</para>
		<para>
		<emphasis>
			Default value is <quote>caller_cseq</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>caller_cseq_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "caller_cseq_column", "column_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>callee_cseq_column</varname> (string)</title>
		<para>
			The column name in the database to store the cseq from callee
			side.
		</para>
		<para>
		<emphasis>
			Default value is <quote>callee_cseq</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>callee_cseq_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "callee_cseq_column", "column_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>caller_route_column</varname> (string)</title>
		<para>
			The column name in the database to store the route records from
			caller side (proxy to caller).
		</para>
		<para>
		<emphasis>
			Default value is <quote>caller_route_set</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>caller_route_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "caller_route_column", "column_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>callee_route_column</varname> (string)</title>
		<para>
			The column name in the database to store the route records from
			callee side (proxy to callee).
		</para>
		<para>
		<emphasis>
			Default value is <quote>callee_route_set</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>to_route_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "to_route_column", "column_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>caller_contact_column</varname> (string)</title>
		<para>
			The column name in the database to store the caller's contact 
			uri.
		</para>
		<para>
		<emphasis>
			Default value is <quote>from_contact</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>caller_contact_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "caller_contact_column", "column_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>callee_contact_column</varname> (string)</title>
		<para>
			The column name in the database to store the callee's contact 
			uri.
		</para>
		<para>
		<emphasis>
			Default value is <quote>callee_contact</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>callee_contact_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "callee_contact_column", "column_name")
...
</programlisting>
		</example>
	</section>

<section>
		<title><varname>caller_sock_column</varname> (string)</title>
		<para>
			The column name in the database to store the information about 
			the local interface receiving the traffic from caller.
		</para>
		<para>
		<emphasis>
			Default value is <quote>caller_sock</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>caller_sock_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "caller_sock_column", "column_name")
...
</programlisting>
		</example>
	</section>

<section>
		<title><varname>callee_sock_column</varname> (string)</title>
		<para>
			The column name in the database to store information about the 
			local interface receiving the traffic from callee.
		</para>
		<para>
		<emphasis>
			Default value is <quote>callee_contact</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>callee_sock_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "callee_sock_column", "column_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>h_id_column</varname> (string)</title>
		<para>
			The column name in the database to store the dialogs' 
			hash id information.
		</para>
		<para>
		<emphasis>
			Default value is <quote>hash_id</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>h_id_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "h_id_column", "hash_id_c_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>h_entry_column</varname> (string)</title>
		<para>
			The column name in the database to store the dialogs' hash 
			entry information.
		</para>
		<para>
		<emphasis>
			Default value is <quote>hash_entry</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>h_entry_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "h_entry_column", "h_entry_c_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>state_column</varname> (string)</title>
		<para>
			The column name in the database to store the 
			dialogs' state information.
		</para>
		<para>
		<emphasis>
			Default value is <quote>state</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>state_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "state_column", "state_c_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>start_time_column</varname> (string)</title>
		<para>
			The column name in the database to store the 
			dialogs' start time information.
		</para>
		<para>
		<emphasis>
			Default value is <quote>start_time</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>start_time_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "start_time_column", "start_time_c_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>timeout_column</varname> (string)</title>
		<para>
			The column name in the database to store the dialogs' timeout.
		</para>
		<para>
		<emphasis>
			Default value is <quote>timeout</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>timeout_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "timeout_column", "timeout_c_name")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>sflags_column</varname> (string)</title>
		<para>
			The column name in the database to store the script flags.
		</para>
		<para>
		<emphasis>
			Default value is <quote>sflags</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>sflags_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "sflags_column", "s_flags")
...
</programlisting>
		</example>
	</section>
	<section>
		<title><varname>toroute_column</varname> (string)</title>
		<para>
			The column name in the database to store the index of the
			route to be executed at timeout.
		</para>
		<para>
		<emphasis>
			Default value is <quote>toroute</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>toroute_column</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "toroute_column", "timeout_route")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>profiles_with_value</varname> (string)</title>
		<para>
			List of names for profiles with values.
		</para>
		<para>
		<emphasis>
			Default value is <quote>empty</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>profiles_with_value</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "profiles_with_value", "caller ; my_profile")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>profiles_no_value</varname> (string)</title>
		<para>
			List of names for profiles without values.
		</para>
		<para>
		<emphasis>
			Default value is <quote>empty</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>profiles_no_value</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "profiles_no_value", "inbound ; outbound")
...
</programlisting>
		</example>
	</section>

	<section>
		<title><varname>bridge_controller</varname> (string)</title>
		<para>
			SIP address to be used in From header when initiating a call bridge.
		</para>
		<para>
		<emphasis>
			Default value is <quote>sip:controller@kamailio.org</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>bridge_controller</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("dialog", "bridge_controller", "sip:ctd@kamailio.org")
...
</programlisting>
		</example>
	</section>

	</section>


	<section>
	<title>Exported Functions</title>
	<section>
		<title>
		<function moreinfo="none">set_dlg_profile(profile,[value])</function>
		</title>
		<para>
		Inserts the current dialog into a profile. Note that if the profile does
		not supports values, this will be silently discarded. Also, there is
		no check for inserting the same dialog in the same profile for multiple
		times.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>profile</emphasis> - name of the profile to be 
			added to;
			</para>
		</listitem>
		<listitem>
			<para><emphasis>value</emphasis> (optional) - string value to 
			define the belonging of the dialog to the profile - note that the
			profile must support values.
			Pseudo-variables are supported.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
			REPLY_ROUTE and FAILURE_ROUTE.
		</para>
		<example>
		<title><function>set_dlg_profile</function> usage</title>
		<programlisting format="linespecific">
...
set_dlg_profile("inbound_call");
set_dlg_profile("caller","$fu");
...
</programlisting>
		</example>
	</section>

	<section>
		<title>
		<function moreinfo="none">unset_dlg_profile(profile,[value])</function>
		</title>
		<para>
		Removes the current dialog from a profile.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>profile</emphasis> - name of the profile to be 
			removed from;
			</para>
		</listitem>
		<listitem>
			<para><emphasis>value</emphasis> (optional) - string value to 
			define the belonging of the dialog to the profile - note that the
			profile must support values.
			Pseudo-variables are supported.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from BRANCH_ROUTE,
			REPLY_ROUTE and FAILURE_ROUTE.
		</para>
		<example>
		<title><function>unset_dlg_profile</function> usage</title>
		<programlisting format="linespecific">
...
unset_dlg_profile("inbound_call");
unset_dlg_profile("caller","$fu");
...
</programlisting>
		</example>
	</section>


	<section>
		<title>
		<function moreinfo="none">is_in_profile(profile,[value])</function>
		</title>
		<para>
		Checks if the current dialog belongs to a profile. If the profile 
		supports values, the check can be reinforced to take into account a 
		specific value - if the dialog was inserted into the profile for a 
		specific value. If no value is passed, only the simply belonging of
		the  dialog to the profile is checked. Note that if the profile does
		not supports values, this will be silently discarded.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>profile</emphasis> - name of the profile to be 
			checked against;
			</para>
		</listitem>
		<listitem>
			<para><emphasis>value</emphasis> (optional) - string value to 
			further restrict the check. Pseudo-variables are supported.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
			REPLY_ROUTE and FAILURE_ROUTE.
		</para>
		<example>
		<title><function>is_in_profile</function> usage</title>
		<programlisting format="linespecific">
...
if (is_in_profile("inbound_call")) {
	log("this request belongs to a inbound call\n");
}
...
if (is_in_profile("caller","XX")) {
	log("this request belongs to a call of user XX\n");
}
...
</programlisting>
		</example>
	</section>

	<section>
		<title>
		<function moreinfo="none">get_profile_size(profile,[value],size)</function>
		</title>
		<para>
		Returns the number of dialogs belonging to a profile. If the profile 
		supports values, the check can be reinforced to take into account a 
		specific value - how many dialogs were inserted into the profile with 
		a specific value. If no value is passed, only simply belonging of the 
		dialog to the profile is checked. Note that if the profile does not 
		supports values, this will be silently discarded.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>profile</emphasis> - name of the profile to get 
			the size for;
			</para>
		</listitem>
		<listitem>
			<para><emphasis>value</emphasis> (optional) - string value to 
			further restrict the check. Pseudo-variables are supported;
			</para>
		</listitem>
		<listitem>
			<para><emphasis>size</emphasis> - an AVP or script variable to
			return the profile size in.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from REQUEST_ROUTE, BRANCH_ROUTE,
			REPLY_ROUTE and FAILURE_ROUTE.
		</para>
		<example>
		<title><function>get_profile_size</function> usage</title>
		<programlisting format="linespecific">
...
get_profile_size("inbound_call","$avp(size)");
xlog("currently there are $avp(size) inbound calls\n");
...
get_profile_size("caller","$fu");
xlog("currently, the user %fu has $avp(size) active outgoing calls\n");
...
</programlisting>
		</example>
	</section>

	<section>
		<title>
		<function moreinfo="none">dlg_isflagset(flag)</function>
		</title>
		<para>
		Check if the dialog flag is set or not.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>flag</emphasis> - index of the flag - can be
				pseudo-variable.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from BRANCH_ROUTE,
			REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.
		</para>
		<example>
		<title><function>dlg_isflagset</function> usage</title>
		<programlisting format="linespecific">
...
if(dlg_isflagset("1"))
{
    ...
}
...
</programlisting>
		</example>
	</section>

	<section>
		<title>
		<function moreinfo="none">dlg_setflag(flag)</function>
		</title>
		<para>
		Set the dialog flag.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>flag</emphasis> - index of the flag - can be
				pseudo-variable.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from BRANCH_ROUTE,
			REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.
		</para>
		<example>
		<title><function>dlg_setflag</function> usage</title>
		<programlisting format="linespecific">
...
dlg_setflag("1");
...
</programlisting>
		</example>
	</section>

	<section>
		<title>
		<function moreinfo="none">dlg_resetflag(flag)</function>
		</title>
		<para>
		Reset the dialog flag.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>flag</emphasis> - index of the flag - can be
				pseudo-variable.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from BRANCH_ROUTE,
			REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.
		</para>
		<example>
		<title><function>dlg_resetflag</function> usage</title>
		<programlisting format="linespecific">
...
redlg_setflag("1");
...
</programlisting>
		</example>
	</section>

	<section>
		<title>
		<function moreinfo="none">dlg_bye(side)</function>
		</title>
		<para>
		Send BYE to parties in dialog.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>side</emphasis> - where to send the BYE. It can be:
				caller, callee or both of them.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from BRANCH_ROUTE,
			REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.
		</para>
		<example>
		<title><function>dlg_bye</function> usage</title>
		<programlisting format="linespecific">
...
dlg_bye("all");
...
</programlisting>
		</example>
	</section>

	<section>
		<title>
		<function moreinfo="none">dlg_refer(side, address)</function>
		</title>
		<para>
		Refer the 'side' to a new SIP 'address'.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>side</emphasis> - which part to REFER. It can be:
				caller or callee.
			</para>
		</listitem>
		<listitem>
			<para><emphasis>address</emphasis> - SIP address to refer to.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from BRANCH_ROUTE,
			REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.
		</para>
		<example>
		<title><function>dlg_refer</function> usage</title>
		<programlisting format="linespecific">
...
dlg_refer("caller", "sip:annoucement@kamailio.org");
...
</programlisting>
		</example>
	</section>

	<section>
		<title>
		<function moreinfo="none">dlg_manage()</function>
		</title>
		<para>
		Process current SIP request with dialog module. It is alternative to
		setting dialog flag for initial INVITE and Route-parameter-callback
		execution for within-dialog requests.
		</para>
		<para>
		This function can be used from REQUEST_ROUTE.
		</para>
		<example>
		<title><function>dlg_manage</function> usage</title>
		<programlisting format="linespecific">
...
modparam("dialog", "default_timeout", 100)
...
route {
...
    if(is_method("INVITE") &amp;&amp; !has_totag())
    {
        $dlg_ctx(timeout_route) = 12;
        $dlg_ctx(timeout_bye) = 1;
    }
    dlg_manage();
...
}
...
</programlisting>
		</example>
	</section>

	<section>
		<title>
		<function moreinfo="none">dlg_bridge(from, to, op)</function>
		</title>
		<para>
		Bridge 'from' SIP address to 'to' SIP address via outbound proxy 'op'.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>from</emphasis> - SIP address of first side to call.
			</para>
		</listitem>
		<listitem>
			<para><emphasis>to</emphasis> - SIP address to refer <quote>from</quote> to.
			</para>
		</listitem>
		<listitem>
			<para><emphasis>op</emphasis> - outbound proxy SIP address.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from BRANCH_ROUTE,
			REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.
		</para>
		<example>
		<title><function>dlg_bridge</function> usage</title>
		<programlisting format="linespecific">
...
dlg_bridge("sip:user@kamailio.org", "sip:annoucement@kamailio.org",
   "sip:kamailio.org:5080");
...
</programlisting>
		</example>
	</section>

	<section>
		<title>
		<function moreinfo="none">dlg_get(callid, ftag, ttag)</function>
		</title>
		<para>
			Search and set current dialog based on Call-ID, From-Tag and To-Tag
			parameters.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>callid</emphasis> - SIP call-id.
			</para>
		</listitem>
		<listitem>
			<para><emphasis>ftag</emphasis> - SIP From tag.
			</para>
		</listitem>
		<listitem>
			<para><emphasis>ttag</emphasis> - SIP To tag.
			</para>
		</listitem>
		</itemizedlist>
		<para>
		This function can be used from BRANCH_ROUTE,
			REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.
		</para>
		<example>
		<title><function>dlg_get</function> usage</title>
		<programlisting format="linespecific">
...
if(dlg_get("abcdef", "123", "456"))
{
	dlg_bye("all");
}
...
</programlisting>
		</example>
	</section>

	</section>


	<section>
	<title>Exported statistics</title>
		<section>
			<title><varname>active_dialogs</varname></title>
			<para>
			Returns the number of current active dialogs (may be confirmed or
			not).
			</para>
		</section>
		<section>
			<title><varname>early_dialogs</varname></title>
			<para>
			Returns the number of early dialogs.
			</para>
		</section>		<section>
			<title><varname>processed_dialogs</varname></title>
			<para>
			Returns the total number of processed dialogs (terminated, 
			expired or active) from the startup.
			</para>
		</section>
		<section>
			<title><varname>expired_dialogs</varname></title>
			<para>
			Returns the total number of expired dialogs from the startup.
			</para>
		</section>
		<section>
			<title><varname>failed_dialogs</varname></title>
			<para>
			Returns the number of failed dialogs.
			</para>
		</section>
	</section>


	<section>
	<title>Exported MI Functions</title>

		<section>
		<title><varname>dlg_list</varname></title>
		<para>
		Lists the description of a dialog or of all dialogs (calls). If only
		one dialogs is to be listed, the dialog identifiers are to be passed
		as parameter (callid and fromtag).
		</para>
		<para>
		Name: <emphasis>dlg_list</emphasis>
		</para>
		<para>Parameters:</para>
		<itemizedlist>
			<listitem><para>
				<emphasis>callid</emphasis> (optional) - callid if a single
				dialog to be listed.
			</para></listitem>
			<listitem><para>
				<emphasis>from_tag</emphasis> (optional, but cannot be present
				without the callid parameter) - from tag (as per initial request)
				of the dialog to be listed.  Note that if the from_tag is not
				specified, only dialogs created by a request without a from tag
				are matched, which will only occur with broken clients and is
				thus a very rare situation.
			</para></listitem>
		</itemizedlist>
		<para>
		MI FIFO Command Format:
		</para>
		<programlisting  format="linespecific">
		:dlg_list:_reply_fifo_file_
		_empty_line_
		</programlisting>
		<programlisting  format="linespecific">
		:dlg_list:_reply_fifo_file_
		abcdrssfrs122444@192.168.1.1
		AAdfeEFF33
		</programlisting>
		</section>

		<section>
		<title><varname>dlg_list_ctx</varname></title>
		<para>
		The same as the <quote>dlg_list</quote> but including in the dialog
		description the associated context from modules sitting on top of
		the dialog module.
		</para>
		<para>
		Name: <emphasis>dlg_list_ctx</emphasis>
		</para>
		<para>Parameters: <emphasis>see <quote>dlg_list</quote></emphasis>
		</para>
		<para>
		MI FIFO Command Format:
		</para>
		<programlisting  format="linespecific">
		:dlg_list_ctx:_reply_fifo_file_
		_empty_line_
		</programlisting>
		</section>

		<section>
			<title><varname>dlg_end_dlg</varname></title>
			<para>
			Terminates an ongoing dialog by sending BYE in both directions.
			</para>
		<para>
		Name: <emphasis>dlg_end_dlg</emphasis>
		</para>
		<para>Parameters:</para>
		<itemizedlist>
			<listitem><para>
				<emphasis>h_entry</emphasis> - hash entry of the dialog in the
				internal dialog table
			</para></listitem>
			<listitem><para>
				<emphasis>h_id</emphasis> - hash id of the dialog on the hash
				entry
			</para></listitem>
			<listitem><para>
				<emphasis>extra_hdrs</emphasis> - (optional) string containg 
				extra headers (full format) to be added to the BYE requests.
			</para></listitem>
		</itemizedlist>
		<para>
		The values for the h_entry and h_id can be get via the dlg_list
		MI command.
		</para>
		<para>
		MI FIFO Command Format:
		</para>
		<programlisting  format="linespecific">
		:dlg_end_dlg:_reply_fifo_file_
		342
		56
		_empty_line_
		</programlisting>
		</section>

		<section>
		<title><varname>profile_get_size</varname></title>
		<para>
		Returns the number of dialogs belonging to a profile. If the profile 
		supports values, the check can be reinforced to take into account a 
		specific value - how many dialogs were inserted into the profile with 
		a specific value. If no value is passed, only the simply belonging of
		the dialog to the profile is checked. Note that if the profile does not 
		supports values, this will be silently discarded.
		</para>
		<para>
		Name: <emphasis>profile_get_size</emphasis>
		</para>
		<para>Parameters:</para>
		<itemizedlist>
			<listitem><para>
				<emphasis>profile</emphasis> - name of the profile to get the
				value for.
			</para></listitem>
			<listitem><para>
				<emphasis>value</emphasis> (optional)- string value to 
				further restrict the check;
			</para></listitem>
		</itemizedlist>
		<para>
		MI FIFO Command Format:
		</para>
		<programlisting  format="linespecific">
		:profile_get_size:_reply_fifo_file_
		inbound_calls
		_empty_line_
		</programlisting>
		</section>

		<section>
		<title><varname>profile_list_dlgs</varname></title>
		<para>
		Lists all the dialogs belonging to a profile. If the profile 
		supports values, the check can be reinforced to take into account a 
		specific value - list only the dialogs that were inserted into the 
		profile with that specific value. If no value is passed, all dialogs 
		belonging to the profile will be listed. Note that if the profile does 
		not supports values, this will be silently discarded.
		</para>
		<para>
		Name: <emphasis>profile_list_dlgs</emphasis>
		</para>
		<para>Parameters:</para>
		<itemizedlist>
			<listitem><para>
				<emphasis>profile</emphasis> - name of the profile to list the
				dialog for.
			</para></listitem>
			<listitem><para>
				<emphasis>value</emphasis> (optional)- string value to 
				further restrict the check;
			</para></listitem>
		</itemizedlist>
		<para>
		MI FIFO Command Format:
		</para>
		<programlisting  format="linespecific">
		:profile_list_dlgs:_reply_fifo_file_
		inbound_calls
		_empty_line_
		</programlisting>
		</section>

		<section>
		<title><varname>dlg_bridge</varname></title>
		<para>
			Bridge two SIP addresses in a call using INVITE(hold)-REFER-BYE
			mechanism.
		</para>
		<para>
		Name: <emphasis>dlg_bridge</emphasis>
		</para>
		<para>Parameters:</para>
		<itemizedlist>
			<listitem><para>
				<emphasis>from</emphasis> - SIP address to initiate the call
			</para></listitem>
			<listitem><para>
				<emphasis>to</emphasis> - SIP address to refer 'from' to
			</para></listitem>
			<listitem><para>
				<emphasis>op</emphasis> (optional) - outbound proxy SIP address
			</para></listitem>
		</itemizedlist>
		<para>
		MI FIFO Command Format:
		</para>
		<programlisting  format="linespecific">
		:dlg_bridge:_reply_fifo_file_
		from
		to
		op
		_empty_line_
		</programlisting>
		</section>

	</section>


	<section>
	<title>Exported pseudo-variables</title>

		<section>
			<title><varname>$DLG_count</varname></title>
			<para>
			Returns the number of current active dialogs (may be confirmed or
			not).
			</para>
		</section>

		<section>
			<title><varname>$DLG_status</varname></title>
			<para>
			Returns the status of the dialog corresponding to the processed 
			sequential request. This PV will be available only for sequential
			requests, after doing loose_route().
			</para>
			<para>
			Value may be:
			</para>
			<itemizedlist>
				<listitem><para>
					<emphasis>NULL</emphasis> - Dialog not found.
				</para></listitem>
				<listitem><para>
					<emphasis>3</emphasis> - Confirmed by a final reply but 
					no ACK received yet.
				</para></listitem>
				<listitem><para>
					<emphasis>4</emphasis> - Confirmed by a final reply and
					ACK received.
				</para></listitem>
				<listitem><para>
					<emphasis>5</emphasis> - Dialog ended.
				</para></listitem>
			</itemizedlist>
		</section>

		<section>
			<title><varname>$DLG_lifetime</varname></title>
			<para>
			Returns the duration (in seconds) of the dialog corresponding to 
			the processed sequential request. The duration is calculated from 
			the dialog confirmation and the current moment. This PV will be 
			available only for sequential requests, after doing loose_route().
			</para>
			<para>
			NULL will be returned if there is no dialog for the request.
			</para>
		</section>
		<section>
			<title><varname>$dlg(...)</varname></title>
			<para>Access to dialog attributes.</para>
		</section>
		<section>
			<title><varname>$dlg_ctx(...)</varname></title>
			<para>Access to dialog context attributes.</para>
		</section>

	</section>



</chapter>