# &adminguide;

## Overview

This module collects extensions from &kamailio; TM module.

&kamailio; TM (Transaction Management) module documentation is available at: https://www.kamailio.org/docs/modules/stable/modules/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.

## Parameters

### `precheck_trans` (int)

Enable/disable transaction pre-check via t_precheck_trans() function. If set to 0, the internal structures are not created at startup and the function will return false always.

Default value is 1 (enabled).

#### `precheck_trans` (int)

    ...
    modparam("tmx", "precheck_trans", 0)
    ...

## 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 [, rcode])`

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.

- rcode - code to be added as cause attribute in Reason header for generated CANCEL request. This parameter is optional.

This function can be used in ANY_ROUTE.

#### `t_cancel_callid` usage

    ...
    if (t_cancel_callid("123qaz", "5", "22")) {
    	xlog("transaction cancelled\n");
    }
    ...
    if (t_cancel_callid("123qaz", "5", "22", "200")) {
    	xlog("transaction cancelled with [Reason: cause=200]\n");
    }
    ...

### `t_uac_ack_local(callid, cseq [, headers [, body]])`

ACK the first transaction found with specified Call-ID and C-Seq. Optionally include extra headers and request body.

Parameters:.

- callid - call-id value.

- cseq - cseq number.

- headers - extra headers to append

- body - body to include

This function can be used in ANY_ROUTE.

#### `t_uac_ack_local` usage

    ...
    if (t_uac_ack_local("123qaz", "5")) {
    	xlog("transaction ACKed\n");
    }
    ...

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

Send reply to first 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 makes sense only in routing block if the transaction was created via t_newtran() and the flags have been altered since.

It is not needed to execute this function when using t_relay() (or similar tm relay functions, flags are synchronized automatically in that case).

This function can be used from ANY_ROUTE .

#### `t_flush_flags` usage

    ...
    t_flush_flags();
    ...

### `t_flush_xflags()`

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

It is not needed to execute this function when using t_relay() (or similar tm relay functions, xflags are synchronized automatically in that case).

This function can be used from ANY_ROUTE .

#### `t_flush_xflags` usage

    ...
    t_flush_xflags();
    ...

### `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_is_request_route()`

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

This function can be used from ANY_ROUTE .

#### `t_is_request_route` usage

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

    route[abc] {
        if(t_is_request_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("processing suspended in transaction [$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.

Important note: the route[rtname] is executed in the context of a failure (same behaviour for functions as they were used in a failure_route block).

This function can be used in ANY_ROUTE.

#### `t_continue` usage

    ...
    t_continue('123', '456', 'MYROUTE');
    ...
    route[MYROUTE] {
      xlog("executed by t continue\n");
      ...
    }
    ...

### `t_drop([rcode])`

Drops the transaction with response code (500 default).

Parameters:.

- rcode - response code to set in uas status.

This function can be used in ANY_ROUTE.

#### `t_drop` usage

    ...
    route[MYREQ]
    {
    ...
        if (!t_newtran()) {
            xlog("L_ERROR", "$ci|log|failed to create transaction\n");
            drop;
        }

        t_on_failure("TR_ERROR");
        t_on_reply("TR_OK");
        t_relay();
    }

    failure_route[TR_ERROR]
    {
        xlog("L_INFO", "$ci|log|failed $T_reply_code $T_reply_reason\n");
        t_drop();
    }

    onreply_route[TR_OK]
    {
       xlog("L_INFO", "$ci|log|checking transaction result\n");
       if(status=~"60[0-9]") {
          t_drop();
       }
    ...
    }
    ...

### `t_reuse_branch()`

Creates new "main" branch by making copy of branch-failure branch. Currently the following branch attributes are copied from branch-failure branch: request-uri, ruid, path, instance, and branch flags.

This function can be used from tm:branch-failure event_route.

#### `t_reuse_branch` usage

    ...
    event_route [tm:branch-failure:contact] {
        t_reuse_branch();
        setbflag(10);
        t_relay();
        exit;
    }
    ...

### `t_precheck_trans()`

Check if current processed message is handled by other process. This function is useful to catch retransmissions before transaction is created. The function returns true if the request is handled by another process.

Note that ACK and CANCEL requests are not tracked by this function, the return code being false for them.

This function can be used from REQUEST_ROUTE .

#### `t_precheck_trans` usage

    ...
        # handle retransmissions
        if(t_precheck_trans()) {
            t_check_trans();
            exit;
        }
        t_check_trans();
    ...

## Exported Variables

- $T_branch_idx

- $T_reply_code

- $T_reply_reason

- $T_reply_last

- $T_req(pv)

- $T_rpl(pv)

- $T_reply_ruid

- $T_branch(name)

- $T_inv(pv)

- $T(name)

Exported pseudo-variables are documented at &kamwikilink;.

## Statistics

Exported statistics are listed in the next sections. These statistics cannot be reset (see counters module for alternative).

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

### active_transactions

Number of ongoing transactions at current time.

### rpl_received

Total number of replies received by TM module.

### rpl_absorbed

Total number of replies received and not relayed by TM module.

### rpl_relayed

Total number of replies received and relayed by TM module.

### rpl_generated

Total number of replies locally generated and relayed by TM module.

### rpl_sent

Total number of replies relayed by TM module.