Documentation

Documentation.Script-CoreFunctions-3-1 History

Hide minor edits - Show changes to markup

September 01, 2021, at 10:21 AM by liviu -
Changed lines 145-147 from:

This function fetches from a memory-cache-like storage system the value of an attribute. The result (if any) will be stored in the variable specified by result.

Function returns true if the attribute was found and its value returned.

to:

Fetch the value of an attribute from a memory-cache-like storage system. On a successful fetch, the result will be stored in the variable specified by result_pv.

Function returns true if the attribute was found and its value successfully returned.

July 08, 2021, at 01:19 PM by liviu -
Changed line 748 from:

Takes all currently added branches for parallel forking (with append_branch()), as well as the current branch: (R-URI ($ru) / outbound Proxy ($du) / q value ($ru_q) / branch flags / forced Path headers / forced send socket), and prepares them for serial forking instead. The ordering is done in decreasing "q" order. The serialized branches are internally stored in the "$avp(serial_branch)" AVP - this allows them to be manipulated by the "next_branches()" function, usually within a failure route.

to:

Takes all currently added branches for parallel forking (e.g. with lookup() or append_branch()), as well as the current branch (R-URI ($ru) / outbound Proxy ($du) / q value ($ru_q) / branch flags / forced Path headers / forced send socket), and prepares them for serial forking instead. The ordering is done in decreasing "q" order. The serialized branches are internally stored in the "$avp(serial_branch)" AVP - this allows them to be manipulated by the "next_branches()" function, usually within a failure route.

March 13, 2021, at 01:19 PM by liviu -
Deleted lines 249-254:

break()

Since v0.10.0-dev3, 'break' can no longer be used to stop the execution of a route. The only place to use is to end a 'case' block in a 'switch' statement. 'return' must be now used instead of old 'break'.

'return' and 'break' have now a similar meaning as in c/shell.

March 12, 2021, at 12:27 PM by liviu -
Changed lines 143-144 from:

cache_fetch(storage_id, attribute, result)

to:

cache_fetch(storage_id, attribute, result_pv)

Changed lines 152-153 from:
  • result (var)
to:
  • result_pv (var)
Changed lines 166-167 from:

cache_counter_fetch(storage_id, counter_attribute, result)

to:

cache_counter_fetch(storage_id, counter_attribute, result_pv)

Changed lines 175-177 from:
  • result (var)
to:
  • result_pv (var)
Changed lines 188-189 from:

cache_add( storage_id, attribute, increment, expire, [new_val])

to:

cache_add( storage_id, attribute, increment, expire, [new_val_pv])

Changed lines 199-200 from:
  • new_val (var, optional) - variable in which to fetch the new value of the counter.
to:
  • new_val_pv (var, optional) - variable in which to fetch the new value of the counter.
Changed lines 210-211 from:

cache_sub(storage_id, attribute, decrement, expire, [new_val])

to:

cache_sub(storage_id, attribute, decrement, expire, [new_val_pv])

Changed lines 221-222 from:
  • new_val (var, optional) - variable in which to fetch the new value of the counter.
to:
  • new_val_pv (var, optional) - variable in which to fetch the new value of the counter.
Changed lines 232-235 from:

cache_raw_query(storage_id, raw_query, result)

The function runs the provided raw query (in the back-end dependent language) and returns the results (if any) in the AVP (or AVP list) provided in result. This parameter may be missing, if the query returns no results.

to:

cache_raw_query(storage_id, raw_query, result_avps)

The function runs the provided raw query (in the back-end dependent language) and returns the results (if any) in the AVP list provided in result. This parameter may be missing, if the query returns no results.

Changed line 241 from:
  • result (string, optional, no expand)
to:
  • result_avps (string, optional)
August 07, 2020, at 08:32 PM by rvlad_patrascu -
Changed lines 234-235 from:

The function runs the provided raw query (in the back-end dependent language) and returns the results (if any) in the provided AVP. The result_avp can be missing, if the query returns no results.

to:

The function runs the provided raw query (in the back-end dependent language) and returns the results (if any) in the AVP (or AVP list) provided in result. This parameter may be missing, if the query returns no results.

Changed lines 241-242 from:
  • result (var, optional)
to:
  • result (string, optional, no expand)
Changed line 245 from:

cache_raw_query("mongodb", "{ \"op\" : \"count\",\"query\": { \"username\" : $rU} }", $avp(mongo_count_result));

to:

cache_raw_query("mongodb", "{ \"op\" : \"count\",\"query\": { \"username\" : $rU} }", "$avp(mongo_count_result)");

July 28, 2020, at 08:04 PM by rvlad_patrascu -
Changed lines 482-484 from:
  • attrs (var, optional) - AVP containing the the names of the attributes
  • vals (var, optional) - AVP containing values attached to the event
to:
  • attrs (var, optional) - AVP containing the the names of the attributes; if this parameter is missing and vals is provided, the attributes will be written as array(positional) params in the JSON-RPC payload
  • vals (var, optional) - AVP containing values attached to the event; if this parameter is missing, the raised event will not have any attributes, even if the attrs parameter is provided.
Added lines 499-506:

@]

Example of usage (raises an event with two unnamed attributes):

[@ $avp(attr-val) = 1; $avp(attr-val) = "2"; raise_event("E_TWO_PARAMS", , $avp(attr-val));

June 02, 2020, at 06:14 PM by rvlad_patrascu -
Changed line 412 from:
    if (isbflagset(1, "NAT_PING"))
to:
    if (isbflagset("NAT_PING", 1))
Changed line 594 from:
    resetbflag(1, "NAT_PING");
to:
    resetbflag("NAT_PING", 1);
Changed line 596 from:
    resetbflag("NAT_PING"); # same as resetbflag(0, "NAT_PING")
to:
    resetbflag("NAT_PING"); # same as resetbflag("NAT_PING", 0)
Changed line 833 from:
    setbflag(1, "NAT_PING");
to:
    setbflag("NAT_PING", 1);
Changed line 835 from:
    setbflag("NAT_PING"); # same as setbflag(0, "NAT_PING")
to:
    setbflag("NAT_PING"); # same as setbflag("NAT_PING", 1)
April 21, 2020, at 05:48 PM by liviu -
Changed line 497 from:

$avp(attr-val) = "2"

to:

$avp(attr-val) = "2";

August 08, 2019, at 05:14 PM by rvlad_patrascu -
Added lines 614-615:

Note that the rewritehost alias for this function has been removed.

Added lines 627-628:

Note that the rewritehostport alias for this function has been removed.

Added lines 640-641:

Note that the rewriteuser alias for this function has been removed.

Added lines 653-654:

Note that the rewriteuserpass alias for this function has been removed.

Added lines 666-667:

Note that the rewriteport alias for this function has been removed.

Added lines 675-679:

Parameters:

  • uri (string)

Note that the rewriteuri alias for this function has been removed.

August 08, 2019, at 04:43 PM by rvlad_patrascu -
Changed lines 640-641 from:

rewriteuserpass() / setuserpass()

to:

setuserpass(pass)

Added lines 644-646:

Parameters:

  • pass (string)
Changed lines 649-652 from:
    rewriteuserpass("my_secret_passwd");

rewriteport() / setport()

to:
    setuserpass("my_secret_passwd");

setport(port)

Added lines 655-657:

Parameters:

  • port (string)
Changed lines 660-663 from:
    rewriteport("5070");

rewriteuri(str) / seturi(str)

to:
    setport("5070");

seturi(str)

Changed lines 668-669 from:
    rewriteuri("sip:test@opensips.org");
to:
    seturi("sip:test@opensips.org");
Changed lines 682-683 from:

script_trace([log_level, pv_format_string[, info_string]])

to:

script_trace([log_level, pv_format_string, [info]])

Added lines 692-696:

Parameters:

  • log_level (int, optional)
  • pv_format_string (string, optional)
  • info (string, static, optional)
Changed lines 716-719 from:

Send the original SIP message to a specific destination in stateless mode. This is definied as [proto:]host[:port]. No changes are applied to received message, no Via header is added, unless headers parameter is specified. Host can be an IP or hostname; supported protocols are UDP, TCP and TLS. (For TLS, you need to compile the TLS support into core). If proto or port are not specified, NAPTR and SRV lookups will be used to determine them (if possible). The headers parameter should end in '\r\n' and can accept both plain text and pseudo variables.

Parameter is mandatory and has string format.

to:

Send the original SIP message to a specific destination in stateless mode. This is definied as [proto:]host[:port]. No changes are applied to received message, no Via header is added, unless headers parameter is specified. Host can be an IP or hostname; supported protocols are UDP, TCP and TLS. (For TLS, you need to compile the TLS support into core). If proto or port are not specified, NAPTR and SRV lookups will be used to determine them (if possible). The headers parameter should end in '\r\n'.

Parameters:

  • destination (string)
  • headers (string, optional)
Changed lines 741-744 from:

If "clear_previous" is set to non-zero, all previous results of another "serialize_branches()" (serial forking set which is no longer needed) will be deleted before starting a new set.

If "keep_order" is set to non-zero, the added branches as well as the current branch, will be serialized exactly in the order in which they are found.

to:

Parameters:

  • clear_previous (int) - if set to non-zero, all previous results of another "serialize_branches()" (serial forking set which is no longer needed) will be deleted before starting a new set
  • keep_order (int, optional) - if set to non-zero, the added branches as well as the current branch, will be serialized exactly in the order in which they are found.
Changed lines 758-759 from:

set_advertised_address(ip|string)

to:

set_advertised_address(adv_addr)

Added lines 762-764:

Parameters:

  • adv_addr (string)
Changed lines 769-770 from:

set_advertised_port(int)

to:

set_advertised_port(adv_port)

Added lines 773-775:

Parameters:

  • adv_port (string)
Changed lines 778-781 from:
    set_advertised_port(5080);

setdsturi(string)

to:
    set_advertised_port("5080");

setdsturi(uri)

Added lines 784-786:

Parameters:

  • uri (string)
Changed lines 791-792 from:

setflag(string)

to:

setflag(flag)

Added lines 795-797:

Parameters:

  • flag (string, static)
Changed line 801 from:
    setflag(NAT_PING);
to:
    setflag("NAT_PING");
Changed lines 805-808 from:

setbflag([branch_idx,] flag)

Set a flag for a specific branch. The value of the "flag" parameter must be an unquoted string. "branch_idx" identifies the branch for which the flag is set - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default. The OpenSIPS script supports, at most, 32 unique string branch flags.

to:

setbflag(flag, [branch_idx])

Set a flag for a specific branch. "branch_idx" identifies the branch for which the flag is set - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default. The OpenSIPS script supports, at most, 32 unique string branch flags.

Added lines 811-814:

Parameters:

  • flag (string, static)
  • branch_idx (int, optional)
Changed line 818 from:
    setbflag(1, NAT_PING);
to:
    setbflag(1, "NAT_PING");
Changed line 820 from:
    setbflag(NAT_PING); # same as setbflag(0, NAT_PING)
to:
    setbflag("NAT_PING"); # same as setbflag(0, "NAT_PING")
Changed lines 823-824 from:

strip(int)

to:

strip(n)

Added lines 827-829:

Parameters:

  • n (int)
Changed lines 834-835 from:

strip_tail(int)

to:

strip_tail(n)

Added lines 838-840:

Parameters:

  • n (int)
Changed lines 850-851 from:

The first parameter is a string represents the name of the event an external application should be notified for. The second parameter is a string that specifies the socket of the external application. Note that this socket should follow the syntax of an existing loaded Event Interface transport module (example: event_datagram, event_rabbitmq). The last parameter is optional and specifies the expire time of the subscription. If it is not present, then the subscription does not expire at all.

to:

Parameters:

  • event (string) - the name of the event an external application should be notified for.
  • socket (string) - the socket of the external application. Note that this socket should follow the syntax of an existing loaded Event Interface transport module (example: event_datagram, event_rabbitmq).
  • expire (int, optional) - the expire time of the subscription. If it is not present, then the subscription does not expire at all.
Changed lines 871-872 from:

use_blacklist(string)

to:

use_blacklist(bl_name)

Added lines 874-877:

Parameters:

  • bl_name (string)
Added lines 880-890:

@]

