# &adminguide;

## Overview

This module loads data indexed by prefixes from database and returns associated string or precompiled value.

## Dependencies

### &kamailio; Modules

The following modules must be loaded before this module:

- A &kamailio; database module (e.g., mysql).

### External Libraries or Applications

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

- None.

## Parameters

### `db_url` (string)

URL of the database server to be used.

Default value is &defaultdb;.

#### Set `db_url` parameter

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

### `db_table` (string)

Name of database table where data for trees is stored. It is ignored if a 'mtree' parameter is defined.

Default value is mtrees.

#### Set `db_table` parameter

    ...
    modparam("mtree", "db_table", "mymtrees")
    ...

### `mtree` (string)

Definition of memory tree with parameters name, dbtable, type, and multi. Name is name of the tree, dbtable is name of dbtable where tree is stored, type is type of tree elements (0 = string, 2 = integer), and multi tells if dbtable can contain more than one tree (0 = one tree, 1 = more than one tree identified by tname column).

This parameter can be set many times to add more trees in memory.

Default value is none.

#### Set `mtree` parameter

    ...
    modparam("mtree", "mtree", "name=mytree1;dbtable=routes1;type=0")
    modparam("mtree", "mtree", "name=mytree2;dbtable=routes2;type=0;multi=1")
    ...

### `tname_column` (string)

Name of 'tname' column.

Default value is tname.

#### Set `tname_column` parameter

    ...
    modparam("mtree", "tname_column", "name")
    ...

### `tprefix_column` (string)

Name of 'tprefix' column.

Default value is tprefix.

#### Set `tprefix_column` parameter

    ...
    modparam("mtree", "tprefix_column", "prefix")
    ...

### `tvalue_column` (string)

Name of 'tvalue' column.

Default value is tvalue.

#### Set `tvalue_column` parameter

    ...
    modparam("mtree", "tvalue_column", "ipaddr")
    ...

### `fetch_rows` (integer)

Number of rows to be loaded in one step from database.

Default value is 1000.

#### Set `fetch_rows` parameter

    ...
    modparam("mtree", "fetch_rows", 4000)
    ...

### `char_list` (string)

The list with characters allowed in prefix.

Default value is 0123456789.

#### Set `char_list` parameter

    ...
    modparam("mtree", "char_list", "0123456789*+")
    ...

### `pv_value` (string)

The PV spec where to store the matched value. It can be any writable PV.

Default value is $avp(s:tvalue).

#### Set `pv_value` parameter

    ...
    modparam("mtree", "pv_value", "$var(mtval)")
    ...

### `pv_values` (string)

The PV spec where to store the matched values when mtree is of type 0 or 2 and mode of mt_match() call has value 2. It can be any AVP.

Default value is $avp(s:tvalues).

#### Set `pv_values` parameter

    ...
    modparam("mtree", "pv_values", "$avp(mtvals)")
    ...

### `mt_tree_type` (integer)

Default payload type for trees data stored in 'db_table'. Documented values are 0 for string payloads and 2 for integer payloads.

Default value is 0.

#### Set `mt_tree_type` parameter

    ...
    modparam("mtree", "mt_tree_type", 2)
    ...

### `mt_ignore_duplicates` (integer)

Ignore duplicated prefixes when loading data.

Default value is 0.

#### Set `mt_ignore_duplicates` parameter

    ...
    modparam("mtree", "mt_ignore_duplicates", 1)
    ...

### `mt_allow_duplicates` (integer)

Allow duplicate prefixes when loading data.

Default value is 0.

#### Set `mt_allow_duplicates` parameter

    ...
    modparam("mtree", "mt_allow_duplicates", 1)
    ...

## Functions

### `mt_match(mtree, pv, mode)`

Match 'pv' value against 'mtree'. If 'mtree' type is 0 or 2 and value of 'mode' is NOT 2, sets a value of the longest matching prefix to pseudo variable specified by pv_value parameter. If 'mtree' type is 0 or 2 and value of 'mode' is 2, sets values of all matching prefixes to avp specified by pv_values parameter so that a value of longest matching prefix is in avp index 0. Parameter 'mode' can be an integer constant or a pseudo variable with integer value.

#### `mt_match` usage

    ...
    mt_match("mytree", "$rU", "0");
    ...

## MI Commands

### `mt_list`

List content of a tree.

Name: mt_list

Parameters:

- _mtree_ : name of tree to list.

MI FIFO Command Format:

    		:mt_list:_reply_fifo_file_
    		_mtname_
    		_empty_line_

### `mt_reload`

Reload mtree from database.

Name: mt_mtree

Parameters:

- _mtname_

  - name of mem tree

MI FIFO Command Format:

    		:mt_reload:_reply_fifo_file_
    		_mtname_
    		_empty_line_

### `mt_summary`

List usage summary for all trees.

Name: mt_summary

Parameters: none.

MI FIFO Command Format:

    		:mt_summary:_reply_fifo_file_
    		_empty_line_

## RPC Commands

### `mtree.summary`

List usage summary for all trees.

Parameters: none.

### `mtree.reload`

Reload mtree from database to memory.

Parameters:

- _mtree_

  - name of mtree or empty string meaning all mtrees