### Install OpenSIPS Source: https://docs.opensips.org/manual/4-0/install-compileandinstall Install the compiled binaries, modules, and documentation to the configured prefix. ```bash make install ``` -------------------------------- ### Example HTTP GET Query Source: https://docs.opensips.org/manual/4-0/modules/db_http Shows the format of a GET request sent to the database server. ```HTTP GET /presentity/?c=username,domain,event,expires HTTP/1.1 ``` -------------------------------- ### Route to Carrier Examples Source: https://docs.opensips.org/manual/4-0/modules/drouting Examples demonstrating how to use route_to_carrier with and without partitions enabled. ```OpenSIPS Script # 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 Script # 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 Script # 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; } ``` -------------------------------- ### HTTP Request Examples Source: https://docs.opensips.org/manual/4-0/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 POST /active_watchers HTTP/1.1 k=id&v=100&query_type=insert ``` -------------------------------- ### Call example function Source: https://docs.opensips.org/manual/4-0/modules/example Executes the example function to log a message indicating it has been called. ```OpenSIPS ... example(); ... ``` -------------------------------- ### Socket Configuration Examples Source: https://docs.opensips.org/manual/4-0/modules/event_datagram Examples of UNIX and UDP socket address formats used by the module. ```text unix:/tmp/opensips_event.sock ``` ```text udp:127.0.0.1:8081 ``` -------------------------------- ### Install Launch Darkly C Server SDK Source: https://docs.opensips.org/manual/4-0/modules/launch_darkly Commands to clone, configure, and install the required ldserverapi 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 ... ``` -------------------------------- ### Deploy Localstack for SQS Testing Source: https://docs.opensips.org/manual/4-0/modules/event_sqs Commands to install and start a local SQS environment for development and testing. ```bash pip install localstack localstack start ``` -------------------------------- ### E_PROFILING_PROC Event Output Example Source: https://docs.opensips.org/manual/4-0/interface-coreevents Example output showing a sequence of process profiling events including start, enter, exit, and end actions. ```text {'sec': 1776767469, 'usec': 200446, 'session': 3463978, 'verb': 'start', 'name': 'SIP receiver udp:127.0.0.1:5060', 'type': 1, 'depth': 0} {'sec': 1776767469, 'usec': 201035, 'session': 3463978, 'verb': 'enter', 'name': 'udp proto reading', 'type': 1, 'depth': 1, 'file': 'handle_io', 'line': 317} {'sec': 1776767469, 'usec': 201485, 'session': 3463978, 'verb': 'enter', 'name': 'receive_msg', 'type': 1, 'depth': 2, 'file': 'receive_msg', 'line': 120} {'sec': 1776767469, 'usec': 202558, 'session': 3463978, 'verb': 'enter', 'name': 'request_script', 'type': 1, 'depth': 3, 'file': 'receive_msg', 'line': 235} {'sec': 1776767469, 'usec': 203201, 'session': 3463978, 'verb': 'exit', 'name': 'request_script', 'type': 1, 'depth': 2, 'file': 'receive_msg', 'line': 237, 'status': 1} {'sec': 1776767469, 'usec': 203533, 'session': 3463978, 'verb': 'exit', 'name': 'receive_msg', 'type': 1, 'depth': 1, 'file': 'receive_msg', 'line': 316, 'status': 0} {'sec': 1776767469, 'usec': 203663, 'session': 3463978, 'verb': 'exit', 'name': 'reading done', 'type': 1, 'depth': 0, 'file': 'handle_io', 'line': 324, 'status': 0} {'sec': 1776767469, 'usec': 203786, 'session': 3463978, 'verb': 'end', 'name': 'SIP receiver udp:127.0.0.1:5060', 'type': 1, 'depth': 0, 'status': 0} ``` -------------------------------- ### Configure Speeddial in OpenSIPS Script Source: https://docs.opensips.org/manual/4-0/modules/speeddial Example configuration showing module loading, parameter setup, and the usage of sd_lookup within the request routing logic. ```opensips # sample config script to use speeddial module # # ----------- global configuration parameters ------------------------ check_via=no # (cmd. line: -v) dns=no # (cmd. line: -r) rev_dns=no # (cmd. line: -R) # ------------------ module loading ---------------------------------- mpath="/usr/local/lib/opensips/modules" loadmodule "sl.so" loadmodule "tm.so" loadmodule "rr.so" loadmodule "maxfwd.so" loadmodule "usrloc.so" loadmodule "registrar.so" loadmodule "textops.so" loadmodule "mysql.so" loadmodule "speeddial.so" loadmodule "mi_fifo.so" # ----------------- setting module-specific parameters --------------- # -- mi_fifo params -- modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo") # -- usrloc params -- modparam("usrloc", "working_mode_preset", "single-instance-no-db") # ------------------------- request routing logic ------------------- # main routing logic route{ # initial sanity checks 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; }; if (!$rm=="REGISTER") record_route(); if (loose_route()) { if (!t_relay()) { sl_reply_error(); }; exit; }; if (!is_myself("$rd")) { if (!t_relay()) { sl_reply_error(); }; exit; }; if (is_myself("$rd")) { if ($rm=="REGISTER") { save("location"); exit; }; if($ru=~"sip:[0-9]{2}@.*") sd_lookup("speeddial"); lookup("aliases"); if (!is_myself("$rd")) { if (!t_relay()) { sl_reply_error(); }; exit; }; if (!lookup("location")) { sl_send_reply(404, "Not Found"); exit; }; }; if (!t_relay()) { sl_reply_error(); }; } ``` -------------------------------- ### Kafka socket configuration example Source: https://docs.opensips.org/manual/4-0/modules/event_kafka Example of a Kafka socket string with timeout and key configuration. ```Text kafka:127.0.0.1:9092/topic1?t.message.timeout.ms=1000&key=callid ``` -------------------------------- ### Start MySQL server Source: https://docs.opensips.org/manual/4-0/modules/db_unixodbc Command to start the MySQL server with specific socket configuration. ```shell shell>safe_mysqld --user=mysql --socket=/var/lib/mysql/mysql.sock ``` -------------------------------- ### Partition Status Report Example Source: https://docs.opensips.org/manual/4-0/modules/dispatcher Example JSON output showing the status of a partition during DB data loading. ```json { "Name": "default", "Reports": [ { "Timestamp": 1652373212, "Date": "Thu May 12 19:33:32 2022", "Log": "starting DB data loading" }, { "Timestamp": 1652373212, "Date": "Thu May 12 19:33:32 2022", "Log": "DB data loading successfully completed" }, { "Timestamp": 1652373212, "Date": "Thu May 12 19:33:32 2022", "Log": "2 destinations loaded (0 discarded)" } ] } ``` -------------------------------- ### Query Type Examples Source: https://docs.opensips.org/manual/4-0/modules/db_http Examples of POST requests for delete and update operations. ```http POST /active_watchers HTTP/1.1 k=id&op=%3D&v=100&query_type=delete POST /active_watchers HTTP/1.1 k=id&op=%3D&v=100&uk=id&uv=101&query_type=update ``` -------------------------------- ### Start dynamic tracing with tracer:start Source: https://docs.opensips.org/manual/4-0/modules/tracer Commands to initiate dynamic tracing destinations with specific filters for IP or user-based traffic. ```bash opensips-cli -x mi tracer:start id=ip_filter uri=hep:10.0.0.1:9060 filter=ip=127.0.0.1 ``` ```bash opensips-cli -x mi tracer:start id=alice_bob uri=hep:10.0.0.1:9060 filter=caller=Alice filter=caller=Bob ``` -------------------------------- ### Get system uptime with uptime Source: https://docs.opensips.org/manual/4-0/interface-coremi Provides the current time, start time, and total duration the instance has been running. ```bash $ opensips-mi uptime { "Now": "Mon Jul 21 17:41:03 2008", "Up since": "Mon Jul 21 17:36:33 2008", "Up time": "270 [sec]" } ``` -------------------------------- ### Configure Installation Prefix Source: https://docs.opensips.org/manual/4-0/install-compileandinstall Set the root directory for the OpenSIPS installation. ```makefile PREFIX ?= /opt/opensips/ ``` -------------------------------- ### Partition Events Report Example Source: https://docs.opensips.org/manual/4-0/modules/dispatcher Example JSON output showing destination state change events for a specific partition. ```json { "Name": "default;events", "Reports": [ { "Timestamp": 1652373308, "Date": "Thu May 12 19:35:08 2022", "Log": "DESTINATION , set 1 switched to [inactive] due to negative probing reply\n" }, { "Timestamp": 1652373308, "Date": "Thu May 12 19:35:08 2022", "Log": "DESTINATION , set 1 switched to [inactive] due to negative probing reply\n" } ] }, ``` -------------------------------- ### Additional Credentials Syntax Examples Source: https://docs.opensips.org/manual/4-0/modules/auth_aaa Examples of how additional credentials are formatted as AVP name-value pairs. ```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) .... ``` -------------------------------- ### Install libmemcached Source: https://docs.opensips.org/manual/4-0/modules/cachedb_memcached Commands to download, compile, and install the libmemcached library required by the module. ```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 ``` -------------------------------- ### DNS TXT record example for bl_algorithm Source: https://docs.opensips.org/manual/4-0/modules/enum Example DNS records when bl_algorithm is set to txt. ```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" ``` -------------------------------- ### Complete UAC Redirect script example Source: https://docs.opensips.org/manual/4-0/modules/uac_redirect A full script example demonstrating module loading, configuration, 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", "working_mode_preset", "single-instance-no-db") 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(); } ``` -------------------------------- ### Route to Gateway Examples Source: https://docs.opensips.org/manual/4-0/modules/drouting Examples demonstrating how to use route_to_gw to route calls to specific gateways or lists of gateways. ```OpenSIPS Script # use_partitions is not set if ( route_to_gw("gw_europe") ) { t_relay(); exit; } ``` ```OpenSIPS Script # 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 Script # use_partitions is enabled if ( route_to_gw("gw_europe", , , "my_partition") ) { t_relay(); exit; } ``` ```OpenSIPS Script # 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; } ``` -------------------------------- ### example() Source: https://docs.opensips.org/manual/4-0/modules/example Prints a message to the log indicating that the function has been called. This function can be invoked 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(); ``` ``` -------------------------------- ### Install LDAP Dependencies Source: https://docs.opensips.org/manual/4-0/modules/ldap Install the required OpenLDAP libraries on Debian or Ubuntu systems. ```bash $ apt-get install libldap2 libldap2-dev ``` -------------------------------- ### SNMP Table Output Example Source: https://docs.opensips.org/manual/4-0/modules/snmpstats Example output format returned by the snmptable command for the registration user table. ```text index openserSIPUserUri openserSIPUserAuthenticationFailures 1 DefaultUser 0 2 bogdan 0 3 jeffrey.magder 0 ``` -------------------------------- ### Configure DB_TEXT Parameters Source: https://docs.opensips.org/manual/4-0/modules/db_text Examples of setting module parameters in the OpenSIPS configuration file. ```c ... modparam("db_text", "db_mode", 1) ... ``` ```c ... modparam("db_text", "buffer_size", 8192) ... ``` -------------------------------- ### IF-ELSE Usage Example Source: https://docs.opensips.org/manual/4-0/script-statements Demonstrates conditional execution based on SIP method and port. ```OpenSIPS if ( is_method("INVITE") && $rp==5060 ) { log("this sip message is an invite\n"); } else { log("this sip message is not an invite\n"); } ``` -------------------------------- ### Example ASCII dump of certificate fields Source: https://docs.opensips.org/manual/4-0/modules/tls_mgm An example of the output format for certificate subject or issuer fields. ```text /C=AT/ST=Vienna/L=Vienna/O=enum.at/CN=enum.at ``` -------------------------------- ### IMC Command Examples Source: https://docs.opensips.org/manual/4-0/modules/imc Examples of various IMC commands used to manage conference rooms, including creation, joining, and membership management. ```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 ``` -------------------------------- ### Generate a sample framework file Source: https://docs.opensips.org/manual/4-0/modules/pi_http Use the opensips-cli tool to create a basic XML framework file for the provisioning interface. ```bash opensips-cli pframework create ``` -------------------------------- ### msrp_ua:start_session Source: https://docs.opensips.org/manual/4-0/modules/msrp_ua Starts a MSRP session. ```APIDOC ## msrp_ua:start_session ### Description Starts a MSRP session. The advertised contact is mandatory if this function is used. ### Parameters - **content_types** (string) - Required - Content types advertised in the accept-types SDP attribute. - **from_uri** (string) - Required - From URI to be used in the INVITE. - **to_uri** (string) - Required - To URI to be used in the INVITE. - **ruri** (string) - Required - Request URI and destination of the INVITE. ### Request Example opensips-cli -x mi msrp_ua:start_session text/plain sip:oss@opensips.org sip:alice@opensips.org sip:alice@opensips.org ``` -------------------------------- ### Initialize Makefile.conf Source: https://docs.opensips.org/manual/4-0/install-compileandinstall Create the configuration file from the template if it does not exist. ```bash cp Makefile.conf.template Makefile.conf ``` -------------------------------- ### Basic Preprocessor Usage Source: https://docs.opensips.org/manual/4-0/templating-config-files Demonstrates using standard tools like cat or sed to process configuration files via the -p option. ```bash opensips -f opensips.cfg -p /bin/cat ``` ```bash opensips -f opensips.cfg -p "/bin/sed s/PRIVATE_IP/10.0.0.10/g" ``` -------------------------------- ### Regex Configuration File Format Source: https://docs.opensips.org/manual/4-0/modules/regex Example of the expected file structure where expressions are categorized into groups starting with a bracketed number. ```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}$ ``` -------------------------------- ### Global Blacklist Table Structure Source: https://docs.opensips.org/manual/4-0/modules/userblacklist Example of a global blacklist table where calls starting with '1' are allowed, while specific prefixes are blocked. ```sql +----+-----------+-----------+ | id | prefix | whitelist | +----+-----------+-----------+ | 1 | | 0 | | 2 | 1 | 1 | | 3 | 123456 | 0 | | 4 | 123455787 | 0 | +----+-----------+-----------+ ``` -------------------------------- ### Streaming Music on Hold with RTPproxy Source: https://docs.opensips.org/manual/4-0/modules/rtpproxy Example of conditionally starting or stopping a music-on-hold stream based on SDP content during an INVITE request. ```opensips ... if (is_method("INVITE")) { rtpproxy_offer(); if ($rb=~ "0\.0\.0\.0") { rtpproxy_stream2uas("/var/rtpproxy/prompts/music_on_hold", -1); } else { rtpproxy_stop_stream2uas(); }; }; ... ``` -------------------------------- ### Call example_str function Source: https://docs.opensips.org/manual/4-0/modules/example Logs a provided string or the default_str parameter if no argument is passed. ```OpenSIPS ... example_str("test"); ... ``` -------------------------------- ### Recording RTP Streams Source: https://docs.opensips.org/manual/4-0/modules/rtpproxy Examples of starting RTP stream recording, including options for remote UDP destinations and specific media stream selection. ```opensips ... 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); ... ``` -------------------------------- ### Syntax variants for launch() Source: https://docs.opensips.org/manual/4-0/script-async Demonstrates the different ways to invoke the launch() statement, including optional report routes and parameter passing. ```OpenSIPS Script 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"); } ``` -------------------------------- ### OpenSIPS Dispatcher Configuration Script Source: https://docs.opensips.org/manual/4-0/modules/dispatcher A sample configuration file demonstrating module loading, database parameter setup, and basic routing logic 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(); } ``` -------------------------------- ### lb_start(grp, resources[, flags], [attrs]) Source: https://docs.opensips.org/manual/4-0/modules/load_balancer Starts a new load-balancing session to find the least loaded destination that meets the requested resource requirements. ```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 destination attributes. ### Returns - **1 (true)** - Destination URI set. - **-1 (false)** - Internal error. - **-2 (false)** - No capacity available. - **-3 (false)** - No destinations available. - **-4 (false)** - Bad resources. ``` -------------------------------- ### Configure OpenSIPS as WeSIP front-end Source: https://docs.opensips.org/manual/4-0/modules/seas Example opensips.cfg configuration for using OpenSIPS as a front-end for WeSIP. ```opensips.cfg log_level=9 # debug level (cmd line: -dddddddddd) log_stderror=yes # (cmd line: -E) check_via=no # (cmd. line: -v) dns=no # (cmd. line: -r) rev_dns=no # (cmd. line: -R) port=5060 children=4 listen = tcp:localhost:5060 listen = udp:localhost:5060 mpath="/home/elias/src/sipservlet/seas" loadmodule "modules/tm/tm.so" loadmodule "modules/seas/seas.so" loadmodule "modules/mi_fifo/mi_fifo.so" modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo") modparam("seas", "listen_sockets","127.0.0.1:5080") route{ if(!as_relay_t("app_server_1")){ t_reply("500","Application Server error"); } } ``` -------------------------------- ### Get version information with version Source: https://docs.opensips.org/manual/4-0/interface-coremi Prints the version string of the running OpenSIPS instance. ```bash $ opensips-mi version { "Server": "OpenSIPS (4.0.0-dev (x86_64/linux))" } ``` -------------------------------- ### rtpengine_start_recording([flags [, sock_var]]) Source: https://docs.opensips.org/manual/4-0/modules/rtpengine Signals the RTP proxy to start recording the RTP stream. ```APIDOC ## rtpengine_start_recording([flags [, sock_var]]) ### Description Sends a signal to the RTP proxy to record the RTP stream on the RTP proxy. ``` -------------------------------- ### B2B Flag Example Source: https://docs.opensips.org/manual/4-0/modules/b2b_logic_xml Example of a topology hiding scenario timeout flag. ```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. ``` -------------------------------- ### Clone the SIPssert tests repository Source: https://docs.opensips.org/manual/4-0/conformance-tests Initial command to fetch the testing framework repository. ```bash git clone git@github.com:OpenSIPS/sipssert-opensips-tests.git ``` -------------------------------- ### Install Compilation Dependencies Source: https://docs.opensips.org/manual/4-0/modules/cachedb_mongodb Commands to install development packages required to compile the 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 ``` -------------------------------- ### Use LDAP API Function Source: https://docs.opensips.org/manual/4-0/modules/ldap Example of calling an LDAP API function after successful initialization. ```c ... rc = ldap_api.ldap_rfc4515_escape(str1, str2, 0); ... ``` -------------------------------- ### Check or Start Standalone Configuration Source: https://docs.opensips.org/manual/4-0/generating-configs Run or validate a configuration file that has already been rendered from a template. ```bash opensips -C -f opensips.cfg opensips -f opensips.cfg ``` -------------------------------- ### XML-RPC request and response example Source: https://docs.opensips.org/manual/4-0/modules/mi_xmlrpc Example of an XML-RPC request for get_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 . ``` -------------------------------- ### Start a UAC session Source: https://docs.opensips.org/manual/4-0/modules/b2b_entities Initiates a new UAC session by sending an INVITE request. ```bash opensips-cli -x mi b2b_entities:ua_session_client_start ruri=sip:bob@opensips.org \ to=sip:bob@opensips.org from=sip:alice@opensips.org flags=arhb ``` -------------------------------- ### Accessing Contact Instance Fields Source: https://docs.opensips.org/manual/4-0/script-corevar Examples for retrieving specific fields from contact instances. ```OpenSIPS Script $ct.fields(uri) ``` ```OpenSIPS Script $(ct.fields(name)[1]) ``` -------------------------------- ### Initialize OpenSIPS Database Tables Source: https://docs.opensips.org/manual/4-0/modules/db_berkeley Commands to create the required and optional database table groups using opensipsdbctl. ```bash opensipsdbctl create (required) opensipsdbctl presence (optional) opensipsdbctl extra (optional) ``` -------------------------------- ### Call example_int function Source: https://docs.opensips.org/manual/4-0/modules/example Logs a provided integer or the default_int parameter if no argument is passed. ```OpenSIPS ... example_int(10); ... ``` -------------------------------- ### H.350 callPreferenceURI Examples Source: https://docs.opensips.org/manual/4-0/modules/h350 Examples of callPreferenceURI attribute formats for different call 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 ``` -------------------------------- ### Retrieve OpenSIPS startup arguments Source: https://docs.opensips.org/manual/4-0/interface-coremi Returns the full list of arguments used when OpenSIPS was started. ```bash $ opensips-mi arg [ "./opensips", "-f", "/etc/openser/test.cfg" ] ``` -------------------------------- ### init_uac(accept_types, from_uri, to_uri, ruri, hdl) Source: https://docs.opensips.org/manual/4-0/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 an MSRP UA session by sending a SIP INVITE to a destination. ### Parameters - **accept_types** (str) - Required - The value of the “accept-types” attribute to include in the SDP offer. - **from_uri** (str) - Required - URI to use in the From header of the INVITE. - **to_uri** (str) - Required - URI to use in the To header of the INVITE. - **ruri** (str) - Required - Request URI to use in the for the INVITE. - **hdl** (struct msrp_ua_handler) - Required - Handler structure used to register the callbacks for SIP level and MSRP level notifications. ``` -------------------------------- ### DNS EBL record example for bl_algorithm Source: https://docs.opensips.org/manual/4-0/modules/enum Example DNS records when bl_algorithm is set to ebl. ```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" ``` -------------------------------- ### Initialize git submodules Source: https://docs.opensips.org/manual/4-0/modules/tls_wolfssl Command to fetch the wolfSSL library code if the repository was cloned without the --recursive flag. ```bash git submodule update --init ``` -------------------------------- ### Loading and Using the Benchmark API Source: https://docs.opensips.org/manual/4-0/modules/benchmark Demonstrates how to load the benchmark API using load_bm_api and perform timer operations within a module function. ```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); ... ``` -------------------------------- ### NULL Value Query Example Source: https://docs.opensips.org/manual/4-0/modules/db_http Example of a delete operation using a NULL value represented by %00. ```http POST /active_watchers HTTP/1.1 k=id&op=%3D&v=%00&query_type=delete ``` -------------------------------- ### AVP Naming Format Examples Source: https://docs.opensips.org/manual/4-0/modules/avpops Examples of how to identify AVPs using numeric or string identifiers. ```text $avp(11) - the AVP identified by name 11 $avp(foo) - the AVP identified by the string 'foo' ``` -------------------------------- ### Install Required Packages Source: https://docs.opensips.org/manual/4-0/modules/cachedb_mongodb Commands to install necessary runtime dependencies for the 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 ``` -------------------------------- ### Production Setup Configuration Source: https://docs.opensips.org/manual/4-0/modules/auth_web3 Standard production configuration using Ethereum mainnet for ENS and Oasis Sapphire mainnet for authentication. ```OpenSIPS loadmodule "auth_web3.so" # Oasis Sapphire Mainnet modparam("auth_web3", "web3_authentication_rpc_url", "https://sapphire.oasis.io") modparam("auth_web3", "web3_authentication_contract_address", "0xYourProductionContract") # Ethereum Mainnet for ENS modparam("auth_web3", "web3_ens_rpc_url", "https://eth.drpc.org") modparam("auth_web3", "web3_ens_registry_address", "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e") # Optional: Enable debug logging modparam("auth_web3", "web3_contract_debug_mode", 0) ``` -------------------------------- ### JSON-RPC Event Payload Example Source: https://docs.opensips.org/manual/4-0/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" } } ``` -------------------------------- ### Start a benchmark timer Source: https://docs.opensips.org/manual/4-0/modules/benchmark Initializes a timer with a specific name to begin tracking duration. ```OpenSIPS Script ... bm_start_timer("test"); ... ``` -------------------------------- ### Set Start Time Column Name Source: https://docs.opensips.org/manual/4-0/modules/fraud_detection Specifies the database column name for the rule start time. ```OpenSIPS Script ... modparam("fraud_detection", "start_h", "the_start_time") ... ``` -------------------------------- ### Configure ACC module and accounting in script Source: https://docs.opensips.org/manual/4-0/modules/acc Example showing how to load the ACC module and trigger accounting for specific calls using the do_accounting function. ```OpenSIPS Script 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 */ }; ``` -------------------------------- ### Apply Patch and Install RADIUS Library Source: https://docs.opensips.org/manual/4-0/modules/aaa_radius Commands to apply the OpenSIPS async patch to the extracted source and perform the installation. ```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 ........ ``` -------------------------------- ### Testing Setup Configuration Source: https://docs.opensips.org/manual/4-0/modules/auth_web3 Development configuration using Sepolia testnet for ENS and Oasis Sapphire testnet for authentication with debug mode enabled. ```OpenSIPS loadmodule "auth_web3.so" # Oasis Sapphire Testnet modparam("auth_web3", "web3_authentication_rpc_url", "https://testnet.sapphire.oasis.dev") modparam("auth_web3", "web3_authentication_contract_address", "0xYourTestContract") # Ethereum Sepolia for ENS modparam("auth_web3", "web3_ens_rpc_url", "https://ethereum-sepolia-rpc.publicnode.com") modparam("auth_web3", "web3_ens_registry_address", "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e") # Enable debug logging for testing modparam("auth_web3", "web3_contract_debug_mode", 1) ``` -------------------------------- ### Example DB_TEXT Table Formats Source: https://docs.opensips.org/manual/4-0/modules/db_text Examples of the internal structure for DB_TEXT tables, including column definitions and row data. ```text ... id(int,auto) name(str) flag(double) desc(str,null) 1:nick:0.34:a\tgood\: friend 2:cole:-3.75:colleague 3:bob:2.50: ... ``` ```text ... username(str) contact(str) expires(int) q(double) callid(str) cseq(int) ... ``` ```text ... username(str) password(str) ha1(str) domain(str) ha1b(str) suser:supasswd:xxx:alpha.org:xxx ... ``` -------------------------------- ### Configure Accounting with do_accounting Source: https://docs.opensips.org/manual/4-0/modules/acc Demonstrates enabling database and syslog accounting for INVITE requests and AAA accounting for BYE requests. ```OpenSIPS Script ... if (!has_totag()) { if (is_method("INVITE")) { /* enable cdr and missed calls accounting in the database * and to syslog; db accounting shall be done in "my_acc" table */ do_accounting("db|log", "cdr|missed", "my_acc"); } } ... if (is_method("BYE")) { /* do normal accounting via aaa */ do_accounting("aaa"); } ... ``` -------------------------------- ### LDAP search operation example Source: https://docs.opensips.org/manual/4-0/modules/ldap Example demonstrating how to perform an LDAP search and retrieve an attribute value using the loaded ldap_api. ```c ... int rc, ld_result_count, scope = 0; char* sip_username = "test"; /* * get LDAP search scope integer */ scope = ldap_api.ldap_str2scope("sub"); if (scope == -1) { LM_ERR("ldap_str2scope failed\n"); return -1; } /* * perform LDAP search */ if (ldap_api.ldap_params_search( &ld_result_count, "campus", "dc=example,dc=com", scope, NULL, "(&(objectClass=SIPIdentity)(SIPIdentityUserName=%s))", sip_username) != 0) { LM_ERR("LDAP search failed\n"); return -1; } /* * check result count */ if (ld_result_count < 1) { LM_ERR("LDAP search returned no entry\n"); return 1; } /* * get password attribute value */ struct berval **attr_vals = NULL; str ldap_pwd_attr_name = str_init("SIPIdentityPassword"); str res_password; rc = ldap_api.ldap_result_attr_vals(&ldap_pwd_attr_name, &attr_vals); if (rc < 0) { LM_ERR("ldap_result_attr_vals failed\n"); ldap_api.ldap_value_free_len(attr_vals); return -1; } if (rc == 1) { LM_INFO("No password attribute value found for [%s]\n", sip_username); ldap_api.ldap_value_free_len(attr_vals); return 2; } res_password.s = attr_vals[0]->bv_val; res_password.len = attr_vals[0]->bv_len; ldap_api.ldap_value_free_len(attr_vals); LM_INFO("Password for user [%s]: [%s]\n", sip_username, res_password.s); ... return 0; ``` -------------------------------- ### Example LDAP Session Specification Source: https://docs.opensips.org/manual/4-0/modules/ldap A complete example of an LDAP session definition including server URLs, credentials, and TLS settings. ```ini [example_ldap] ldap_server_url = "ldap://ldap1.example.com, ldap://ldap2.example.com" ldap_bind_dn = "cn=sip_proxy,ou=accounts,dc=example,dc=com" ldap_bind_password = "pwd" ldap_network_timeout = 500 ldap_client_bind_timeout = 500 ldap_ca_cert_file = "/usr/share/ca-certificates/mycert.pem" ldap_cert_file = "/var/my-certificate/certificate.pem" ldap_key_file = "/var/my-certificate/key.pem" ldap_require_certificate = "ALLOW" ``` -------------------------------- ### Configure authentication and database modules Source: https://docs.opensips.org/manual/4-0/modules/db_unixodbc Loads required authentication modules and sets parameters for database interaction. ```opensips .... loadmodule "/usr/local/lib/opensips/modules/auth.so" loadmodule "/usr/local/lib/opensips/modules/auth_db.so" modparam("usrloc", "working_mode_preset", "single-instance-sql-write-back") modparam("auth_db", "calculate_ha1", yes) modparam("auth_db", "password_column", "password") .... ``` -------------------------------- ### Example of async() usage with resume route Source: https://docs.opensips.org/manual/4-0/script-async Demonstrates pausing script execution for a database query and handling the result in a resume route. ```OpenSIPS Script route { /* preparation code */ ... async( sql_query("SELECT credit FROM users WHERE uid='$avp(uid)'", "$avp(credit)"), resume_credit); /* script execution is paused right away! */ } route [resume_credit] { if ($rc < 0) { xlog("error $rc in avp_db_query()\n"); exit; } xlog("Credit of user $avp(uid) is $avp(credit)\n"); ... t_relay(); } ``` -------------------------------- ### Execute all conformance tests Source: https://docs.opensips.org/manual/4-0/conformance-tests Run the full suite of available tests using the default configuration. ```bash sipssert * ``` -------------------------------- ### {s.rindex} Source: https://docs.opensips.org/manual/4-0/script-tran Searches for one string within another starting at the end of the first string. Returns the starting index of the found string or NULL if not found. ```APIDOC ## {s.rindex} ### Description Searches for one string within another starting at the end of the first string. Returns the starting index of the string found or NULL if not found. The optional index specifies an offset to start the search before. ### Usage $(var(strtosearch){s.rindex, $var(str)}) $(var(strtosearch){s.rindex, $var(str), index}) ``` -------------------------------- ### rtpengine_start_forwarding([flags[, sockvar]]) Source: https://docs.opensips.org/manual/4-0/modules/rtpengine Starts forwarding media to a TLS destination specified in the tls-send-to parameter of RTPEngine. ```APIDOC ## rtpengine_start_forwarding([flags[, sockvar]]) ### Description This function starts forwarding media to a TLS destination. You can select the media stream to forward by specifying the from-tag of the entity; if missing, all media streams are forwarded. ``` -------------------------------- ### Perform Asynchronous HTTP GET Source: https://docs.opensips.org/manual/4-0/modules/rest_client Uses the async function to execute a non-blocking GET request, suspending script execution until the response is received. ```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; } ... } ``` -------------------------------- ### Configure FreeSWITCH ESL Subscriptions Source: https://docs.opensips.org/manual/4-0/modules/freeswitch_scripting Adds FreeSWITCH ESL URLs for startup connections, including optional event subscriptions. ```OpenSIPS Script ... 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") ... ```