# Functions

## `sl_send_reply(code, reason)`

For the current request, a reply is sent back having the given code and text reason. The reply is sent stateless, totally independent of the Transaction module and with no retransmission for the INVITE's replies.

If the code is in the range 300-399 (redirect reply), the current destination set is appended to the reply as Contact headers. The destination set contains the request URI (R-URI), if it is modified compared to the received one, plus the branches added to the request (e.g., after an append_branch() or lookup("location")). If the R-URI was changed but it is not desired to be part of the destination set, it can be reverted using the function revert_uri().

Custom headers to the reply can be added using append_to_reply() function from textops module.

Meaning of the parameters is as follows:

- code - Return code.

- reason - Reason phrase.

### `sl_send_reply` usage

    ...
    sl_send_reply("404", "Not found");
    ...

## `send_reply(code, reason)`

For the current request, a reply is sent back having the given code and text reason. The reply is sent stateful or stateless, depending of the TM module: if a transaction exists for the current request, then the reply is sent statefully, otherwise stateless.

Meaning of the parameters is as follows:

- code - Return code.

- reason - Reason phrase.

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE. It can be used on ONREPLY_ROUTE executed by tm module (upon a t_on_reply() callback).

### `send_reply` usage

    ...
    send_reply("404", "Not found");
    ...
    send_reply("403", "Invalid user - $fU");
    ...

## `send_reply_mode(code, reason, mode)`

Similar to send_reply() function, with additional third parameter mode, which can specify extra operations to be done along with sending the SIP response.

The parameter mode is a flag-based value and can be a combination of:

- 1 - do not connect to send the response (similar to set_reply_no_connect()).

- 2 - close the connection after sending the response (similar to set_reply_close()).

### `send_reply_mode` usage

    ...
    send_reply_mode("404", "Not found", "3");
    ...
    send_reply_mode("403", "Invalid user - $fU", "3");
    ...

## `sl_reply_error()`

Sends back an error reply describing the nature of the last internal error. Usually this function should be used after a script function that returned an error code.

### `sl_reply_error` usage

    ...
    sl_reply_error();
    ...

## `sl_forward_reply([ code, [ reason ] ])`

Forward statelessly the current received SIP reply, with the option to change the status code and reason text. The new code has to be in the same class. The received reply is forwarded as well by core when the config execution ended, unless it is dropped from config.

Meaning of the parameters is as follows:

- code - Status code.

- reason - Reason phrase.

This function can be used from ONREPLY_ROUTE.

### `send_reply` usage

    ...
    if(status=="408")
        sl_forward_reply("404", "Not found");
    ...

## `send_reply_error()`

For the current request, the internal error code reply is sent back stateful or stateless, depending of the TM module: if a transaction exists for the current request, then the reply is sent statefully, otherwise stateless.

It can be used from REQUEST_ROUTE, ONREPLY_ROUTE and FAILURE_ROUTE.

### `send_reply_error` usage

    ...
    send_reply_error();
    ...