# &adminguide;

## Overview

The module does specific handling for notify-subscribe events using xml bodies. It is used with the general event handling module, presence. It constructs and adds 3 events to it:

- presence - SIMPLE status presence: RFC 3856

- presence.winfo - SIMPLE watcher info: RFC 3857

- dialog;sla (or dialog;ma) - Bridged Line Appearances (BLA) (or Multiple Line Appearances (MLA)): draft-anil-sipping-bla

You can control which events are enabled via module parameters.

This module takes the XCAP permission rule documents from xcap_table. The presence permission rules are interpreted according to the specifications in RFC 4745 and RFC 5025.

## Dependencies

### &kamailio; Modules

The following modules must be loaded before this module:

- a database module.

- presence.

- sl.

- xcap_client.

  Needed only when not using the integrated xcap server (if 'integrated_xcap_server' parameter is set to 0).

### External Libraries or Applications

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

- libxml.

## Parameters

### `db_url`(str)

The database URL.

Default value is &defaultdb;.

#### Set `db_url` parameter

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

### `xcap_table`(str)

The name of the database table where XCAP documents are stored.

Default value is xcap.

#### Set `xcap_table` parameter

    ...
    modparam("presence_xml", "xcap_table", "xcaps")
    ...

### `disable_presence`(int)

Set this parameter to disable the handling of the "presence" event.

Default value: 0.

#### Set `disable_presence` parameter

    ...
    modparam("presence_xml", "disable_presence", 1)
    ...

### `disable_winfo`(int)

Set this parameter to disable the handling of the "presence.winfo" event.

Default value: 0.

#### Set `disable_winfo` parameter

    ...
    modparam("presence_xml", "disable_winfo", 1)
    ...

### `disable_bla`(int)

Set this parameter to disable the handling of the "dialog;sla" event.

Default value: 1 (0 - enabled, 1 - disabled).

#### Set `disable_bla` parameter

    ...
    modparam("presence_xml", "disable_bla", 1)
    ...

### `disable_xcapdiff`(int)

Set this parameter to disable the handling of the "xcap-diff" event.

Default value: 0.

#### Set `disable_xcapdiff` parameter

    ...
    modparam("presence_xml", "disable_xcapdiff", 1)
    ...

### `force_active` (int)

This parameter is used for permissions when handling Subscribe messages. If set to 1, subscription state is considered active and the presentity is not queried for permissions (should be set to 1 if not using an XCAP server). Otherwise, the XCAP server is queried and the subscription states is according to user defined permission rules. If no rules are defined for a certain watcher, the subscriptions remains in pending state and the Notify sent will have no body.

Note: When switching from one value to another, the watchers table must be emptied.

Default value is 0.

#### Set `force_active` parameter

    ...
    modparam("presence_xml", "force_active", 1)
    ...

### `integrated_xcap_server` (int)

This parameter is a flag for the type of XCAP servers used. If the XCAP server is integrated with &kamailio; presence_xml module and access the same database tables directly, like the embedded XCAP server implemented in xcap_server module, the parameter has to be set to 1. Apart from updating in xcap table, if the integrated server is not running on the same &kamailio; instance, it must send an RPC command presence.refreshWatchers [pres_uri] [event] when a user modifies a rules document, to instruct the presence_xml module to update states from the database and, if needed, send NOTIFY updates.

Otherwise (if set to 0) it uses xcap_client module to fetch documents from the XCAP servers with HTTP requests.

Default value is 0.

#### Set `integrated_xcap_server` parameter

    ...
    modparam("presence_xml", "integrated_xcap_server", 1)
    ...

### `xcap_server` (str)

The address of the xcap servers used for storage. This parameter is compulsory if the integrated_xcap_server parameter is not set. It can be set more than once, to construct an address list of trusted XCAP servers.

#### Set `xcap_server` parameter

    ...
    modparam("presence_xml", "xcap_server", "xcap_server.example.org")
    modparam("presence_xml", "xcap_server", "xcap_server.ag.org")
    ...

### `passive_mode`(int)

If set to 1, module acts in passive mode - no bind to presence module, no connection to database. Useful when needing only to use $xml(...) pseudo-variable.

