# &adminguide;

## Overview

The ims_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. The ims_dialog module extends the original dialog module by providing support for forked calling and early dialog termination. It is the intention that the ims_dialog module will eventually replace the dialog module.

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.

## How it works

To create the dialog associated to an initial request, the flag dlg_flag ( ) must be set before creating the corresponding transaction.

The dialog is automatically destroyed when a BYE is received. In case of no BYE, the dialog lifetime is controlled via the default timeout (see default_timeout - ) and custom timeout (see timeout_avp - ). The dialog timeout is reset each time a sequential request passes.

## Dialog profiling

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

There are two types of profiles:

- with no value - 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;

- with value - 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.

A dialog can be added to multiple profiles in the same time.

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.

## Dependencies

### &kamailio; Modules

The following modules must be loaded before this module:

- TM - Transaction module

- RR - Record-Route module

### External Libraries or Applications

The following libraries or applications must be installed before running &kamailio; with this module loaded:

- None.

## Parameters

### `enable_stats` (integer)

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `hash_size` (integer)

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.

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.

Default value is 4096.

#### Set `hash_size` parameter

    ...
    modparam("ims_dialog", "hash_size", 1024)
    ...

### `rr_param` (string)

Name of the Record-Route parameter to be added with the dialog cookie. It is used for the fast dialog matching of sequential requests.

Default value is did.

#### Set `rr_param` parameter

    ...
    modparam("ims_dialog", "rr_param", "xyz")
    ...

### `dlg_flag` (integer)

Flag to be used for marking if a dialog should be constructed for the current request (this makes sense only for initial requests).

Default value is none.

#### Set `dlg_flag` parameter

    ...
    modparam("ims_dialog", "dlg_flag", 4)
    ...

### `timeout_avp` (string)

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

Default value is none.

#### Set `timeout_avp` parameter

    ...
    modparam("ims_dialog", "timeout_avp", "$avp(i:10)")
    ...

### `default_timeout` (integer)

The default dialog timeout (in seconds) if no custom one is set.

Default value is 43200 (12 hours).

#### Set `default_timeout` parameter

    ...
    modparam("ims_dialog", "default_timeout", 21600)
    ...

### `dlg_extra_hdrs` (string)

A string containing the extra headers (full format, with EOH) to be added in the requests generated by the module (like BYEs).

Default value is NULL.

#### Set `dlf_extra_hdrs` parameter

    ...
    modparam("ims_dialog", "dlg_extra_hdrs", "Hint: credit expired\r\n")
    ...

### `dlg_match_mode` (integer)

Deprecated - in the new dialog module we always match using DID ONLY

### `detect_spirals` (integer)

Whether spirals (i.e., messages routed through the proxy multiple times) should be detected or not.

If set to 0, spirals will not be detected and result in the generation of a new, possibly dangling dialog structure per occurring spiral. If set to 1, spirals are detected and internally mapped to existing dialog structures.

Default value is 1.

#### Set `detect_spirals` parameter

    ...
    modparam("ims_dialog", "detect_spirals", 1)
    ...

### `db_url` (string)

In order to store information about dialogs in a database, a database URL must be specified.

Default value is &defaultdb;.

#### Set `db_url` parameter

        ...
        modparam("ims_dialog", "db_url", "&exampledb;")
        ...

### `db_mode` (integer)

This is the database mode to be used for dialog persistent storage.

- 0 - NO_DB - the memory content is not flushed into DB;

- 1 - REALTIME - any dialog information changes will be reflected into the database immediately.

- 2 - DELAYED - the dialog information changes will be flushed into DB periodically, based on a timer routine.

- 3 - SHUTDOWN - the dialog information will be flushed into DB only at shutdown - no runtime updates.

Default value is 0.

#### Set `db_mode` parameter

        ...
        modparam("ims_dialog", "db_mode", 1)
        ...

### `db_update_period` (integer)