unuse_blacklist(bl_name)

Disables the DNS blacklist name received as parameter.

Parameters:

  • bl_name (string)

[@

    unuse_blacklist("pstn-gws");
August 08, 2019, at 03:17 PM by rvlad_patrascu -
Changed lines 44-46 from:
  • uri (string, optional)
  • qvalue(string, optional)
to:
  • uri (string, optional)
  • qvalue (string, optional)
Changed lines 104-108 from:
  • storage_id (string)
  • attribute (string)
  • value (string)
  • timeout (int, optional)
to:
  • storage_id (string)
  • attribute (string)
  • value (string)
  • timeout (int, optional)
Changed lines 127-129 from:
  • storage_id (string)
  • attribute (string)
to:
  • storage_id (string)
  • attribute (string)
Changed lines 150-153 from:
  • storage_id (string)
  • attribute (string)
  • result (var)
to:
  • storage_id (string)
  • attribute (string)
  • result (var)
Changed lines 173-177 from:
  • storage_id (string)
  • attribute (string)
  • result (var)
to:
  • storage_id (string)
  • attribute (string)
  • result (var)
Changed lines 195-200 from:
  • storage_id (string)
  • attribute (string)
  • increment (int)
  • expire (int) - if greater than 0, the key will also expire in the specified number of seconds
  • new_val (var, optional) - variable in which to fetch the new value of the counter.
to:
  • storage_id (string)
  • attribute (string)
  • increment (int)
  • expire (int) - if greater than 0, the key will also expire in the specified number of seconds
  • new_val (var, optional) - variable in which to fetch the new value of the counter.
Changed lines 217-222 from:
  • storage_id (string)
  • attribute (string)
  • increment (int)
  • expire (int) - if greater than 0, the key will also expire in the specified number of seconds
  • new_val (var, optional) - variable in which to fetch the new value of the counter.
to:
  • storage_id (string)
  • attribute (string)
  • increment (int)
  • expire (int) - if greater than 0, the key will also expire in the specified number of seconds
  • new_val (var, optional) - variable in which to fetch the new value of the counter.
Changed lines 239-242 from:
  • storage_id (string)
  • raw_query (string)
  • result (var, optional)
to:
  • storage_id (string)
  • raw_query (string)
  • result (var, optional)
Changed lines 262-268 from:
  • proto (string)
  • user (string, optional)
  • domain (string)
  • port (string, optional)
  • extra (string, optional)
  • result(var)
to:
  • proto (string)
  • user (string, optional)
  • domain (string)
  • port (string, optional)
  • extra (string, optional)
  • result (var)
Changed lines 328-329 from:
  • socket (string)
to:
  • socket (string)
Changed lines 340-341 from:
  • port_alias (int, optional)
to:
  • port_alias (int, optional)
Changed lines 352-353 from:
  • destination (string, optional) - if missing, the forward will be done based on RURI.
to:
  • destination (string, optional) - if missing, the forward will be done based on RURI.
Changed lines 365-367 from:
  • sec_avp (var)
  • usec_avp (var)
to:
  • sec_avp (var)
  • usec_avp (var)
Changed lines 390-391 from:
  • flag (string, static)
to:
  • flag (string, static)
Changed lines 399-402 from:

isbflagset([branch_idx,] flag)

Test if a flag is set for a specific branch. The value of the "flag" parameter must be an unquoted string. "branch_idx" identifies the branch for which the flags are tested - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

to:

isbflagset(flag, [branch_idx])

Test if a flag is set for a specific branch. "branch_idx" identifies the branch for which the flags are tested - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

Added lines 405-408:

Parameters:

  • flag (string, static)
  • branch_idx (int, optional)
Changed line 412 from:
    if (isbflagset(1, NAT_PING))
to:
    if (isbflagset(1, "NAT_PING"))
Changed lines 449-450 from:

prefix(string)

to:

prefix(str)

Changed lines 454-455 from:
  • prefix (string)
to:
  • str (string)
Changed lines 465-467 from:
  • pv (var)
  • string (string)
to:
  • pv (var)
  • string (string)
Changed lines 481-484 from:
  • event (string) - the name of the event which should be raised
  • attrs (var, optional) - AVP containing the the names of the attributes
  • vals (var, optional) - AVP containing values attached to the event
to:
  • event (string) - the name of the event which should be raised
  • attrs (var, optional) - AVP containing the the names of the attributes
  • vals (var, optional) - AVP containing values attached to the event
Changed lines 501-502 from:

remove_branch(pv|int)

to:

remove_branch(branch_idx)

Changed lines 507-508 from:
  • branch_idx (int)
to:
  • branch_idx (int)
Changed lines 574-575 from:
  • flags (string, static)
to:
  • flags (string, static)
Changed lines 582-585 from:

resetbflag([branch_idx,] flag)

Reset a flag for a specific branch (unset its value). The value of the "flag" parameter is an unquoted string. "branch_idx" identifies the branch for which the flag is reset - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

to:

resetbflag(flag, [branch_idx])

Reset a flag for a specific branch (unset its value). "branch_idx" identifies the branch for which the flag is reset - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

Parameters:

  • flag (string, static)
  • branch_idx (int, optional)
Changed line 594 from:
    resetbflag(1, NAT_PING);
to:
    resetbflag(1, "NAT_PING");
Changed line 596 from:
    resetbflag(NAT_PING); # same as resetbflag(0, NAT_PING)
to:
    resetbflag("NAT_PING"); # same as resetbflag(0, "NAT_PING")
Changed lines 607-608 from:

sethost()

to:

sethost(host)

Added lines 611-613:

Parameters:

  • host (string)
Changed lines 618-619 from:

rewritehostport() / sethostport()

to:

sethostport(hostport)

Added lines 622-624:

Parameters:

  • hostport (string)
Changed lines 627-630 from:
    rewritehostport("1.3.1.4:5080");

rewriteuser(string) / setuser(string)

to:
    sethostport("1.3.1.4:5080");

setuser(user)

Added lines 633-635:

Parameters:

  • user (string)
Changed line 638 from:
    rewriteuser("newuser");
to:
    setuser("newuser");
August 07, 2019, at 07:52 PM by rvlad_patrascu -
Added lines 327-329:

Parameters:

  • socket (string)
Changed lines 332-333 from:
    force_send_socket(tcp:10.10.10.10:5060);
to:
    force_send_socket("tcp:10.10.10.10:5060");
Added lines 339-341:

Parameters:

  • port_alias (int, optional)
Changed lines 351-352 from:

If destination parameter is missing, the forward will be done based on RURI.

to:

Parameters:

  • destination (string, optional) - if missing, the forward will be done based on RURI.
Added lines 364-367:

Parameters:

  • sec_avp (var)
  • usec_avp (var)
Added lines 389-391:

Parameters:

  • flag (string, static)
Changed line 395 from:
    if (isflagset(NAT_PING))
to:
    if (isflagset("NAT_PING"))
Changed lines 414-415 from:

Test if the host and optionally the port represent one of the addresses that OpenSIPS listens on. This checks the list of local IP addresses, hostnames and aliases that have been set in the OpenSIPS configuration file. Both the host and port may contain pseudo-variables.

to:

Test if the host and optionally the port represent one of the addresses that OpenSIPS listens on. This checks the list of local IP addresses, hostnames and aliases that have been set in the OpenSIPS configuration file.

Parameters:

  • host (string)
  • port (int, optional)
Changed line 422 from:
    if (is_myself("$rd", "$rp")
to:
    if (is_myself("$rd", $rp)
Added lines 449-451:

Parameters:

  • prefix (string)
Changed lines 456-461 from:

pv_printf(pv, string)

Prints the formatted 'string' in the AVP 'pv'. The 'string' parameter can include any pseudo-variable defined in OpenSIPS. The 'pv' can be any writable pseudo-variable -- e.g.,: AVPs, VARs, $ru, $rU, $rd, $du, $br, $fs.

It was extended from the avp_printf(...) function exported in previous versions by the avpops module. Starting with 1.3.1, avp_printf(...) is just an alias to pv_printf(...).

to:

pv_printf(pv, fmt_str)

Prints the formatted string 'fmt_str' in the AVP 'pv'. The 'fmt_str' parameter can include any pseudo-variable defined in OpenSIPS. The 'pv' can be any writable pseudo-variable -- e.g.,: AVPs, VARs, $ru, $rU, $rd, $du, $br, $fs.

Parameters:

  • pv (var)
  • string (string)
Changed lines 466-468 from:
    pv_printf("$var(x)", "r-uri: $ru");
    pv_printf("$avp(i:3)", "from uri: $fu");
to:
    pv_printf($var(x), "r-uri: $ru");
    pv_printf($avp(i:3), "from uri: $fu");
Changed lines 470-473 from:

raise_event(string[, avp[, avp ] ] )

Raises from script an event through OpenSIPS Event Interface. The first parameter is a string that indicates the event which should be raised. The next two parameters should be AVPs and they are optional. If only one is present, it should contain the values attached to the event. If both of them are specified, the first one should contain the names of the attributes, and the last one the values attached to the event.

to:

raise_event(event, [attrs], [vals])

Raises from script an event through OpenSIPS Event Interface.

Added lines 476-480:

Parameters:

  • event (string) - the name of the event which should be raised
  • attrs (var, optional) - AVP containing the the names of the attributes
  • vals (var, optional) - AVP containing values attached to the event
Changed lines 499-501 from:

Removes a given branch. The branch to be removed can be given via an integer or a pseudovariable. Once a branch is remove, all the subsequent branches are shifted (i.e. if branch n is removed, then the old n+1 branch becomes the new n branch, the old n+2 branch becomes n+1 and so on).

to:

Removes a given branch. Once a branch is removed, all the subsequent branches are shifted (i.e. if branch n is removed, then the old n+1 branch becomes the new n branch, the old n+2 branch becomes n+1 and so on).

Parameters:

  • branch_idx (int)
Changed lines 563-564 from:

resetflag(string)

to:

resetflag(flag)

Added lines 569-571:

Parameters:

  • flags (string, static)
Changed line 575 from:
    resetflag(NAT_PING);
to:
    resetflag("NAT_PING");
Changed lines 599-600 from:

rewritehost() / sethost()

to:

sethost()

Changed line 605 from:
    rewritehost("1.3.1.4");
to:
    sethost("1.3.1.4");
August 07, 2019, at 07:04 PM by rvlad_patrascu -
Changed lines 257-259 from:

construct_uri(proto,user,domain,port,extra,result_avp)

The function builds a valid sip uri based on the arguments it receives. The result (if any) will be stored in the result_avp AVP variable. The function accepts plain text arguments, as well as $var and $avp variables. If you want to omit a part of the sip uri, just set the respective parameter to a blank string.

to:

construct_uri(proto,[user],domain,[port],[extra],result)

The function builds a valid sip uri based on the arguments it receives. The result (if any) will be stored in the result AVP variable. If you want to omit a part of the sip uri, just omit the respective parameter.

Parameters:

  • proto (string)
  • user (string, optional)
  • domain (string)
  • port (string, optional)
  • extra (string, optional)
  • result(var)
August 07, 2019, at 03:08 PM by rvlad_patrascu -
Changed lines 143-146 from:

cache_fetch(storage_id, attribute_str, result_pvar)

This function fetches from a memory-cache-like storage system the value of an attribute. The attribute name may contain pseudo-variables. The result (if any) will be stored in the pseudo-variable specified by result_pvar.

to:

cache_fetch(storage_id, attribute, result)

This function fetches from a memory-cache-like storage system the value of an attribute. The result (if any) will be stored in the variable specified by result.

Added lines 149-153:

Parameters:

  • storage_id (string)
  • attribute (string)
  • result (var)
Changed lines 166-169 from:

cache_counter_fetch(storage_id, counter_attribute_str, result_avp)

This function fetches from a memory-cache-like storage system the value of a counter. The attribute string may contain pseudo-variables. The result (if any) will be stored in the pseudo-variable specified by result_pvar.

to:

cache_counter_fetch(storage_id, counter_attribute, result)

This function fetches from a memory-cache-like storage system the value of a counter. The result (if any) will be stored in the variable specified by result.

Added lines 172-177:

Parameters:

  • storage_id (string)
  • attribute (string)
  • result (var)
Changed lines 188-191 from:

cache_add( storage_id, attribute_str, increment_value, expire[, new_val_pvar])

This increments an attribute in a memory-cache-like storage system that supports such an operation. The attribute name may contain pseudo-variables. If the attribute does not exit, it will be created with the increment_value. If expire > 0, the key will also expire in the specified number of seconds.

to:

cache_add( storage_id, attribute, increment, expire, [new_val])

This increments an attribute in a memory-cache-like storage system that supports such an operation. If the attribute does not exit, it will be created with the value of increment.

Changed lines 194-195 from:

Optionally, the function receives one last parameter as a pvar in which to fetch the new value of the counter.

to:

Parameters:

  • storage_id (string)
  • attribute (string)
  • increment (int)
  • expire (int) - if greater than 0, the key will also expire in the specified number of seconds
  • new_val (var, optional) - variable in which to fetch the new value of the counter.
Changed line 205 from:

cache_add("redis:cluster1", 5);

to:

cache_add("redis:cluster1", "my_counter", 5, 0);

Changed lines 210-213 from:

cache_sub(storage_id, attribute_str, increment_value, expire[, new_val_pvar])

This decrements an attribute in a memory-cache-like storage system that supports such an operation. The attribute name may contain pseudo-variables. If expire > 0, the key will also expire in the specified number of seconds.

to:

cache_sub(storage_id, attribute, decrement, expire, [new_val])

This decrements an attribute in a memory-cache-like storage system that supports such an operation.

Changed lines 216-217 from:

Optionally, the function receives one last parameter as a pvar in which to fetch the new value of the counter.

to:

Parameters:

  • storage_id (string)
  • attribute (string)
  • increment (int)
  • expire (int) - if greater than 0, the key will also expire in the specified number of seconds
  • new_val (var, optional) - variable in which to fetch the new value of the counter.
Changed line 227 from:

cache_sub("redis:cluster1", 5);

to:

cache_sub("redis:cluster1", "my_counter", 5, 0);

Changed lines 232-233 from:

cache_raw_query(storage_id, raw_query, result_avp)

to:

cache_raw_query(storage_id, raw_query, result)

Added lines 238-242:

Parameters:

  • storage_id (string)
  • raw_query (string)
  • result (var, optional)
Changed line 245 from:

cache_raw_query("mongodb", "{ \"op\" : \"count\",\"query\": { \"username\" : $rU} }", "$avp(mongo_count_result)");

to:

cache_raw_query("mongodb", "{ \"op\" : \"count\",\"query\": { \"username\" : $rU} }", $avp(mongo_count_result));

August 07, 2019, at 02:31 PM by rvlad_patrascu -
Changed lines 122-125 from:

cache_remove(storage_id, attribute_str)

This removes an attribute from a memory-cache-like storage system. The attribute name may contain pseudo-variables. Function returns false only if the storage_id is invalid.

to:

cache_remove(storage_id, attribute)

This removes an attribute from a memory-cache-like storage system. Function returns false only if the storage_id is invalid.

Parameters:

  • storage_id (string)
  • attribute (string)
August 07, 2019, at 02:29 PM by rvlad_patrascu -
Changed lines 97-100 from:

cache_store(storage_id, attribute_str, value_str[, timeout])

This sets in a memory-cache-like storage system a new value for an attribute. Both the attribute name and value may contain pseudo-variables. If the attribute does not already exist in the memcache, it will be inserted with the given value; if already present, its value will be replaced with the new one. The function may optionally take an extra parameter, a timeout (or lifetime) value for the attribute - after the lifetime is exceeded, the attribute is automatically purged from memcache. If "timeout" is omitted or has a value or 0, the attribute/value pair will never expire.

to:

cache_store(storage_id, attribute, value, [timeout])

This sets in a memory-cache-like storage system a new value for an attribute. If the attribute does not already exist in the memcache, it will be inserted with the given value; if already present, its value will be replaced with the new one. The function may optionally take an extra parameter, a timeout (or lifetime) value for the attribute - after the lifetime is exceeded, the attribute is automatically purged from memcache. If "timeout" is omitted or has a value or 0, the attribute/value pair will never expire.

Added lines 102-107:

Parameters:

  • storage_id (string)
  • attribute (string)
  • value (string)
  • timeout (int, optional)
August 07, 2019, at 02:13 PM by rvlad_patrascu -
Changed lines 33-34 from:

append_branch()

to:

append_branch([uri], [qvalue])

Added lines 42-45:

Parameters:

  • uri (string, optional)
  • qvalue(string, optional)
May 09, 2019, at 01:47 PM by liviu -
Changed line 95 from:

This sets in a memory-cache-like storage system a new value for an attribute. Both the attribute name and value may contain pseudo-variables. If the attribute does not already exist in the memcache, it will be inserted with the given value; if already present, its value will be replaced with the new one. The function may optionally take an extra parameter, a timeout (or lifetime) value for the attribute - after the lifetime is exceeded, the attribute is automatically purged from memcache.

to:

This sets in a memory-cache-like storage system a new value for an attribute. Both the attribute name and value may contain pseudo-variables. If the attribute does not already exist in the memcache, it will be inserted with the given value; if already present, its value will be replaced with the new one. The function may optionally take an extra parameter, a timeout (or lifetime) value for the attribute - after the lifetime is exceeded, the attribute is automatically purged from memcache. If "timeout" is omitted or has a value or 0, the attribute/value pair will never expire.

April 19, 2019, at 05:10 PM by liviu -
Changed lines 95-96 from:

This sets in a memory-cache-like-storage system a new value for an attribute. Both the attribute name and value may contain pseudo-variables. If the attribute does not already exist in the memcache, it will be inserted with the given value; if already present, its value will be replaced with the new one. The function may optionally take an extra parameter, a timeout (or lifetime) value for the attribute - after the lifetime is exceeded, the attribute is automatically purged from memcache.

to:

This sets in a memory-cache-like storage system a new value for an attribute. Both the attribute name and value may contain pseudo-variables. If the attribute does not already exist in the memcache, it will be inserted with the given value; if already present, its value will be replaced with the new one. The function may optionally take an extra parameter, a timeout (or lifetime) value for the attribute - after the lifetime is exceeded, the attribute is automatically purged from memcache.

Changed line 114 from:

This removes an attribute from a memory-cache-like-storage system. The attribute name may contain pseudo-variables.

to:

This removes an attribute from a memory-cache-like storage system. The attribute name may contain pseudo-variables.

Changed lines 132-133 from:

This function fetches from a memory-cache-like-storage system the value of an attribute. The attribute name may contain pseudo-variables. The result (if any) will be stored in the pseudo-variable specified by result_pvar.

to:

This function fetches from a memory-cache-like storage system the value of an attribute. The attribute name may contain pseudo-variables. The result (if any) will be stored in the pseudo-variable specified by result_pvar.

Changed lines 150-151 from:

This function fetches from a memory-cache-like-storage system the value of a counter. The attribute string may contain pseudo-variables. The result (if any) will be stored in the pseudo-variable specified by result_pvar.

to:

This function fetches from a memory-cache-like storage system the value of a counter. The attribute string may contain pseudo-variables. The result (if any) will be stored in the pseudo-variable specified by result_pvar.

Changed lines 166-167 from:

This increments an attribute in a memory-cache-like-storage system that supports such an operation. The attribute name may contain pseudo-variables. If the attribute does not exit, it will be created with the increment_value. If expire > 0, the key will also expire in the specified number of seconds.

to:

This increments an attribute in a memory-cache-like storage system that supports such an operation. The attribute name may contain pseudo-variables. If the attribute does not exit, it will be created with the increment_value. If expire > 0, the key will also expire in the specified number of seconds.

Changed line 183 from:

This decrements an attribute in a memory-cache-like-storage system that supports such an operation. The attribute name may contain pseudo-variables. If expire > 0, the key will also expire in the specified number of seconds.

to:

This decrements an attribute in a memory-cache-like storage system that supports such an operation. The attribute name may contain pseudo-variables. If expire > 0, the key will also expire in the specified number of seconds.

August 22, 2018, at 06:34 PM by liviu -
Changed lines 137-138 from:

cache_fetch("local", "credit_$fU", $avp(ret));

to:

cache_fetch("local", "credit_$fU", $var(ret));

Changed line 143 from:

cache_fetch("redis:cluster1", "credit_$fU", $avp(ret));

to:

cache_fetch("redis:cluster1", "credit_$fU", $var(ret));

Changed lines 155-156 from:

cache_counter_fetch("local", "my_counter", $avp(counter_val));

to:

cache_counter_fetch("local", "my_counter", $var(counter_val));

Changed line 161 from:

cache_fetch("redis:cluster1", "my_counter", $avp(redis_counter_val));

to:

cache_fetch("redis:cluster1", "my_counter", $var(redis_counter_val));

April 23, 2018, at 03:45 PM by razvancrainea -
Deleted lines 661-665:

setdebug([level]) (Removed in OpenSIPS 3.1)

Replaced as functionality by the $log_level script variable.

March 30, 2018, at 11:54 AM by liviu -
Changed line 620 from:

Takes all currently added branches for parallel forking (with append_branch()), as well as the current branch: (R-URI, $ru / outbound Proxy, $du / q value, $ru_q / branch flags / forced Path headers / forced send socket), and prepares them for serial forking instead. The ordering is done in decreasing "q" order. The serialized branches are internally stored in the "$avp(serial_branch)" AVP - this allows them to be manipulated by the "next_branches()" function, usually within a failure route.

to:

Takes all currently added branches for parallel forking (with append_branch()), as well as the current branch: (R-URI ($ru) / outbound Proxy ($du) / q value ($ru_q) / branch flags / forced Path headers / forced send socket), and prepares them for serial forking instead. The ordering is done in decreasing "q" order. The serialized branches are internally stored in the "$avp(serial_branch)" AVP - this allows them to be manipulated by the "next_branches()" function, usually within a failure route.

March 30, 2018, at 11:53 AM by liviu -
Changed lines 624-625 from:

NOTE that (according to RFC3261), the branches with the same "q" value will still be parallel forked during a certain step in the serial forking (it will result a combination of serial with parallel forking). In other words, this function will clear all added branches, and keep re-adding them as long as they have identical highest "q" values. A similar grouping process takes place during a "next_branches()" function call.

to:

NOTE that (according to RFC3261), the branches with the same "q" value will still be parallel forked during a certain step in the serial forking (it will result a combination of serial with parallel forking). In other words, this function will clear all added branches and keep re-adding them as long as they have identical highest "q" values, while throwing all other "lower-than-highest q" branches in the "$avp(serial_branch)". A similar grouping process takes place during each "next_branches()" function call.

Changed lines 630-632 from:

If "clear_previous" is set to non-zero, all previous results of another "serialize_branches()" (serial forking set which is no longer needed) will be deleted before starting a new set.

If "keep_order" is set to non-zero, the added branches as well as the current branch, will be serialized exactly in the order in which they are found.

to:

If "clear_previous" is set to non-zero, all previous results of another "serialize_branches()" (serial forking set which is no longer needed) will be deleted before starting a new set.

If "keep_order" is set to non-zero, the added branches as well as the current branch, will be serialized exactly in the order in which they are found.

March 30, 2018, at 11:49 AM by liviu -
Changed lines 620-621 from:

Clears all currently added branches for parallel forking (with append_branch()), including the current branch: (R-URI, $ru / outbound Proxy, $du / q value, $ru_q / branch flags / forced Path headers / forced send socket), and prepares them for serial forking instead. The ordering is done in decreasing "q" order. The serialized branches are internally stored in the "$avp(serial_branch)" AVP - this allows them to be manipulated by the "next_branches()" function, usually within a failure route.
NOTE that (according to RFC3261), the branches with the same "q" value will still be parallel forked during a certain step in the serial forking (it will result a combination of serial with parallel forking).\\

to:

Takes all currently added branches for parallel forking (with append_branch()), as well as the current branch: (R-URI, $ru / outbound Proxy, $du / q value, $ru_q / branch flags / forced Path headers / forced send socket), and prepares them for serial forking instead. The ordering is done in decreasing "q" order. The serialized branches are internally stored in the "$avp(serial_branch)" AVP - this allows them to be manipulated by the "next_branches()" function, usually within a failure route.


NOTE that (according to RFC3261), the branches with the same "q" value will still be parallel forked during a certain step in the serial forking (it will result a combination of serial with parallel forking). In other words, this function will clear all added branches, and keep re-adding them as long as they have identical highest "q" values. A similar grouping process takes place during a "next_branches()" function call.


March 30, 2018, at 11:45 AM by liviu -
Changed lines 371-373 from:

Adds to the request a new destination set that includes all highest priority class contacts ('q' value based) from the serialized branches (see serialize_branches()). If called from a route block, it rewrites the request uri with first contact and adds the remaining contacts as parallel branches. If called from failure route block, adds all contacts as parallel branches. All used contacts are removes the serialized branches.

to:

Adds to the request a new destination set that includes all highest priority class contacts ('q' value based) from the serialized branches (see serialize_branches()). If called from a route block, it rewrites the request uri with first contact and adds the remaining contacts as parallel branches. If called from failure route block, adds all contacts as parallel branches. All used contacts are removes the serialized branches.

Changed lines 618-620 from:

serialize_branches(clear)

Takes all the branches added for parallel forking (with append_branch() and including the current RURI) and prepare them for serial forking. The ordering is done in increasing "q" order. The serialized branches are internally stored in AVPs - you will be able to fetch and use via the "next_branches()" function.\\

to:

serialize_branches(clear_previous[, keep_order])

Clears all currently added branches for parallel forking (with append_branch()), including the current branch: (R-URI, $ru / outbound Proxy, $du / q value, $ru_q / branch flags / forced Path headers / forced send socket), and prepares them for serial forking instead. The ordering is done in decreasing "q" order. The serialized branches are internally stored in the "$avp(serial_branch)" AVP - this allows them to be manipulated by the "next_branches()" function, usually within a failure route.\\

Changed lines 622-625 from:

NOTE that this function is not changing RURI in the messages - it is just converting from parallel to serial branches (preparing branches).

If "clear" is set to non-zero, all previous results of another "serialize_branches" (serialized branches which were not yet used) will be deleted before setting the new serialized branches.

to:

NOTE that this function is not altering the current branch (R-URI, outbound proxy, etc.) - it is just preparing a serial forking set with the above-mentioned branches. You may need to call "next_branches()" immediately after calling this function, see the example below.

If "clear_previous" is set to non-zero, all previous results of another "serialize_branches()" (serial forking set which is no longer needed) will be deleted before starting a new set.

If "keep_order" is set to non-zero, the added branches as well as the current branch, will be serialized exactly in the order in which they are found.

Changed lines 630-631 from:
   serialize_branches(1);
to:
    if (!lookup("location")) {
        t_reply("480", "Temporarily Unavailable");
        exit;
    }

    serialize_branches(1);
    next_branches(); # Pop the R-URI from the serialized branches set
March 21, 2018, at 02:35 PM by liviu -
Changed lines 740-743 from:
  • L_WARN (0)
  • L_NOTICE (1)
  • L_INFO (2)
  • L_DBG (3)
to:
  • L_WARN (1)
  • L_NOTICE (2)
  • L_INFO (3)
  • L_DBG (4)
November 21, 2017, at 11:29 AM by liviu -
Changed line 675 from:

Set a flag for a specific branch. The value of the "flag" parameter must be an unquoted string. "branch_idx" identifies the branch for which the flag is set - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

to:

Set a flag for a specific branch. The value of the "flag" parameter must be an unquoted string. "branch_idx" identifies the branch for which the flag is set - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default. The OpenSIPS script supports, at most, 32 unique string branch flags.

November 21, 2017, at 11:18 AM by liviu -
Changed line 595 from:
    [line 581][me][core setsflag] -> (INVITE from 127.0.0.1 , ruri=sip:111211@opensips.org)
to:
    [line 581][me][core setbflag] -> (INVITE from 127.0.0.1 , ruri=sip:111211@opensips.org)
Deleted lines 685-697:

setsflag(flag_idx) (Removed in OpenSIPS 3.1)

Set a script flag (set flag to value 0). The value of the "flag_idx" parameter can be in range of 0..31.

For more about script flags, see Flags Documentation.

Example of usage:

    setsflag(2);
November 21, 2017, at 11:17 AM by liviu -
Changed lines 334-336 from:
    if (isflagset(NAT_PING)) {
        log("flag 3 is set\n");
    }
to:
    if (isflagset(NAT_PING))
        log("flag NAT_PING is set\n");
Changed lines 347-349 from:
    if (isbflagset(1, NAT_PING)) {
        log("flag 3 is set in branch 1\n");
    }
to:
    if (isbflagset(1, NAT_PING))
        log("flag NAT_PING is set in branch 1\n");
Changed lines 351-356 from:

issflagset(flag_idx) (Removed in OpenSIPS 3.1)

Test if a script flag is set (if the flag value is 1). The value of the "flag_idx" parameter can be in range of 0..31.

For more about script flags, see Flags Documentation.

to:

is_myself(host, [port])

Test if the host and optionally the port represent one of the addresses that OpenSIPS listens on. This checks the list of local IP addresses, hostnames and aliases that have been set in the OpenSIPS configuration file. Both the host and port may contain pseudo-variables.

Deleted lines 356-365:
    if(issflagset(2)) {
        log("script flag 2 is set\n");
    };

is_myself(host, [port])

Test if the host and optionally the port represent one of the addresses that OpenSIPS listens on. This checks the list of local IP addresses, hostnames and aliases that have been set in the OpenSIPS configuration file. Both the host and port may contain pseudo-variables.

Example of usage:

Deleted lines 509-520:

resetsflag(flag_idx) (Removed in OpenSIPS 3.1)

Reset a script flag (set flag to value 0). The value of the "flag_idx" parameter can be in range of 0..31.

For more about script flags, see Flags Documentation.

Example of usage:

    resetsflag(2);
November 21, 2017, at 11:15 AM by liviu -
Changed lines 339-342 from:

isbflagset([branch_idx,] flag_idx)

Test if a flag is set for a specific branch (if the flag value is 1). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flags are tested - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

to:

isbflagset([branch_idx,] flag)

Test if a flag is set for a specific branch. The value of the "flag" parameter must be an unquoted string. "branch_idx" identifies the branch for which the flags are tested - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

Changed lines 347-348 from:
    if(isbflagset(1,3)) {
to:

[@

    if (isbflagset(1, NAT_PING)) {
Changed lines 350-351 from:
    };
to:
    }

@]

Changed lines 512-515 from:

resetbflag([branch_idx,] flag_idx)

Reset a flag for a specific branch (set flag to value 0). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flag is reset - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

to:

resetbflag([branch_idx,] flag)

Reset a flag for a specific branch (unset its value). The value of the "flag" parameter is an unquoted string. "branch_idx" identifies the branch for which the flag is reset - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

Changed line 520 from:
    resetbflag(1,3);
to:
    resetbflag(1, NAT_PING);
Changed line 522 from:
    resetbflag(3); # same with resetbflag(0,3)
to:
    resetbflag(NAT_PING); # same as resetbflag(0, NAT_PING)
Changed lines 699-702 from:

setbflag([branch_idx,] flag_idx)

Set a flag for a specific branch (set flag to value 1). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flag is set - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

to:

setbflag([branch_idx,] flag)

Set a flag for a specific branch. The value of the "flag" parameter must be an unquoted string. "branch_idx" identifies the branch for which the flag is set - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

Changed lines 707-708 from:
    setbflag(1,3);
to:

[@

    setbflag(1, NAT_PING);
Changed lines 710-711 from:
    setbflag(3); # same with setbflag(0,3)
to:
    setbflag(NAT_PING); # same as setbflag(0, NAT_PING)

@]

November 21, 2017, at 11:05 AM by liviu -
Changed lines 327-328 from:

Test if a flag is set for current processed message.

to:

Test if a flag is set for currently processed message.

Changed lines 500-501 from:

Reset a flag for current processed message (unset its value).

to:

Reset a flag for currently processed message (unset its value).

Added line 506:

[@

Changed lines 508-509 from:
to:

@]

Added line 692:

[@

Added line 694:

@]

November 21, 2017, at 11:03 AM by liviu -
Changed lines 325-328 from:

isflagset(int)

Test if a flag is set for current processed message (if the flag value is 1). The value of the parameter can be in range of 0..31.

to:

isflagset(string)

Test if a flag is set for current processed message.

Changed lines 333-334 from:
    if(isflagset(3)) {
to:

[@

    if (isflagset(NAT_PING)) {
Changed lines 336-337 from:
    };
to:
    }

@]

Changed lines 498-501 from:

resetflag(int)

Reset a flag for current processed message (set the value to 0). The value of the parameter can be in range of 0..31.

to:

resetflag(string)

Reset a flag for current processed message (unset its value).

Changed lines 506-507 from:
    resetflag(3);
to:
    resetflag(NAT_PING);
Changed lines 684-687 from:

setflag(int)

Set a flag for current processed message. The value of the parameter can be in range of 0..31. The flags are used to mark the message for special processing (e.g., accounting) or to keep some state (e.g., message authenticated).

to:

setflag(string)

Set a flag for currently processed message. The flags are used to mark the message for special processing (e.g. pinging NAT'ed contacts, TCP connect behavior, etc.) or to keep some state (e.g. message authenticated). The OpenSIPS script supports, at most, 32 unique string flags.

Changed line 690 from:
    setflag(3);
to:
    setflag(NAT_PING);
October 31, 2017, at 04:53 PM by liviu -
Changed line 287 from:

Enables TCP connection reusage (RFC 5923) for the current TLS (or WSS, TCP, WS) connection (source IP + **source port** + transport), regardless if the Via header field contains an ";alias" parameter or not. All backwards SIP requests, towards the same (source IP + **Via port** + transport) pair will be forced over this connection, for as long as it stays open. The main purpose of this function (and of RFC 5923) is to minimize the number of TLS connections a SIP proxy must set up, due to the significant CPU overhead of the TLS cipher negotiation phase.

to:

Enables TCP connection reusage (RFC 5923) for the current TLS (or WSS, TCP, WS) connection (source IP + source port + transport), regardless if the Via header field contains an ";alias" parameter or not. All backwards SIP requests, towards the same (source IP + Via port + transport) pair will be forced over this connection, for as long as it stays open. The main purpose of this function (and of RFC 5923) is to minimize the number of TLS connections a SIP proxy must set up, due to the significant CPU overhead of the TLS cipher negotiation phase.

October 31, 2017, at 04:53 PM by liviu -
Changed line 287 from:

Enables TCP connection reusage (RFC 5923) for the current TLS (or WSS, TCP, WS) connection (source IP + Via port + transport), regardless if the Via header field contains an ";alias" parameter or not. All backwards SIP requests, towards the same (source IP + Via port + transport) pair will be forced over this connection, for as long as it stays open. The main purpose of this function (and of RFC 5923) is to minimize the number of TLS connections a SIP proxy must set up, due to the significant CPU overhead of the TLS cipher negotiation phase.

to:

Enables TCP connection reusage (RFC 5923) for the current TLS (or WSS, TCP, WS) connection (source IP + **source port** + transport), regardless if the Via header field contains an ";alias" parameter or not. All backwards SIP requests, towards the same (source IP + **Via port** + transport) pair will be forced over this connection, for as long as it stays open. The main purpose of this function (and of RFC 5923) is to minimize the number of TLS connections a SIP proxy must set up, due to the significant CPU overhead of the TLS cipher negotiation phase.

July 17, 2017, at 05:56 PM by rvlad_patrascu -
Changed line 47 from:
    if (method=="INVITE" && uri=~"sip:B@xx.xxx.xx ")
to:
    if ($rm=="INVITE" && $ru=~"sip:B@xx.xxx.xx ")
Changed line 239 from:
        if(status=="183") {
to:
        if($rs=="183") {
July 14, 2017, at 12:48 PM by rvlad_patrascu -
Changed line 13 from:

(:toc-float Table of Content:)

to:

(:toc-float Table of Contents:)

Added lines 360-368:

is_myself(host, [port])

Test if the host and optionally the port represent one of the addresses that OpenSIPS listens on. This checks the list of local IP addresses, hostnames and aliases that have been set in the OpenSIPS configuration file. Both the host and port may contain pseudo-variables.

Example of usage:

    if (is_myself("$rd", "$rp")
        xlog("the request is for local processing\n");
November 04, 2016, at 08:31 PM by liviu -
Changed lines 100-101 from:

cache_store("local", "total_credit", "$avp(credit)", 1200);

to:

cache_store("local", "total_minutes_$fU", "$avp(mins)", 1200);

Changed line 104 from:

modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")

to:

modparam("cachedb_redis", "cachedb_url", "redis:cluster1://193.168.3.134:6379/")

Changed lines 112-113 from:

cache_remove( storage_id, attribute_name)

to:

cache_remove(storage_id, attribute_str)

Changed lines 118-119 from:

cache_remove("local","my_attr");

to:

cache_remove("local", "total_minutes_$fU");

Changed line 122 from:

modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")

to:

modparam("cachedb_redis", "cachedb_url", "redis:cluster1://193.168.3.134:6379/")

Changed line 124 from:

cache_remove("redis:cluster1","my_attr");

to:

cache_remove("redis:cluster1", "total_minutes_$fU");

Changed lines 130-131 from:

cache_fetch( storage_id, attribute_name, result_pvar)

to:

cache_fetch(storage_id, attribute_str, result_pvar)

Changed lines 137-138 from:

cache_fetch("local","my_attr", $avp(i:11) );

to:

cache_fetch("local", "credit_$fU", $avp(ret));

Changed line 141 from:

modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")

to:

modparam("cachedb_redis", "cachedb_url", "redis:cluster1://193.168.3.134:6379/")

Changed line 143 from:

cache_fetch("redis:cluster1","my_attr",$avp(i:11));

to:

cache_fetch("redis:cluster1", "credit_$fU", $avp(ret));

Changed lines 148-151 from:

cache_counter_fetch( storage_id, counter_attribute_name, result_avp)

This function fetches from a memory-cache-like-storage system the value of a counter. The attribute name may contain pseudo-variables. The result (if any) will be stored in the pseudo-variable specified by result_pvar.

to:

cache_counter_fetch(storage_id, counter_attribute_str, result_avp)

This function fetches from a memory-cache-like-storage system the value of a counter. The attribute string may contain pseudo-variables. The result (if any) will be stored in the pseudo-variable specified by result_pvar.

Changed lines 155-156 from:

cache_counter_fetch("local","my_counter", $avp(counter_val) );

to:

cache_counter_fetch("local", "my_counter", $avp(counter_val));

Changed line 159 from:

modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")

to:

modparam("cachedb_redis", "cachedb_url", "redis:cluster1://193.168.3.134:6379/")

Changed line 161 from:

cache_fetch("redis:cluster1","my_counter",$avp(redis_counter_val));

to:

cache_fetch("redis:cluster1", "my_counter", $avp(redis_counter_val));

Changed lines 164-165 from:

cache_add( storage_id, attribute_name,increment_value,expire,[new_val_pvar])

to:

cache_add( storage_id, attribute_str, increment_value, expire[, new_val_pvar])

Changed line 174 from:

modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")

to:

modparam("cachedb_redis", "cachedb_url", "redis:cluster1://193.168.3.134:6379/")

Changed line 176 from:

cache_add("redis:cluster1",5);

to:

cache_add("redis:cluster1", 5);

Changed lines 181-182 from:

cache_sub( storage_id, attribute_name,increment_value,expire,[new_val_pvar])

to:

cache_sub(storage_id, attribute_str, increment_value, expire[, new_val_pvar])

Changed line 191 from:

modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")

to:

modparam("cachedb_redis", "cachedb_url", "redis:cluster1://193.168.3.134:6379/")

Changed line 193 from:

cache_sub("redis:cluster1",5);

to:

cache_sub("redis:cluster1", 5);

Changed lines 198-201 from:

cache_raw_query( storage_id, raw_query,result_avp)

The function runs the provided raw query ( in the back-end dependent language ) and returns the results ( if any ) in the provided AVP. The result_avp can be missing, if the query returns no results.

to:

cache_raw_query(storage_id, raw_query, result_avp)

The function runs the provided raw query (in the back-end dependent language) and returns the results (if any) in the provided AVP. The result_avp can be missing, if the query returns no results.

Changed line 206 from:

cache_raw_query("mongodb","{ \"op\" : \"count\",\"query\": { \"username\" : $rU} }","$avp(mongo_count_result)");

to:

cache_raw_query("mongodb", "{ \"op\" : \"count\",\"query\": { \"username\" : $rU} }", "$avp(mongo_count_result)");

November 04, 2016, at 08:24 PM by liviu -
Changed lines 93-94 from:

cache_store( storage_id, attribute_name, attribute_name [,timeout])

to:

cache_store(storage_id, attribute_str, value_str[, timeout])

Changed lines 97-98 from:

Function returns true is the new attribute was successfully inserted.

to:

Function returns true if the new attribute was successfully inserted.

Changed lines 100-101 from:

cache_store("local","my_attr","$avp(i:55)",1200);

to:

cache_store("local", "total_credit", "$avp(credit)", 1200);

Changed line 106 from:

cache_store("redis:cluster1","passwd_$tu","$var(x)");

to:

cache_store("redis:cluster1", "passwd_$tu", "$var(x)");

June 21, 2016, at 12:29 PM by liviu -
Changed line 287 from:

Employs TCP connection reusage (RFC 5923) for the current TLS (or WSS, TCP, WS) connection (source IP + Via port + transport), regardless if the Via header field contains an ";alias" parameter or not. All backwards SIP requests, towards the same (source IP + Via port + transport) pair will be forced over this connection, for as long as it stays open. The main purpose of this function (and of RFC 5923) is to minimize the number of TLS connections a SIP proxy must set up, due to the significant CPU overhead of the TLS cipher negotiation phase.

to:

Enables TCP connection reusage (RFC 5923) for the current TLS (or WSS, TCP, WS) connection (source IP + Via port + transport), regardless if the Via header field contains an ";alias" parameter or not. All backwards SIP requests, towards the same (source IP + Via port + transport) pair will be forced over this connection, for as long as it stays open. The main purpose of this function (and of RFC 5923) is to minimize the number of TLS connections a SIP proxy must set up, due to the significant CPU overhead of the TLS cipher negotiation phase.

June 21, 2016, at 12:25 PM by liviu -
Added lines 288-289:

\\

June 21, 2016, at 12:05 PM by liviu -
Changed line 287 from:

Employs TCP connection reusage (RFC 5923) for the current TLS (or WSS, TCP, WS) connection (source IP + Via port + transport), regardless if the Via header field contains an ";alias" parameter or not. All backwards SIP requests, towards the same (source IP + Via port + transport) pair will be forced over this connection. The main purpose of this function (and of RFC 5923) is to minimize the number of TLS connections a SIP proxy must set up, due to the significant CPU overhead of the TLS cipher negotiation phase.

to:

Employs TCP connection reusage (RFC 5923) for the current TLS (or WSS, TCP, WS) connection (source IP + Via port + transport), regardless if the Via header field contains an ";alias" parameter or not. All backwards SIP requests, towards the same (source IP + Via port + transport) pair will be forced over this connection, for as long as it stays open. The main purpose of this function (and of RFC 5923) is to minimize the number of TLS connections a SIP proxy must set up, due to the significant CPU overhead of the TLS cipher negotiation phase.

June 21, 2016, at 12:03 PM by liviu -
Changed line 287 from:

Employs TCP connection reusage (RFC 5923) for the current TLS (or WSS, TCP, WS) connection (source IP + Via port + transport), regardless if the Via header field contains an ";alias" parameter or not. All backwards SIP requests, towards the same (source IP + Via port + proto) pair will be forced over this connection. The main purpose of this function (and of RFC 5923) is to minimize the number of TLS connections a SIP proxy must set up, due to the significant CPU overhead of the TLS cipher negotiation phase.

to:

Employs TCP connection reusage (RFC 5923) for the current TLS (or WSS, TCP, WS) connection (source IP + Via port + transport), regardless if the Via header field contains an ";alias" parameter or not. All backwards SIP requests, towards the same (source IP + Via port + transport) pair will be forced over this connection. The main purpose of this function (and of RFC 5923) is to minimize the number of TLS connections a SIP proxy must set up, due to the significant CPU overhead of the TLS cipher negotiation phase.

June 21, 2016, at 12:03 PM by liviu -
Changed lines 287-293 from:

Adds a TCP port alias for the current TCP connection. Has no effect for other protocols. Useful if you want to send all traffic to port_alias through the same connection this request came from (it could help for firewall or NAT traversal). If no port is given, the port of the Via header field will be used. When the "aliased" connection is closed (e.g. idle for too much time), all port aliases are removed.

to:

Employs TCP connection reusage (RFC 5923) for the current TLS (or WSS, TCP, WS) connection (source IP + Via port + transport), regardless if the Via header field contains an ";alias" parameter or not. All backwards SIP requests, towards the same (source IP + Via port + proto) pair will be forced over this connection. The main purpose of this function (and of RFC 5923) is to minimize the number of TLS connections a SIP proxy must set up, due to the significant CPU overhead of the TLS cipher negotiation phase.

WARNING! Do not perform force_tcp_alias() for end-user initiated connections (who are most likely grouped by one or more public IPs), as this would create an open vector for call hijacking!

June 21, 2016, at 11:49 AM by liviu -
Changed line 284 from:
to:

March 24, 2016, at 09:22 PM by 109.102.83.252 -
Changed lines 663-677 from:

setdebug([level])

Changes the debug level of the current process from script. If called without the parameter then the debug level of the current process will be reset to its default level. This function is very helpful if you are tracing and debugging only a specific piece of code.

Example of usage:

    debug= -1 # errors only
    .....
    {
      ......
      setdebug(4); # set the debug level of the current process to DBG
      uac_replace_from(....);
      setdebug(); # reset the debug level of the current process to its default level
      .......
    }
to:

setdebug([level]) (Removed in OpenSIPS 3.1)

Replaced as functionality by the $log_level script variable.

March 21, 2016, at 12:05 PM by liviu -
Changed lines 289-290 from:

the same connection this request came from [it could help for firewall or nat traversal].

to:

the same connection this request came from (it could help for firewall or NAT traversal).

March 21, 2016, at 12:04 PM by liviu -
Changed lines 285-290 from:

force_tcp_alias()

force_tcp_alias(port)

adds a tcp port alias for the current connection (if tcp). Usefull if you want to send all the trafic to port_alias through

to:

force_tcp_alias([port_alias])

Adds a TCP port alias for the current TCP connection. Has no effect for other protocols. Useful if you want to send all traffic to port_alias through

Changed lines 291-293 from:

With no parameters adds the port from the message via as the alias. When the "aliased" connection is closed (e.g. it's idle for too much time), all the port aliases are removed.

to:

If no port is given, the port of the Via header field will be used. When the "aliased" connection is closed (e.g. idle for too much time), all port aliases are removed.

March 07, 2016, at 05:36 PM by liviu -
Changed lines 353-354 from:

issflagset(flag_idx)

to:

issflagset(flag_idx) (Removed in OpenSIPS 3.1)

Changed lines 516-517 from:

resetsflag(flag_idx)

to:

resetsflag(flag_idx) (Removed in OpenSIPS 3.1)

Changed line 713 from:

setsflag(flag_idx)

to:

setsflag(flag_idx) (Removed in OpenSIPS 3.1)

April 01, 2015, at 06:27 PM by liviu -
Changed lines 276-277 from:

force_send_socket([proto:]address[:port])

to:

force_send_socket(proto:address[:port])

Changed line 282 from:
    force_send_socket(10.10.10.10:5060);
to:
    force_send_socket(tcp:10.10.10.10:5060);
March 16, 2015, at 02:04 PM by liviu -
Changed line 26 from:

Only works if enable_asserts is set to true. Immediately aborts script execution and runs the error_route. If abort_on_assert is enabled, OpenSIPS will also shutdown.

to:

Only works if enable_asserts is set to true. If the given expression evaluates to false, script execution is stopped and the error_route is executed. If abort_on_assert is enabled, OpenSIPS will also shutdown.

March 16, 2015, at 01:59 PM by liviu -
Changed line 30 from:
    assert($ua == "friendly-scanner", "Forbidden UA: \"friendly-scanner\"");
to:
    assert($ua != "friendly-scanner", "Forbidden UA: \"friendly-scanner\"");
March 16, 2015, at 12:26 PM by liviu -
Changed line 26 from:

Only works if enable_asserts is set to true. Immediately aborts script execution and runs the error_route. If abort_on_assert is enabled, OpenSIPS will shutdown.

to:

Only works if enable_asserts is set to true. Immediately aborts script execution and runs the error_route. If abort_on_assert is enabled, OpenSIPS will also shutdown.

March 16, 2015, at 12:25 PM by liviu -
Changed line 26 from:

Only works if enable_asserts is set to true. Immediately aborts script execution, and runs the error_route. If abort_on_assert is enabled, OpenSIPS will shutdown.

to:

Only works if enable_asserts is set to true. Immediately aborts script execution and runs the error_route. If abort_on_assert is enabled, OpenSIPS will shutdown.

March 13, 2015, at 07:02 PM by liviu -
Changed line 26 from:

Only works if enable_asserts? is set to true. Immediately aborts script execution, and runs the error_route. If abort_on_assert? is enabled, OpenSIPS will shutdown.

to:

Only works if enable_asserts is set to true. Immediately aborts script execution, and runs the error_route. If abort_on_assert is enabled, OpenSIPS will shutdown.

March 13, 2015, at 06:52 PM by liviu -
Added lines 23-31:

assert()

Only works if enable_asserts? is set to true. Immediately aborts script execution, and runs the error_route. If abort_on_assert? is enabled, OpenSIPS will shutdown.

Example of usage:

    assert($ua == "friendly-scanner", "Forbidden UA: \"friendly-scanner\"");
February 27, 2015, at 12:57 PM by liviu -
Changed lines 334-335 from:

Test if a flag is set for a specific branch (if the flag value is 1). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flags are tested - it must be a positiv number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

to:

Test if a flag is set for a specific branch (if the flag value is 1). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flags are tested - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

Changed lines 494-495 from:

Reset a flag for a specific branch (set flag to value 0). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flag is reset - it must be a positiv number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

to:

Reset a flag for a specific branch (set flag to value 0). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flag is reset - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

Changed line 691 from:

Set a flag for a specific branch (set flag to value 1). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flag is set - it must be a positiv number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

to:

Set a flag for a specific branch (set flag to value 1). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flag is set - it must be a positive number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

January 27, 2015, at 06:36 PM by liviu -
Changed line 585 from:

script_trace( log_level, pv_format_string[, info_string])

to:

script_trace([log_level, pv_format_string[, info_string]])

September 12, 2014, at 04:01 PM by liviu -
Changed lines 764-770 from:

L_ALERT (-3) L_CRIT (-2) L_ERR (-1) - this is used by default if log_level is omitted L_WARN (0) L_NOTICE (1) L_INFO (2) L_DBG (3)

to:
  • L_ALERT (-3)
  • L_CRIT (-2)
  • L_ERR (-1) - this is used by default if log_level is omitted
  • L_WARN (0)
  • L_NOTICE (1)
  • L_INFO (2)
  • L_DBG (3)

\\

September 12, 2014, at 04:00 PM by liviu -
Changed line 762 from:

Allows various debugging / runtime / critical messages to be printed as the execution of the OpenSIPS script is done. All pseudo-variables included in the **format_string** parameter will be expanded. There are several optional logging levels which can be specified. They work in accordance with the severity levels of syslog. The levels are named as follows:

to:

Allows various debugging / runtime / critical messages to be printed as the execution of the OpenSIPS script is done. All pseudo-variables included in the format_string parameter will be expanded. There are several optional logging levels which can be specified. They work in accordance with the severity levels of syslog. The levels are named as follows:

September 12, 2014, at 04:00 PM by liviu -
Added lines 759-776:

xlog([log_level, ]format_string)

Allows various debugging / runtime / critical messages to be printed as the execution of the OpenSIPS script is done. All pseudo-variables included in the **format_string** parameter will be expanded. There are several optional logging levels which can be specified. They work in accordance with the severity levels of syslog. The levels are named as follows:

L_ALERT (-3) L_CRIT (-2) L_ERR (-1) - this is used by default if log_level is omitted L_WARN (0) L_NOTICE (1) L_INFO (2) L_DBG (3)

    # a few xlog scripting examples
    xlog("Received $rm from $fu (callid: $ci)\n");
    xlog("L_ERR", "key $var(username) not found in cache!\n");
August 12, 2014, at 02:16 PM by razvancrainea -
Changed line 397 from:

raise_event(string[, avp[, avp]])

to:

raise_event(string[, avp[, avp ] ] )

August 12, 2014, at 12:19 PM by liviu -
Changed line 658 from:

Changes the debug level of the current process from script. If called without the parameter then the debug level of the current process will be reset its default level. This function is very helpful if you are tracing and debugging only a specific piece of code.

to:

Changes the debug level of the current process from script. If called without the parameter then the debug level of the current process will be reset to its default level. This function is very helpful if you are tracing and debugging only a specific piece of code.

August 12, 2014, at 12:19 PM by liviu -
Changed lines 658-659 from:

Changes the debug level of the current process from script. If called without the parameter then the debug level of the current process will be reset to the global level. If the debug level of the current process is changed then changing the global debug level (using MI function) does not affect it, so be careful and make sure to reset the process debug level when you are done. This function is very helpful if you are tracing and debugging only a specific piece of code.

to:

Changes the debug level of the current process from script. If called without the parameter then the debug level of the current process will be reset its default level. This function is very helpful if you are tracing and debugging only a specific piece of code.

Changed line 668 from:
      setdebug(); # reset the debug level of the current process to the global level
to:
      setdebug(); # reset the debug level of the current process to its default level
March 20, 2014, at 08:31 PM by razvancrainea -
Added lines 1-758:
Documentation -> Manuals -> Manual 3.1 -> Core functions

(:title Core Functions - 3.1:)


(:allVersions Script-CoreFunctions 3.1:)


Core functions v3.1
PrevNext

(:toc-float Table of Content:) This section lists the all the functions exported by OpenSIPS core for script usage (to be used in opensips.cfg)

add_local_rport()

Add 'rport' parameter to the Via header generated by server (see RFC3581 for its meaning). It affects only the current processed request.

Example of usage:

    add_local_rport()

append_branch()

Similarly to t_fork_to, it extends destination set by a new entry. The difference is that current URI is taken as new entry.

Without parameter, the function copies the current URI into a new branch. Thus, leaving the main branch (the URI) for further manipulation.

With a parameter, the function copies the URI in the parameter into a new branch. Thus, the current URI is not manipulated.

Note that it's not possible to append a new branch in "on_failure_route" block if a 6XX response has been previously received (it would be against RFC 3261).

Example of usage:

    # if someone calls B, the call should be forwarded to C too.
    #
    if (method=="INVITE" && uri=~"sip:B@xx.xxx.xx ")
    {
        # copy the current branch (branches[0]) into
        # a new branch (branches[1])
        append_branch();
        # all URI manipulation functions work on branches[0]
        # thus, URI manipulation does not touch the 
        # appended branch (branches[1])
        seturi("sip:C@domain");

        # now: branch 0 = C@domain
        #      branch 1 = B@xx.xx.xx.xx

        # and if you need a third destination ...

        # copy the current branch (branches[0]) into
        # a new branch (branches[2])
        append_branch();

        # all URI manipulation functions work on branches[0]
        # thus, URI manipulation does not touch the 
        # appended branch (branches[1-2])
        seturi("sip:D@domain");

        # now: branch 0 = D@domain
        #      branch 1 = B@xx.xx.xx.xx
        #      branch 2 = C@domain

        t_relay();
        exit;
    };

    # You could also use append_branch("sip:C@domain") which adds a branch with the new URI:


    if(method=="INVITE" && uri=~"sip:B@xx.xxx.xx ") {
        # append a new branch with the second destination
        append_branch("sip:user@domain");
        # now: branch 0 = B@xx.xx.xx.xx
        # now: branch 1 = C@domain

        t_relay();
        exit;
}

cache_store( storage_id, attribute_name, attribute_name [,timeout])

This sets in a memory-cache-like-storage system a new value for an attribute. Both the attribute name and value may contain pseudo-variables. If the attribute does not already exist in the memcache, it will be inserted with the given value; if already present, its value will be replaced with the new one. The function may optionally take an extra parameter, a timeout (or lifetime) value for the attribute - after the lifetime is exceeded, the attribute is automatically purged from memcache.

Function returns true is the new attribute was successfully inserted.

cache_store("local","my_attr","$avp(i:55)",1200);

OR

modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")
...
cache_store("redis:cluster1","passwd_$tu","$var(x)");

More complex examples can be found in the Key-Value Interface Tutorial.

cache_remove( storage_id, attribute_name)

This removes an attribute from a memory-cache-like-storage system. The attribute name may contain pseudo-variables. Function returns false only if the storage_id is invalid.

cache_remove("local","my_attr");

OR

modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")
...
cache_remove("redis:cluster1","my_attr");

More complex examples can be found in the Key-Value Interface Tutorial.

cache_fetch( storage_id, attribute_name, result_pvar)

This function fetches from a memory-cache-like-storage system the value of an attribute. The attribute name may contain pseudo-variables. The result (if any) will be stored in the pseudo-variable specified by result_pvar.

Function returns true if the attribute was found and its value returned.

cache_fetch("local","my_attr", $avp(i:11) );

OR

modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")
...
cache_fetch("redis:cluster1","my_attr",$avp(i:11));

More complex examples can be found in the Key-Value Interface Tutorial.

cache_counter_fetch( storage_id, counter_attribute_name, result_avp)

This function fetches from a memory-cache-like-storage system the value of a counter. The attribute name may contain pseudo-variables. The result (if any) will be stored in the pseudo-variable specified by result_pvar.

Function returns true if the attribute was found and its value returned.

cache_counter_fetch("local","my_counter", $avp(counter_val) );

OR

modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")
...
cache_fetch("redis:cluster1","my_counter",$avp(redis_counter_val));

cache_add( storage_id, attribute_name,increment_value,expire,[new_val_pvar])

This increments an attribute in a memory-cache-like-storage system that supports such an operation. The attribute name may contain pseudo-variables. If the attribute does not exit, it will be created with the increment_value. If expire > 0, the key will also expire in the specified number of seconds.

Function returns false if increment fails.

Optionally, the function receives one last parameter as a pvar in which to fetch the new value of the counter.


modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")
...
cache_add("redis:cluster1",5);

More complex examples can be found in the Key-Value Interface Tutorial.

cache_sub( storage_id, attribute_name,increment_value,expire,[new_val_pvar])

This decrements an attribute in a memory-cache-like-storage system that supports such an operation. The attribute name may contain pseudo-variables. If expire > 0, the key will also expire in the specified number of seconds.

Function returns false if decrement fails.

Optionally, the function receives one last parameter as a pvar in which to fetch the new value of the counter.


modparam("cachedb_redis","cachedb_url","redis:cluster1://193.168.3.134:6379/")
...
cache_sub("redis:cluster1",5);

More complex examples can be found in the Key-Value Interface Tutorial.

cache_raw_query( storage_id, raw_query,result_avp)

The function runs the provided raw query ( in the back-end dependent language ) and returns the results ( if any ) in the provided AVP. The result_avp can be missing, if the query returns no results.

Function returns false if query fails.

...
cache_raw_query("mongodb","{ \"op\" : \"count\",\"query\": { \"username\" : $rU} }","$avp(mongo_count_result)");
...

More complex examples can be found in the Key-Value Interface Tutorial.

break()

Since v0.10.0-dev3, 'break' can no longer be used to stop the execution of a route. The only place to use is to end a 'case' block in a 'switch' statement. 'return' must be now used instead of old 'break'.

'return' and 'break' have now a similar meaning as in c/shell.

construct_uri(proto,user,domain,port,extra,result_avp)

The function builds a valid sip uri based on the arguments it receives. The result (if any) will be stored in the result_avp AVP variable. The function accepts plain text arguments, as well as $var and $avp variables. If you want to omit a part of the sip uri, just set the respective parameter to a blank string.

Example usage:

construct_uri("$var(proto)", "vlad", "$var(domain)", "", "$var(params)",$avp(s:newuri));
xlog("Constructed URI is <$avp(s:newuri)> \n");

drop()

Stop the execution of the configuration script and alter the implicit action which is done afterwards.

If the function is called in a 'branch_route' then the branch is discarded (implicit action for 'branch_route' is to forward the request).

If the function is called in a 'onreply_route' then any provisional reply is discarded (implicit action for 'onreply_route' is to send the reply upstream according to Via header).

Example of usage:

    onreply_route {
        if(status=="183") {
            drop();
        }
    }

exit()

Stop the execution of the configuration script -- it has the same behaviour as return(0). It does not affect the implicit action to be taken after script execution.

  route {
    if (route(2)) {
      xlog("L_NOTICE","method $rm is INVITE\n");
    } else {
      xlog("L_NOTICE","method is $rm\n");
    };
  }

  route[2] {
    if (is_method("INVITE")) {
      return(1);
    } else if (is_method("REGISTER")) {
      return(-1);
    } else if (is_method("MESSAGE")) {
      sl_send_reply("403","IM not allowed");
      exit;
    };
  }

force_rport()

Force_rport() adds the rport parameter to the first Via header. Thus, OpenSIPS will add the received IP port to the top most via header in the SIP message, even if the client does not indicate support for rport. This enables subsequent SIP messages to return to the proper port later on in a SIP transaction.

The rport parameter is defined in RFC 3581.

Example of usage:

    force_rport();

force_send_socket([proto:]address[:port])

Force OpenSIPS to send the message from the specified socket (it _must_ be one of the sockets OpenSIPS listens on). If the protocol doesn't match (e.g. UDP message "forced" to a TCP socket) the closest socket of the same protocol is used.

Example of usage:

    force_send_socket(10.10.10.10:5060);

force_tcp_alias()

force_tcp_alias(port)

adds a tcp port alias for the current connection (if tcp). Usefull if you want to send all the trafic to port_alias through the same connection this request came from [it could help for firewall or nat traversal]. With no parameters adds the port from the message via as the alias. When the "aliased" connection is closed (e.g. it's idle for too much time), all the port aliases are removed.

forward(destination)

Forward the SIP request to the given destination in stateless mode. This has the format of [proto:]host[:port]. Host can be an IP or hostname; supported protocols are UDP, TCP and TLS. (For TLS, you need to compile the TLS support into core). If proto or port are not specified, NAPTR and SRV lookups will be used to determine them (if possible).

If destination parameter is missing, the forward will be done based on RURI.

Example of usage:

    forward("10.0.0.10:5060");
    #or
    forward();

get_timestamp(sec_avp,usec_avp)

Returns the current timestamp, seconds and microseconds of the current second, from a single system call.

Example of usage:

     get_timestamp($avp(sec),$avp(usec));

isdsturiset()

Test if the dst_uri field (next hop address) is set.

Example of usage:

    if(isdsturiset()) {
        log("dst_uri is set\n");
    };

isflagset(int)

Test if a flag is set for current processed message (if the flag value is 1). The value of the parameter can be in range of 0..31.

For more see Flags Documentation.

Example of usage:

    if(isflagset(3)) {
        log("flag 3 is set\n");
    };

isbflagset([branch_idx,] flag_idx)

Test if a flag is set for a specific branch (if the flag value is 1). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flags are tested - it must be a positiv number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

For more about script flags, see Flags Documentation.

Example of usage:

    if(isbflagset(1,3)) {
        log("flag 3 is set in branch 1\n");
    };

issflagset(flag_idx)

Test if a script flag is set (if the flag value is 1). The value of the "flag_idx" parameter can be in range of 0..31.

For more about script flags, see Flags Documentation.

Example of usage:

    if(issflagset(2)) {
        log("script flag 2 is set\n");
    };

log([level,] string)

Write text message to standard error terminal or syslog. You can specify the log level as first parameter.

Example of usage:

    log("just some text message\n");

next_branches()

Adds to the request a new destination set that includes all highest priority class contacts ('q' value based) from the serialized branches (see serialize_branches()). If called from a route block, it rewrites the request uri with first contact and adds the remaining contacts as parallel branches. If called from failure route block, adds all contacts as parallel branches. All used contacts are removes the serialized branches.

Returns true if at least one contact was added for the request's destination set - returns 1 if other branches are still pending and return 2 if no other branches are left for future processing - shortly, if 2: this is the last branch, if 1: other will follow. False is return is nothing was done (no more serialized branches).

Example of usage:

    next_branches();

prefix(string)

Add the string parameter in front of username in R-URI.

Example of usage:

    prefix("00");

pv_printf(pv, string)

Prints the formatted 'string' in the AVP 'pv'. The 'string' parameter can include any pseudo-variable defined in OpenSIPS. The 'pv' can be any writable pseudo-variable -- e.g.,: AVPs, VARs, $ru, $rU, $rd, $du, $br, $fs.

It was extended from the avp_printf(...) function exported in previous versions by the avpops module. Starting with 1.3.1, avp_printf(...) is just an alias to pv_printf(...).

Example of usage:

    pv_printf("$var(x)", "r-uri: $ru");
    pv_printf("$avp(i:3)", "from uri: $fu");

raise_event(string[, avp[, avp]])

Raises from script an event through OpenSIPS Event Interface. The first parameter is a string that indicates the event which should be raised. The next two parameters should be AVPs and they are optional. If only one is present, it should contain the values attached to the event. If both of them are specified, the first one should contain the names of the attributes, and the last one the values attached to the event.

This function triggers an event for all subscribers for that event, regardless the transport module used.

Example of usage (raises an event with no attributes):

raise_event("E_NO_PARAM");

Example of usage (raises an event with two attributes):

$avp(attr-name) = "param1";
$avp(attr-name) = "param2";
$avp(attr-val) = 1;
$avp(attr-val) = "2"
raise_event("E_TWO_PARAMS", $avp(attr-name), $avp(attr-val));

remove_branch(pv|int)

Removes a given branch. The branch to be removed can be given via an integer or a pseudovariable. Once a branch is remove, all the subsequent branches are shifted (i.e. if branch n is removed, then the old n+1 branch becomes the new n branch, the old n+2 branch becomes n+1 and so on).

Example of usage (remove all branches with URI hostname "127.0.0.1"):

$var(i) = 0;
while ($(branch(uri)[$var(i)]) != null) {
   xlog("L_INFO","$$(branch(uri)[$var(i)])=[$(branch(uri)[$var(i)])]\n");
   if ($(branch(uri)[$var(i)]{uri.host}) == "127.0.0.1") {
       xlog("L_INFO","removing branch $var(i) with URI=[$(branch(uri)[$var(i)])]\n");
       remove_branch($var(i));
   } else {
       $var(i) = $var(i) + 1;
   }
}

return(int)

The return() function allows you to return any integer value from a called route() block. You can test the value returned by a route using "$retcode" variable.

return(0) is same as "exit()";

In bool expressions:

  * Negative and ZERO is FALSE
  * Positive is TRUE

Example usage:

route {
  if (route(2)) {
    xlog("L_NOTICE","method $rm is INVITE\n");
  } else {
    xlog("L_NOTICE","method $rm is REGISTER\n");
  };
}
route[2] {
  if (is_method("INVITE")) {
    return(1);
  } else if (is_method("REGISTER")) {
    return(-1);
  } else {
    return(0);
  };
}

resetdsturi()

Set the value of dst_uri filed to NULL. dst_uri field is usually set after loose_route() or lookup("location") if the contact address is behind a NAT.

Example of usage:

    resetdsturi();

resetflag(int)

Reset a flag for current processed message (set the value to 0). The value of the parameter can be in range of 0..31.

For more see Flags Documentation.

Example of usage:

    resetflag(3);

resetbflag([branch_idx,] flag_idx)

Reset a flag for a specific branch (set flag to value 0). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flag is reset - it must be a positiv number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

For more about script flags, see Flags Documentation.

Example of usage:

    resetbflag(1,3);
    # or
    resetbflag(3); # same with resetbflag(0,3)

resetsflag(flag_idx)

Reset a script flag (set flag to value 0). The value of the "flag_idx" parameter can be in range of 0..31.

For more about script flags, see Flags Documentation.

Example of usage:

    resetsflag(2);

revert_uri()

Set the R-URI to the value of the R-URI as it was when the request was received by server (undo all changes of R-URI).

Example of usage:

    revert_uri();

rewritehost() / sethost()

Rewrite the domain part of the R-URI with the value of function's parameter. Other parts of the R-URI like username, port and URI parameters remain unchanged.

Example of usage:

    rewritehost("1.3.1.4");

rewritehostport() / sethostport()

Rewrite the domain part and port of the R-URI with the value of function's parameter. Other parts of the R-URI like username and URI parameters remain unchanged.

Example of usage:

    rewritehostport("1.3.1.4:5080");

rewriteuser(string) / setuser(string)

Rewrite the user part of the R-URI with the value of function's parameter.

Example of usage:

    rewriteuser("newuser");

rewriteuserpass() / setuserpass()

Rewrite the password part of the R-URI with the value of function's parameter.

Example of usage:

    rewriteuserpass("my_secret_passwd");

rewriteport() / setport()

Rewrites/sets the port part of the R-URI with the value of function's parameter.

Example of usage:

    rewriteport("5070");

rewriteuri(str) / seturi(str)

Rewrite the request URI.

Example of usage:

    rewriteuri("sip:test@opensips.org");

route(name [, param1 [, param2 [, ...] ] ] )

This function is used to run the code from the 'name' route, declared in the script. Optionally, it can receive several parameters (up to 7), that can be later retrieved using the '$param(idx)' pseudo-variable.

The name of the route is an identifier format, whereas the parameters can be either int, string, or a pseudo-variable.

Example of usage:

   route(HANDLE_SEQUENTIALS);
   route(HANDLE_SEQUENTIALS, 1, "param", $var(param));

script_trace( log_level, pv_format_string[, info_string])

This function start the script tracing - this helps to better understand the flow of execution in the OpenSIPS script, like what function is executed, what line it is, etc. Moreover, you can also trace the values of pseudo-variables, as script execution progresses.

The blocks of the script where script tracing is enabled will print a line for each individual action that is done (e.g. assignments, conditional tests, module functions, core functions, etc.). Multiple pseudo-variables can be monitored by specifying a pv_format_string (e.g. "$ru---$avp(var1)").

The logs produced by multiple/different traced regions of your script can be differentiated (tagged) by specifying an additional plain string - info_string - as the 3rd parameter.

To disable script tracing, just do script_trace(). Otherwise, the tracing will automatically stop at the end the end of the top route.

Example of usage:

    script_trace( 1, "$rm from $si, ruri=$ru", "me");

will produce:

    [line 578][me][module consume_credentials] -> (INVITE from 127.0.0.1 , ruri=sip:111211@opensips.org)
    [line 581][me][core setsflag] -> (INVITE from 127.0.0.1 , ruri=sip:111211@opensips.org)
    [line 583][me][assign equal] -> (INVITE from 127.0.0.1 , ruri=sip:111211@opensips.org)
    [line 592][me][core if] -> (INVITE from 127.0.0.1 , ruri=sip:tester@opensips.org)
    [line 585][me][module is_avp_set] -> (INVITE from 127.0.0.1 , ruri=sip:tester@opensips.org)
    [line 589][me][core if] -> (INVITE from 127.0.0.1 , ruri=sip:tester@opensips.org)
    [line 586][me][module is_method] -> (INVITE from 127.0.0.1 , ruri=sip:tester@opensips.org)
    [line 587][me][module trace_dialog] -> (INVITE 127.0.0.1 , ruri=sip:tester@opensips.org)
    [line 590][me][core setflag] -> (INVITE from 127.0.0.1 , ruri=sip:tester@opensips.org) 

send(destination [, headers])

Send the original SIP message to a specific destination in stateless mode. This is definied as [proto:]host[:port]. No changes are applied to received message, no Via header is added, unless headers parameter is specified. Host can be an IP or hostname; supported protocols are UDP, TCP and TLS. (For TLS, you need to compile the TLS support into core). If proto or port are not specified, NAPTR and SRV lookups will be used to determine them (if possible). The headers parameter should end in '\r\n' and can accept both plain text and pseudo variables.

Parameter is mandatory and has string format.

Example of usage:

   send("udp:10.10.10.10:5070");
   send("udp:10.10.10.10:5070", "Server: opensips\r\n");

serialize_branches(clear)

Takes all the branches added for parallel forking (with append_branch() and including the current RURI) and prepare them for serial forking. The ordering is done in increasing "q" order. The serialized branches are internally stored in AVPs - you will be able to fetch and use via the "next_branches()" function.
NOTE that (according to RFC3261), the branches with the same "q" value will still be parallel forked during a certain step in the serial forking (it will result a combination of serial with parallel forking).
NOTE that this function is not changing RURI in the messages - it is just converting from parallel to serial branches (preparing branches).

If "clear" is set to non-zero, all previous results of another "serialize_branches" (serialized branches which were not yet used) will be deleted before setting the new serialized branches.

Example of usage:

   serialize_branches(1);

set_advertised_address(ip|string)

Same as 'advertised_address' but it affects only the current message. It has priority if 'advertised_address' is also set.

Example of usage:

    set_advertised_address("opensips.org");

set_advertised_port(int)

Same as 'advertised_port' but it affects only the current message. It has priority over 'advertised_port'.

Example of usage:

    set_advertised_port(5080);

setdebug([level])

Changes the debug level of the current process from script. If called without the parameter then the debug level of the current process will be reset to the global level. If the debug level of the current process is changed then changing the global debug level (using MI function) does not affect it, so be careful and make sure to reset the process debug level when you are done. This function is very helpful if you are tracing and debugging only a specific piece of code.

Example of usage:

    debug= -1 # errors only
    .....
    {
      ......
      setdebug(4); # set the debug level of the current process to DBG
      uac_replace_from(....);
      setdebug(); # reset the debug level of the current process to the global level
      .......
    }

setdsturi(string)

Explicitely set the dst_uri field to the value of the paramater. The parameter has to be a valid SIP URI.

Example of usage:

    setdsturi("sip:10.10.10.10:5090");

setflag(int)

Set a flag for current processed message. The value of the parameter can be in range of 0..31. The flags are used to mark the message for special processing (e.g., accounting) or to keep some state (e.g., message authenticated).

Example of usage:

    setflag(3);

setbflag([branch_idx,] flag_idx)

Set a flag for a specific branch (set flag to value 1). The value of the "flag_idx" parameter can be in range of 0..31. "branch_idx" identify the branch for which the flag is set - it must be a positiv number. Branch index 0 refers to the RURI branch. If this parameter is missing, 0 branch index is used as default.

For more about script flags, see Flags Documentation.

Example of usage:

    setbflag(1,3);
    # or
    setbflag(3); # same with setbflag(0,3)

setsflag(flag_idx)

Set a script flag (set flag to value 0). The value of the "flag_idx" parameter can be in range of 0..31.

For more about script flags, see Flags Documentation.

Example of usage:

    setsflag(2);

strip(int)

Strip the first N-th characters from username of R-URI (N is the value of the parameter).

Example of usage:

    strip(3);

strip_tail(int)

Strip the last N-th characters from username of R-URI (N is the value of the parameter).

Example of usage:

  strip_tail(3);

subscribe_event(string, string [, int])

Subscribes an external application for a certain event for the OpenSIPS Event Interface. This is used for transport protocols that cannot subscribe by themselves (example event_rabbitmq). This function should be called only once in the startup_route if the subscription doesn't expire, or in a timer route if the subscription should be renewed once in a while.

The first parameter is a string represents the name of the event an external application should be notified for. The second parameter is a string that specifies the socket of the external application. Note that this socket should follow the syntax of an existing loaded Event Interface transport module (example: event_datagram, event_rabbitmq). The last parameter is optional and specifies the expire time of the subscription. If it is not present, then the subscription does not expire at all.

Example of usage (subscriber that never expires, notified by the RabbitMQ module):

startup_route {
    subscribe_event("E_PIKE_BLOCKED", "rabbitmq:127.0.0.1/pike");
}

Example of usage (subscriber expires every 5 seconds, notified through UDP):

timer_route[event_subscribe, 4] {
    subscribe_event("E_PIKE_BLOCKED", "udp:127.0.0.1:5051", 5);
}

use_blacklist(string)

Enables the DNS blacklist name received as parameter. Its primary purposes will be to prevent sending requests to critical IPs (like GWs) due DNS or to avoid sending to destinations that are known to be unavailable (temporary or permanent).

    use_blacklist("pstn-gws");

Page last modified on September 01, 2021, at 10:21 AM