# &adminguide;

## Overview

This module collects extensions from &kamailio; TM module.

&kamailio; TM (Transaction Management) module documentation is available at: http://www.kamailio.org/docs/modules/1.5.x/tm.html

## Dependencies

### &kamailio; Modules

The following modules must be loaded before this module:

- tm - transaction management.

### External Libraries or Applications

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

- None.

## Functions

### `t_cancel_branches(which)`

Cancel branches of an active SIP transaction. The function can be called for a SIP reply that will identify the current branch.

Parameter can be:.

- all - cancel all branches.

- others - cancel all branches but the current one.

- this - cancel current branch.

This function can be used in ONREPLY_ROUTE.

#### `t_cancel_branches` usage

    ...
    if (t_cancel_branches("all")) {
    	xlog("cancelled all branches\n");
    }
    ...

### `t_cancel_callid(callid, cseq, flag)`

Cancel first INVITE transaction identified by callid and cseq. It sets the flag if the value is greater than zero

Parameters:.

- callid - call-id value.

- cseq - cseq number.

- flag - index of the flag to set.

This function can be used in ANY_ROUTE.

#### `t_cancel_callid` usage

    ...
    if (t_cancel_callid("123qaz", "5", "22")) {
    	xlog("transaction cancelled\n");
    }
    ...

### `t_reply_callid(callid, cseq, code, reason)`

Send reply to first INVITE transaction identified by callid and cseq.

Parameters:.

- callid - call-id value.

- cseq - cseq number.

- code - reply code.

- reason - reply reason.

This function can be used in ANY_ROUTE.

#### `t_reply_callid` usage

    ...
    if (t_reply_callid("123qaz", "5", "458", "Replied remotely")) {
    	xlog("transaction replied\n");
    }
    ...

### `t_flush_flags()`

Flush the flags from current SIP message into the already created transaction. It make sense only in routing block if the transaction was created via t_newtran() and the flags have been altered since.

This function can be used from ANY_ROUTE .

#### `t_flush_flags` usage

    ...
    t_flush_flags();
    ...

### `t_is_failure_route()`

Returns true if the top-executed route block is failure_route.

This function can be used from ANY_ROUTE .

#### `t_is_failure_route` usage

    ...
    failure_route[xyz] {
        route(abc);
    }

    route[abc] {
        if(t_is_failure_route()) { ... }
    }
    ...

### `t_is_branch_route()`

Returns true if the top-executed route block is branch_route.

This function can be used from ANY_ROUTE .

#### `t_is_branch_route` usage

    ...
    branch_route[xyz] {
        route(abc);
    }

    route[abc] {
        if(t_is_branch_route()) { ... }
    }
    ...

### `t_is_reply_route()`

Returns true if the top-executed route block is reply_route.

This function can be used from ANY_ROUTE .

#### `t_is_reply_route` usage

    ...
    reply_route[xyz] {
        route(abc);
    }

    route[abc] {
        if(t_is_reply_route()) { ... }
    }
    ...

### `t_suspend()`

Suspend the execution of SIP request in a transaction. If transaction was not created yet, it is created by this function. Returns true in case of success and internal transaction index and label are available via $T(id_index) and $T(id_label).

This function can be used from ANY_ROUTE .

#### `t_suspend` usage

    ...
    if(t_suspend())
    {
        xlog("proceesing suspended in trasaction [$T(id_index):$T(id_label)]\n");
        exit;
    }
    ...

### `t_continue(tindex, tlabel, rtname)`

Continue the execution of the transaction identified by tindex and tlabel with the actions defined in route[rtname].

Parameters:.

- tindex - internal index of transaction. Can be an integer or a pseudo-variable.

- tlabel - internal label of transaction. Can be an integer or a pseudo-variable.

- rtname - the name of the route block to execute. Can be a static string value or a dynamic string with pseudo-variables.

This function can be used in ANY_ROUTE.

#### `t_continue` usage

    ...
    tcontinue('123', '456', 'MYROUTE');
    ...

## Exported pseudo-variables

- $T_branch_idx

- $T_reply_code

- $T_reply_reason

- $T_reply_last

- $T_req(pv)

- $T_rpl(pv)

- $T_reply_ruid

Exported pseudo-variables are documented at &kamwikilink;.

## MI Commands

### `t_uac_dlg`

Generates and sends a local SIP request.

Parameters:

- method - request method

- RURI - request SIP URI

- NEXT HOP - next hop SIP URI (OBP); use . if no value.

- socket - local socket to be used for sending the request; use . if no value.

- headers - set of additional headers to be added to the request; at least From and To headers must be specify)

- body - (optional, may not be present) request body (if present, requires the Content-Type and Content-length headers)

### `t_uac_cancel`

Generates and sends a CANCEL for an existing local SIP request.

Parameters:

- callid - callid of the INVITE request to be cancelled.

- cseq - cseq of the INVITE request to be cancelled.

### `t_hash`

Gets information about the load of TM internal hash table.

Parameters:

- none

### `t_reply`

Generates and sends a reply for an existing inbound SIP transaction.

Parameters:

- code - reply code

- reason - reason phrase.

- trans_id - transaction identifier (has the hash_entry:label format)

- to_tag - To tag to be added to TO header

- new_headers - extra headers to be appended to the reply; use a dot (.) char only if there are no headers;

- body - (optional, may not be present) reply body (if present, requires the Content-Type and Content-length headers)

### `t_reply_callid`

Generates and sends a reply for an existing inbound SIP transaction.

Parameters:

- code - reply code

- reason - reason phrase.

- callid - SIP Call-ID header

- cseq - SIP CSeq header

- to_tag - To tag to be added to TO header

- new_headers - extra headers to be appended to the reply; use a dot (.) char only if there are no headers;

- body - (optional, may not be present) reply body (if present, requires the Content-Type and Content-length headers)

## Statistics

Exported statistics are listed in the next sections. All statistics except inuse_transactions can be reset.

### received_replies

Total number of total replies received by TM module.

### relayed_replies

Total number of replies received and relayed by TM module.

### local_replies

Total number of replies local generated by TM module.

### UAS_transactions

Total number of transactions created by received requests.

### UAC_transactions

Total number of transactions created by local generated requests.

### 2xx_transactions

Total number of transactions completed with 2xx replies.

### 3xx_transactions

Total number of transactions completed with 3xx replies.

### 4xx_transactions

Total number of transactions completed with 4xx replies.

### 5xx_transactions

Total number of transactions completed with 5xx replies.

### 6xx_transactions

Total number of transactions completed with 6xx replies.

### inuse_transactions

Number of transactions existing in memory at current time.