The interval (seconds) at which to update dialogs' information, if the server is configured to store the dialog information at a given interval. A too short interval will generate intensive database operations, while an excessively long one will miss dialogs with a short lifetime.

Default value is 60 seconds.

#### Set `db_update_period` parameter

        ...
        modparam("ims_dialog", "db_update_period", 120)
        ...

### `db_fetch_rows` (integer)

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 the fetch_result() capability. A value of 0 means the database fetch is not limited.

Default value is 200.

#### Set `db_fetch_rows` parameter

        ...
        modparam("ims_dialog", "db_fetch_rows", 500)
        ...

### `profiles_with_value` (string)

List of names for profiles with values.

Default value is empty.

#### Set `profiles_with_value` parameter

    ...
    modparam("ims_dialog", "profiles_with_value", "caller ; my_profile")
    ...

### `profiles_no_value` (string)

List of names for profiles without values.

Default value is empty.

#### Set `profiles_no_value` parameter

    ...
    modparam("ims_dialog", "profiles_no_value", "inbound ; outbound")
    ...

### `bridge_controller` (string)

SIP address to be used in From header when initiating a call bridge.

Default value is sip:controller@kamailio.org.

#### Set `bridge_controller` parameter

    ...
    modparam("ims_dialog", "bridge_controller", "sip:ctd@kamailio.org")
    ...

### `initial_cbs_inscript` (string)

This has been deprecated since dlg_manage has been removed.

## Functions

### `set_dlg_profile(profile[, value])`

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.

Meaning of the parameters is as follows:

- profile - name of the profile to be added to;

- value (optional) - string value to define the belonging of the dialog to the profile - note that the profile must support values. Pseudo-variables are supported.

This function can be used from REQUEST_ROUTE, BRANCH_ROUTE, REPLY_ROUTE and FAILURE_ROUTE.

#### `set_dlg_profile` usage

    ...
    set_dlg_profile("inbound_call");
    set_dlg_profile("caller","$fu");
    ...

### `unset_dlg_profile(profile[, value])`

Removes the current dialog from a profile.

Meaning of the parameters is as follows:

- profile - name of the profile to be removed from;

- value (optional) - string value to define the belonging of the dialog to the profile - note that the profile must support values. Pseudo-variables are supported.

This function can be used from BRANCH_ROUTE, REPLY_ROUTE and FAILURE_ROUTE.

#### `unset_dlg_profile` usage

    ...
    unset_dlg_profile("inbound_call");
    unset_dlg_profile("caller","$fu");
    ...

### `is_in_profile(profile[, value])`

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.

Meaning of the parameters is as follows:

- profile - name of the profile to be checked against;

- value (optional) - string value to further restrict the check. Pseudo-variables are supported.

This function can be used from REQUEST_ROUTE, BRANCH_ROUTE, REPLY_ROUTE and FAILURE_ROUTE.

#### `is_in_profile` usage

    ...
    if (is_in_profile("inbound_call")) {
    	log("this request belongs to an inbound call\n");
    }
    ...
    if (is_in_profile("caller","XX")) {
    	log("this request belongs to a call of user XX\n");
    }
    ...

### `get_profile_size(profile[, value], size)`

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.

Meaning of the parameters is as follows:

- profile - name of the profile to get the size for;

- value (optional) - string value to further restrict the check. Pseudo-variables are supported;

- size - an AVP or script variable to return the profile size in.

This function can be used from REQUEST_ROUTE, BRANCH_ROUTE, REPLY_ROUTE and FAILURE_ROUTE.

#### `get_profile_size` usage

    ...
    if(get_profile_size("inbound_call","$avp(size)"))
        xlog("currently there are $avp(size) inbound calls\n");
    ...
    if(get_profile_size("caller","$fu","$avp(size)"))
        xlog("currently, the user $fu has $avp(size) active outgoing calls\n");
    ...

### `dlg_isflagset(flag)`

Check if the dialog flag is set or not.

