# &adminguide;

## Overview

The module exports utility functions to work with position inside the SIP message buffer.

Among them are function to add or remove content at a specific position.

## Dependencies

### &kamailio; Modules

The following modules must be installed (but not loaded) to use this module:

- none.

### External Libraries or Applications

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

- none.

## Parameters

### `idx0` (int)

The value to return by functions seeking a position when the index is 0 (note: returning 0 is stopping the execution of configuration file like 'exit', but for KEMI usage it is ok).

Default value is -255.

#### Set `idx0` parameter

    ...
    modparam("posops", "idx0", -200)
    ...

## Functions

### `pos_append(idx, val)`

Append the value val after the position idx in the SIP message buffer.

The idx can be an integer value or a variable holding an integer. If the value is negative, the position is counted from the end of the buffer.

The val can be a static string or variables.

This function can be used from ANY_ROUTE.

#### `pos_append()` usage

    ...
    pos_append("100", "kamailio-$si");
    ...

### `pos_insert(idx, val)`

Insert the value val at the position idx in the SIP message buffer.

The idx can be an integer value or a variable holding an integer. If the value is negative, the position is counted from the end of the buffer.

The val can be a static string or variables.

This function can be used from ANY_ROUTE.

#### `pos_insert()` usage

    ...
    pos_insert("100", "kamailio-$si");
    ...

### `pos_rm(idx, len)`

Remove len characters starting at the position idx in the SIP message buffer.

The idx can be an integer value or a variable holding an integer. If the value is negative, the position is counted from the end of the buffer.

The idx can be a positive integer value or a variable holding a positive integer.

This function can be used from ANY_ROUTE.

#### `pos_rm()` usage

    ...
    pos_insert("100", "10");
    ...

### `pos_set_char(idx, val)`

Set the char at position index to first character in val.

Important: it changes the character directly in the SIP message buffer, the update being immediately visible.

The idx can be an integer value or a variable holding an integer. If the value is negative, the position is counted from the end of the buffer.

The val can be a static string or variables.

This function can be used from ANY_ROUTE.

#### `pos_set_char()` usage

    ...
    pos_set_char("100", "x");
    ...

### `pos_headers_start()`

Return the position in the message buffer where headers start.

This function can be used from ANY_ROUTE.

#### `pos_headers_start()` usage

    ...
    $var(pos) = pos_headers_start();
    ...

### `pos_headers_end()`

Return the position in the message buffer where headers end.

This function can be used from ANY_ROUTE.

#### `pos_headers_end()` usage

    ...
    $var(pos) = pos_headers_end();
    ...

### `pos_body_start()`

Return the position in the message buffer where body starts.

This function can be used from ANY_ROUTE.

#### `pos_body_start()` usage

    ...
    $var(pos) = pos_body_start();
    ...

### `pos_body_end()`

Return the position in the message buffer where body ends.

This function can be used from ANY_ROUTE.

#### `pos_body_end()` usage

    ...
    $var(pos) = pos_body_end();
    ...

### `pos_find_str(idx, val)`

Return the position of the val in message buffer starting at idx. In case of not finding it or error, the return code is negative. If val is at index 0, it returns the value specified by modparam idx0.

The idx can be an integer value or a variable holding an integer. If the value is negative, the position is counted from the end of the buffer.

The val can be a static string or variables.

This function can be used from ANY_ROUTE.

#### `pos_find_str()` usage

    ...
    $var(idx) = pos_find_str("100", "kamailio");
    ...

### `pos_findi_str(idx, val)`

Return the position of the val (matching case insensitive) in message buffer starting at idx. In case of not finding it or error, the return code is negative. If val is at index 0, it returns the value specified by modparam idx0.

The idx can be an integer value or a variable holding an integer. If the value is negative, the position is counted from the end of the buffer.

The val can be a static string or variables.

This function can be used from ANY_ROUTE.

#### `pos_findi_str()` usage

    ...
    $var(idx) = pos_findi_str("100", "kamailio");
    ...

### `pos_rfind_str(idx, val)`

Return the last position of the val in message buffer starting at idx (reverse search). In case of not finding it or error, the return code is negative. If val is at index 0, it returns the value specified by modparam idx0.

The idx can be an integer value or a variable holding an integer. If the value is negative, the position is counted from the end of the buffer.

The val can be a static string or variables.

This function can be used from ANY_ROUTE.

#### `pos_find_str()` usage

    ...
    $var(idx) = pos_rfind_str("100", "kamailio");
    ...

### `pos_rfindi_str(idx, val)`

Return the last position of the val (matching case insensitive) in message buffer starting at idx (reverse search). In case of not finding it or error, the return code is negative. If val is at index 0, it returns the value specified by modparam idx0.

The idx can be an integer value or a variable holding an integer. If the value is negative, the position is counted from the end of the buffer.

The val can be a static string or variables.

This function can be used from ANY_ROUTE.

#### `pos_rfindi_str()` usage

    ...
    $var(idx) = pos_rfindi_str("100", "kamailio");
    ...

### `pos_search(idx, re)`

Return the position that starts matching the regular expression re in message buffer starting at idx. In case of not finding it or error, the return code is negative. If val is at index 0, it returns the value specified by modparam idx0.

The idx can be an integer value or a variable holding an integer. If the value is negative, the position is counted from the end of the buffer.

The re can be a static regular expression string.

This function can be used from ANY_ROUTE.

#### `pos_search()` usage

    ...
    $var(idx) = pos_search("100", "[0-9]+");
    ...

### `pos_rsearch(idx, re)`

Return the position of last match that starts matching the regular expression re in message buffer starting at idx. In case of not finding it or error, the return code is negative. If val is at index 0, it returns the value specified by modparam idx0.

The idx can be an integer value or a variable holding an integer. If the value is negative, the position is counted from the end of the buffer.

The re can be a static regular expression string.

This function can be used from ANY_ROUTE.

#### `pos_rsearch()` usage

    ...
    $var(idx) = pos_rsearch("100", "[0-9]+");
    ...

## Pseudo Variables

The module exports a pseudo-variable class, $pos(key), to access attributes upon specific function execution.

These are documented in the appropriate Wiki pages hosted on the project web site.