### Example HTTP GET Query
Source: https://docs.opensips.org/manual/3-6/modules/db_http
Demonstrates the format of a GET request sent to the database server.
```http
GET /presentity/?c=username,domain,event,expires HTTP/1.1
```
--------------------------------
### Install OpenSIPS
Source: https://docs.opensips.org/manual/3-6/install-compileandinstall
Install the compiled binaries and files to the configured prefix.
```bash
make install
```
--------------------------------
### Sample HttpServlet Implementation
Source: https://docs.opensips.org/manual/3-6/modules/seas
A standard Java HttpServlet example demonstrating how to handle HTTP GET requests and output HTML content based on request headers.
```Java
public final class Hello extends HttpServlet {
protected void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.println("");
writer.println("
");
writer.println("Sample Application Servlet");
writer.println("");
writer.println("");
writer.println("");
Enumeration names = request.getHeaderNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
writer.println("");
writer.println("| "+name+": | ");
writer.println(""+request.getHeader(name)+" | ");
writer.println("
");
}
writer.println("
");
writer.println("");
writer.println("");
}
}
```
--------------------------------
### Call example() function
Source: https://docs.opensips.org/manual/3-6/modules/example
Executes the example function to print a log message. Can be used from any route.
```OpenSIPS Script
...
example();
...
```
--------------------------------
### Complete script example
Source: https://docs.opensips.org/manual/3-6/modules/uac_redirect
A full configuration example demonstrating module loading and usage of get_redirects within a failure route.
```OpenSIPS Script
loadmodule "modules/sl/sl.so"
loadmodule "modules/usrloc/usrloc.so"
loadmodule "modules/registrar/registrar.so"
loadmodule "modules/tm/tm.so"
loadmodule "modules/acc/acc.so"
loadmodule "modules/uac_redirect/uac_redirect.so"
modparam("usrloc", "db_mode", 0)
route{
if (is_myself("$rd")) {
if ($rm=="REGISTER") {
save("location");
exit;
};
if (!lookup("location")) {
sl_send_reply(404, "Not Found");
exit;
};
}
t_on_failure("do_redirect");
if (!t_relay()) {
sl_reply_error();
};
}
failure_route[do_redirect] {
if (get_redirects(3, 1))
t_relay();
}
```
--------------------------------
### HTTP Database Query Examples
Source: https://docs.opensips.org/manual/3-6/modules/db_http
Examples of GET and POST requests for database operations using URL parameters.
```HTTP
GET /presentity/?c=username,domain,event,expires HTTP/1.1
GET /version/?k=table_name&v=xcap&c=table_version HTTP/1.1
```
```HTTP
POST /active_watchers HTTP/1.1
k=id&v=100&query_type=insert
```
--------------------------------
### Route to Carrier Examples
Source: https://docs.opensips.org/manual/3-6/modules/drouting
Examples of using route_to_carrier with and without partitions enabled.
```opensips
# use_partitions is not set
if ( route_to_carrier("my_top_carrier, def_carrier", , $var(carrier_att)) ) {
xlog("Routing to \"my_top_carrier\" - $var(carrier_att)\n");
t_on_failure("next_gw");
t_relay();
exit;
}
```
```opensips
# use_partitions is enabled
if ( route_to_carrier("my_top_carrier", , $var(carrier_att), "part") ) {
xlog("Routing to \"my_top_carrier\" - $var(carrier_att)\n");
t_on_failure("next_gw");
t_relay();
exit;
}
```
```opensips
# use_partitions is enabled
if ( route_to_carrier($var(carrierId), , , $var(my_partition)) ) {
xlog("Routing to \"my_top_carrier\"\n");
t_on_failure("next_gw");
t_relay();
exit;
}
```
--------------------------------
### Deploy LocalStack for SQS Testing
Source: https://docs.opensips.org/manual/3-6/modules/event_sqs
Commands to install and start LocalStack for local SQS development.
```bash
pip install localstack
localstack start
```
--------------------------------
### Install libmemcached
Source: https://docs.opensips.org/manual/3-6/modules/cachedb_memcached
Commands to download, compile, and install the required libmemcached library.
```bash
$ wget http://download.tangent.org/libmemcached-0.31.tar.gz
$ tar -xzvf libmemcached-0.31.tar.gz
$ cd libmemcached-0.31
$ ./configure
$ make
$ sudo make install
```
--------------------------------
### Install ldserverapi library
Source: https://docs.opensips.org/manual/3-6/modules/launch_darkly
Instructions for cloning and installing the required ldserverapi library as a shared library.
```bash
$ git clone https://github.com/launchdarkly/c-server-sdk.git
$ cd c-server-sdk
$ cmake -DBUILD_SHARED_LIBS=On -DBUILD_TESTING=OFF .
$ sudo make install
```
--------------------------------
### Start MySQL server
Source: https://docs.opensips.org/manual/3-6/modules/db_unixodbc
Command to start the MySQL server with a specific socket path.
```shell
shell>safe_mysqld --user=mysql --socket=/var/lib/mysql/mysql.sock
```
--------------------------------
### Additional Credentials Syntax Examples
Source: https://docs.opensips.org/manual/3-6/modules/auth_aaa
Examples of how additional credentials are formatted as strings to be stored as OpenSIPS AVPs.
```text
....
"email:joe@yahoo.com"
- STRING NAME AVP (email) with STRING VALUE (joe@yahoo.com)
"#14:joe@yahoo.com"
- ID AVP (14) with STRING VALUE (joe@yahoo.com)
"age#28"
- STRING NAME AVP (age) with INTEGER VALUE (28)
"#14#28"
- ID AVP (14) with INTEGER VALUE (28)
....
```
--------------------------------
### Measure duration in script
Source: https://docs.opensips.org/manual/3-6/modules/benchmark
Example of wrapping a function call with timer start and log commands.
```opensips
...
bm_start_timer("usrloc-lookup");
lookup("location");
bm_log_timer("usrloc-lookup");
...
```
--------------------------------
### Configure Installation Prefix
Source: https://docs.opensips.org/manual/3-6/install-compileandinstall
Set the root directory for the OpenSIPS installation.
```makefile
PREFIX ?= /opt/opensips/
```
--------------------------------
### Infrastructure ENUM TXT record example
Source: https://docs.opensips.org/manual/3-6/modules/enum
Example DNS records for the 'txt' branching algorithm.
```dns
i.1.e164.arpa. IN TXT "4"
9.9.9.8.7.6.5.i.4.3.2.1.e164.arpa. IN NAPTR "NAPTR content for +1 234 5678 999"
```
--------------------------------
### Configure authentication modules
Source: https://docs.opensips.org/manual/3-6/modules/db_unixodbc
Example configuration for auth and auth_db modules to work with the database.
```opensips
....
loadmodule "/usr/local/lib/opensips/modules/auth.so"
loadmodule "/usr/local/lib/opensips/modules/auth_db.so"
modparam("usrloc", "db_mode", 2)
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
....
```
--------------------------------
### Retrieve startup arguments
Source: https://docs.opensips.org/manual/3-6/interface-coremi
Returns the full list of arguments used to start the OpenSIPS binary.
```bash
$ opensips-cli -x mi arg
[
"./opensips",
"-f",
"/etc/openser/test.cfg"
]
```
--------------------------------
### rtpengine_start_forwarding([flags[, sockvar]])
Source: https://docs.opensips.org/manual/3-6/modules/rtpengine
Starts forwarding media to a TLS destination.
```APIDOC
## rtpengine_start_forwarding
### Description
Starts forwarding the media to a TLS destination specified in the tls-send-to parameter of RTPEngine. You can select the media stream to forward by specifying the from-tag.
### Parameters
- **flags** (string) - Optional - A list of flags.
- **sockvar** (var) - Optional - Socket variable.
```
--------------------------------
### SNMP Table Output Example
Source: https://docs.opensips.org/manual/3-6/modules/snmpstats
Example output format returned by the snmptable command.
```text
index openserSIPUserUri openserSIPUserAuthenticationFailures
1 DefaultUser 0
2 bogdan 0
3 jeffrey.magder 0
```
--------------------------------
### example()
Source: https://docs.opensips.org/manual/3-6/modules/example
Prints a message to the log indicating that the function has been called. This function can be used from any route.
```APIDOC
## example()
### Description
Prints a message to the log indicating that the function has been called. This function can be used from any route.
### Usage
```
example();
```
```
--------------------------------
### Kafka socket syntax example
Source: https://docs.opensips.org/manual/3-6/modules/event_kafka
Example of a Kafka socket string including broker address, topic, and configuration properties.
```OpenSIPS Script
kafka:127.0.0.1:9092/topic1?t.message.timeout.ms=1000&key=callid
```
--------------------------------
### IMC Command Examples
Source: https://docs.opensips.org/manual/3-6/modules/imc
Examples of various IMC commands used for managing conference rooms and memberships.
```text
#create chat-000 private
```
```text
join sip:chat-000@opensips.org
```
```text
#join
```
```text
#invite sip:john@opensips.org sip:chat-000@opensips.org
```
```text
#invite john@opensips.org
```
```text
#accept sip:john@opensips.org
```
```text
#remove sip:john@opensips.org
```
--------------------------------
### Alternative Regex Grouping Example
Source: https://docs.opensips.org/manual/3-6/modules/regex
A secondary example showing how different input groups are mapped to compiled regex output.
```text
[1]
^aaa
^bbb
[2]
^ccc
^ddd
```
```text
group 0: ((^aaa)|(^bbb))
group 1: ((^ccc)|(^ddd))
```
--------------------------------
### Configure b2b_init_request flags
Source: https://docs.opensips.org/manual/3-6/modules/b2b_logic_xml
Example of flag definitions for the b2b_init_request function.
```text
*t[nn]* - Call setup timeout for topology hiding scenario.
Example: t300.
*a* - Transparent authentication. In this mode b2b passes your 401
or 407 authentication request to destination server.
*p* - Preserve To: header.
```
--------------------------------
### Configure launch_darkly module parameters
Source: https://docs.opensips.org/manual/3-6/modules/launch_darkly
Configuration examples for the mandatory SDK key and optional module parameters.
```opensips
modparam("launch_darkly", "sdk_key", "sdk-12345678-abcd-12ab-1234-0123456789abc")
```
```opensips
modparam("launch_darkly", "ld_log_level", "LD_LOG_CRITICAL")
```
```opensips
modparam("launch_darkly", "connect_wait", 100)
```
```opensips
modparam("launch_darkly", "re_init_interval", 30)
```
--------------------------------
### Carrierroute Routing Table Example
Source: https://docs.opensips.org/manual/3-6/modules/carrierroute
Example of a routing table configuration for the carrierroute module, demonstrating prefix-based routing and carrier selection.
```SQL
+----+---------+--------+-------------+-------+------+---------------+
| id | carrier | domain | scan_prefix | flags | prob | rewrite_host |
+----+---------+--------+-------------+-------+------+---------------+
| 1 | 1 | 0 | 49 | 0 | 0.5 | de-1.carrier1 |
| 2 | 1 | 0 | 49 | 0 | 0.5 | de-2.carrier1 |
| 3 | 1 | 0 | 49 | 16 | 1 | de-3.carrier1 |
| 4 | 1 | 0 | | 0 | 1 | gw.carrier1-1 |
| 5 | 1 | 1 | 49 | 0 | 1 | gw.carrier1-1 |
| 6 | 1 | 2 | | 0 | 1 | gw.carrier1-2 |
| 7 | 1 | 3 | | 0 | 1 | gw.carrier1-3 |
| 8 | 2 | 0 | 49 | 0 | 0.5 | de-1.carrier2 |
| 9 | 2 | 0 | 49 | 0 | 0.5 | de-2.carrier2 |
| 10 | 2 | 0 | | 0 | 1 | gw.carrier2 |
| 11 | 2 | 1 | 49 | 0 | 1 | gw.carrier2 |
| 12 | 3 | start | 49 | 0 | 1 | de-gw.default |
| 13 | 3 | start | | 0 | 1 | gw.default |
+----+---------+--------+-------------+-------+------+---------------+
```
--------------------------------
### ua_session_client_start
Source: https://docs.opensips.org/manual/3-6/modules/b2b_entities
Starts a new UAC session by sending an initial INVITE.
```APIDOC
## ua_session_client_start
### Description
Starts a new UAC session by sending an initial INVITE. Further requests/replies will be handled via the E UA SESSION event.
### Parameters
- **ruri** (string) - Required - Request URI
- **to** (string) - Required - To URI; can include display name (e.g., display_name,uri)
- **from** (string) - Required - From URI; can include display name (e.g., display_name,uri)
- **proxy** (string) - Optional - URI of the outbound proxy
- **body** (string) - Optional - Message body
- **content_type** (string) - Optional - Content Type header
- **extra_headers** (string) - Optional - Extra headers
- **flags** (string) - Optional - Session flags
- **socket** (string) - Optional - OpenSIPS sending socket
### Command
`opensips-cli -x mi ua_session_client_start ruri=sip:bob@opensips.org to=sip:bob@opensips.org from=sip:alice@opensips.org flags=arhb`
```
--------------------------------
### rtpengine_start_recording([flags [, sock_var]])
Source: https://docs.opensips.org/manual/3-6/modules/rtpengine
Sends a signal to the RTP proxy to start recording the RTP stream.
```APIDOC
## rtpengine_start_recording([flags [, sock_var]])
### Description
This function sends a signal to the RTP proxy to record the RTP stream.
### Parameters
- **flags** (string, optional) - Flags to change recorder behavior (e.g., call-id).
- **sock_var** (var, optional) - Variable to store the rtpengine socket.
```
--------------------------------
### Start Media Forwarding
Source: https://docs.opensips.org/manual/3-6/modules/rtpengine
Initiates media forwarding to a TLS destination.
```OpenSIPS Script
...
rtpengine_start_forwarding();
...
```
--------------------------------
### Handle feature status in script routes
Source: https://docs.opensips.org/manual/3-6/modules/presence_dfks
Example implementation of set and get routes using $dfks pseudo-variables to manage feature status and values.
```OpenSIPS Script
...
route[dfks_set] {
# CallForwardingAlways is not allowed
if ($dfks(feature) == "CallForwardingAlways")
$dfks(status) = 0;
xlog("New status: $dfks(status) for feature '$dfks(feature)' of user '$dfks(presentity)'\n");
}
route[dfks_get] {
if ($dfks(feature) == "CallForwardingNoAnswer") {
$dfks(status) = 1;
$dfks(value/forwardTo) = "sip:bob@10.0.0.11";
$dfks(value/ringCount) = "3";
} else if ($dfks(feature) == "CallForwardingAlways")
$dfks(assigned) = 0;
} else {
...
}
}
...
```
--------------------------------
### Basic Preprocessor Usage
Source: https://docs.opensips.org/manual/3-6/templating-config-files
Demonstrates the -p option for piping configuration files through standard command-line tools.
```bash
opensips -f opensips.cfg -p /bin/cat
```
```bash
opensips -f opensips.cfg -p "/bin/sed s/PRIVATE_IP/10.0.0.10/g"
```
--------------------------------
### Start RTP Stream Recording
Source: https://docs.opensips.org/manual/3-6/modules/rtpproxy
Examples of initiating RTP stream recording, including options for remote UDP destinations and specific media stream selection.
```OpenSIPS Script
...
rtpproxy_start_recording();
# copy RTP stream to a different listener
rtpproxy_start_recording(,,,"udp:127.0.0.1:60000");
# copy only first RTP stream (audio stream)
rtpproxy_start_recording(,,,"udp:127.0.0.1:60000", 1);
...
```
--------------------------------
### Load and Configure Modules
Source: https://docs.opensips.org/manual/3-6/script-syntax
Demonstrates loading modules using loadmodule and setting parameters with modparam.
```text
loadmodule "modules/mi_datagram/mi_datagram.so"
modparam("mi_datagram", "socket_name", "udp:127.0.0.1:4343")
modparam("mi_datagram", "children_count", 3)
```
```text
mpath="/usr/local/opensips_proxy/lib/modules"
loadmodule "mi_datagram.so"
modparam("mi_datagram", "socket_name", "udp:127.0.0.1:4343")
modparam("mi_datagram", "children_count", 3)
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
```
--------------------------------
### Regex Configuration File Format
Source: https://docs.opensips.org/manual/3-6/modules/regex
Example of the required file format for grouping regular expressions. Lines starting with symbols like # are ignored, and each expression must occupy a single line.
```text
### List of User-Agents publishing presence status
[0]
# Softphones
^Twinkle/1
^X-Lite
^eyeBeam
^Bria
^SIP Communicator
^Linphone
# Deskphones
^Snom
# Others
^SIPp
^PJSUA
### Blacklisted source IP's
[1]
^190\.232\.250\.226$
^122\.5\.27\.125$
^86\.92\.112\.
### Free PSTN destinations in Spain
[2]
^1\d{3}$
^((\+|00)34)?900\d{6}$
```
--------------------------------
### launch() syntax variants
Source: https://docs.opensips.org/manual/3-6/script-async
Demonstrates the different ways to invoke the launch() statement, including optional report routes and parameter passing.
```opensips
launch(blocking_function(...));
or
launch(blocking_function(...), report_route);
route[report_route] {}
or
launch(blocking_function(...), report_route, "Something with $var(xx) to be passed to report route");
route[report_route] {
xlog("received as input the <$param(1)> string\n");
}
```
--------------------------------
### Example of do_routing usage
Source: https://docs.opensips.org/manual/3-6/modules/drouting
Basic usage snippet for the do_routing function.
```OpenSIPS Script
...
# all groups, sort on order,
```
--------------------------------
### Start UAC Session
Source: https://docs.opensips.org/manual/3-6/modules/b2b_entities
Initiates a new UAC session by sending an INVITE request.
```bash
opensips-cli -x mi ua_session_client_start ruri=sip:bob@opensips.org \
to=sip:bob@opensips.org from=sip:alice@opensips.org flags=arhb
```
--------------------------------
### Initialize Makefile.conf
Source: https://docs.opensips.org/manual/3-6/install-compileandinstall
Create the configuration file from the template before editing build settings.
```bash
cp Makefile.conf.template Makefile.conf
```
--------------------------------
### Call example_str() function
Source: https://docs.opensips.org/manual/3-6/modules/example
Logs a provided string or the default_str parameter if no argument is passed.
```OpenSIPS Script
...
example_str("test");
...
```
--------------------------------
### Configure onreply_route blocks in OpenSIPS
Source: https://docs.opensips.org/manual/3-6/script-routes
Example demonstrating the configuration of global, branch-specific, and transaction-specific reply routes.
```opensips
route {
$ru = "sip:bob@opensips.org"; # first branch
$msg.branch = "sip:alice@opensips.org"; # second branch
t_on_reply("global"); # the "global" reply route
# is set the whole transaction
t_on_branch("1");
t_relay();
}
branch_route[1] {
if ($rU=="alice")
t_on_reply("alice"); # the "alice" reply route
# is set only for second branch
}
onreply_route {
xlog("OpenSIPS received a reply from $si\n");
}
onreply_route[alice] {
xlog("received reply on the branch from alice\n");
}
onreply_route[global] {
if (t_check_status("1[0-9][0-9]")) {
setflag("PROVISIONAL_REPLY");
log("provisional reply received\n");
if (t_check_status("183"))
drop;
}
}
```
--------------------------------
### Default Configuration File Path
Source: https://docs.opensips.org/manual/3-6/configure-file
The standard location for the OpenSIPS configuration file after installation.
```text
[INSTALL_PATH]/etc/opensips/opensips.cfg
```
--------------------------------
### Authorize a call with cgrates_cmd
Source: https://docs.opensips.org/manual/3-6/modules/cgrates
Example of setting session parameters and executing an authorization command.
```OpenSIPS Script
...
# cgrates_auth($fU, $rU); simulation
$cgr_opt(Tenant) = $fd;
$cgr(Account) = $fU;
$cgr(OriginID) = $ci;
$cgr(SetupTime) = "" + $Ts;
$cgr(RequestType) = "*prepaid";
$cgr(Destination) = $rU;
cgrates_cmd("SessionSv1.AuthorizeEvent");
xlog("Call is allowed to run $cgr_ret seconds\n");
...
```
--------------------------------
### AVP Copy Examples
Source: https://docs.opensips.org/manual/3-6/modules/avpops
Examples of copying or moving AVPs using avp_copy.
```opensips
...
avp_copy("$avp(foo)", "$avp(bar)/g");
avp_copy("$avp(old)", "$avp(new)/gd"); # also deletes $avp(old)
...
```
--------------------------------
### OpenSIPS Dispatcher Configuration Script
Source: https://docs.opensips.org/manual/3-6/modules/dispatcher
A sample configuration file demonstrating module loading, database parameter setup, and basic request routing using the dispatcher module.
```opensips
#
# sample config file for dispatcher module
#
socket= udp:*:5060
udp_workers = 2
check_via = off # (cmd. line: -v)
dns = off # (cmd. line: -r)
rev_dns = off # (cmd. line: -R)
# for more info: opensips -h
# ------------------ module loading ----------------------------------
mpath = "/usr/lib/x86_64-linux-gnu/opensips/modules"
loadmodule "maxfwd.so"
loadmodule "signaling.so"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "db_mysql.so"
loadmodule "dispatcher.so"
loadmodule "proto_udp.so"
# ----------------- setting module-specific parameters ---------------
modparam("dispatcher", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
route {
if (!mf_process_maxfwd_header(10)) {
send_reply(483, "Too Many Hops");
exit;
}
if (!ds_select_dst(2, 0)) {
send_reply(503, "Service Unavailable");
exit;
}
t_relay();
}
```
--------------------------------
### General ACC Module Configuration
Source: https://docs.opensips.org/manual/3-6/modules/acc
Example demonstrating how to load the ACC module and trigger accounting for specific calls using the do_accounting function.
```opensips
loadmodule "modules/acc/acc.so"
if ($ru=~"sip:+40") /* calls to Romania */ {
if (!proxy_authorize("sip_domain.net" /* realm */,
"subscriber" /* table name */)) {
proxy_challenge("sip_domain.net" /* realm */, "0" /* no qop */ );
exit;
}
if (is_method("INVITE") && $au!=$fU) {
xlog("FROM URI != digest username\n");
sl_send_reply(403,"Forbidden");
}
do_accounting("log"); /* set for accounting via syslog */
t_relay(); /* enter stateful mode now */
};
```
--------------------------------
### lb_start(grp, resources[, flags][, attrs])
Source: https://docs.opensips.org/manual/3-6/modules/load_balancer
Starts a new load-balancing session to find the least loaded destination that matches the requested resources and group.
```APIDOC
## lb_start(grp, resources[, flags][, attrs])
### Description
Starts a new load-balancing session over available destinations. It identifies the least loaded destination capable of providing the requested resources within the specified group.
### Parameters
- **grp** (int) - Required - Group ID for the destinations.
- **resources** (string) - Required - Semi-colon separated list of required resources.
- **flags** (string) - Optional - Control flags: 'n' (negative availability), 'r' (relative value), 's' (random selection).
- **attrs** (var) - Optional - Writable variable to store attributes of the selected destination.
### Returns
- **1 (true)** - Destination URI set.
- **-1 (false)** - Internal error.
- **-2 (false)** - No capacity available.
- **-3 (false)** - No destinations available.
- **-4 (false)** - Bad resources.
```
--------------------------------
### XML-RPC request and response example
Source: https://docs.opensips.org/manual/3-6/modules/mi_xmlrpc_ng
Example of an XML-RPC request for statistics and the corresponding response.
```XML
POST /xmlrpc HTTP/1.0
Host: my.host.com
User-Agent: My xmlrpc UA
Content-Type: text/xml
Content-Length: 216
get_statistics
statistics
shmem:
core:
HTTP/1.0 200 OK
Content-Length: 236
Content-Type: text/xml; charset=utf-8
Date: Mon, 8 Mar 2013 12:00:00 GMT
.
net:waiting_udp0net:waiting_tcp0net:waiting_tls0shmem:total_size268435456shmem:used_size40032shmem:real_used_size277112shmem:max_used_size277112shmem:free_size268158344shmem:fragments194
.
```
--------------------------------
### AVP Substitution Examples
Source: https://docs.opensips.org/manual/3-6/modules/avpops
Examples of applying Perl/sed-like substitutions to AVP string values.
```opensips
# if avp 678 has a string value in e-mail format, replace the
# domain part with the value of domain part from R-URI
avp_subst("$avp(678)", "/(.*)@(.*)/\1@$rd/");
# if any avp 678 has a string value in e-mail format, replace the
# domain part with the value of domain part from R-URI
# and place the result in avp 679
avp_subst("$avp(678)/$avp(679)/g", "/(.*)@(.*)/\1@$rd/");
...
```
--------------------------------
### Install Compilation Dependencies
Source: https://docs.opensips.org/manual/3-6/modules/cachedb_mongodb
Commands to install the development packages required to compile the CACHEDB_MONGODB module.
```bash
# Debian / Ubuntu
sudo apt-get install libjson-c-dev libmongoc-dev libbson-dev
# Red Hat / CentOS
sudo yum install json-c-devel mongo-c-driver-devel
```
--------------------------------
### Clone the SIPssert tests repository
Source: https://docs.opensips.org/manual/3-6/conformance-tests
Initial command to fetch the testing framework repository.
```bash
git clone git@github.com:OpenSIPS/sipssert-opensips-tests.git
```
--------------------------------
### H.350 callPreferenceURI rule examples
Source: https://docs.opensips.org/manual/3-6/modules/h350
Examples of callPreferenceURI attribute formats for different forwarding scenarios.
```text
# Example 1:
# forward to sip:voicemail@example.com on no answer after 15 seconds:
callPreferenceURI: sip:voicemail@example.com n:15000
# Example 2:
# unconditionally forward to sip:alice@example.com:
callPreferenceURI: sip:alice@example.com u
# Example 3:
# forward to sip:bob@example.com and sip:alice@example.com
# (forking) on destination not found:
callPreferenceURI: sip:bob@example.com f
callPreferenceURI: sip:alice@example.com f
```
--------------------------------
### Initialize Berkeley DB Tables
Source: https://docs.opensips.org/manual/3-6/modules/db_berkeley
Commands to create the required and optional database table groups using the opensipsdbctl utility.
```bash
opensipsdbctl create (required)
opensipsdbctl presence (optional)
opensipsdbctl extra (optional)
```
--------------------------------
### AVP Check Examples
Source: https://docs.opensips.org/manual/3-6/modules/avpops
Examples of using avp_check to compare AVP values against operators and other variables.
```opensips
...
avp_check("$avp(678)", "lt/345/g");
avp_check("$fd", "eq/$td/I");
avp_check("$avp(foo)", "gt/$avp($bar)/g");
avp_check("$avp(foo)", "re/sip:.*@bar.net/g");
avp_check("$avp(foo)", "fm/$avp(fm_avp)/g");
...
```
--------------------------------
### AVP Naming Examples
Source: https://docs.opensips.org/manual/3-6/modules/avpops
Examples of how to identify AVPs using numeric or string identifiers.
```OpenSIPS Script
$avp(11) - the AVP identified by name 11
$avp(foo) - the AVP identified by the string 'foo'
```
--------------------------------
### SST Call Flow Example
Source: https://docs.opensips.org/manual/3-6/modules/sst
A visual representation of the SIP Session Timer negotiation process, including MIN_SE validation and dialog creation.
```text
+-------+ +-------+ +-------+
| UAC-1 | | PROXY | | UAC-2 |
+-------+ +-------+ +-------+
|(1) INVITE | |
|SE: 50 | |
|----------->| |
| |(2)sstCheckMin |
| |-----+ |
| | | |
| |<----+ |
|(3) 422 | |
|MSE:1800 | |
|<-----------| |
| | |
|(4)ACK | |
|----------->| |
| | |
|(5) INVITE | |
|SE: 1800 | |
|MSE: 1800 | |
|----------->| |
| |(6)sstCheckMin |
| |-----+ |
| | | |
| |<----+ |
| |(7)setflag |
| |create dialog |
| |Set expire |
| |-----+ |
| | | |
| |<----+ |
| | |
|(8)INVITE |
|SE: 1800 |
|MSE: 1800 |
|-------------->|
| |
...
```
--------------------------------
### Route to Gateway Examples
Source: https://docs.opensips.org/manual/3-6/modules/drouting
Examples of using route_to_gw to route calls to specific gateways or lists of gateways.
```opensips
# use_partitions is not set
if ( route_to_gw("gw_europe") ) {
t_relay();
exit;
}
```
```opensips
# use_partitions is not set
if ( route_to_gw("gw1,gw2,gw3", $var(gw_attrs)) ) {
xlog("Relaying to first gateway from our list - $var(gw_attrs)\n");
t_relay();
exit;
}
```
```opensips
# use_partitions is enabled
if ( route_to_gw("gw_europe", , , "my_partition") ) {
t_relay();
exit;
}
```
```opensips
# use_partitions is enabled
if ( route_to_gw("gw1,gw2,gw3", $var(gw_attrs), , "my_partition") ) {
xlog("Relaying to first gateway from our list - $var(gw_attrs)\n");
t_relay();
exit;
}
```
--------------------------------
### Using the Benchmark API in OpenSIPS Modules
Source: https://docs.opensips.org/manual/3-6/modules/benchmark
Demonstrates loading the benchmark API and using it to register and track execution time for specific operations.
```c
#include "../benchmark/benchmark.h"
...
struct bm_binds bmb;
...
...
/* load the benchmarking API */
if (load_bm_api( &bmb )!=0) {
LM_ERR("can't load benchmark API\n");
goto error;
}
...
...
/* Start/log timers during a (usually user-exported) module function */
bmb.bm_register("test", 1, &id)
bmb.bm_start(id);
do_something();
bmb.bm_log(id);
...
```
--------------------------------
### XMLRPC Request Example
Source: https://docs.opensips.org/manual/3-6/modules/event_xmlrpc
An example of the raw HTTP POST request sent by the module to an XMLRPC server.
```HTTP
POST /RPC2 HTTP/1.1.
Host: 127.0.0.1:8081.
Connection: close.
User-Agent: OpenSIPS XMLRPC Notifier.
Content-type: text/xml.
Content-length: 240.
.
e_dummy_h
E_MY_EVENT
ip
192.168.2.11
```
--------------------------------
### Subscribe to Events via Configuration
Source: https://docs.opensips.org/manual/3-6/modules/event_sqs
Register an event subscription in the startup_route.
```opensips
subscribe_event("MY_EVENT",
"sqs:http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/Queue2");
```
--------------------------------
### Carrierfailureroute Table Example
Source: https://docs.opensips.org/manual/3-6/modules/carrierroute
Example of a failure route table configuration for handling gateway failover scenarios.
```SQL
+----+---------+--------+---------------+------------+-------------+
| id | carrier | domain | host_name | reply_code | next_domain |
+----+---------+--------+---------------+------------+-------------+
| 1 | 1 | 0 | gw.carrier1-2 | ... | 3 |
| 2 | 1 | 0 | gw.carrier1-3 | ... | 2 |
+----+---------+--------+---------------+------------+-------------+
```
--------------------------------
### init_uac(accept_types, from_uri, to_uri, ruri, hdl)
Source: https://docs.opensips.org/manual/3-6/modules/msrp_ua
Initializes an MSRP UA session by sending a SIP INVITE to a destination.
```APIDOC
## init_uac(accept_types, from_uri, to_uri, ruri, hdl)
### Description
Initializes a MSRP UA session by sending a SIP INVITE to a destination.
### Parameters
- **accept_types** (str) - The value of the “accept-types” attribute to include in the SDP offer.
- **from_uri** (str) - URI to use in the From header of the INVITE.
- **to_uri** (str) - URI to use in the To header of the INVITE.
- **ruri** (str) - Request URI to use in the for the INVITE.
- **hdl** (struct msrp_ua_handler) - Handler structure used to register the callbacks for SIP level and MSRP level notifications.
```
--------------------------------
### OpenSIPS Config Script with DB_TEXT
Source: https://docs.opensips.org/manual/3-6/modules/db_text
A complete configuration example showing module loading, parameter settings for dbtext, and request routing logic.
```opensips
#
# simple quick-start config script with dbtext
#
# ----------- global configuration parameters ------------------------
#debug_mode=yes
udp_workers=4
check_via=no # (cmd. line: -v)
dns=no # (cmd. line: -r)
rev_dns=no # (cmd. line: -R)
socket=udp:10.100.100.1:5060
# ------------------ module loading ----------------------------------
# use dbtext database
loadmodule "modules/dbtext/dbtext.so"
loadmodule "modules/sl/sl.so"
loadmodule "modules/tm/tm.so"
loadmodule "modules/rr/rr.so"
loadmodule "modules/maxfwd/maxfwd.so"
loadmodule "modules/usrloc/usrloc.so"
loadmodule "modules/registrar/registrar.so"
loadmodule "modules/textops/textops.so"
loadmodule "modules/textops/mi_fifo.so"
# modules for digest authentication
loadmodule "modules/auth/auth.so"
loadmodule "modules/auth_db/auth_db.so"
# ----------------- setting module-specific parameters ---------------
# -- mi_fifo params --
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
# -- usrloc params --
# use dbtext database for persistent storage
modparam("usrloc", "db_mode", 2)
modparam("usrloc|auth_db", "db_url", "text:///tmp/opensipsdb")
# -- auth params --
#
modparam("auth_db", "calculate_ha1", 1)
modparam("auth_db", "password_column", "password")
modparam("auth_db", "user_column", "username")
modparam("auth_db", "domain_column", "domain")
# ------------------------- request routing logic -------------------
# main routing logic
route{
# initial sanity checks -- messages with
# max_forwards==0, or excessively long requests
if (!mf_process_maxfwd_header("10")) {
sl_send_reply(483,"Too Many Hops");
exit;
};
if ($ml >= 65535 ) {
sl_send_reply(513, "Message too big");
exit;
};
# we record-route all messages -- to make sure that
# subsequent messages will go through our proxy; that's
# particularly good if upstream and downstream entities
# use different transport protocol
if (!$rm=="REGISTER") record_route();
# subsequent messages withing a dialog should take the
# path determined by record-routing
if (loose_route()) {
# mark routing logic in request
append_hf("P-hint: rr-enforced\r\n");
route(1);
exit;
};
if (!is_myself("$rd")) {
# mark routing logic in request
append_hf("P-hint: outbound\r\n");
route(1);
exit;
};
# if the request is for other domain use UsrLoc
# (in case, it does not work, use the following command
# with proper names and addresses in it)
if (is_myself("$rd")) {
if ($rm=="REGISTER") {
# digest authentication
if (!www_authorize("", "subscriber")) {
www_challenge("", "0");
exit;
};
save("location");
exit;
};
lookup("aliases");
if (!is_myself("$rd")) {
append_hf("P-hint: outbound alias\r\n");
route(1);
exit;
};
# native SIP destinations are handled using our USRLOC DB
if (!lookup("location")) {
sl_send_reply(404, "Not Found");
exit;
};
};
append_hf("P-hint: usrloc applied\r\n");
route(1);
}
route[1]
{
# send it out now; use stateful forwarding as it works reliably
# even for UDP2TCP
if (!t_relay()) {
sl_reply_error();
};
}
```
--------------------------------
### JSON-RPC Event Payload Example
Source: https://docs.opensips.org/manual/3-6/modules/event_datagram
Example of an event payload formatted as a JSON-RPC notification, as generated by the pike module.
```json
{
"jsonrpc": "2.0",
"method": "E_PIKE_BLOCKED",
"params": {
"ip": "192.168.2.11"
}
}
```
--------------------------------
### Implement custom route_offer logic
Source: https://docs.opensips.org/manual/3-6/modules/rtp_relay
Example implementation of the route triggered during SDP offer processing.
```OpenSIPS Script
...
route[rtp_relay_offer] {
# manually engaging RTPEngine, get the SDP, and replace it in the message
return (1, $var(body));
}
...
```
--------------------------------
### Perform Asynchronous HTTP GET
Source: https://docs.opensips.org/manual/3-6/modules/rest_client
Executes a non-blocking GET request and handles the response in a resume route.
```OpenSIPS Script
route {
...
async(rest_get("http://getcredit.org/?account=$fU",
$var(credit), , $var(rcode)), resume);
}
route [resume] {
$var(rc) = $rc;
if ($var(rc) < 0) {
xlog("async rest_get() failed with $var(rc), acc=$fU\n");
send_reply(500, "Server Internal Error");
exit;
}
if ($var(rcode) != 200) {
xlog("L_INFO", "async rest_get() rcode=$var(rcode), acc=$fU\n");
send_reply(403, "Forbidden");
exit;
}
...
}
```
--------------------------------
### Install Required Packages
Source: https://docs.opensips.org/manual/3-6/modules/cachedb_mongodb
Commands to install the necessary runtime dependencies for the CACHEDB_MONGODB module on Debian/Ubuntu and Red Hat/CentOS systems.
```bash
# Debian / Ubuntu
sudo apt-get install libjson-c2 libmongoc-1.0
# Red Hat / CentOS
sudo yum install json-c mongo-c-driver
```
--------------------------------
### Initialize Git Submodules
Source: https://docs.opensips.org/manual/3-6/modules/tls_wolfssl
Use this command to fetch the wolfSSL library code if the repository was cloned without the --recursive option.
```bash
git submodule update --init
```
--------------------------------
### Carrier Mapping Table Example
Source: https://docs.opensips.org/manual/3-6/modules/carrierroute
Example of the carrier mapping table structure used to associate IDs with carrier names.
```text
+----+----------+
| id | carrier |
+----+----------+
| 1 | carrier1 |
| 2 | carrier2 |
| 3 | default |
+----+----------+
```
--------------------------------
### Call example_int() function
Source: https://docs.opensips.org/manual/3-6/modules/example
Logs a provided integer or the default_int parameter if no argument is passed.
```OpenSIPS Script
...
example_int(10);
...
```
--------------------------------
### Infrastructure ENUM EBL record example
Source: https://docs.opensips.org/manual/3-6/modules/enum
Example DNS records for the 'ebl' branching algorithm using record type 65300.
```dns
i.1.e164.arpa. TYPE65300 \# 14 (
04 ; position
01 69 ; separator
04 65 31 36 34 04 61 72 70 61 00 ; e164.arpa
; )
9.9.9.8.7.6.5.i.4.3.2.1.e164.arpa. IN NAPTR "NAPTR content for +1 234 5678 999"
```
--------------------------------
### Check or start OpenSIPS with a rendered configuration
Source: https://docs.opensips.org/manual/3-6/generating-configs
Once rendered, the configuration file can be used directly with standard OpenSIPS commands.
```bash
opensips -C -f opensips.cfg
opensips -f opensips.cfg
```
--------------------------------
### List available commands with which
Source: https://docs.opensips.org/manual/3-6/interface-coremi
Returns an array of all available MI commands, which may vary based on loaded modules.
```bash
$ opensips-cli -x mi which
[
"get_statistics",
"list_statistics",
"reset_statistics",
"uptime",
"version",
"pwd",
"arg",
"which",
"ps",
"kill",
"log_level",
"xlog_level",
"shm_check",
"cache_store",
"cache_fetch",
"cache_remove",
"event_subscribe",
"events_list",
...
```
--------------------------------
### Configure FreeSWITCH Subscriptions
Source: https://docs.opensips.org/manual/3-6/modules/freeswitch_scripting
Adds FreeSWITCH ESL URLs for connection at startup, supporting event subscription lists.
```opensips
modparam("freeswitch_scripting", "fs_subscribe", ":ClueCon@10.0.0.10?CHANNEL_STATE")
modparam("freeswitch_scripting", "fs_subscribe", ":ClueCon@10.0.0.11:8021?DTMF,BACKGROUND_JOB")
```
--------------------------------
### Accessing Contact Instance Fields
Source: https://docs.opensips.org/manual/3-6/script-corevar
Examples demonstrating how to retrieve specific fields from contact instances using index notation.
```OpenSIPS Script
$ct.fields(uri)
```
```OpenSIPS Script
$(ct.fields(name)[1])
```
--------------------------------
### Apply patch and install freeRADIUS client
Source: https://docs.opensips.org/manual/3-6/modules/aaa_radius
Commands to apply the OpenSIPS async patch to the library source and proceed with the standard installation process.
```bash
........
cd freeRADIUS-client/freeradius-client-1.1.7.tar.gz
patch -p1 < /path/to/opensips/modules/aaa_radius/radius_async_support.patch
./configure --any-options-you-want
make
sudo make install
........
```
--------------------------------
### Configure H350 Module Parameters
Source: https://docs.opensips.org/manual/3-6/modules/h350
Configuration examples for the H350 module parameters including LDAP session, base DN, and search scope.
```c
modparam("h350", "ldap_session", "h350");
```
```c
modparam("h350", "base_dn", "ou=h350,dc=example,dc=com");
```
```c
modparam("h350", "search_scope", "sub");
```
--------------------------------
### LDAP Search URL Examples
Source: https://docs.opensips.org/manual/3-6/modules/ldap
Examples of LDAP URLs used to define search operations, including base DN, scope, and filters.
```text
ldap://sipaccounts/ou=sip,dc=example,dc=com??one?(cn=schlatter)
```
```text
ldap://ldap_1/dc=example,dc=com?
SIPIdentityUserName,SIPIdentityServiceLevel?sub?(cn=$(avp(name)))
```