当前位置:   article > 正文

opensips 配置文件_error, some other host already uses address 192.16

error, some other host already uses address 192.168.1.8.

opensips 配置文件

  1. Upon installation, the default configuration file path is :
  2. [INSTALL_PATH]/etc/opensips/opensips.cfg
  3. The configuration file is text-based, written in an OpenSIPS custom language, very similar to the C language. You will find different variables ( each with different scopes - explained further down the manual ), you can do the classical constructs like if / while / switch, etc, and you can also call sub-routines with parameters, so the script should be fairly easily read-able by somebody with some SIP & programming skills.
  4. If you do any change to the configuration file, in order for them to take effect, you MUST restart OpenSIPS
  5. Due to the fact that you must restart OpenSIPS every time you make a change to the configuration file, it is of vital importance to ensure that all the changes you have made are correct according to the OpenSIPS language syntax.
  6. You can check the OpenSIPS configuration file validity by running
  7. [INSTALL_PATH]/sbin/opensips -C [PATH_TO_CFG]
  8. When checking the configuration file for validity, If the cfg is OK, OpenSIPS will return 0.
  9. If the config file contains any errors, they will be displayed in the console and OpenSIPS will return -1
  10. Generating OpenSIPS config files is accomplished by using the menuconfig tool. Because the graphical interface is ncurses based, please make sure to first install the ncurses development library ( typically libncurses5-dev ).
  11. 1. Using the Menuconfig Tool
  12. The menuconfig can be ran either directly from the OpenSIPS sources, or post installation, from the installation path :
  13. From sources, you can run
  14. make menuconfig
  15. After installation, you can run menuconfig directly from the installation path, by running
  16. [install_path]/sbin/osipsconfig
  17. Once in the menuconfig tool, navigate to the 'Generate OpenSIPS Script' option, and then choose your desired script type. Once you have chosen you script type, you will be able to go to configure the various available options for that script ( described below ). Enabling certain options per script is done by using the spacebar key. Once you have configured your desired options, you can hit the 'q' key to go to the previous menu, and hit 'Save Changes'. Then, you can generate the OpenSIPS script with your configurations. At the end, the graphical tool will give you the path for your newly generated config file ( eg : Config generated : /usr/local/opensips_proxy_1.11/etc/opensips/opensips_residential_2013-5-21_11:39:48.cfg )
  18. 2. Types of Configs
  19. So far, the OpenSIPS 1.11 menuconfig automated script generator supports 3 types of scripts. Here are the types of scripts, along with the available options per script :
  20. Residential Script
  21. ENABLE_TCP : OpenSIPS will listen on TCP for SIP requests
  22. ENABLE_TLS : OpenSIPS will listen on TCP for SIP requests
  23. USE_ALIASES : OpenSIPS will allow the use of Aliases for SIP users
  24. USE_AUTH : OpenSIPS will authenticate Register & Invite requests
  25. USE_DBACC : OpenSIPS will save ACC entries in DB for all calls
  26. USE_DBUSRLOC : OpenSIPS will persistently store User Location entries in the DB
  27. USE_DIALOG : OpenSIPS will keep track of active dialogs
  28. USE_MULTIDOMAIN : OpenSIPS will handle multiple domains for subscribers
  29. USE_NAT : OpenSIPS will try to cope with NAT by fixing SIP msgs and engaging RTPProxy
  30. USE_PRESENCE : OpenSIPS will act as a Presence server
  31. USE_DIALPLAN : OpenSIPS will use dialplan for transformation of local numbers
  32. VM_DIVERSION : OpenSIPS will redirect to VM calls not reaching the subscribers
  33. HAVE_INBOUND_PSTN : OpenSIPS will accept calls from PSTN gateways (with static IP authentication)
  34. HAVE_OUTBOUND_PSTN : OpenSIPS will send numerical dials to PSTN gateways (with static IP definition)
  35. USE_DR_PSTN : OpenSIPS will use Dynamic Routing Support ( LCR ) for PSTN interconnection
  36. Trunking Script
  37. ENABLE_TCP : OpenSIPS will listen on TCP for SIP requests
  38. ENABLE_TLS : OpenSIPS will listen on TCP for SIP requests
  39. USE_DBACC : OpenSIPS will save ACC entries in DB for all calls
  40. USE_DIALPLAN : OpenSIPS will use dialplan for transformation of local numbers
  41. USE_DIALOG : OpenSIPS will keep track of active dialogs
  42. DO_CALL_LIMITATION : OpenSIPS will limit the number of parallel calls per trunk
  43. Load-Balancer Script
  44. ENABLE_TCP : OpenSIPS will listen on TCP for SIP requests
  45. ENABLE_TLS : OpenSIPS will listen on TCP for SIP requests
  46. USE_DBACC : OpenSIPS will save ACC entries in DB for all calls
  47. USE_DISPATCHER : OpenSIPS will use DISPATCHER instead of Load-Balancer for distributing the traffic
  48. DISABLE_PINGING : OpenSIPS will not ping at all the destinations (otherwise it will ping when detected as failed)
  49. 3. Post-Generation Script editing
  50. After generating your OpenSIPS script with the menuconfig tool, you need to open the script with your favorite editor, and go through all the '# CUSTOMIZE ME' comments in the script. Those comments mark the places where user attention is needed, and usually refer to customizing the OpenSIPS listening address or setting the proper database URL.
  51. Upon making the appropriate '# CUSTOMIZE ME' changes, you can save your script and take it for a test drive.
  52. The OpenSIPs configuration script has three main logical parts :
  53. global parameters
  54. modules section
  55. routing logic
  56. Global parameters
  57. Usually, in the first part, you declare the OpenSIPS global parameters - these global or core parameters are affecting the OpenSIPS core and possible the modules.
  58. Configuring the network listeners, available transport protocols, forking (and number of processes), the logging and other global stuff is provided by these global parameters.
  59. Example:
  60. disable_tcp = yes
  61. listen = udp:192.168.2.10:5060
  62. listen = udp:192.168.2.10:5070
  63. fork = yes
  64. children = 4
  65. log_stderror = no
  66. Modules section
  67. In regards to the OpenSIPS modules,the modules that are to be loaded (no module is loaded by default) are specified by using the directive loadmodule. Modules are to be specified by name and an optional path (to the .so file). If no path is provided (and just the name of the module), the default path will be assumed for locating the loading the module (default path is /usr/lib/opensips/modules if not other one configured at compile time. For configuring a different path, either the path is pushed directly with the module name (to get control per module) or it can be globally (for all modules) configured via the mpath global parameter.
  68. Once the modules are loaded, the parameters of the modules may be set using the modparam directive - to list of available parameters for each module, the type of parameter value (integer or string) can be found in the documentation of the modules, the Parameters section.
  69. Examples:
  70. loadmodule "modules/mi_datagram/mi_datagram.so"
  71. modparam("mi_datagram", "socket_name", "udp:127.0.0.1:4343")
  72. modparam("mi_datagram", "children_count", 3)
  73. or
  74. mpath="/usr/local/opensips_proxy/lib/modules"
  75. loadmodule "mi_datagram.so"
  76. modparam("mi_datagram", "socket_name", "udp:127.0.0.1:4343")
  77. modparam("mi_datagram", "children_count", 3)
  78. loadmodule "mi_fifo.so"
  79. modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
  80. Routing logic
  81. The routing logic is actually a sum of routes (script routes) that contain the OpenSIPS logic for routing SIP traffic. The description of OpenSIPS behavior in relation to the SIP traffic is done via this routes.
  82. There are different types of routes :
  83. top routes - routes that are directly triggered by OpenSIPs when some events occurs (like SIP request received, SIP reply received, transaction failed, etc)
  84. sub-routes - routes that are triggered / used from other routes in script.
  85. What are the existing top routes, when they are triggered, what kind of SIP messages is handled, what SIP operations are allowed and other are documented in the types of routes section.
  86. The sub-routes have names and they are to be called from any other route (top or sub) in the script via their names. The sub-routes may take parameters (when called) or return a numerical code (avoid returning 0 value as this will terminate your whole script. The sub-routes are similar to functions / procedure in any programing language. See the description of the route directive.
  87. Example:
  88. route { # top route triggered on incoming SIP requests
  89. if ( route(src_ip_is_gw) ) {
  90. xlog("request $rm comes from GW\n");
  91. }
  92. }
  93. onreply_route { # top route triggered on incoming SIP replies
  94. if ( route(src_ip_is_gw) ) {
  95. xlog("reply $rc comes from GW\n");
  96. }
  97. }
  98. route[src_ip_is_gw] { #sub-route
  99. if ($si=='11.22.33.44' || $si=='11.22.33.45')
  100. return 1;
  101. return -1;
  102. }
  103. This section lists the all the parameters exported by OpenSIPS core for script usage (to be used in opensips.cfg)
  104. This document is for OpenSIPS 1.11.x
  105. Core keywords
  106. Core values
  107. Core parameters
  108. 1. Core Keywords
  109. Keywords specific to SIP messages which can be used mainly in 'if' expressions.
  110. 1.1 af
  111. The address family of the received SIP message. It is INET if the message was received over IPv4 or INET6 if the message was received over IPv6.
  112. Exampe of usage:
  113. if(af==INET6) {
  114. log("Message received over IPv6 link\n");
  115. };
  116. 1.2 dst_ip
  117. The IP of the local interface where the SIP message was received. When the proxy listens on many network interfaces, makes possible to detect which was the one that received the packet.
  118. Example of usage:
  119. if(dst_ip==127.0.0.1) {
  120. log("message received on loopback interface\n");
  121. };
  122. 1.3 dst_port
  123. The local port where the SIP packet was received. When OpenSIPS is listening on many ports, it is useful to learn which was the one that received the SIP packet.
  124. Example of usage:
  125. if(dst_port==5061)
  126. {
  127. log("message was received on port 5061\n");
  128. };
  129. 1.4 from_uri
  130. This script variable is a reference to the URI of 'From' header. It can be used to test 'From'- header URI value.
  131. Example of usage:
  132. if(is_method("INVITE") && from_uri=~".*@opensips.org")
  133. {
  134. log("the caller is from opensips.org\n");
  135. };
  136. 1.5 method
  137. The variable is a reference to the SIP method of the message.
  138. Example of usage:
  139. if(method=="REGISTER")
  140. {
  141. log("this SIP request is a REGISTER message\n");
  142. };
  143. 1.6 msg:len
  144. The variable is a reference to the size of the message. It can be used in 'if' constructs to test message's size.
  145. Example of usage:
  146. if(msg:len>2048)
  147. {
  148. sl_send_reply("413", "message too large");
  149. exit;
  150. };
  151. 1.7 $retcode
  152. It represents the value returned by last function executed (similar to $? from bash -- if you wish, you can use also $? in OpenSIPS config, both names '$retcode' and '$?' are supported). If tested after a call of a route, it is the value retuned by that route.
  153. Example of usage:
  154. route {
  155. route(1);
  156. if($retcode==1)
  157. {
  158. log("The request is an INVITE\n");
  159. };
  160. }
  161. route[1] {
  162. if(is_method("INVITE"))
  163. return(1);
  164. return(2);
  165. }
  166. 1.8 proto
  167. This variable can be used to test the transport protocol of the SIP message.
  168. Example of usage:
  169. if(proto==UDP)
  170. {
  171. log("SIP message received over UDP\n");
  172. };
  173. 1.9 status
  174. If used in onreply_route, this variable is a reference to the status code of the reply. If it used in a standard route block, the variable is a reference to the status of the last reply sent out for the current request.
  175. Example of usage:
  176. if(status=="200")
  177. {
  178. log("this is a 200 OK reply\n");
  179. };
  180. 1.10 src_ip
  181. Reference to source IP address of the SIP message.
  182. Example of usage:
  183. if(src_ip==127.0.0.1)
  184. {
  185. log("the message was sent from localhost!\n");
  186. };
  187. 1.11 src_port
  188. Reference to source port of the SIP message (from which port the message was sent by previous hop).
  189. Example of usage:
  190. if(src_port==5061)
  191. {
  192. log("message sent from port 5061\n");
  193. }
  194. 1.12 to_uri
  195. This variable can be used to test the value of URI from To header.
  196. Example of usage:
  197. if(to_uri=~"sip:.+@opensips.org")
  198. {
  199. log("this is a request for opensips.org users\n");
  200. };
  201. 1.13 uri
  202. This variable can be used to test the value of the request URI.
  203. Example of usage:
  204. if(uri=~"sip:.+@opensips.org")
  205. {
  206. log("this is a request for opensips.org users\n");
  207. };
  208. ↑ Contents
  209. 2. Core Values
  210. Values that can be used in 'if' expressions to check against Core Keywords
  211. 2.1 INET
  212. This keyword can be used to test whether the SIP packet was received over an IPv4 connection.
  213. Example of usage:
  214. if(af==INET)
  215. {
  216. log("the SIP message was received over IPv4\n");
  217. };
  218. 2.2 INET6
  219. This keyword can be used to test whether the SIP packet was received over an IPv6 connection.
  220. Example of usage:
  221. if(af==INET6)
  222. {
  223. log("the SIP message was received over IPv6\n");
  224. };
  225. 2.3 TCP
  226. This keyword can be used to test the value of 'proto' and check whether the SIP packet was received over TCP or not.
  227. Example of usage:
  228. if(proto==TCP)
  229. {
  230. log("the SIP message was received over TCP\n");
  231. };
  232. 2.4 UDP
  233. This keyword can be used to test the value of 'proto' and check whether the SIP packet was received over UDP or not.
  234. Example of usage:
  235. if(proto==UDP)
  236. {
  237. log("the SIP message was received over UDP\n");
  238. };
  239. 2.5 max_len
  240. This keyword is set to the maximum size of an UDP packet. It can be used to test message's size.
  241. Example of usage:
  242. if(msg:len>max_len)
  243. {
  244. sl_send_reply("413", "message too large to be forwarded over UDP without fragmentation");
  245. exit;
  246. }
  247. 2.6 myself
  248. It is a reference to the list of local IP addresses, hostnames and aliases that has been set in OpenSIPS configuration file. This lists contain the domains served by OpenSIPS.
  249. The variable can be used to test if the host part of an URI is in the list. The usefulness of this test is to select the messages that has to be processed locally or has to be forwarded to another server.
  250. See "alias" to add hostnames,IP addresses and aliases to the list.
  251. Example of usage:
  252. if(uri==myself) {
  253. log("the request is for local processing\n");
  254. };
  255. 2.7 null
  256. Can be used in assignment to reset the value of a per-script variable or to delete an avp.
  257. Example of usage:
  258. $avp(i:12) = null;
  259. $var(x) = null;
  260. ↑ Contents
  261. 3. Core parameters
  262. Global parameters that can be set in configuration file. Accepted values are, depending on the actual parameters strings, numbers and yes/ no. If you need to specify either "yes" or "no" as part of a string, wrap this in double quotes.
  263. 3.1 advertised_address
  264. It can be an IP address or string and represents the address advertised in Via header and other destination lumps (e.g RR header). If empty or not set (default value) the socket address from where the request will be sent is used.
  265. WARNING:
  266. - don't set it unless you know what you are doing (e.g. nat traversal)
  267. - you can set anything here, no check is made (e.g. foo.bar will be
  268. accepted even if foo.bar doesn't exist)
  269. Example of usage:
  270. advertised_address="opensips.org"
  271. NOTE: Aside this global approach, you can also define an advertise IP and port in a per-interface manner (see the "listen" parameter). When advertise values are defined per interface, they will be used only for traffic leaving that interface only.
  272. 3.2 advertised_port
  273. The port advertised in Via header and other destination lumps (e.g. RR). If empty or not set (default value) the port from where the message will be sent is used. Same warnings as for 'advertised_address'.
  274. Example of usage:
  275. advertised_port=5080
  276. NOTE: Aside this global approach, you can also define an advertise IP and port in a per-interface manner (see the "listen" parameter). When advertise values are defined per interface, they will be used only for traffic leaving that interface only.
  277. 3.3 alias
  278. Parameter to set alias hostnames for the server. It can be set many times, each value being added in a list to match the hostname when 'myself' is checked.
  279. It is necessary to include the port (the port value used in the "port=" or "listen=" definitions) in the alias definition otherwise the loose_route() function will not work as expected for local forwards
  280. Example of usage:
  281. alias=other.domain.com:5060
  282. alias=another.domain.com:5060
  283. 3.4 auto_aliases
  284. This parameter controls if aliases should be automatically discovered and added during fixing listening sockets. The auto discovered aliases are result of the DNS lookup (if listen is a name and not IP) or of a reverse DNS lookup on the listen IP.
  285. Far backward compatibility reasons, the default value is "on".
  286. Example of usage:
  287. auto_aliases=no
  288. auto_aliases=0
  289. 3.5 bin_listen
  290. Defines a UDP listening interface for one or more Binary Packet Receivers. Default value is "null" (not listening).
  291. Example of usage:
  292. bin_listen=10.0.0.150:5062
  293. 3.6 bin_children
  294. The number of UDP listeners for the Binary Internal Interface. Default value is 1.
  295. Example of usage:
  296. bin_children=4
  297. 3.7 check_via
  298. Check if the address in top most via of replies is local. Default value is 0 (check disabled).
  299. Example of usage:
  300. check_via=1
  301. 3.8 children
  302. Number of children to fork for each UDP or SCTP interface you have defined. Default value is 8.
  303. Example of usage:
  304. children=16
  305. NOTE: this global value (applicable for all UDP/SCTP interfaces) can be override if you set a different number of children in the definition of a specific interface - so actually you can define a different number of children for each interface (see the "listen" parameter for syntax).
  306. 3.9 chroot
  307. The value must be a valid path in the system. If set, OpenSIPS will chroot (change root directory) to its value.
  308. Example of usage:
  309. chroot=/other/fakeroot
  310. 3.10 db_version_table
  311. The name of the table version to be used by the DB API to check the version of the used tables.
  312. Default value is "version"
  313. Example of usage:
  314. db_version_table="version_1_8"
  315. 3.11 db_default_url
  316. The default DB URL to be used by modules if no per-module URL is given. Default is NULL (not defined)
  317. Example of usage:
  318. db_default_url="mysql://opensips:opensipsrw@localhost/opensips"
  319. 3.12 debug
  320. Set the debug level. Higher values make OpenSIPS to print more debug messages.
  321. Examples of usage:
  322. debug=1 -- print only important messages (like errors or more critical situations)
  323. - recommended for running proxy as daemon
  324. debug=4 -- print a lot of debug messages - use it only when doing debugging sessions
  325. Actual values are:
  326. -3 - Alert level
  327. -2 - Critical level
  328. -1 - Error level
  329. 1 - Warning level
  330. 2 - Notice level
  331. 3 - Info level
  332. 4 - Debug level
  333. The 'debug' parameter is usually used in concordance with 'log_stderror' parameter.
  334. Value of 'debug' parameter can also be get and set dynamically using 'debug' Core MI function.
  335. 3.13 disable_503_translation
  336. If 'yes', OpenSIPS will not translate the received 503 replies into 500 replies (RFC 3261 clearly states that a proxy should never relay a 503 response, but instead it must transform it into a 500).
  337. Default value is 'no' (do translation).
  338. 3.14 disable_core_dump
  339. Can be 'yes' or 'no'. By default core dump limits are set to unlimited or a high enough value. Set this config variable to 'yes' to disable core dump-ing (will set core limits to 0).
  340. Default value is 'no'.
  341. Example of usage:
  342. disable_core_dump=yes
  343. 3.15 disable_dns_blacklist
  344. The DNS resolver, when configured with failover, can automatically store in a temporary blacklist the failed destinations. This will prevent (for a limited period of time) OpenSIPS to send requests to destination known as failed. So, the blacklist can be used as a memory for the DNS resolver.
  345. The temporary blacklist created by DNS resolver is named "dns" and it is by default selected for usage (no need use the use_blacklist()) function. The rules from this list have a life time of 4 minutes - you can change it at compile time, from resolve.c .
  346. Can be 'yes' or 'no'. By default the blacklist is disabled (Default value is 'yes').
  347. Example of usage:
  348. disable_dns_blacklist=no
  349. 3.16 disable_dns_failover
  350. Can be 'yes' or 'no'. By default DNS-based failover is enabled. Set this config variable to 'yes' to disable the DNS-based failover. This is a global option, affecting the core and the modules also.
  351. Default value is 'no'.
  352. Example of usage:
  353. disable_dns_failover=yes
  354. 3.17 disable_stateless_fwd
  355. Can be 'yes' or 'no'. This parameter controls the handling of stateless replies:
  356. yes - drop stateless replies if stateless fwd functions (like forward) are not used in script
  357. no - forward stateless replies
  358. Default value is 'yes'.
  359. 3.18 disable_tcp
  360. Global parameter to disable TCP support in the SIP server. Default value is 'no'.
  361. Example of usage:
  362. disable_tcp=yes
  363. 3.19 disable_tls
  364. Global parameter to disable TLS support in the SIP server. Default value is 'yes'.
  365. Example of usage:
  366. disable_tcp=no
  367. 3.20 dns
  368. This parameter controls if the SIP server should attempt to lookup its own domain name in DNS. If this parameter is set to yes and the domain name is not in DNS a warning is printed on syslog and a "received=" field is added to the via header.
  369. Default is no.
  370. 3.21 dns_retr_time
  371. Time in seconds before retrying a dns request. Default value is system specific, depends also on the '/etc/resolv.conf' content (usually 5s).
  372. Example of usage:
  373. dns_retr_time=3
  374. 3.22 dns_retr_no
  375. Number of dns retransmissions before giving up. Default value is system specific, depends also on the '/etc/resolv.conf' content (usually 4).
  376. Example of usage:
  377. dns_retr_no=3
  378. 3.23 dns_servers_no
  379. How many dns servers from the ones defined in '/etc/resolv.conf' will be used. Default value is to use all of them.
  380. Example of usage:
  381. dns_servers_no=2
  382. 3.24 dns_try_ipv6
  383. Can be 'yes' or 'no'. If it is set to 'yes' and a DNS lookup fails, it will retry it for ipv6 (AAAA record). Default value is 'no'.
  384. Example of usage:
  385. dns_try_ipv6=yes
  386. 3.25 dns_try_naptr
  387. Disables the NAPTR lookups when doing DNS based routing for SIP requests - if disabled, the DNS lookup will start with SRV lookups. Can be 'yes' or 'no'. By default it is enabled, value 'yes'.
  388. Example of usage:
  389. dns_try_naptr=no
  390. 3.26 dns_use_search_list
  391. Can be 'yes' or 'no'. If set to 'no', the search list in '/etc/resolv.conf' will be ignored (=> fewer lookups => gives up faster). Default value is 'yes'.
  392. HINT: even if you don't have a search list defined, setting this option to 'no' will still be "faster", because an empty search list is in fact search "" (so even if the search list is empty/missing there will still be 2 dns queries, eg. foo+'.' and foo+""+'.')
  393. Example of usage:
  394. dns_use_search_list=no
  395. 3.27 dst_blacklist
  396. Definition of a static (read-only) IP/destination blacklist. These lists can be selected from script (at runtime) to filter the outgoing requests, based on IP, protocol, port, etc.
  397. 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).
  398. Example of usage:
  399. # filter out requests going to ips of my gws
  400. dst_blacklist = gw:{( tcp , 192.168.2.100 , 5060 , "" ),( any , 192.168.2.101 , 0 , "" )}
  401. # block requests going to "evil" networks
  402. dst_blacklist = net_filter:{ ( any , 192.168.1.110/255.255.255.0 , 0 , "" )}
  403. # block message requests with nasty words
  404. dst_blacklist = msg_filter:{ ( any , 192.168.20.0/255.255.255.0 , 0 , "MESSAGE*ugly_word" )}
  405. # block requests not going to a specific subnet
  406. dst_blacklist = net_filter2:{ !( any , 192.168.30.0/255.255.255.0 , 0 , "" )}
  407. Each rule is defined by:
  408. protocol : TCP, UDP, TLS or "any" for anything
  409. port : number or 0 for any
  410. ip/mask
  411. test patter - is a filename like matching (see "man 3 fnmatch") applied on the outgoing request buffer (first_line+hdrs+body)
  412. 3.28 event_pkg_threshold
  413. A number representing the percentage threshold above which the E_CORE_PKG_THRESHOLD event is raised, warning about low amount of free private memory. It accepts integer values between 0 and 100.
  414. Default value is 0 ( event disabled ).
  415. Example of usage:
  416. event_pkg_threshold = 90
  417. 3.29 event_shm_threshold
  418. A number representing the percentage threshold above which the E_CORE_SHM_THRESHOLD event is raised, warning about low amount of free shared memory. It accepts integer values between 0 and 100.
  419. Default value is 0 ( event disabled ).
  420. Example of usage:
  421. event_shm_threshold = 90
  422. 3.30 exec_dns_threshold
  423. A number representing the maximum number of microseconds a DNS query is expected to last. Anything above the set number will trigger a warning message to the logging facility.
  424. Default value is 0 ( logging disabled ).
  425. Example of usage:
  426. exec_dns_threshold = 60000
  427. 3.31 exec_msg_threshold
  428. A number representing the maximum number of microseconds the processing of a SIP msg is expected to last. Anything above the set number will trigger a warning message to the logging facility. Aside from the message and the processing time, the most time consuming function calls from the script will also be logged.
  429. Default value is 0 ( logging disabled ).
  430. Example of usage:
  431. exec_msg_threshold = 60000
  432. 3.32 fork
  433. If set to 'yes' the proxy will fork and run in daemon mode - one process will be created for each network interface the proxy listens to and for each protocol (TCP/UDP), multiplied with the value of 'children' parameter.
  434. When set to 'no', the proxy will stay bound to the terminal and runs as single process. First interface is used for listening to. OpenSIPS will only listen on UDP. Since the process is attached to the controlling terminal, not PID file will be created even if the -P command line option was specified.
  435. Default value is 'yes'.
  436. Example of usage:
  437. fork=no
  438. 3.33 group gid
  439. The group id to run OpenSIPS.
  440. Example of usage:
  441. group="opensips"
  442. 3.34 include_file
  443. Can be called from outside route blocks to load additional routes/blocks or from inside them to simply preform more functions. The file path can be relative or absolute. If it is not an absolute path, first attempt is to locate it relative to current directory. If that fails, second try is relative to directory of the file that includes it. Will throw an error if file is not found.
  444. Example of usage:
  445. include_file "proxy_regs.cfg"
  446. 3.35 import_file
  447. Same as include_file but will not throw an error if file is not found.
  448. Example of usage:
  449. import_file "proxy_regs.cfg"
  450. 3.36 listen
  451. Set the network addresses the SIP server should listen to. It can be an IP address, hostname or network interface id or combination of protocol:address:port (e.g., udp:10.10.10.10:5060). This parameter can be set multiple times in same configuration file, the server listening on all addresses specified.
  452. The listen definition may accept several optional parameters for:
  453. configuring an advertise IP and port only for this interface. Syntax "AS 11.22.33.44:5060"
  454. setting a different number of children for this interface only (for UDP and SCTP interfaces only). This will override the global "children" parameter. Syntax "use_children 5"
  455. Remember that this parameters have affect only for the interface they are configured for; if not defined per interface, the global values will be used.
  456. Example of usage:
  457. listen=10.10.10.10
  458. listen=eth1:5062
  459. listen=udp:10.10.10.10:5064
  460. listen=udp:127.0.0.1:5060 use_children 5
  461. listen=udp:127.0.0.1:5060 as 99.88.44.33:5060 use_children 3
  462. listen=127.0.0.1 use_children 3
  463. If you omit this directive then the SIP server will listen on all interfaces. On start the SIP server reports all the interfaces that it is listening on. Even if you specify only UDP interfaces here, the server will start the TCP engine too. If you don't want this, you need to disable the TCP support completely with the core parameter disable_tcp.
  464. 3.37 log_facility
  465. If OpenSIPS logs to syslog, you can control the facility for logging. Very useful when you want to divert all OpenSIPS logs to a different log file. See the man page syslog(3) for more details.
  466. For more see: http://www.voice-system.ro/docs/ser-syslog/
  467. Default value is LOG_DAEMON.
  468. Example of usage:
  469. log_facility=LOG_LOCAL0
  470. 3.38 log_name
  471. Set the id to be printed in syslog. The value must be a string and has effect only when OpenSIPS runs in daemon mode (fork=yes), after daemonize. Default value is argv[0].
  472. Example of usage:
  473. log_name="osips-5070"
  474. 3.39 log_stderror
  475. With this parameter you can make OpenSIPS to write log and debug messages to standard error. Possible values are:
  476. - "yes" - write the messages to standard error
  477. - "no" - write the messages to syslog
  478. Default value is "no".
  479. For more see: http://www.voice-system.ro/docs/ser-syslog/
  480. Example of usage:
  481. log_stderror=yes
  482. 3.40 max_while_loops
  483. The parameters set the value of maximum loops that can be done within a "while". Comes as a protection to avoid infinite loops in config file execution. Default is 100.
  484. Example of usage:
  485. max_while_loops=200
  486. 3.41 maxbuffer
  487. The size in bytes not to be exceeded during the auto-probing procedure of discovering the maximum buffer size for receiving UDP messages. Default value is 262144.
  488. Example of usage:
  489. maxbuffer=65536
  490. 3.42 mem_warming
  491. Default value: off
  492. Only relevant when the HP_MALLOC compile flag is enabled. If set to "on", on each startup, OpenSIPS will attempt to restore the memory fragmentation pattern it had before the stop/restart. If no pattern_file from a previous run is found, memory warning is skipped, and the memory allocator simply starts with a big chunk of memory.
  493. Memory warming is useful when dealing with high volumes of traffic (thousands of cps on multi-core machines - the more cores, the more useful), because processes must mutually exclude themselves when chopping up the initial big memory chunk. By performing fragmentation on startup, OpenSIPS will also behave optimally in the first minute(s) after a restart. Fragmentation usually lasts a few seconds - OpenSIPS will not process traffic during this period.
  494. Example of usage:
  495. mem_warming = on
  496. 3.43 mem_warming_percentage
  497. Default value: 75
  498. How much of OpenSIPS's memory should be fragmented with the pattern of the previous run, upon a restart. Used at startup, if mem_warming is enabled.
  499. Example of usage:
  500. mem_warming_percentage = 50
  501. 3.44 mem_warming_pattern_file
  502. Default value: "CFG_DIR/mem_warming_pattern"
  503. The memory fragmentation pattern of a previous OpenSIPS run. Used at startup, if mem_warming is enabled.
  504. Example of usage:
  505. mem_warming_pattern_file = "/var/tmp/my_memory_pattern"
  506. 3.45 memdump | mem_dump
  507. Log level to print memory status information (runtime and shutdown). It has to be less than the value of 'debug' parameter if you want memory info to be logged. Default: memdump=L_DBG (4)
  508. Example of usage:
  509. memdump=2
  510. NOTE that setting memlog (see below), will also set the memdump parameter - if you want different values for memlog and memdump, you need to first set memlog and then memdump.
  511. 3.46 memlog | mem_log
  512. Log level to print memory debug info. It has to be less than the value of 'debug' parameter if you want memory info to be logged. Default: memlog=L_DBG (4)
  513. Example of usage:
  514. memlog=2
  515. NOTE: by setting memlog parameter, the memdump will automatically be set to the same value (see memdump docs).
  516. 3.47 mcast_loopback
  517. It can be 'yes' or 'no'. If set to 'yes', multicast datagram are sent over loopback. Default value is 'no'.
  518. Example of usage:
  519. mcast_loopback=yes
  520. 3.48 mcast_ttl
  521. Set the value for multicast ttl. Default value is OS specific (usually 1).
  522. Example of usage:
  523. mcast_ttl=32
  524. 3.49 mhomed
  525. Set the server to try to locate outbound interface on multihomed host. By default is not (0) - it is rather time consuming.
  526. Example of usage:
  527. mhomed=1
  528. 3.50 mpath
  529. Set the module search path. This can be used to simplify the loadmodule parameter
  530. Example of usage:
  531. mpath="/usr/local/lib/opensips/modules"
  532. loadmodule "mysql.so"
  533. loadmodule "uri.so"
  534. loadmodule "uri_db.so"
  535. loadmodule "sl.so"
  536. loadmodule "tm.so"
  537. ...
  538. 3.51 open_files_limit
  539. If set and bigger than the current open file limit, OpenSIPS will try to increase its open file limit to this number. Note: OpenSIPS must be started as root to be able to increase a limit past the hard limit (which, for open files, is 1024 on most systems).
  540. Example of usage:
  541. open_files_limit=2048
  542. 3.52 port
  543. The port the SIP server listens to. The default value for it is 5060.
  544. Example of usage:
  545. port=5080
  546. 3.53 reply_to_via
  547. If it is set to 1, any local reply is sent to the address advertised in top most Via of the request. Default value is 0 (off).
  548. Example of usage:
  549. reply_to_via=0
  550. 3.54 query_buffer_size
  551. If set to a value greater than 1, inserts to DB will not be flushed one by one. Rows to be inserted will be kept in memory until until they gather up to query_buffer_size rows, and only then they will be flushed to the database.
  552. Example of usage:
  553. query_buffer_size=5
  554. 3.55 query_flush_time
  555. If query_buffer_size is set to a value greater than 1, a timer will trigger once every query_flush_time seconds, ensuring that no row will be kept for too long in memory.
  556. Example of usage:
  557. query_flush_time=10
  558. 3.56 rev_dns
  559. This parameter controls if the SIP server should attempt to lookup its own IP address in DNS. If this parameter is set to yes and the IP address is not in DNS a warning is printed on syslog and a "received=" field is added to the via header.
  560. Default is no.
  561. 3.57 server_header
  562. The body of Server header field generated by OpenSIPS when it sends a request as UAS. It defaults to "OpenSIPS (<version> (<arch>/<os>))".
  563. Example of usage:
  564. server_header="Server: My Company SIP Proxy"
  565. Please note that you have to add the header name "Server:", otherwise OpenSIPS will just write a header like:
  566. My Company SIP Proxy
  567. 3.58 server_signature
  568. This parameter controls the "Server" header in any locally generated message.
  569. Example of usage:
  570. server_signature=no
  571. If it is enabled (default=yes) a header is generated as in the following example:
  572. Server: OpenSIPS (0.9.5 (i386/linux))
  573. 3.59 shm_hash_split_percentage
  574. Only relevant when the HP_MALLOC compile flag is enabled. It controls how many memory buckets will be optimized. (e.g. setting it to 2% will optimize the first 81 most used buckets as frequency). The default value is 1.
  575. 3.60 shm_secondary_hash_size
  576. Only relevant when the HP_MALLOC compile flag is enabled. It represents the optimization factor of a single bucket (e.g. setting it to 4 will cause the optimized buckets to be further split into 4). The default value is 8.
  577. 3.61 sip_warning
  578. Can be 0 or 1. If set to 1 (default value is 0) a 'Warning' header is added to each reply generated by OpenSIPS. The header contains several details that help troubleshooting using the network traffic dumps.
  579. Example of usage:
  580. sip_warning=0
  581. 3.62 tcp_async
  582. If the TCP connect and write operations should be done in an asynchronous mode. Default value is 0 ( blocking connect & write )
  583. Example of usage:
  584. tcp_async = 1
  585. 3.63 tcp_async_local_connect_timeout
  586. If tcp_async is enabled, this specifies the number of milliseconds during which connects will be done in blocking mode (optimization). If the connect operation lasts more than this, it will switch to async mode and will be passed to TCP MAIN for polling. Default value is 100 ms.
  587. Example of usage:
  588. tcp_async_local_connect_timeout = 10
  589. 3.64 tcp_async_local_write_timeout
  590. If tcp_async is enabled, this specifies the number of milliseconds during which a write op will be tried in blocking mode (optimization). If the write operation lasts more than this, it will switch to async mode and will be passed to TCP MAIN for polling. Default value is 10 ms.
  591. Example of usage:
  592. tcp_async_local_write_timeout = 20
  593. 3.65 tcp_async_max_postponed_chunks
  594. If tcp_async is enabled, this specifies the maximum number of SIP messages that can be stashed for later/async writing. If the connection pending writes exceed this number, the connection will be marked as broken and dropped. Default value is 32
  595. Example of usage:
  596. tcp_async_max_postponed_chunks = 64
  597. 3.66 tcp_children
  598. Number of children processes to be created for reading from TCP connections. If no value is explicitly set, the same number of TCP children as UDP children (see "children" parameter) will be used.
  599. Example of usage:
  600. tcp_children = 4
  601. 3.67 tcp_accept_aliases
  602. 3.68 tcp_listen_backlog
  603. The backlog argument defines the maximum length to which the queue of pending connections for the TCP listeners may grow. If a connection request arrives when the queue is full, the client may receive an error with an indication of ECONNREFUSED or, if the underlying protocol supports retransmission, the request may be ignored so that a later reattempt at connection succeeds.
  604. Default configured value is 10.
  605. 3.69 tcp_send_timeout
  606. Time in milliseconds after a TCP connection will be closed if it is not available for blocking writing in this interval (and OpenSIPS wants to send something on it). Default is 100ms
  607. Example of usage:
  608. tcp_send_timeout = 200
  609. 3.70 tcp_connect_timeout
  610. Time in milliseconds before an ongoing blocking attempt to connect will be aborted. Default is 100ms
  611. Example of usage:
  612. tcp_connect_timeout = 10
  613. 3.71 tcp_connection_lifetime!!!!
  614. Lifetime in seconds for TCP sessions. TCP sessions which are inactive for >tcp_connection_lifetime will be closed by OpenSIPS. Default value is defined in tcp_conn.h: #define DEFAULT_TCP_CONNECTION_LIFETIME 120. Setting this value to 0 will close the TCP connection pretty quick ;-). You can also set the TCP lifetime to the expire value of the REGISTER by using the tcp_persistent_flag parameter of the registrar module.
  615. Example of usage:
  616. tcp_connection_lifetime = 3600
  617. 3.72 tcp_max_connections
  618. maximum number of tcp connections (if the number is exceeded no new tcp connections will be accepted). Default is defined in tcp_conn.h: #define DEFAULT_TCP_MAX_CONNECTIONS 2048
  619. Example of usage:
  620. tcp_max_connections = 4096
  621. 3.73 tcp_max_msg_chunks
  622. The maximum number of chunks that a SIP message is expected to arrive via TCP. If a packet is received more fragmented than this, the connection is dropped ( either the connection is very overloaded and this leads to high fragmentation - or we are the victim of an ongoing attack where the attacker is sending the traffic very fragmented in order to decrease our performance ). Default value is is 4
  623. Example of usage:
  624. tcp_max_msg_chunks = 8
  625. 3.74 tcp_max_msg_time
  626. The maximum number of seconds that a SIP message is expected to arrive via TCP. If a single SIP packet is still not fully received after this number of seconds, the connection is dropped ( either the connection is very overloaded and this leads to high fragmentation - or we are the victim of an ongoing attack where the attacker is sending the traffic very fragmented in order to decrease our performance ). Default value is is 4
  627. Example of usage:
  628. tcp_max_msg_time = 8
  629. 3.75 tcp_poll_method
  630. poll method used (by default the best one for the current OS is selected). For available types see io_wait.c and poll_types.h: none, poll, epoll_lt, epoll_et, sigio_rt, select, kqueue, /dev/poll
  631. Example of usage:
  632. tcp_poll_method = select
  633. 3.76 tcp_no_new_conn_bflag
  634. A branch flag to be used as marker to instruct OpenSIPS not to attempt to open a new TCP connection when delivering a request, but only to reuse an existing one (if available). If no existing conn, a generic send error will be returned.
  635. This is intended to be used in NAT scenarios, where makes no sense to open a TCP connection towards a destination behind a NAT (like TCP connection created during registration was lost, so there is no way to contact the device until it re-REGISTER). Also this can be used to detect when a NATed registered user lost his TCP connection, so that opensips can disable his registration as useless.
  636. Example of usage:
  637. tcp_no_new_conn_bflag = 6
  638. ....
  639. route{
  640. ....
  641. if( destination_behin_nat && proto==TCP )
  642. setbflag(6);
  643. ....
  644. t_relay("0x02"); # no auto error reply
  645. $var(retcode) = $rc;
  646. if ($var(retcode)==-6) {
  647. #send error
  648. xlog("unable to send request to destination");
  649. send_reply("404","Not found");
  650. exit;
  651. } else if ($var(retcode)<0) {
  652. sl_reply_error();
  653. exit;
  654. }
  655. ....
  656. }
  657. 3.77 tcp_threshold
  658. A number representing the maximum number of microseconds sending of a TCP request is expected to last. Anything above the set number will trigger a warning message to the logging facility.
  659. Default value is 0 ( logging disabled ).
  660. Example of usage:
  661. tcp_threshold = 60000
  662. 3.78 tcp_keepalive
  663. Enable / disable TCP keepalive
  664. Example of usage:
  665. tcp_keepalive = 1
  666. 3.79 tcp_keepcount
  667. Number of keepalives to send before closing the connection (Linux only)
  668. Example of usage:
  669. tcp_keepcount = 5
  670. 3.80 tcp_keepidle
  671. Amount of time before OpenSIPS will start to send keepalives if the connection is idle (Linux only)
  672. Example of usage:
  673. tcp_keepidle = 30
  674. 3.81 tcp_keepinterval
  675. Interval between keepalive probes, if the previous one failed (Linux only)
  676. Example of usage:
  677. tcp_keepinterval = 10
  678. 3.82 tls_ca_list
  679. 3.83 tls_certificate
  680. 3.84 tls_ciphers_list
  681. 3.85 tls_domain
  682. 3.86 tls_handshake_timeout
  683. 3.87 tls_log
  684. 3.88 tls_method
  685. 3.89 tls_port_no
  686. 3.90 tls_private_key
  687. 3.91 tls_require_certificate
  688. 3.92 tls_send_timeout
  689. 3.93 tls_verify
  690. 3.94 tos
  691. The TOS (Type Of Service) to be used for the sent IP packages (both TCP and UDP).
  692. Example of usage:
  693. tos=IPTOS_LOWDELAY
  694. tos=0x10
  695. tos=IPTOS_RELIABILITY
  696. 3.95 user uid
  697. The user id to run OpenSIPS (OpenSIPS will suid to it).
  698. Example of usage:
  699. user="opensips"
  700. 3.96 user_agent_header
  701. The body of User-Agent header field generated by OpenSIPS when it sends a request as UAC. It defaults to "OpenSIPS (<version> (<arch>/<os>))".
  702. Example of usage:
  703. user_agent_header="User-Agent: My Company SIP Proxy"
  704. Please note that you have to include the header name "User-Agent:" as OpenSIPS does not add it and you will get an erroneous header like:
  705. My Company SIP Proxy
  706. 3.97 wdir
  707. The working directory used by OpenSIPS at runtime. You might find it usefull when come to generating core files :)
  708. Example of usage:
  709. wdir="/usr/local/opensips"
  710. or
  711. wdir=/usr/opensips_wd
  712. 3.98 xlog_buf_size
  713. Default value: 4096
  714. Size of the buffer used to print a single line on the chosen logging facility of OpenSIPS. If the buffer is too small, an overflow error will be printed, and the concerned line will be skipped.
  715. Usage example:
  716. xlog_buf_size = 8388608 #given in bytes
  717. 3.99 xlog_force_color
  718. Default value: false
  719. Only relevant when log_stderror is set to true. Enables the use of the color escape sequences, otherwise they will have no effect.
  720. Usage example:
  721. xlog_force_color = true
  722. OpenSIPS routing logic uses several types of routes. Each type of route is triggered by a certain event and allows you to process a certain type of message (request or reply).
  723. 1. route
  724. Request routing block. It contains a set of actions to be taken for SIP requests.
  725. Triggered by : receiving an external request from the network.
  726. Processing : the triggering SIP request.
  727. Type : initially stateless, may be forced to stateful by using TM functions.
  728. Default action : if the request is not either forwarded nor replied, the route will simply discard the request at the end.
  729. The main 'route' block identified by 'route{...}' or 'route[0]{...}' is executed for each SIP request.
  730. The implicit action after execution of the main route block is to drop the SIP request. To send a reply or forward the request, explicit actions must be called inside the route block.
  731. Example of usage:
  732. route {
  733. if(is_method("OPTIONS")) {
  734. # send reply for each options request
  735. sl_send_reply("200", "ok");
  736. exit();
  737. }
  738. route(1);
  739. }
  740. route[1] {
  741. # forward according to uri
  742. forward();
  743. }
  744. Note that if a 'route(X)' is called from a 'branch_route[Y]' then in 'route[X]' is just processed each separate branch instead of all branches together as occurs in main route.
  745. 2. branch_route
  746. Request's branch routing block. It contains a set of actions to be taken for each branch of a SIP request.
  747. Triggered by : preparation a new branch (of a request); the branch is well formed, but not yet sent out.
  748. Processing : the SIP request (with the branch particularities, like RURI, branch flags)
  749. Type : stateful
  750. Default action : if the branch is not dropped (via "drop" statement), the branch will be automatically sent out.
  751. It is executed only by TM module after it was armed via t_on_branch("branch_route_index").
  752. Example of usage:
  753. route {
  754. lookup("location");
  755. t_on_branch("1");
  756. if(!t_relay()) {
  757. sl_send_reply("500", "relaying failed");
  758. }
  759. }
  760. branch_route[1] {
  761. if(uri=~"10\.10\.10\.10") {
  762. # discard branches that go to 10.10.10.10
  763. drop();
  764. }
  765. }
  766. 3. failure_route
  767. Failed transaction routing block. It contains a set of actions to be taken each transaction that received only negative replies (>=300) for all branches.
  768. Triggered by : receiving or generation(internal) of a negative reply that completes the transaction (all branches are terminated with negative replies)
  769. Processing : the original SIP request (that was sent out)
  770. Type : stateful
  771. Default action : if no new branch is generated or no reply is forced over, by default, the winning reply will be sent back to UAC.
  772. The 'failure_route' is executed only by TM module after it was armed via t_on_failure("failure_route_index").
  773. Note that inside the 'failure_route', the request that initiated the transaction is being processed, and not its reply.
  774. Example of usage:
  775. route {
  776. lookup("location");
  777. t_on_failure("1");
  778. if(!t_relay()) {
  779. sl_send_reply("500", "relaying failed");
  780. }
  781. }
  782. failure_route[1] {
  783. if(is_method("INVITE")) {
  784. # call failed - relay to voice mail
  785. t_relay("udp:voicemail.server.com:5060");
  786. }
  787. }
  788. 4. onreply_route
  789. Reply routing block. It contains a set of actions to be taken for SIP replies.
  790. Triggered by : receiving of a reply from the network
  791. Processing : the received reply
  792. Type : stateful (if bound to a transaction) or stateless (if global reply route).
  793. Default action : if the reply is not dropped (only provisional replies can be), it will be injected and processed by the transaction engine.
  794. There are three types of onreply routes:
  795. global - it catches all replies received by OpenSIPS and does not need any special arming (simple definition is enough) - named 'onreply_route {...}' or 'onreply_route[0] {...}'.
  796. per request/transaction - it catches all received replies belonging to a certain transaction and need to be armed (via "t_on_reply()" ) at request time, in REQUEST ROUTE - named 'onreply_route[N] {...}'.
  797. per branch - it catches only the replies that belong to a certain branch from a transaction. It needs to be armed (also via "t_on_reply()" ) at request time, but in BRANCH ROUTE, when a certain outgoing branch is processed - named 'onreply_route[N] {...}'.
  798. Certain 'onreply_route' blocks can be executed by TM module for special replies. For this, the 'onreply_route' must be armed for the SIP requests whose replies should be processed within it, via t_on_reply("onreply_route_index").
  799. route {
  800. seturi("sip:bob@opensips.org"); # first branch
  801. append_branch("sip:alice@opensips.org"); # second branch
  802. t_on_reply("global"); # the "global" reply route
  803. # is set the whole transaction
  804. t_on_branch("1");
  805. t_relay();
  806. }
  807. branch_route[1] {
  808. if ($rU=="alice")
  809. t_on_reply("alice"); # the "alice" reply route
  810. # is set only for second branch
  811. }
  812. onreply_route {
  813. xlog("OpenSIPS received a reply from $si\n");
  814. }
  815. onreply_route[alice] {
  816. xlog("received reply on the branch from alice\n");
  817. }
  818. onreply_route[global] {
  819. if (t_check_status("1[0-9][0-9]")) {
  820. setflag(1);
  821. log("provisional reply received\n");
  822. if (t_check_status("183"))
  823. drop;
  824. }
  825. }
  826. 5. error_route
  827. The error route is executed automatically when a parsing error occurred during SIP request processing. This allow the administrator to decide what to do in case of error.
  828. Triggered by : parsing error in "route"
  829. Processing : failed request
  830. Type : stateless (recommended)
  831. Default action : discard request.
  832. In error_route, the following pseudo-variables are available to get access to error details:
  833. $(err.class) - the class of error (now is '1' for parsing errors)
  834. $(err.level) - severity level for the error
  835. $(err.info) - text describing the error
  836. $(err.rcode) - recommended reply code
  837. $(err.rreason) - recommended reply reason phrase
  838. error_route {
  839. xlog("--- error route class=$(err.class) level=$(err.level)
  840. info=$(err.info) rcode=$(err.rcode) rreason=$(err.rreason) ---\n");
  841. xlog("--- error from [$si:$sp]\n+++++\n$mb\n++++\n");
  842. sl_send_reply("$err.rcode", "$err.rreason");
  843. exit;
  844. }
  845. 6. local_route
  846. The local route is executed automatically when a new SIP request is generated by TM, internally (no UAC side). This is a route intended to be used for message inspection, accounting and for applying last changes on the message headers. Routing and signaling functions are not allowed.
  847. Triggered by : TM generating a brand new request
  848. Processing : the new request
  849. Type : stateful
  850. Default action : send the request out
  851. local_route {
  852. if (is_method("INVITE") && $ru=~"@foreign.com") {
  853. append_hf("P-hint: foreign request\r\n");
  854. exit;
  855. }
  856. if (is_method("BYE") ) {
  857. acc_log_request("internally generated BYE");
  858. }
  859. }
  860. 7. startup_route
  861. The startup_route is executed only once when OpenSIPS is started and before the processing of SIP messages begins. This is useful if some initiation actions are needed, like loading some data in the cache, to ease up the future processing. Notice that this route, compared to the others is not triggered at the receipt of a message, so the functions that can be called here must not do processing on the message.
  862. Triggered : At startup, before the listener processes are started.
  863. Processing : Initializing functions.
  864. startup_route {
  865. avp_db_query("select gwlist where ruleid==1",$avp(i:100));
  866. cache_store("local", "rule1", "$avp(i:100)");
  867. }
  868. 8. timer_route
  869. The timer_route is as the name suggests, a route executed periodically at a configured interval of time specified next to the name(in seconds). The same as the startup_route, this route does not process a message. You can defined more timer routes.
  870. Triggered by : The time keeper.
  871. Processing : Functions that do refresh actions.
  872. timer_route[gw_update, 300] {
  873. avp_db_query("select gwlist where ruleid==1",$avp(i:100));
  874. $shv(i:100) =$avp(i:100);
  875. }
  876. 9. event_route
  877. The event_route is used by the OpenSIPS Event Interface to execute script code when an event is triggered. The name of the route is the event that has to be handled by that route.
  878. Triggered by : the event_route module when an event raised by the OpenSIPS Event Interface
  879. Processing : the event triggered
  880. Type : stateless (recommended)
  881. Default action : no script code is executed when the event is raised.
  882. event_route[E_PIKE_BLOCKED] {
  883. xlog("The E_PIKE_BLOCKED event was raised\n");
  884. }
  885. Assignments, string and arithmetic operations can be done directly in the configuration file.
  886. 1. Assignment
  887. Assignments can be done like in C, via '=' (equal) operator. Not that not all variables (from script) can be written, some are read-only. Check with listing of variables to see which ones can be written too.
  888. $var(a) = 123;
  889. $ru = "sip:user@domain";
  890. There is a special assign operator ':=' (colon equal) that can be used with AVPs. If the right value is null, all AVPs with that name are deleted. If different, the new value will overwrite any existing values for the AVPs with than name (on other words, delete existing AVPs with same name, add a new one with the right side value).
  891. $avp(val) := 123;
  892. 2. String operations
  893. For strings, '+' is available to concatenate.
  894. $var(a) = "test";
  895. $var(b) = "sip:" + $var(a) + "@" + $fd;
  896. 3. Arithmetic and bitwise operations
  897. For numbers, one can use:
  898. + : plus
  899. - : minus
  900. / : divide
  901. * : multiply
  902. % : modulo
  903. | : bitwise OR
  904. & : bitwise AND
  905. ^ : bitwise XOR
  906. ~ : bitwise NOT
  907. << : bitwise left shift
  908. >> : bitwise right shift
  909. Example:
  910. $var(a) = 4 + ( 7 & ( ~2 ) );
  911. NOTE: to ensure the priority of operands in expression evaluations do use __parenthesis__.
  912. Arithmetic expressions can be used in condition expressions via test operator ' [ ... ] '.
  913. if( [ $var(a) & 4 ] )
  914. log("var a has third bit set\n");
  915. Statements you can use in the OpenSIPS config file while building the routing logic.
  916. 1. if
  917. IF-ELSE statement
  918. Prototype:
  919. if (expr) {
  920. actions;
  921. } else {
  922. actions;
  923. }
  924. The 'expr' should be a valid logical expression.
  925. The logical operators that can be used in the logical expressions:
  926. == - equal
  927. != - not equal
  928. =~ - regular expression matching (e.g. $rU =~ '^1800*' is "$rU begins with 1800" )
  929. !~ - regular expression not-matching
  930. > - greater
  931. >= - greater or equal
  932. < - less
  933. <= - less or equal
  934. && - logical AND
  935. || - logical OR
  936. ! - logical NOT
  937. [ ... ] - test operator - inside can be any arithmetic expression
  938. Example of usage:
  939. if ( is_method("INVITE") && $rp==5060 )
  940. {
  941. log("this sip message is an invite\n");
  942. } else {
  943. log("this sip message is not an invite\n");
  944. }
  945. 2. switch
  946. SWITCH statement - it can be used to test the value of a pseudo-variable.
  947. IMPORTANT NOTE: 'break' can be used only to mark the end of a 'case' branch (as it is in shell scripts). If you are trying to use 'break' outside a 'case' block the script will return error -- you must use 'return' there.
  948. Example of usage:
  949. route {
  950. route(my_logic);
  951. switch($retcode)
  952. {
  953. case -1:
  954. log("process INVITE requests here\n");
  955. break;
  956. case 1:
  957. log("process REGISTER requests here\n");
  958. break;
  959. case 2:
  960. case 3:
  961. log("process SUBSCRIBE and NOTIFY requests here\n");
  962. break;
  963. default:
  964. log("process other requests here\n");
  965. }
  966. # switch of R-URI username
  967. switch($rU)
  968. {
  969. case "101":
  970. log("destination number is 101\n");
  971. break;
  972. case "102":
  973. log("destination number is 102\n");
  974. break;
  975. case "103":
  976. case "104":
  977. log("destination number is 103 or 104\n");
  978. break;
  979. default:
  980. log("unknown destination number\n");
  981. }
  982. }
  983. route[my_logic]{
  984. if(is_method("INVITE"))
  985. {
  986. return(-1);
  987. };
  988. if(is_method("REGISTER"))
  989. return(1);
  990. }
  991. if(is_method("SUBSCRIBE"))
  992. return(2);
  993. }
  994. if(is_method("NOTIFY"))
  995. return(3);
  996. }
  997. return(-2);
  998. }
  999. Take care while using 'return' - 'return(0)' stops the execution of the script.
  1000. 3. while
  1001. while statement
  1002. Example of usage:
  1003. $var(i) = 0;
  1004. while($var(i) < 10)
  1005. {
  1006. xlog("counter: $var(i)\n");
  1007. $var(i) = $var(i) + 1;
  1008. }
  1009. 4. for each
  1010. for each statement - easy iteration over indexed pseudo variables
  1011. Example of usage:
  1012. $avp(arr) = 0;
  1013. $avp(arr) = 1;
  1014. $avp(arr) = 2;
  1015. $avp(arr) = 3;
  1016. $avp(arr) = 4;
  1017. for ($var(it) in $(avp(arr)[*]))
  1018. xlog("array value: $var(it)\n");
  1019. # iterate through all Contact URIs from each Contact header
  1020. for ($var(ct) in $(ct[*]))
  1021. xlog("Contact: $var(ct)\n");
  1022. # iterate through all Via headers of a SIP request
  1023. for ($var(via) in $(hdr(Via)[*]))
  1024. xlog("Found \"Via\" header: $var(via)\n");
  1025. This section lists the all the functions exported by OpenSIPS core for script usage (to be used in opensips.cfg)
  1026. 1. add_local_rport()
  1027. Add 'rport' parameter to the Via header generated by server (see RFC3581 for its meaning). It affects only the current processed request.
  1028. Example of usage:
  1029. add_local_rport()
  1030. 2. append_branch()
  1031. Similarly to t_fork_to, it extends destination set by a new entry. The difference is that current URI is taken as new entry.
  1032. Without parameter, the function copies the current URI into a new branch. Thus, leaving the main branch (the URI) for further manipulation.
  1033. With a parameter, the function copies the URI in the parameter into a new branch. Thus, the current URI is not manipulated.
  1034. 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).
  1035. Example of usage:
  1036. # if someone calls B, the call should be forwarded to C too.
  1037. #
  1038. if (method=="INVITE" && uri=~"sip:B@xx.xxx.xx ")
  1039. {
  1040. # copy the current branch (branches[0]) into
  1041. # a new branch (branches[1])
  1042. append_branch();
  1043. # all URI manipulation functions work on branches[0]
  1044. # thus, URI manipulation does not touch the
  1045. # appended branch (branches[1])
  1046. seturi("sip:C@domain");
  1047. # now: branch 0 = C@domain
  1048. # branch 1 = B@xx.xx.xx.xx
  1049. # and if you need a third destination ...
  1050. # copy the current branch (branches[0]) into
  1051. # a new branch (branches[2])
  1052. append_branch();
  1053. # all URI manipulation functions work on branches[0]
  1054. # thus, URI manipulation does not touch the
  1055. # appended branch (branches[1-2])
  1056. seturi("sip:D@domain");
  1057. # now: branch 0 = D@domain
  1058. # branch 1 = B@xx.xx.xx.xx
  1059. # branch 2 = C@domain
  1060. t_relay();
  1061. exit;
  1062. };
  1063. # You could also use append_branch("sip:C@domain") which adds a branch with the new URI:
  1064. if(method=="INVITE" && uri=~"sip:B@xx.xxx.xx ") {
  1065. # append a new branch with the second destination
  1066. append_branch("sip:user@domain");
  1067. # now: branch 0 = B@xx.xx.xx.xx
  1068. # now: branch 1 = C@domain
  1069. t_relay();
  1070. exit;
  1071. }
  1072. 3. cache_store( storage_id, attribute_name, attribute_name [,timeout])
  1073. 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.
  1074. Function returns true is the new attribute was successfully inserted.
  1075. cache_store("local","my_attr","$avp(i:55)",1200);
  1076. OR
  1077. modparam("cachedb_redis","cachedb_url","redis:cluster1://192.168.2.134:6379/")
  1078. ...
  1079. cache_store("redis:cluster1","passwd_$tu","$var(x)");
  1080. More complex examples can be found in the Key-Value Interface Tutorial.
  1081. 4. cache_remove( storage_id, attribute_name)
  1082. 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.
  1083. cache_remove("local","my_attr");
  1084. OR
  1085. modparam("cachedb_redis","cachedb_url","redis:cluster1://192.168.2.134:6379/")
  1086. ...
  1087. cache_remove("redis:cluster1","my_attr");
  1088. More complex examples can be found in the Key-Value Interface Tutorial.
  1089. 5. cache_fetch( storage_id, attribute_name, result_pvar)
  1090. 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.
  1091. Function returns true if the attribute was found and its value returned.
  1092. cache_fetch("local","my_attr", $avp(i:11) );
  1093. OR
  1094. modparam("cachedb_redis","cachedb_url","redis:cluster1://192.168.2.134:6379/")
  1095. ...
  1096. cache_fetch("redis:cluster1","my_attr",$avp(i:11));
  1097. More complex examples can be found in the Key-Value Interface Tutorial.
  1098. 6. cache_counter_fetch( storage_id, counter_attribute_name, result_avp)
  1099. 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.
  1100. Function returns true if the attribute was found and its value returned.
  1101. cache_counter_fetch("local","my_counter", $avp(counter_val) );
  1102. OR
  1103. modparam("cachedb_redis","cachedb_url","redis:cluster1://192.168.2.134:6379/")
  1104. ...
  1105. cache_fetch("redis:cluster1","my_counter",$avp(redis_counter_val));
  1106. 7. cache_add( storage_id, attribute_name,increment_value,expire,[new_val_pvar])
  1107. 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.
  1108. Function returns false if increment fails.
  1109. Optionally, the function receives one last parameter as a pvar in which to fetch the new value of the counter.
  1110. modparam("cachedb_redis","cachedb_url","redis:cluster1://192.168.2.134:6379/")
  1111. ...
  1112. cache_add("redis:cluster1",5);
  1113. More complex examples can be found in the Key-Value Interface Tutorial.
  1114. 8. cache_sub( storage_id, attribute_name,increment_value,expire,[new_val_pvar])
  1115. 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.
  1116. Function returns false if decrement fails.
  1117. Optionally, the function receives one last parameter as a pvar in which to fetch the new value of the counter.
  1118. modparam("cachedb_redis","cachedb_url","redis:cluster1://192.168.2.134:6379/")
  1119. ...
  1120. cache_sub("redis:cluster1",5);
  1121. More complex examples can be found in the Key-Value Interface Tutorial.
  1122. 9. cache_raw_query( storage_id, raw_query,result_avp)
  1123. 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.
  1124. Function returns false if query fails.
  1125. ...
  1126. cache_raw_query("mongodb","{ \"op\" : \"count\",\"query\": { \"username\" : $rU} }","$avp(mongo_count_result)");
  1127. ...
  1128. More complex examples can be found in the Key-Value Interface Tutorial.
  1129. 10. break()
  1130. 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'.
  1131. 'return' and 'break' have now a similar meaning as in c/shell.
  1132. 11. construct_uri(proto,user,domain,port,extra,result_avp)
  1133. 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.
  1134. Example usage:
  1135. construct_uri("$var(proto)", "vlad", "$var(domain)", "", "$var(params)",$avp(s:newuri));
  1136. xlog("Constructed URI is <$avp(s:newuri)> \n");
  1137. 12. drop()
  1138. Stop the execution of the configuration script and alter the implicit action which is done afterwards.
  1139. If the function is called in a 'branch_route' then the branch is discarded (implicit action for 'branch_route' is to forward the request).
  1140. 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).
  1141. Example of usage:
  1142. onreply_route {
  1143. if(status=="183") {
  1144. drop();
  1145. }
  1146. }
  1147. 13. exit()
  1148. 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.
  1149. route {
  1150. if (route(2)) {
  1151. xlog("L_NOTICE","method $rm is INVITE\n");
  1152. } else {
  1153. xlog("L_NOTICE","method is $rm\n");
  1154. };
  1155. }
  1156. route[2] {
  1157. if (is_method("INVITE")) {
  1158. return(1);
  1159. } else if (is_method("REGISTER")) {
  1160. return(-1);
  1161. } else if (is_method("MESSAGE")) {
  1162. sl_send_reply("403","IM not allowed");
  1163. exit;
  1164. };
  1165. }
  1166. 14. force_rport()
  1167. 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.
  1168. The rport parameter is defined in RFC 3581.
  1169. Example of usage:
  1170. force_rport();
  1171. 15. force_send_socket([proto:]address[:port])
  1172. 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.
  1173. Example of usage:
  1174. force_send_socket(10.10.10.10:5060);
  1175. 16. force_tcp_alias()
  1176. force_tcp_alias(port)
  1177. 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.
  1178. 17. forward(destination)
  1179. 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).
  1180. If destination parameter is missing, the forward will be done based on RURI.
  1181. Example of usage:
  1182. forward("10.0.0.10:5060");
  1183. #or
  1184. forward();
  1185. 18. get_timestamp(sec_avp,usec_avp)
  1186. Returns the current timestamp, seconds and microseconds of the current second, from a single system call.
  1187. Example of usage:
  1188. get_timestamp($avp(sec),$avp(usec));
  1189. 19. isdsturiset()
  1190. Test if the dst_uri field (next hop address) is set.
  1191. Example of usage:
  1192. if(isdsturiset()) {
  1193. log("dst_uri is set\n");
  1194. };
  1195. 20. isflagset(int)
  1196. 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.
  1197. For more see Flags Documentation.
  1198. Example of usage:
  1199. if(isflagset(3)) {
  1200. log("flag 3 is set\n");
  1201. };
  1202. 21. isbflagset([branch_idx,] flag_idx)
  1203. 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.
  1204. For more about script flags, see Flags Documentation.
  1205. Example of usage:
  1206. if(isbflagset(1,3)) {
  1207. log("flag 3 is set in branch 1\n");
  1208. };
  1209. 22. issflagset(flag_idx)
  1210. 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.
  1211. For more about script flags, see Flags Documentation.
  1212. Example of usage:
  1213. if(issflagset(2)) {
  1214. log("script flag 2 is set\n");
  1215. };
  1216. 23. log([level,] string)
  1217. Write text message to standard error terminal or syslog. You can specify the log level as first parameter.
  1218. Example of usage:
  1219. log("just some text message\n");
  1220. 24. next_branches()
  1221. 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.
  1222. 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).
  1223. Example of usage:
  1224. next_branches();
  1225. 25. prefix(string)
  1226. Add the string parameter in front of username in R-URI.
  1227. Example of usage:
  1228. prefix("00");
  1229. 26. pv_printf(pv, string)
  1230. 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.
  1231. It was extended from the avp_printf(...) function exported in previous versions by the avpops module. Starting with 1.3.0, avp_printf(...) is just an alias to pv_printf(...).
  1232. Example of usage:
  1233. pv_printf("$var(x)", "r-uri: $ru");
  1234. pv_printf("$avp(i:3)", "from uri: $fu");
  1235. 27. raise_event(string[, avp[, avp]])
  1236. 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.
  1237. This function triggers an event for all subscribers for that event, regardless the transport module used.
  1238. Example of usage (raises an event with no attributes):
  1239. raise_event("E_NO_PARAM");
  1240. Example of usage (raises an event with two attributes):
  1241. $avp(attr-name) = "param1";
  1242. $avp(attr-name) = "param2";
  1243. $avp(attr-val) = 1;
  1244. $avp(attr-val) = "2"
  1245. raise_event("E_TWO_PARAMS", $avp(attr-name), $avp(attr-val));
  1246. 28. remove_branch(pv|int)
  1247. 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).
  1248. Example of usage (remove all branches with URI hostname "127.0.0.1"):
  1249. $var(i) = 0;
  1250. while ($(branch(uri)[$var(i)]) != null) {
  1251. xlog("L_INFO","$$(branch(uri)[$var(i)])=[$(branch(uri)[$var(i)])]\n");
  1252. if ($(branch(uri)[$var(i)]{uri.host}) == "127.0.0.1") {
  1253. xlog("L_INFO","removing branch $var(i) with URI=[$(branch(uri)[$var(i)])]\n");
  1254. remove_branch($var(i));
  1255. } else {
  1256. $var(i) = $var(i) + 1;
  1257. }
  1258. }
  1259. 29. return(int)
  1260. 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.
  1261. return(0) is same as "exit()";
  1262. In bool expressions:
  1263. * Negative and ZERO is FALSE
  1264. * Positive is TRUE
  1265. Example usage:
  1266. route {
  1267. if (route(2)) {
  1268. xlog("L_NOTICE","method $rm is INVITE\n");
  1269. } else {
  1270. xlog("L_NOTICE","method $rm is REGISTER\n");
  1271. };
  1272. }
  1273. route[2] {
  1274. if (is_method("INVITE")) {
  1275. return(1);
  1276. } else if (is_method("REGISTER")) {
  1277. return(-1);
  1278. } else {
  1279. return(0);
  1280. };
  1281. }
  1282. 30. resetdsturi()
  1283. 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.
  1284. Example of usage:
  1285. resetdsturi();
  1286. 31. resetflag(int)
  1287. Reset a flag for current processed message (set the value to 0). The value of the parameter can be in range of 0..31.
  1288. For more see Flags Documentation.
  1289. Example of usage:
  1290. resetflag(3);
  1291. 32. resetbflag([branch_idx,] flag_idx)
  1292. 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.
  1293. For more about script flags, see Flags Documentation.
  1294. Example of usage:
  1295. resetbflag(1,3);
  1296. # or
  1297. resetbflag(3); # same with resetbflag(0,3)
  1298. 33. resetsflag(flag_idx)
  1299. Reset a script flag (set flag to value 0). The value of the "flag_idx" parameter can be in range of 0..31.
  1300. For more about script flags, see Flags Documentation.
  1301. Example of usage:
  1302. resetsflag(2);
  1303. 34. revert_uri()
  1304. 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).
  1305. Example of usage:
  1306. revert_uri();
  1307. 35. rewritehost() / sethost()
  1308. 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.
  1309. Example of usage:
  1310. rewritehost("1.2.3.4");
  1311. 36. rewritehostport() / sethostport()
  1312. 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.
  1313. Example of usage:
  1314. rewritehostport("1.2.3.4:5080");
  1315. 37. rewriteuser(string) / setuser(string)
  1316. Rewrite the user part of the R-URI with the value of function's parameter.
  1317. Example of usage:
  1318. rewriteuser("newuser");
  1319. 38. rewriteuserpass() / setuserpass()
  1320. Rewrite the password part of the R-URI with the value of function's parameter.
  1321. Example of usage:
  1322. rewriteuserpass("my_secret_passwd");
  1323. 39. rewriteport() / setport()
  1324. Rewrites/sets the port part of the R-URI with the value of function's parameter.
  1325. Example of usage:
  1326. rewriteport("5070");
  1327. 40. rewriteuri(str) / seturi(str)
  1328. Rewrite the request URI.
  1329. Example of usage:
  1330. rewriteuri("sip:test@opensips.org");
  1331. 41. route(name [, param1 [, param2 [, ...] ] ] )
  1332. 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.
  1333. The name of the route is an identifier format, whereas the parameters can be either int, string, or a pseudo-variable.
  1334. Example of usage:
  1335. route(HANDLE_SEQUENTIALS);
  1336. route(HANDLE_SEQUENTIALS, 1, "param", $var(param));
  1337. 42. script_trace( log_level, pv_format_string[, info_string])
  1338. This function enables script tracing - this helps to better understand the flow of execution in the OpenSIPS script (current function and line). Moreover, you can also trace the values of pseudo-variables, as script execution progresses.
  1339. 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)").
  1340. 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.
  1341. To disable script tracing, just do script_trace(). Otherwise, the tracing will automatically stop at the end the end of the top route.
  1342. Example of usage:
  1343. script_trace( 1, "$rm from $si, ruri=$ru", "me");
  1344. will produce:
  1345. [line 578][me][module consume_credentials] -> (INVITE from 127.0.0.1 , ruri=sip:111111@opensips.org)
  1346. [line 581][me][core setsflag] -> (INVITE from 127.0.0.1 , ruri=sip:111111@opensips.org)
  1347. [line 583][me][assign equal] -> (INVITE from 127.0.0.1 , ruri=sip:111111@opensips.org)
  1348. [line 592][me][core if] -> (INVITE from 127.0.0.1 , ruri=sip:tester@opensips.org)
  1349. [line 585][me][module is_avp_set] -> (INVITE from 127.0.0.1 , ruri=sip:tester@opensips.org)
  1350. [line 589][me][core if] -> (INVITE from 127.0.0.1 , ruri=sip:tester@opensips.org)
  1351. [line 586][me][module is_method] -> (INVITE from 127.0.0.1 , ruri=sip:tester@opensips.org)
  1352. [line 587][me][module trace_dialog] -> (INVITE 127.0.0.1 , ruri=sip:tester@opensips.org)
  1353. [line 590][me][core setflag] -> (INVITE from 127.0.0.1 , ruri=sip:tester@opensips.org)
  1354. 43. send(destination [, headers])
  1355. 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.
  1356. Parameter is mandatory and has string format.
  1357. Example of usage:
  1358. send("udp:10.10.10.10:5070");
  1359. send("udp:10.10.10.10:5070", "Server: opensips\r\n");
  1360. 44. serialize_branches(clear)
  1361. 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.
  1362. 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).
  1363. NOTE that this function is not changing RURI in the messages - it is just converting from parallel to serial branches (preparing branches).
  1364. 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.
  1365. Example of usage:
  1366. serialize_branches(1);
  1367. 45. set_advertised_address(ip|string)
  1368. Same as 'advertised_address' but it affects only the current message. It has priority if 'advertised_address' is also set.
  1369. Example of usage:
  1370. set_advertised_address("opensips.org");
  1371. 46. set_advertised_port(int)
  1372. Same as 'advertised_port' but it affects only the current message. It has priority over 'advertised_port'.
  1373. Example of usage:
  1374. set_advertised_port(5080);
  1375. 47. setdebug([level])
  1376. 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.
  1377. Example of usage:
  1378. debug= -1 # errors only
  1379. .....
  1380. {
  1381. ......
  1382. setdebug(4); # set the debug level of the current process to DBG
  1383. uac_replace_from(....);
  1384. setdebug(); # reset the debug level of the current process to the global level
  1385. .......
  1386. }
  1387. 48. setdsturi(string)
  1388. Explicitely set the dst_uri field to the value of the paramater. The parameter has to be a valid SIP URI.
  1389. Example of usage:
  1390. setdsturi("sip:10.10.10.10:5090");
  1391. 49. setflag(int)
  1392. 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).
  1393. Example of usage:
  1394. setflag(3);
  1395. 50. setbflag([branch_idx,] flag_idx)
  1396. 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.
  1397. For more about script flags, see Flags Documentation.
  1398. Example of usage:
  1399. setbflag(1,3);
  1400. # or
  1401. setbflag(3); # same with setbflag(0,3)
  1402. 51. setsflag(flag_idx)
  1403. Set a script flag (set flag to value 0). The value of the "flag_idx" parameter can be in range of 0..31.
  1404. For more about script flags, see Flags Documentation.
  1405. Example of usage:
  1406. setsflag(2);
  1407. 52. strip(int)
  1408. Strip the first N-th characters from username of R-URI (N is the value of the parameter).
  1409. Example of usage:
  1410. strip(3);
  1411. 53. strip_tail(int)
  1412. Strip the last N-th characters from username of R-URI (N is the value of the parameter).
  1413. Example of usage:
  1414. strip_tail(3);
  1415. 54. subscribe_event(string, string [, int])
  1416. 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.
  1417. 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.
  1418. Example of usage (subscriber that never expires, notified by the RabbitMQ module):
  1419. startup_route {
  1420. subscribe_event("E_PIKE_BLOCKED", "rabbitmq:127.0.0.1/pike");
  1421. }
  1422. Example of usage (subscriber expires every 5 seconds, notified through UDP):
  1423. timer_route[event_subscribe, 4] {
  1424. subscribe_event("E_PIKE_BLOCKED", "udp:127.0.0.1:5051", 5);
  1425. }
  1426. 55. use_blacklist(string)
  1427. 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).
  1428. use_blacklist("pstn-gws");
  1429. 56. xlog([log_level, ]format_string)
  1430. 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:
  1431. L_ALERT (-3)
  1432. L_CRIT (-2)
  1433. L_ERR (-1) - this is used by default if log_level is omitted
  1434. L_WARN (0)
  1435. L_NOTICE (1)
  1436. L_INFO (2)
  1437. L_DBG (3)
  1438. # a few xlog scripting examples
  1439. xlog("Received $rm from $fu (callid: $ci)\n");
  1440. xlog("L_ERR", "key $var(username) not found in cache!\n");
  1441. OpenSIPS provides multiple type of variables to be used in the routing script. The difference between the types of variables comes from (1) the visibility of the variable (when it is visible), (2) what the variable is attached to (where the variable resides), (3) read-write status of the variable (some types of the variables are read-only and (4) how multiple values (for the same variable are handled).
  1442. The OpenSIPS variables can be easily identified in the script as all their names (or notations) start with the $ sign.
  1443. Syntax:
  1444. The complete syntax for a pseudo variable is:
  1445. $(<context>name(subname)[index]{transformation})
  1446. The fields written in green are optional. The fields meaning is:
  1447. name(compulsory) - the pseudo-variable name(type).
  1448. Ex: pvar, avp, ru, DLG_status, etc.
  1449. subname - the identifier of a certain pv from the given type.
  1450. Ex: hdr(From), avp(name).
  1451. index - a pv can store more than one value - it can refer to a list of values. You can access a certain value from the list if you specify its index. You can also specify indexes with negative values, -1 means the last inserted, -2 the value before the previous inserted one.
  1452. transformation - a series of processing actions can be applied on pseudo-variable. You can find the whole list of possible transformations here. The transformations can be cascaded, using the output of one transformation as the input of another.
  1453. context - the context in which the pseudo0variable will be evaluated. Now there are 2 pv contexts: reply and request. The reply context can be used in the failure route to request for the pseudo-variable to be evaluated in the context of the reply message. The request context can be used if in a reply route is desired for the pv to be evaluated in the context of the corresponding request.
  1454. Usage examples:
  1455. Only name: $ru
  1456. Name and 'subname: $hdr(Contact)
  1457. Name and index: $(ct[0])
  1458. Name, subname and index: $(avp(i:10)[2])
  1459. Context
  1460. $(<request>ru) from a reply route will get the Request-URI from the request
  1461. $(<reply>hdr(Contact)) context can be used from failure route to access information from the reply
  1462. Types of variables:
  1463. script variables - as the name says, these variables are strictly bound to the script routes. The variables are visible only in the routing blocks - they are not message or transaction related, but they are process related (script variables will be inherited by script routes executed by the same OpenSIPS process).
  1464. Script variables are read write and they can have integer or string values. A script variable can only hold a single value. A new assignment (or write operation) will overwrite the existing value.
  1465. AVP - Attribute Value Pair - the AVPs are dynamic variables (as name) that can be created - the AVPS are linked to a singular message or transaction (if stateful processing is used). A message or a transaction will initially (when received or created) have an empty list of AVPS attached to it. During the routing script, the script directly or functions called from script may create new AVPS that will automatically attached to the message/transaction. The AVPS will be visible in all routes where any message (reply or request) of the transaction will be processed - branch_route , failure_route, onreply_route (for this last route you need to enable the TM parameter onreply_avp_mode).
  1466. AVPs are read write and an existing AVP can be even deleted (removed). An AVP may contain multiple values - a new assignment (or write operation) will add a new value to the AVP; the values are kept in "last added first to be used" order (stack).
  1467. pseudo variables - pseudo-variables (or PV) provide access to information from the processed SIP message (headers, RURI, transport level info, a.s.o) or from OpenSIPS inners (time values, process PID, return code of a function). Depending of what info they provide, the PVs are either bound to the message, either to nothing (global). Most of the PVs are read-only and only several allow write operations. A PV may return several values or only one, depending of the referred info (if can have multiple values or not).
  1468. Standard PV is read-only and returns a single value (if not otherwise documented).
  1469. escape sequences - escape sequences used to format the strings; they are actually not variables, but rather formatters.
  1470. 1. Script variables
  1471. Naming: **$var(name)**
  1472. Hints:
  1473. if you want to start using a script variable in a route, better initialize it with same value (or reset it), otherwise you may inherit a value from a previous route that was executed by the same process.
  1474. script variables are faster than AVPs, as they directly reference a memory location.
  1475. the value of script variables persists over a OpenSIPS process.
  1476. a script value can have only one value.
  1477. Example of usage:
  1478. $var(a) = 2; # sets the value of variable 'a' to integer '2'
  1479. $var(a) = "2"; # sets the value of variable 'a' to string '2'
  1480. $var(a) = 3 + (7&(~2)); # arithmetic and bitwise operation
  1481. $var(a) = "sip:" + $au + "@" + $fd; # compose a value from authentication username and From URI domain
  1482. # using a script variable for tests
  1483. if( [ $var(a) & 4 ] ) {
  1484. xlog("var a has third bit set\n");
  1485. }
  1486. Setting a variable to NULL is actually initializing the value to integer '0'. Script variables don't have NULL value.
  1487. 2. AVP variables
  1488. Naming: **$avp(name)** or **$(avp(name)[N])**
  1489. When using the index "N" you can force the AVP to return a certain value (the N-th value). If no index is given, the first value will be returned.
  1490. Hints:
  1491. to enable AVPs in onreply_route, use "modparam("tm", "onreply_avp_mode", 1)"
  1492. if multiple values are used for a single AVP, the values are index in revert order than added
  1493. AVPs are part of the transaction context, so they will be visible everywhere where the transaction is present.
  1494. the value of an AVP can be deleted
  1495. Example of usage:
  1496. Transaction persistence example
  1497. # enable avps in onreply route
  1498. modparam("tm", "onreply_avp_mode", 1)
  1499. ...
  1500. route{
  1501. ...
  1502. $avp(tmp) = $Ts ; # store the current time (at request processing)
  1503. ...
  1504. t_onreply("1");
  1505. t_relay();
  1506. ...
  1507. }
  1508. onreply_route[1] {
  1509. if (t_check_status("200")) {
  1510. # calculate the setup time
  1511. $var(setup_time) = $Ts - $avp(tmp);
  1512. }
  1513. }
  1514. Multilple values example
  1515. $avp(17) = "one";
  1516. # we have a single value
  1517. $avp(17) = "two";
  1518. # we have two values ("two","one")
  1519. $avp(17) = "three";
  1520. # we have three values ("three","two","one")
  1521. xlog("accessing values with no index: $avp(17)\n");
  1522. # this will print the first value, which is the last added value -> "three"
  1523. xlog("accessing values with no index: $(avp(17)[2])\n");
  1524. # this will print the index 2 value (third one), -> "one"
  1525. # remove the last value of the avp; if there is only one value, the AVP itself will be destroyed
  1526. $avp(17) = NULL;
  1527. # delete all values and destroy the AVP
  1528. avp_delete("$avp(17)/g");
  1529. # delete the value located at a certain index
  1530. $(avp(17)[1]) = NULL;
  1531. #overwrite the value at a certain index
  1532. $(avp(17)[0]) = "zero";
  1533. The AVPOPS module provides a lot of useful functions to operate AVPs (like checking values, pushing values into different other locations, deleting AVPs, etc).
  1534. 3. Pseudo Variables
  1535. Naming: $name
  1536. Hints:
  1537. the PV tokens can be given as parameters to different script functions and they will be replaced with a value before the execution of the function.
  1538. most of PVs are made available by OpenSIPS core, but there are also module exporting PV (to make available info specific to that module) - check the modules documentation.
  1539. Predefined (provided by core) PVs are listed in alphabetical order.
  1540. 3.1 URI in SIP Request's P-Asserted-Identity header
  1541. $ai - reference to URI in request's P-Asserted-Identity header (see RFC 3325)
  1542. 3.2 Authentication Digest URI
  1543. $adu - URI from Authorization or Proxy-Authorization header. This URI is used when calculating the HTTP Digest Response.
  1544. 3.3 Authentication realm
  1545. $ar - realm from Authorization or Proxy-Authorization header
  1546. 3.4 Auth username user
  1547. $au - user part of username from Authorization or Proxy-Authorization header
  1548. 3.5 Auth username domain
  1549. $ad - domain part of username from Authorization or Proxy-Authorization header
  1550. 3.6 Auth nonce
  1551. $an - the nonce from Authorization or Proxy-Authorization header
  1552. 3.7 Auth response
  1553. $auth.resp - the authentication response from Authorization or Proxy-Authorization header
  1554. 3.8 Auth nonce
  1555. $auth.nonce - the nonce string from Authorization or Proxy-Authorization header
  1556. 3.9 Auth opaque
  1557. $auth.opaque - the opaque string from Authorization or Proxy-Authorization header
  1558. 3.10 Auth algorithm
  1559. $auth.alg - the algorithm string from Authorization or Proxy-Authorization header
  1560. 3.11 Auth QOP
  1561. $auth.qop - the value of qop parameter from Authorization or Proxy-Authorization header
  1562. 3.12 Auth nonce count (nc)
  1563. $auth.nc - the value of nonce count parameter from Authorization or Proxy-Authorization header
  1564. 3.13 Auth whole username
  1565. $aU - whole username from Authorization or Proxy-Authorization header
  1566. 3.14 Acc username
  1567. $Au - username for accounting purposes. It's a selective pseudo variable (inherited from acc module). It returns $au if exits or From username otherwise.
  1568. 3.15 Argument options
  1569. $argv - provides access to command line arguments specified with '-o' option. Examples:
  1570. # for option '-o foo=0'
  1571. xlog("foo is $argv(foo) \n");
  1572. 3.16 Branch flags
  1573. $bf - displays a list with the branch flags set for the current SIP request
  1574. 3.17 Branch flags (hexadecimal) (Removed in OpenSIPS 1.9)
  1575. $bF - reference to branch flags - hexa output
  1576. 3.18 Branch
  1577. $branch - this variable is used for creating new branches by writing into it the value of a SIP URI. Examples:
  1578. # creates a new branch
  1579. $branch = "sip:new@doamin.org";
  1580. # print its URI
  1581. xlog("last added branch has URI $(branch(uri)[-1]) \n");
  1582. 3.19 Branch fields
  1583. $branch() - this variable provides read/write access to all fields/attributes of an already existing branch (priorly created with append_branch() ). The fields of the branch are:
  1584. uri - the RURI of the branch (string value)
  1585. duri - destination URI of the branch (outbound proxy of the branch) (string value)
  1586. q - q value of the branch (int value)
  1587. path - the PATH string for this branch (string value)
  1588. flags - the branch flags of this branch (int value)
  1589. socket - the local socket to be used for relaying this branch (string value)
  1590. The variable accepts also index $(branch(uri)[1]) for accessing a specific branch (multiple branches can be defined at a moment). The index starts from 0 (first branch). If the index is negative, it is considered the n-th branch from the end ( index -1 means the last branch).
  1591. To get all branches, use the * index - $(branch(uri)[*]).
  1592. Examples:
  1593. # creates the first branch
  1594. append_branch();
  1595. # creates the second branch
  1596. force_send_socket(udp:192.168.1.11:5060);
  1597. $du = "sip:192.168.2.10";
  1598. append_branch("sip:foo@bar.com","0.5");
  1599. # display branches
  1600. xlog("----- branch 0: $(branch(uri)[0]) , $(branch(q)[0]), $(branch(duri)[0]), $(branch(path)[0]), $(branch(flags)[0]), $(branch(socket)[0]) \n");
  1601. xlog("----- branch 1: $(branch(uri)[1]) , $(branch(q)[1]), $(branch(duri)[1]), $(branch(path)[1]), $(branch(flags)[1]), $(branch(socket)[1]) \n");
  1602. # do some changes over the branches
  1603. $branch(uri) = "sip:user@domain.ro"; # set URI for the first branch
  1604. $(branch(q)[0]) = 1000; # set to 1.00 for the first branch
  1605. $(branch(socket)[1]) = NULL; # reset the socket of the second branch
  1606. $branch(duri) = NULL; # reset the destination URI or the first branch
  1607. It is R/W variable (you can assign values to it from routing logic)
  1608. 3.20 Call-Id
  1609. $ci - reference to body of call-id header
  1610. 3.21 Content-Length
  1611. $cl - reference to body of content-length header
  1612. 3.22 CSeq number
  1613. $cs - reference to cseq number from cseq header
  1614. 3.23 Contact instance
  1615. $ct - reference to contact instance/body from the contact header. A contact instance is display_name + URI + contact_params. As a Contact header may contain multiple Contact instances and a message may contain multiple Contact headers, an index was added to the $ct variable:
  1616. $ct -first contact instance from message
  1617. $(ct[n]) - the n-th contact instance form the beginning of message, starting with index 0
  1618. $(ct[-n]) - the n-th contact instance form the end of the message, starting with index -1 (the last contact instance)
  1619. 3.24 Fields of a contact instance
  1620. $ct.fields() - reference to the fields of a contact instance/body (see above). Supported fields are:
  1621. name - display name
  1622. uri - contact uri
  1623. q - q param (value only)
  1624. expires - expires param (value only)
  1625. methods - methods param (value only)
  1626. received - received param (value only)
  1627. params - all params (including names)
  1628. Examples:
  1629. $ct.fields(uri) - the URI of the first contact instance
  1630. $(ct.fields(name)[1]) - the display name of the second contact instance
  1631. 3.25 Content-Type
  1632. $cT - reference to body of content-type header
  1633. 3.26 Domain of destination URI
  1634. $dd - reference to domain of destination uri
  1635. It is R/W variable (you can assign values to it from routing logic)
  1636. 3.27 Diversion header URI
  1637. $di - reference to Diversion header URI
  1638. 3.28 Diversion "privacy" parameter
  1639. $dip - reference to Diversion header "privacy" parameter value
  1640. 3.29 Diversion "reason" parameter
  1641. $dir - reference to Diversion header "reason" parameter value
  1642. 3.30 Port of destination URI
  1643. $dp - reference to port of destination uri
  1644. It is R/W variable (you can assign values to it from routing logic)
  1645. 3.31 Transport protocol of destination URI
  1646. $dP - reference to transport protocol of destination uri
  1647. 3.32 Destination set
  1648. $ds - reference to destination set
  1649. 3.33 Destination URI
  1650. $du - reference to destination uri (outbound proxy to be used for sending the request) If loose_route() returns TRUE a destination uri is set according to the first Route header.
  1651. It is R/W variable (you can assign values to it from routing logic)
  1652. 3.34 Error class
  1653. $err.class - the class of error (now is '1' for parsing errors)
  1654. 3.35 Error level
  1655. $err.level - severity level for the error
  1656. 3.36 Error info
  1657. $err.info - text describing the error
  1658. 3.37 Error reply code
  1659. $err.rcode - recommended reply code
  1660. 3.38 Error reply reason
  1661. $err.rreason - recommended reply reason phrase
  1662. 3.39 From URI domain
  1663. $fd - reference to domain in URI of 'From' header
  1664. 3.40 From display name
  1665. $fn - reference to display name of 'From' header
  1666. 3.41 Forced socket
  1667. $fs - reference to the forced socket for message sending (if any) in the form proto:ip:port
  1668. It is R/W variable (you can assign values to it routing script)
  1669. 3.42 From tag
  1670. $ft - reference to tag parameter of 'From' header
  1671. 3.43 From URI
  1672. $fu - reference to URI of 'From' header
  1673. 3.44 From URI username
  1674. $fU - reference to username in URI of 'From' header
  1675. 3.45 SIP message buffer
  1676. $mb - reference to SIP message buffer
  1677. 3.46 Message Flags
  1678. $mf - displays a list with the message/transaction flags set for the current SIP request
  1679. 3.47 Message Flags (hexadecimal) (Removed in OpenSIPS 1.9)
  1680. $mF -reference to message/transaction flags set for current SIP request in hexa
  1681. 3.48 SIP message ID
  1682. $mi - reference to SIP message id
  1683. 3.49 SIP message length
  1684. $ml - reference to SIP message length
  1685. 3.50 Domain in SIP Request's original URI
  1686. $od - reference to domain in request's original R-URI
  1687. 3.51 Port of SIP request's original URI
  1688. $op - reference to port of original R-URI
  1689. 3.52 Transport protocol of SIP request original URI
  1690. $oP - reference to transport protocol of original R-URI
  1691. 3.53 SIP Request's original URI
  1692. $ou - reference to request's original URI
  1693. 3.54 Username in SIP Request's original URI
  1694. $oU - reference to username in request's original URI
  1695. 3.55 Route parameter
  1696. $param(idx) - retrieves the parameters of the route. The index can be an integer, or a pseudo-variable (index starts at 1).
  1697. Example:
  1698. route {
  1699. ...
  1700. $var(debug) = "DBUG:"
  1701. route(PRINT_VAR, $var(debug), "param value");
  1702. ...
  1703. }
  1704. route[PRINT_VAR] {
  1705. $var(index) = 2;
  1706. xlog("$param(1): The parameter value is <$param($var(index))>\n");
  1707. }
  1708. 3.56 Domain in SIP Request's P-Preferred-Identity header URI
  1709. $pd - reference to domain in request's P-Preferred-Identity header URI (see RFC 3325)
  1710. 3.57 Display Name in SIP Request's P-Preferred-Identity header
  1711. $pn - reference to Display Name in request's P-Preferred-Identity header (see RFC 3325)
  1712. 3.58 Process id
  1713. $pp - reference to process id (pid)
  1714. 3.59 Protocol of received message
  1715. $pr or $proto - protocol of received message (UDP, TCP, TLS, SCTP)
  1716. 3.60 User in SIP Request's P-Preferred-Identity header URI
  1717. $pU - reference to user in request's P-Preferred-Identity header URI (see RFC 3325)
  1718. 3.61 URI in SIP Request's P-Preferred-Identity header
  1719. $pu - reference to URI in request's P-Preferred-Identity header (see RFC 3325)
  1720. 3.62 Domain in SIP Request's URI
  1721. $rd - reference to domain in request's URI
  1722. It is R/W variable (you can assign values to it routing script)
  1723. 3.63 Body of request/reply
  1724. $rb - reference to message body
  1725. 3.64 Returned code
  1726. $rc - reference to returned code by last invoked function
  1727. $retcode - same as **$rc**
  1728. 3.65 Remote-Party-ID header URI
  1729. $re - reference to Remote-Party-ID header URI
  1730. 3.66 SIP request's method
  1731. $rm - reference to request's method
  1732. 3.67 SIP request's port
  1733. $rp - reference to port of R-URI
  1734. It is R/W variable (you can assign values to it routing script)
  1735. 3.68 Transport protocol of SIP request URI
  1736. $rP - reference to transport protocol of R-URI
  1737. 3.69 SIP reply's reason
  1738. $rr - reference to reply's reason
  1739. 3.70 SIP reply's status
  1740. $rs - reference to reply's status
  1741. 3.71 Refer-to URI
  1742. $rt - reference to URI of refer-to header
  1743. 3.72 SIP Request's URI
  1744. $ru - reference to request's URI
  1745. It is R/W variable (you can assign values to it routing script)
  1746. 3.73 Username in SIP Request's URI
  1747. $rU - reference to username in request's URI
  1748. It is R/W variable (you can assign values to it routing script)
  1749. 3.74 Q value of the SIP Request's URI
  1750. $ru_q - reference to q value of the R-URI
  1751. It is R/W variable (you can assign values to it routing script)
  1752. 3.75 Received IP address
  1753. $Ri - reference to IP address of the interface where the request has been received
  1754. 3.76 Received port
  1755. $Rp - reference to the port where the message was received
  1756. 3.77 Script flags
  1757. $sf - displays a list with the script flags set for the current SIP request
  1758. 3.78 Script flags (hexadecimal) (Removed in OpenSIPS 1.9)
  1759. $sF - reference to script flags - hexa output
  1760. 3.79 IP source address
  1761. $si - reference to IP source address of the message
  1762. 3.80 Source port
  1763. $sp - reference to the source port of the message
  1764. 3.81 To URI Domain
  1765. $td - reference to domain in URI of 'To' header
  1766. 3.82 To display name
  1767. $tn - reference to display name of 'To' header
  1768. 3.83 To tag
  1769. $tt - reference to tag parameter of 'To' header
  1770. 3.84 To URI
  1771. $tu - reference to URI of 'To' header
  1772. 3.85 To URI Username
  1773. $tU - reference to username in URI of 'To' header
  1774. 3.86 Formatted date and time
  1775. $time(format) - returns the string formatted time according to UNIX date (see: man date).
  1776. 3.87 Branch index
  1777. $T_branch_idx - the index (starting with 1 for the first branch) of the branch for which is executed the branch_route[]. If used outside of branch_route[] block, the value is '0'. This is exported by TM module.
  1778. 3.88 String formatted time
  1779. $Tf - reference string formatted time
  1780. 3.89 Current unix time stamp in seconds
  1781. $Ts - reference to current unix time stamp in seconds
  1782. 3.90 Current microseconds of the current second
  1783. $Tsm - reference to current microseconds of the current second
  1784. 3.91 Startup unix time stamp
  1785. $TS - reference to startup unix time stamp
  1786. 3.92 User agent header
  1787. $ua - reference to user agent header field
  1788. 3.93 SIP Headers
  1789. $(hdr(name)[N]) - represents the body of the N-th header identified by 'name'. If [N] is omitted then the body of the first header is printed. The first header is got when N=0, for the second N=1, a.s.o. To print the last header of that type, use -1, no other negative values are supported now. No white spaces are allowed inside the specifier (before }, before or after {, [, ] symbols). When N='*', all headers of that type are printed.
  1790. The module should identify most of compact header names (the ones recognized by OpenSIPS which should be all at this moment), if not, the compact form has to be specified explicitly. It is recommended to use dedicated specifiers for headers (e.g., %ua for user agent header), if they are available -- they are faster.
  1791. $(hdrcnt(name)) -- returns number of headers of type given by 'name'. Uses same rules for specifying header names as $hdr(name) above. Many headers (e.g., Via, Path, Record-Route) may appear more than once in the message. This variable returns the number of headers of a given type.
  1792. Note that some headers (e.g., Path) may be joined together with commas and appear as a single header line. This variable counts the number of header lines, not header values.
  1793. For message fragment below, $hdrcnt(Path) will have value 2 and $(hdr(Path)[0]) will have value <a.com>:
  1794. Path: <a.com>
  1795. Path: <b.com>
  1796. For message fragment below, $hdrcnt(Path) will have value 1 and $(hdr(Path)[0]) will have value <a.com>,<b.com>:
  1797. Path: <a.com>,<b.com>
  1798. Note that both examples above are semantically equivalent but the variables take on different values.
  1799. 4. Escape Sequences
  1800. These sequences are exported, and mainly used, by xlog module to print messages in many colors (foreground and background) using escape sequences.
  1801. 4.1 Foreground and background colors
  1802. $C(xy) - reference to an escape sequence. ¿x¿ represents the foreground color and ¿y¿ represents the background color.
  1803. Colors could be:
  1804. x : default color of the terminal
  1805. s : Black
  1806. r : Red
  1807. g : Green
  1808. y : Yellow
  1809. b : Blue
  1810. p : Purple
  1811. c : Cyan
  1812. w : White
  1813. 4.2 Examples
  1814. A few examples of usage.
  1815. ...
  1816. route {
  1817. ...
  1818. $avp(uuid)="caller_id";
  1819. $avp(tmp)= $avp(uuid) + ": " + $fu;
  1820. xlog("$C(bg)$avp(tmp)$C(xx) [$avp(tmp)] $C(br)$cseq$C(xx)=[$hdr(cseq)]\n");
  1821. ...
  1822. }
  1823. ...
  1824. 1. Types of flags
  1825. message flags (or transaction flags) these flags are transaction persistent. They are visible in all routes and cases where the transaction context is visible
  1826. branch flags are saved also in transaction, but per branch; also they will be saved in usrloc (per contact). A new set of functions were added for manipulating these flags from script. So, there flags will be registration persistent and branch persistent.
  1827. script flags are no-message-related flags - they are only script persistent and you can strictly use them for scripting. Once you exit a top level route, they will be lost. These flags are useful and they offer an option to de-congest the message flags - many flags have no need to be saved as they just reflect some scripting status.
  1828. 2. Corresponding Functions
  1829. Starting from OpenSIPS 1.9, flags may receive alphanumerical values. However, this does not affect performance, since they are converted into bit indexes upon startup. When it comes to DB persistency (only a few modules do this - e.g. usrloc), flags are generally stored in their string form, in order to preserve their semantics, and not the bit index they received during a given OpenSIPS run.
  1830. 2.1 Message/transaction flags
  1831. setflag(FLAG)
  1832. resetflag(FLAG)
  1833. isflagset(FLAG)
  1834. Examples: setflag(accounting), resetflag(DO_NAT) or setflag(19)
  1835. 2.2 Branch flags
  1836. setbflag/setbranchflag(branch_idx, FLAG)
  1837. resetbflag/resetbranchflag(branch_idx, FLAG)
  1838. isbflagset/isbranchflagset(branch_idx, FLAG)
  1839. or, the shorter format, working on the default (branch 0) flags:
  1840. setbflag(FLAG)
  1841. resetbflag(FLAG)
  1842. isbflagset(FLAG)
  1843. 2.3 Script flags
  1844. setsflag/setscriptflag(FLAG)
  1845. resetsflag/resetscriptflag(FLAG)
  1846. issflagset/isscriptflagset(FLAG)
  1847. 3. Flags and Pseudo Variables
  1848. 3.1 Message/transaction flags
  1849. $mf - ReadOnly; outputs a list of flags
  1850. 3.2 Branch flags
  1851. $bf - ReadOnly; returns a list of flags
  1852. 3.3 Script flags
  1853. $sf - ReadOnly; outputs a list of flags
  1854. 4. Flags and routes
  1855. 4.1 Message/transaction flags
  1856. These flags will show up in all routes where messages related to the initial request are processed. So, they will be visible and changeable in onbranch, failure and onreply routes; the flags will be visible in all branch routes; if you change a flag in a branch route, the next branch routes will inherit the change.
  1857. 4.2 Branch flags
  1858. There flags will show up in all routes where messages related to initial branch request are processed. So, in branch route you will see different sets of flags (as they are different branches); in onreply route yo will see the branch flags corresponding to the branch the reply belongs to; in failure route, the branch flags corresponding to the branch the winning reply belongs to will be visible. In request route, you can have multiple branches (as a result of a lookup(), enum query, append_branch(), etc) - the default branch is 0 (corresponding to the RURI); In reply routes there will be only one branch , the 0 one. In branch route the default branch is the current process branch (having index 0); In failure route, initially there is only one branch (index 0), corresponding the failed branch.
  1859. 4.3 Script flags
  1860. There flags are available only in script and are reset after each top level route execution (routes internally triggered by OpenSIPS). They will be persistent per main route, onreply_route, branch_route, failure_route. Note they will be inherit in routes called from other routes.
  1861. 5. Example
  1862. 5.1 Nat flag handling
  1863. ..........
  1864. # 3 - the nat flag
  1865. modparam("usrloc", "nat_bflag", "NAT_BFLAG")
  1866. ..........
  1867. route {
  1868. ..........
  1869. if (nat detected)
  1870. setbflag(NAT_BFLAG); # set branch flag "NAT_BFLAG" for the branch 0
  1871. ..........
  1872. if (is_method("REGISTER")) {
  1873. # the branch flags (including "NAT_BFLAG") will be saved into location
  1874. save("location");
  1875. exit;
  1876. } else {
  1877. # lookup will load the branch flag from location
  1878. if (!lookup("location")) {
  1879. sl_send_reply("404","Not Found");
  1880. exit;
  1881. }
  1882. t_on_branch("1")
  1883. t_relay();
  1884. }
  1885. }
  1886. branch_route[1] {
  1887. xlog("-------branch=$T_branch_idx, branch flags=$bF\n");
  1888. if (isbflagset(NAT_BFLAG)) {
  1889. #current branch is marked as natted
  1890. .........
  1891. }
  1892. }
  1893. if no parallel forking is done, you can get rid of the branch route and add instead of t_on_branch():
  1894. ........
  1895. if (isbflagset(NAT_BFLAG)) {
  1896. #current branch is marked as natted
  1897. .........
  1898. }
  1899. .........
  1900. A Transformation is basically a function that is applied to a variable(script variable, pseudo-variables, AVPS, static strings) to get a special value from it. The value of the original variable is not altered.
  1901. Example of using different kind of variables in OpenSIPS script:
  1902. # check if username in From header is equal with username in To header
  1903. if($fU==$tU) {
  1904. ...
  1905. }
  1906. # r-uri username based processing
  1907. switch($ruri.user) {
  1908. case "1234":
  1909. ...
  1910. break;
  1911. case "5678":
  1912. ...
  1913. break;
  1914. default:
  1915. ...
  1916. }
  1917. # assign integer value to an AVP
  1918. $avp(i:11) = 1;
  1919. #assing string value to an AVP
  1920. $avp(i:22) = "opensips";
  1921. # write ruri in an AVP
  1922. $avp(i:33) = $ruri;
  1923. # concat "sip:" + From username + "@" + To domain in a script variable x
  1924. $var(x) = "sip:" + $fU +"@" + $td;
  1925. The transformations are intended to facilitate access to different attributes of variables (like strlen of value, parts of value, substrings) or complete different value of variables (encoded in hexa, md5 value, escape/unescape value for DB operations...).
  1926. A transformation is represented in between '{' and '}' and follows the name of a variable. When using transformations, the variable name and transformations must be enclosed in between '(' and ')'.
  1927. Example:
  1928. # the length of From URI ($fu is pseudo-variable for From URI)
  1929. $(fu{s.len})
  1930. Many transformations can be applied in the same time to a variable.
  1931. # the length of escaped 'Test' header body
  1932. $(hdr(Test){s.escape.common}{s.len})
  1933. The transformations can be used anywhere, being considered parts of script variables support -- in xlog, avpops or other modules' functions and parameters, in right side assignment expressions or in comparisons.
  1934. IMPORTANT: To learn what variables can be used with transformations see Scripting variables list.
  1935. 1. String Transformations
  1936. The name of these transformation starts with 's.'. They are intended to apply string operations to variables.
  1937. Available transformations in this class:
  1938. 1.1 {s.len}
  1939. Return strlen of variable value
  1940. $var(x) = "abc";
  1941. if($(var(x){s.len}) == 3)
  1942. {
  1943. ...
  1944. }
  1945. 1.2 {s.int}
  1946. Return integer value of a string-represented number
  1947. $var(x) = "1234";
  1948. if($(var(x){s.int})==1234) {
  1949. ...
  1950. }
  1951. 1.3 {s.md5}
  1952. Return md5 over variable value
  1953. xlog("MD4 over From username: $(fU{s.md5})");
  1954. 1.4 {s.substr,offset,length}
  1955. Return substring starting at offset having size of 'length'. If offset is negative, then it is counted from the end of the value, -1 being the last char. In case of positive value, 0 is first char. Length must be positive, in case of 0, substring to the end of variable value is returned. offset and length can be a varibale as well.
  1956. Example:
  1957. $var(x) = "abcd";
  1958. $(var(x){s.substr,1,0}) = "bcd"
  1959. 1.5 {s.select,index,separator}
  1960. Return a field from the value of a variable. The field is selected based on separator and index. The separator must be a character used to identify the fields. Index must be a integer value or a variable. If index is negative, the count of fields starts from end of value, -1 being last field. If index is positive, 0 is the first field.
  1961. Example:
  1962. $var(x) = "12,34,56";
  1963. $(var(x){s.select,1,,}) => "34" ;
  1964. $var(x) = "12,34,56";
  1965. $(var(x){s.select,-2,,}) => "34"
  1966. 1.6 {s.encode.hexa}
  1967. Return encoding in hexa of variable's value
  1968. 1.7 {s.decode.hexa}
  1969. Return decoding from hexa of variable's value
  1970. 1.8 {s.escape.common}
  1971. Return escaped string of variable's value. Characters escaped are ', ", and 0. Useful when doing DB queries (care should be taken for non Latin character set).
  1972. 1.9 {s.unescape.common}
  1973. Return unescaped string of variable's value. Reverse of above transformation.
  1974. 1.10 {s.escape.user}
  1975. Return escaped string of variable's value, changing to '%hexa' the characters that are not allowed in user part of SIP URI following RFC requirements.
  1976. 1.11 {s.unescape.user}
  1977. Return unescaped string of variable's value, changing '%hexa' to character code. Reverse of above transformation.
  1978. 1.12 {s.escape.param}
  1979. Return escaped string of variable's value, changing to '%hexa' the characters that are not allowed in the param part of SIP URI following RFC requirements.
  1980. 1.13 {s.unescape.param}
  1981. Return unescaped string of variable's value, changing '%hexa' to character code. Reverse of above transformation.
  1982. 1.14 {s.tolower}
  1983. Return string with lower case ASCII letters.
  1984. 1.15 {s.toupper}
  1985. Return string with upper case ASCII letters.
  1986. 1.16 {s.dec2hex}
  1987. Converts a decimal(base 10) number to hexadecimal (in base 16), represented as string.
  1988. 1.17 {s.hex2dec}
  1989. Converts a hexadecimal number (base 16) represented as string to decimal (base 10).
  1990. 1.18 {s.index}
  1991. Searches for one string within another starting at the beginning of the first string. Returns starting index of the string found or -1 if not found. The optional index specifies the offset to begin the search at in the string. Negative offsets are supported and will wrap.
  1992. $var(strtosearch) = 'onetwothreeone';
  1993. $var(str) = 'one';
  1994. # Search the string starting at 0 index
  1995. $(var(strtosearch){s.index, $var(str)}) # will return 0
  1996. $(var(strtosearch){s.index, $var(str), 0}) # Same as above
  1997. $(var(strtosearch){s.index, $var(str), 3}) # returns 11
  1998. # Negative offset
  1999. $(var(strtosearch){s.index, $var(str), -11}) # Same as above
  2000. # Negative wrapping offset
  2001. $(var(strtosearch){s.index, $var(str), -25}) # Same as above
  2002. #Test for existence of string in another
  2003. if ($(var(strtosearch){s.index, $var(str)}) >=0)
  2004. xlog("found $var(sstr) in $var(strtosearch)");
  2005. 1.19 {s.rindex}
  2006. Searches for one string within another starting at the end of the first string. Returns starting index of the string found or -1 if not found. The optional index specifies an offset to start the search before, e.g the start of the found string will be before the supplied offset. Negative offsets are supported and will wrap.
  2007. $(var(strtosearch){s.rindex, $var(str)}) # will return 11
  2008. $(var(strtosearch){s.rindex, $var(str), -3}) # will return 11
  2009. $(var(strtosearch){s.rindex, $var(str), 11}) # will return 11
  2010. $(var(strtosearch){s.rindex, $var(str), -4}) # will return 0
  2011. 2. URI Transformations
  2012. The name of transformation starts with 'uri.'. The value of the variable is considered to be a SIP URI. This transformation returns parts of SIP URI (see struct sip_uri). If that part is missing, the returned value is an empty string.
  2013. Available transformations in this class:
  2014. 2.1 {uri.user}
  2015. Returns the user part of the URI schema.
  2016. 2.2 {uri.host}
  2017. (same as {uri.domain})
  2018. Returns the domain part of the URI schema.
  2019. 2.3 {uri.passwd}
  2020. Returns the password part of the URI schema.
  2021. 2.4 {uri.port}
  2022. Returns the port of the URI schema.
  2023. 2.5 {uri.params}
  2024. Returns all the URI parameters into a single string.
  2025. 2.6 {uri.param,name}
  2026. Returns the value of URI parameter with name "name"
  2027. 2.7 {uri.headers}
  2028. Returns URI headers.
  2029. 2.8 {uri.transport}
  2030. Returns the value of transport URI parameter.
  2031. 2.9 {uri.ttl}
  2032. Returns the value of ttl URI parameter.
  2033. 2.10 {uri.uparam}
  2034. Returns the value of user URI parameter
  2035. 2.11 {uri.maddr}
  2036. Returns the value of maddr URI parameter.
  2037. 2.12 {uri.method}
  2038. Returns the value of method URI parameter.
  2039. 2.13 {uri.lr}
  2040. Returns the value of lr URI parameter.
  2041. 2.14 {uri.r2}
  2042. Returns the value of r2 URI parameter.
  2043. 3. VIA Transformations
  2044. These transformations parse Via headers and all starts with via.. The value of the variable is considered to be a SIP Via header. This transformation returns parts of the via header (see struct via_body). If the requested part is missing, the returned value is an empty string. Transformation will fail (with script error) if variable holding the Via header is empty. Unless otherwise specified in descriptions below, the result of transform is a string (not an integer).
  2045. Examples:
  2046. $var(upstreamtransport) = $(hdr(Via)[1]{via.transport}{s.tolower});
  2047. $var(upstreamip) = $(hdr(Via)[1]{via.param,received});
  2048. $var(clientport) = $(hdr(Via)[-1]{via.param,rport});
  2049. Available transformations in this class:
  2050. 3.1 {via.name}
  2051. Returns the protocol-name (of RFC3261 BNF), generally SIP.
  2052. 3.2 {via.version}
  2053. Returns the protocol-version (of RFC3261 BNF), generally 2.0.
  2054. 3.3 {via.transport}
  2055. Returns the transport (of RFC3261 BNF), e.g., UDP, TCP, TLS. This is the transport protocol used to send the request message.
  2056. 3.4 {via.host}
  2057. (same as {via.domain})
  2058. Returns the host portion of the sent-by (of RFC3261 BNF). Typically this is the IP address of the sender of the request message, and is the address to which the response will be sent.
  2059. 3.5 {via.port}
  2060. Returns the port portion of the sent-by (of RFC3261 BNF). Typically this is the IP port of the sender of the request message, and is the address to which the response will be sent. Result of transform is valid as both integer and string.
  2061. 3.6 {via.comment}
  2062. The comment associated with the via header. The struct via_body contains this field, but it isn't clear that RFC3261 allows Via headers to have comments (see text at top of page 221, and the BNF doesn't explicit allow comment within Via). The comment is the text enclosed within parens.
  2063. 3.7 {via.params}
  2064. Returns all the Via headers parameters (via-param of RFC3261 BNF) as single string. Result can be processed using the {param.*} transforms. This is essentially everything after the host and port.
  2065. 3.8 {via.param,name}
  2066. Returns the value of Via header parameter with name name. Typical parameters include branch, rport and received.
  2067. 3.9 {via.branch}
  2068. Returns the value of the branch parameter in the VIA header.
  2069. 3.10 {via.received}
  2070. Returns the value of the received parameter in the VIA header, if any.
  2071. 3.11 {via.rport}
  2072. Returns the value of the rport parameter in the VIA header, if any.
  2073. 4. Parameters List Transformations
  2074. The name of the transformation starts with "param.". The value of the variable is considered to be a string like name1=value1;name2=value2;...". The transformations returns the value for a specific parameter, or the name of a parameter at a specific index.
  2075. Available transformations in this class:
  2076. 4.1 {param.value,name}
  2077. Returns the value of parameter 'name'
  2078. Example:
  2079. "a=1;b=2;c=3"{param.value,c} = "3"
  2080. 'name' can be a variable
  2081. 4.2 {param.exist,name}
  2082. Returns 1 if the parameter name exists (with or without value), else 0. Returned value is both string and integer. name can be variable. This can be used to test existence of parameters that do not have values.
  2083. Example:
  2084. "a=0;b=2;ob;c=3"{param.exist,ob}; # returns 1
  2085. "a=0;b=2;ob;c=3"{param.exist,a}; # returns 1
  2086. "a=0;b=2;ob;c=3"{param.exist,foo}; # returns 0
  2087. 4.3 {param.valueat,index}
  2088. Returns the value of parameter at position give by 'index' (0-based index)
  2089. Example:
  2090. "a=1;b=2;c=3"{param.valueat,1} = "2"
  2091. 'index' can be a variable
  2092. 4.4 {param.name,index}
  2093. Returns the name of parameter at position 'index'.
  2094. Example:
  2095. "a=1;b=2;c=3"{param.name,1} = "b"
  2096. 4.5 {param.count}
  2097. Returns the number of parameters in the list.
  2098. Example:
  2099. "a=1;b=2;c=3"{param.count} = 3
  2100. 5. Name-address Transformations
  2101. The name of the transformation starts with 'nameaddr.'. The value of the variable is considered to be a string like '[display_name] uri'. The transformations returns the value for a specific field.
  2102. Available transformations in this class:
  2103. 5.1 {nameaddr.name}
  2104. Returns the value of display name
  2105. Example:
  2106. '"test" <sip:test@opensips.org>' {nameaddr.name} = "test"
  2107. 5.2 {nameaddr.uri}
  2108. Returns the value of URI
  2109. Example:
  2110. '"test" <sip:test@opensips.org>' {nameaddr.uri} = sip:test@opensips.org
  2111. 5.3 {nameaddr.len}
  2112. Returns the length of the entire name-addr part from the value.
  2113. 5.4 {nameaddr.param,param_name}
  2114. Returns the value of the parameter with name param_name. Example:
  2115. '"test" <sip:test@opensips.org>;tag=dat43h' {nameaddr.param,tag} = dat43h
  2116. 5.5 {nameaddr.params}
  2117. Returns all the parameters and their corresponding values. Example:
  2118. '"test" <sip:test@opensips.org>;tag=dat43h;private=yes' {nameaddr.params} = "tag=dat43h;private=yes"
  2119. 6. IP Transformations
  2120. The name of the transformation starts with 'ip.'. Available transformations in this class:
  2121. 6.1 {ip.pton}
  2122. Returns a binary representation of a string represented IP. Example:
  2123. "192.168.2.134" {ip.pton} returns a 4 byte binary representation of the IP provided
  2124. 6.2 {ip.ntop}
  2125. Returns a string representation of the binary IP provided Example:
  2126. "192.168.2.134"{ip.pton}{ip.ntop} = "192.168.2.134"
  2127. 6.3 {ip.isip}
  2128. Returns 1 or 0, if the string provided is a valid IP or not. Example:
  2129. "192.168.2.134" {ip.isip} = 1
  2130. "192.168.2.134.1" {ip.isip} = 0
  2131. 6.4 {ip.family}
  2132. Returns INET or INET6 if the binary IP representation provided is IPv4 or IPv6. Example:
  2133. "192.168.2.134" {ip.pton}{ip.family} = "INET"
  2134. 6.5 {ip.resolve}
  2135. Returns the resolved IP address coresponding to the string domain provided. Transformation has no effect if a string IP is provided. Example:
  2136. "opensips.org" {ip.resolve} = "78.46.64.50"
  2137. 7. CSV Transformations
  2138. The name of the transformation starts with "csv.". The value of the variable is considered to be a string like "field1,field2,...". The transformations return the number of entries in the provided CSV, or the field at a specified position in the CSV.
  2139. Available transformations in this class:
  2140. 7.1 {csv.count}
  2141. Returns the number of entries in the provided CSV. Example:
  2142. "a,b,c" {csv.count} = 3
  2143. 7.2 {csv.value}
  2144. Returns the entry at the specified positions. Indexing starts from 0. Example:
  2145. "a,b,c" {csv.value,2} = c
  2146. 8. SDP Transformations
  2147. The name of the transformation starts with "sdp.". The value of the variable is considered to be a valid SDP body. The transformation returns a specific line in the SDP body.
  2148. Available transformations in this class:
  2149. 8.1 {sdp.line}
  2150. Returns the specified line in the SDP body. The transformations also accepts a second parameter, that specifies the line number of the first parameter's type to get from the SDP body. Indexing starts from 0. If the second parameter is missing, it is assumed to be 0. Example:
  2151. if (is_method("INVITE"))
  2152. {
  2153. $var(aline) = $(rb{sdp.line,a,1});
  2154. xlog("The second a line in the SDP body is $var(aline)\n");
  2155. }
  2156. if (is_method("INVITE"))
  2157. {
  2158. $var(mline) = $(rb{sdp.line,m});
  2159. xlog("The first m line in the SDP body is $var(mline)\n");
  2160. }
  2161. 9. Regular Expression Transformations
  2162. The name of the transformation starts with "re.". The input can be any string.
  2163. 9.1 {re.subst,reg_exp}
  2164. The reg_exp parameter can either be a plain string or a variable. The format of the reg_exp is :
  2165. /posix_match_expression/replacement_expression/flags
  2166. The flags can be
  2167. i - match ignore case
  2168. s - match within multi-lines strings
  2169. g - replace all matches
  2170. Example:
  2171. $var(reg_input)="abc";
  2172. $var(reg) = "/a/A/g";
  2173. xlog("Applying reg exp $var(reg) to $var(reg_input) : $(var(reg_input){re.subst,$var(reg)})\n");
  2174. ...
  2175. ...
  2176. xlog("Applying reg /b/B/g to $var(reg_input) : $(var(reg_input){re.subst,/b/B/g})\n");
  2177. 10. Examples
  2178. Within a variable, many transformation can be applied, being executed from left to right.
  2179. The length of the value of parameter at postion 1 (remember 0 is first position, 1 is second position)
  2180. $var(x) = "a=1;b=22;c=333";
  2181. $(var(x){param.value,$(var(x){param.name,1})}{s.len}) = 2
  2182. Test if whether is un-registration or not
  2183. if(is_method("REGISTER") && is_present_hf("Expires") && $(hdr(Expires){s.int})==0)
  2184. xlog("This is an un-registrationn");

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/251221?site
推荐阅读
相关标签
  

闽ICP备14008679号