$Revision: 1.6 $
$Date: 2007/06/13 10:37:29 $

# Functions

## `fix_nated_contact()`

Rewrites Contact HF to contain request's source address:port.

### `fix_nated_contact` usage

    ...
    if (search("User-Agent: Cisco ATA.*") {fix_nated_contact();};
    ...

## `fix_nated_sdp(mode)`

Rewrites Contact HF to contain request's source address:port.

Meaning of the parameters is as follows:

- mode - 0x01 (add direction=active), 0x02 (rewrite media IP address with source address of the message).

### `fix_nated_sdp` usage

    ...
    if (search("User-Agent: Cisco ATA.*") {fix_nated_sdp("3");};
    ...

## `force_rtp_proxy()`

Rewrites SDP body to ensure that media is passed through an RTP proxy.

### `force_rtp_proxy` usage

    ...
    if (search("User-Agent: Cisco ATA.*")
    {
        force_rtp_proxy();
    };
    ...

## `add_rcv_param()`

Add received parameter to Contact header fields. The parameter will contain URI created from the source IP, port, and protocol of the packet containing the SIP message. The parameter can be then processed by another registrar, this is useful, for example, when replicating register messages using t_replicate function to another registrar.

### `add_rcv_paramer` usage

    ...
    add_rcv_param();
    ...

## `fix_nated_register()`

The function creates a URI consisting of the source IP, port, and protocol and stores the URI in an Attribute-Value-Pair. The URI will be appended as "received" parameter to Contact in 200 OK and registrar will store it in the user location database.

### `fix_nated_register` usage

    ...
    fix_nated_register();
    ...

## `force_rtp_proxy(ip_address)`

Rewrites SDP body with given IP address to ensure that media is passed through an RTP proxy.

Meaning of the parameters is as follows:

- ip_address - new SDP IP address.

### `force_rtp_proxy` usage

    ...
    if (search("User-Agent: Cisco ATA.*") {force_rtp_proxy("1.2.3.4");};
    ...

## `nat_uac_test(mode)`

Tries to guess if client's request originated behind a nat. The mode parameter determines what heuristics is used. If mode contains:

- 01 - the Contact URI host contains a private IP address (from RFC1981).

- 02 - the address in the topmost Via header differs from the source IP address of the request.

- 04 - the address in the topmost Via contains a private IP address (RFC1918).

- 08 - the SDP body of the request contains a private IP address (RFC1918).

- 16 - the port in the topmost Via differs from the source port of the request.

- 32 - the Contact URI port differs from the source port of the request (Warning: this is might be legal or even intended combination in non natted scenarios).

All of them might be bitwise combined (which is equal to the sum of the values from the list above). If one of the test matched the function returns true.

## `ping_contact(contact)`

Ping contact specified by parameter. It enables pinging independently on usrloc. It may be processed e.g. via timer module.

### `ping_contact` usage

    ...
    $c = @get_a_contact;
    ping_contact($c);
    ...

## `@nathelper.rewrite_contact[n]`

Get n-th Contact value with IP:Port rewritten to source ip:port. N is counted from 1. Only IP:port is rewritten, remaining part are left unchanged. Full nameaddr is supported.

### `@nathelper.rewrite_contact` usage

    ...
    $c = @nathelper.rewrite_contact[1];
    ...
    $c2 = @nathelper.rewrite_contact[1].nameaddr.uri;