Meaning of the parameters is as follows:

- flag - index of the flag - can be pseudo-variable.

This function can be used from BRANCH_ROUTE, REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.

#### `dlg_isflagset` usage

    ...
    if(dlg_isflagset("1"))
    {
        ...
    }
    ...

### `dlg_setflag(flag)`

Set the dialog flag.

Meaning of the parameters is as follows:

- flag - index of the flag - can be pseudo-variable.

This function can be used from BRANCH_ROUTE, REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.

#### `dlg_setflag` usage

    ...
    dlg_setflag("1");
    ...

### `dlg_resetflag(flag)`

Reset the dialog flag.

Meaning of the parameters is as follows:

- flag - index of the flag - can be pseudo-variable.

This function can be used from BRANCH_ROUTE, REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.

#### `dlg_resetflag` usage

    ...
    dlg_resetflag("1");
    ...

### `dlg_terminate`

Terminates a dialog. In ims_dialog module this function now includes support for early as well as confirmed dialogs.

Meaning of the parameters is as follows:

- side - which side to terminate. It can be: caller, callee or both of them.

- reason - reason for termination.

This function can be used from BRANCH_ROUTE, REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.

#### `dlg_terminate` usage

    ...
    dlg_terminate("all", "Insufficient QoS");
    ...

### `dlg_refer(side, address)`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg_manage()`

This has been deprecated in ims_dialog. Instead set dialog flag for initial INVITE and Route-parameter-callback execution for within-dialog requests.

### `dlg_bridge(from, to, op)`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg_get(callid, ftag, ttag)`

Search and set current dialog based on Call-ID, From-Tag and To-Tag parameters.

Meaning of the parameters is as follows:

- callid - SIP call-id.

- ftag - SIP From tag.

- ttag - SIP To tag.

This function can be used from BRANCH_ROUTE, REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.

#### `dlg_get` usage

    ...
    if(dlg_get("abcdef", "123", "456"))
    {
    	dlg_bye("all");
    }
    ...

### `is_known_dlg()`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

## Exported statistics

### `active_dialogs`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `early_dialogs`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `processed_dialogs`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `expired_dialogs`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `failed_dialogs`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

## MI Commands

### `dlg_list`

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). In ims_dialog module this also now also lists all dlg_out entries for early dialogs.

Name: dlg_list

Parameters:

- callid (optional) - callid if a single dialog to be listed.

- from_tag (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.

MI FIFO Command Format:

    		:dlg_list:_reply_fifo_file_
    		_empty_line_

    		:dlg_list:_reply_fifo_file_
    		abcdrssfrs122444@192.168.1.1
    		AAdfeEFF33

### `dlg_list_ctx`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg_end_dlg`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg_terminate_dlg`

Terminates a single dialog, identified by the call_id, ftag, ttag. In ims_dialog module this dialog can be terminated in the early or confirmed states.

Name: dlg_terminate_dlg

Parameters:

- callid - callid of the dialog to be terminated.

- ftag fromtag of dialog to be terminated.

- ttag totag of dialog to be terminated.

Note: Works for confirmed and early dialogs.

MI FIFO Command Format:

    		:dlg_terminate_dlg:_reply_fifo_file_
    		abcdrssfrs122444@192.168.1.1
    		AAdfeEFF33 ftag-1234 t-tag1234

### `profile_get_size`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `profile_list_dlgs`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg_bridge`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

## RPC Commands

### `dlg.list`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg.list_ctx`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg.dlg_list`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg.dlg_list_ctx`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg.end_dlg`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg.profile_get_size`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg.profile_list`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `dlg.bridge_dlg`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

## Exported pseudo-variables

### `$DLG_count`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `$DLG_status`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `$DLG_lifetime`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `$dlg(...)`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `$dlg_ctx(...)`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.

### `$dlg_var(key)`

This function is currently not supported by the ims_dialog module. To be incorporated in the future.