Default value: 0 (0 - active mode, 1 - passive mode).

#### Set `passive_mode` parameter

    ...
    modparam("presence_xml", "passive_mode", 1)
    ...

### `xcapauth_userdel_reason`(str)

This parameter represents the reason that will be included in the Subscription-State header of the Notify when a rule is no longer found in the XCAP pres-auth document for a user that was previously allowed. The Subscription state in this case switches to "terminated". Because it is not clear which reason is most appropriate in this case from the ones defined by the RFC 3265, this parameter offers the possibility for the admin to decide which one he wishes to use.

Default value: probation . Since probation also accepts a retry-after parameter to specify after at least how may seconds the client should reattempt to resubscribe, you can include this in the parameter also.

#### Set `xcapauth_userdel_reason` parameter

    ...
    modparam("presence_xml", "xcapauth_userdel_reason", "probation;retry-after=30")
    modparam("presence_xml", "xcapauth_userdel_reason", "rejected")
    ...

### `force_dummy_presence`(int)

Set this parameter to enable simple body notify with status 'open' when presentity info is not available.

Default value: 0.

#### Set `force_dummy_presence` parameter

    ...
    modparam("presence_xml", "force_dummy_presence", 1)
    ...

### `force_presence_single_body`(int)

Set this parameter to enable single body notify. One presentity can have multiple dialogs and will by default notify all the dialogs and this can be a problem when dealing with large ring-groups or attendants, use this parameter to only send one body. Look at `presence_single_body_priorities` and `presence_single_body_lookup_element` to customize the behaviour.

Default value: 0.

#### Set `force_presence_single_body` parameter

    ...
    modparam("presence_xml", "force_presence_single_body", 1)
    ...

### `presence_single_body_priorities`(str)

Change this parameter to set the priorities when choosing the dialog that will be the final.

Importance is left to right.

Default value: Available|Ringing|On the Phone.

#### Set `presence_single_body_priorities` parameter

    ...
    modparam("presence_xml", "presence_single_body_priorities", "Offline|Online|Busy|Really Busy")
    ...

### `presence_single_body_lookup_element`(str)

Set the name of the element that should be used to get the priority. If the value obtained is not in the list of `presence_single_body_priorities` the priority is 0.

Default value: note.

#### Set `presence_single_body_lookup_element` parameter

    ...
    modparam("presence_xml", "presence_single_body_lookup_element", "status")
    ...

### `default_expires` (int)

The default expires value used when missing from SUBSCRIBE message (in seconds).

Default value is 3600.

#### Set `default_expires` parameter

    ...
    modparam("presence_xml", "default_expires", 3600)
    ...

## Functions

### `pres_check_basic(presentity_uri, status)`

Checks the /presence/tuple/status/basic nodes in the presentity for presentity_uri against the value in status.

This function can be used from ANY_ROUTE.

Return code:

- 1 - if a match is found.

- -1 - if a match is not found.

#### `pres_check_basic` usage

    ...
        if (pres_check_basic("$ru", "open")) {
            ...
        } else {
            if (is_method("MESSAGE"))
                m_store();
        else
            send_reply("404", "Not Found");
        }
    ...

### `pres_check_activities(presentity_uri, activity)`

Checks whether a /presence/person/activities/activity node exists in the presentity for presentity_uri.

This function can be used from ANY_ROUTE.

Return code:

- 1 - if a match is found.

- -1 - if a match is not found.

- -2 - if /presence/person or /presence/person/activity do not exist.

#### `pres_check_activities` usage

    ...
        if (pres_check_basic("$ru", "open")) {
    	pres_check_activities("$ru", "unknown");
    	if ($retcode || $retcode == -2 || !is_method("INVITE"))
                t_relay();
    	else
                send_reply("486", "Busy Here");
        } else {
            ...
        }
    ...

## Installation

The module requires one table in &kamailio; database: xcap. The SQL syntax to create it can be found in presence-create.sql script in the database directories in the kamailio/scripts folder. You can also find the complete database documentation on the project webpage, &kamailiodbdocs;.