Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
core-cookbook:1.3.x [2007/12/17 11:17] – created 212.227.35.68 | core-cookbook:1.3.x [2011/06/06 07:27] (current) – 95.135.119.19 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== OpenSER Core CookBook for version 1.3.x ====== | ||
+ | |||
+ | < | ||
+ | Main author: | ||
+ | | ||
+ | </ | ||
+ | |||
+ | This page is dedicated to OpenSER core interaction with the configuration script (openser.cfg). These parameters, keywords, and functions are exported by OpenSER' | ||
+ | |||
+ | This list is not complete yet. It will eventually, and with your help, that will happen sooner. | ||
+ | |||
+ | Please contribute only to the items you are sure you know what they mean. | ||
+ | |||
+ | Thank you! | ||
+ | |||
+ | IMPORTANT: This document is only valid for OpenSER 1.3.x version. | ||
+ | |||
+ | IMPORTANT: To learn what variables can be used directly in configuration file see [[pseudovariables: | ||
+ | |||
+ | ===== Core Keywords ===== | ||
+ | |||
+ | Keywords specific to SIP messages which can be used mainly in ' | ||
+ | |||
+ | ==== af ==== | ||
+ | |||
+ | 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. | ||
+ | |||
+ | Exampe of usage: | ||
+ | |||
+ | if(af==INET6) { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | |||
+ | |||
+ | ==== dst_ip ==== | ||
+ | |||
+ | 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. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | |||
+ | ==== dst_port ==== | ||
+ | |||
+ | The local port where the SIP packet was received. When OpenSER is listening on many ports, it is useful to learn which was the one that received the SIP packet. | ||
+ | |||
+ | Example of usage: | ||
+ | | ||
+ | { | ||
+ | | ||
+ | }; | ||
+ | |||
+ | |||
+ | ==== from_uri ==== | ||
+ | |||
+ | This script variable is a reference to the URI of ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(is_method(" | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== method ==== | ||
+ | |||
+ | The variable is a reference to the SIP method of the message. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(method==" | ||
+ | { | ||
+ | | ||
+ | }; | ||
+ | |||
+ | ==== msg:len ==== | ||
+ | |||
+ | The variable is a reference to the size of the message. It can be used in ' | ||
+ | |||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(msg: | ||
+ | { | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | }; | ||
+ | |||
+ | ==== $retcode ==== | ||
+ | |||
+ | It represents the value returned by last function executed (similar to $? from bash -- if you wish, you can use also $? in OpenSER config, both names ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | route { | ||
+ | | ||
+ | | ||
+ | { | ||
+ | | ||
+ | }; | ||
+ | } | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | ==== proto ==== | ||
+ | |||
+ | This variable can be used to test the transport protocol of the SIP message. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(proto==UDP) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | |||
+ | ==== status ==== | ||
+ | |||
+ | If used in onreply_route, | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(status==" | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== src_ip ==== | ||
+ | |||
+ | Reference to source IP address of the SIP message. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(src_ip==127.0.0.1) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== src_port ==== | ||
+ | |||
+ | Reference to source port of the SIP message (from which port the message was sent by previous hop). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(src_port==5061) | ||
+ | { | ||
+ | log(" | ||
+ | } | ||
+ | |||
+ | ==== to_uri ==== | ||
+ | |||
+ | This variable can be used to test the value of URI from To header. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(to_uri=~" | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | |||
+ | ==== uri ==== | ||
+ | |||
+ | |||
+ | This variable can be used to test the value of the request URI. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(uri=~" | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ===== Core Values ===== | ||
+ | |||
+ | Values that can be used in ' | ||
+ | |||
+ | ==== INET ==== | ||
+ | |||
+ | This keyword can be used to test whether the SIP packet was received over an IPv4 connection. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(af==INET) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== INET6 ==== | ||
+ | |||
+ | This keyword can be used to test whether the SIP packet was received over an IPv6 connection. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(af==INET6) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== TCP ==== | ||
+ | |||
+ | This keyword can be used to test the value of ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(proto==TCP) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== UDP ==== | ||
+ | |||
+ | This keyword can be used to test the value of ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(proto==UDP) | ||
+ | { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== max_len ==== | ||
+ | |||
+ | This keyword is set to the maximum size of an UDP packet. It can be used to test message' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(msg: | ||
+ | { | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | ==== myself ==== | ||
+ | |||
+ | It is a reference to the list of local IP addresses, hostnames and aliases that has been set in OpenSER configuration file. This lists contain the domains served by OpenSER. | ||
+ | |||
+ | 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. | ||
+ | |||
+ | See " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(uri==myself) { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== null ==== | ||
+ | |||
+ | Can be used in assignment to reset the value of a per-script variable or to delete an avp. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | $avp(i:12) = null; | ||
+ | $var(x) = null; | ||
+ | |||
+ | ===== Core parameters ===== | ||
+ | |||
+ | Global parameters that can be set in configuration file. | ||
+ | |||
+ | |||
+ | ==== advertised_address ==== | ||
+ | |||
+ | 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. | ||
+ | |||
+ | WARNING: | ||
+ | - don't set it unless you know what you are doing (e.g. nat traversal) | ||
+ | - you can set anything here, no check is made (e.g. foo.bar will be | ||
+ | accepted even if foo.bar doesn' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | advertised_address=" | ||
+ | |||
+ | ==== advertised_port ==== | ||
+ | |||
+ | 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 ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | advertised_port=5080 | ||
+ | |||
+ | |||
+ | |||
+ | ==== alias ==== | ||
+ | |||
+ | 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 ' | ||
+ | |||
+ | It is necessary to include the port (the port value used in the " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | < | ||
+ | alias=other.domain.com: | ||
+ | alias=another.domain.com: | ||
+ | </ | ||
+ | |||
+ | ==== avp_aliases ==== | ||
+ | |||
+ | Contains a multiple definition of aliases for AVP names. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | < | ||
+ | avp_aliases=" | ||
+ | </ | ||
+ | ==== auto_aliases ==== | ||
+ | |||
+ | 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. | ||
+ | |||
+ | For backward compatibility reasons, the default value is " | ||
+ | |||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | auto_aliases=no | ||
+ | auto_aliases=0 | ||
+ | |||
+ | ==== check_via ==== | ||
+ | |||
+ | Check if the address in top most via of replies is local. Default value is 0 (check disabled). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | check_via=1 | ||
+ | |||
+ | ==== children ==== | ||
+ | |||
+ | Number of children to fork for the UDP interfaces (one set for each interface - ip:port). Default value is 8. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | children=16 | ||
+ | |||
+ | ==== chroot ==== | ||
+ | |||
+ | The value must be a valid path in the system. If set, OpenSER will chroot (change root directory) to its value. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | chroot=/ | ||
+ | |||
+ | ==== debug ==== | ||
+ | |||
+ | Set the debug level. Higher values make SER to print more debug messages. | ||
+ | |||
+ | Examples of usage: | ||
+ | |||
+ | debug=3 -- print only important messages (like errors or more critical situations) | ||
+ | - recommended for running proxy as daemon | ||
+ | |||
+ | debug=9 -- print a lot of debug messages - use it only when doing debugging sessions | ||
+ | |||
+ | The ' | ||
+ | |||
+ | For more see: http:// | ||
+ | |||
+ | ==== disable_core_dump ==== | ||
+ | |||
+ | Can be ' | ||
+ | a high enough value. Set this config variable to ' | ||
+ | (will set core limits to 0). | ||
+ | |||
+ | Default value is ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | disable_core_dump=yes | ||
+ | |||
+ | ==== disable_dns_blacklist ==== | ||
+ | |||
+ | 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) openser to send requests to destination known as failed. So, the blacklist can be used as a memory for the DNS resolver. | ||
+ | |||
+ | The temporary blacklist created by DNS resolver is named " | ||
+ | |||
+ | Can be ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | disable_dns_blacklist=no | ||
+ | |||
+ | |||
+ | |||
+ | ==== disable_dns_failover ==== | ||
+ | |||
+ | Can be ' | ||
+ | |||
+ | Default value is ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | disable_dns_failover=yes | ||
+ | |||
+ | ==== disable_tcp ==== | ||
+ | |||
+ | Global parameter to disable TCP support in the SIP server. Default value is ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | disable_tcp=yes | ||
+ | ==== disable_tls ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== dns ==== | ||
+ | |||
+ | 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 " | ||
+ | |||
+ | Default is no. | ||
+ | |||
+ | ==== dns_retr_time ==== | ||
+ | |||
+ | Time in seconds before retrying a dns request. Default value is system specific, | ||
+ | depends also on the '/ | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | dns_retr_time=3 | ||
+ | |||
+ | ==== dns_retr_no ==== | ||
+ | |||
+ | Number of dns retransmissions before giving up. Default value is system specific, | ||
+ | depends also on the '/ | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | dns_retr_no=3 | ||
+ | |||
+ | ==== dns_servers_no ==== | ||
+ | |||
+ | How many dns servers from the ones defined in '/ | ||
+ | Default value is to use all of them. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | dns_servers_no=2 | ||
+ | |||
+ | ==== dns_try_ipv6 ==== | ||
+ | |||
+ | Can be ' | ||
+ | for ipv6 (AAAA record). Default value is ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | dns_try_ipv6=yes | ||
+ | |||
+ | ==== dns_use_search_list ==== | ||
+ | |||
+ | Can be ' | ||
+ | will be ignored (=> fewer lookups => gives up faster). Default value is ' | ||
+ | |||
+ | HINT: even if you don't have a search list defined, setting this option | ||
+ | to ' | ||
+ | fact search "" | ||
+ | still be 2 dns queries, eg. foo+' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | dns_use_search_list=no | ||
+ | |||
+ | ==== dst_blacklist ==== | ||
+ | |||
+ | Definition of a static (read-only) IP/ | ||
+ | |||
+ | 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). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | < | ||
+ | # filter out requests going to ips of my gws | ||
+ | | ||
+ | # block requests going to " | ||
+ | | ||
+ | # block message requests with nasty words | ||
+ | | ||
+ | # block requests not going to a specific subnet | ||
+ | | ||
+ | </ | ||
+ | |||
+ | |||
+ | Each rule is defined by: | ||
+ | - protocol : TCP, UDP, TLS or " | ||
+ | - port : number or 0 for any | ||
+ | - ip/mask | ||
+ | - test patter - is a filename like matching (see "man 3 fnmatch" | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== fork ==== | ||
+ | |||
+ | If set to ' | ||
+ | |||
+ | When set to ' | ||
+ | |||
+ | Default value is ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | fork=no | ||
+ | |||
+ | ==== group gid ==== | ||
+ | |||
+ | The group id to run OpenSER. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | group=" | ||
+ | |||
+ | ==== listen ==== | ||
+ | |||
+ | Set the network addresses the SIP server should listen to. It can be an IP address, hostname or network iterface id or combination of protocol: | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | listen=10.10.10.10 | ||
+ | listen=eth1: | ||
+ | listen=udp: | ||
+ | |||
+ | 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. | ||
+ | |||
+ | ==== log_facility ==== | ||
+ | |||
+ | If OpenSER logs to syslog, you can control the facility for logging. Very | ||
+ | useful when you want to divert all OpenSER logs to a different log file. | ||
+ | See man page syslog(3) for more details. | ||
+ | |||
+ | For more see: http:// | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | log_facility=LOG_LOCAL0 | ||
+ | |||
+ | |||
+ | ==== log_name ==== | ||
+ | |||
+ | Set the id to be printed in syslog. The value must be a string and has | ||
+ | effect only when OpenSER runs in daemon mode (fork=yes), after daemonize. | ||
+ | Default value is argv[0]. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | log_name=" | ||
+ | |||
+ | |||
+ | ==== log_stderror ==== | ||
+ | |||
+ | With this parameter you can make OpenSER to write log and debug messages to standard error. Possible values are: | ||
+ | |||
+ | - " | ||
+ | |||
+ | - " | ||
+ | |||
+ | Default value is " | ||
+ | |||
+ | For more see: http:// | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | log_stderror=yes | ||
+ | |||
+ | ==== max_while_loops ==== | ||
+ | |||
+ | The parameters set the value of maximum loops that can be done within a " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | max_while_loops=200 | ||
+ | |||
+ | ==== maxbuffer ==== | ||
+ | |||
+ | The size in bytes not to be exceeded during the auto-probing procedure of descovering the maximum buffer size for receiving UDP messages. Default value is 262144. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | maxbuffer=65536 | ||
+ | |||
+ | ==== memlog ==== | ||
+ | |||
+ | Log level to print memory debug info. It has be less than the value of ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | memlog=2 | ||
+ | |||
+ | ==== mcast_loopback ==== | ||
+ | |||
+ | It can be ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | mcast_loopback=yes | ||
+ | |||
+ | ==== mcast_ttl ==== | ||
+ | |||
+ | Set the value for multicast ttl. Default value is OS specific (usually 1). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | mcast_ttl=32 | ||
+ | |||
+ | ==== mhomed ==== | ||
+ | |||
+ | Set the server to try to locate outbound interface on multihomed host. By default is not (0) - it is rather time consuming. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | mhomed=1 | ||
+ | |||
+ | ==== mpath ==== | ||
+ | |||
+ | Set the module search path. This can be used to simplify the loadmodule parameter | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | mpath="/ | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | loadmodule " | ||
+ | ... | ||
+ | |||
+ | ==== open_files_limit ==== | ||
+ | |||
+ | If set and bigger than the current open file limit, OpenSER will try | ||
+ | to increase its open file limit to this number. Note: OpenSER 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). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | open_files_limit=2048 | ||
+ | |||
+ | ==== port ==== | ||
+ | |||
+ | The port the SIP server listens to. The default value for it is 5060. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | port=5080 | ||
+ | |||
+ | ==== reply_to_via ==== | ||
+ | |||
+ | 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). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | reply_to_via=0 | ||
+ | |||
+ | ==== rev_dns ==== | ||
+ | |||
+ | This parameter controls if the SIP server shold 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 " | ||
+ | |||
+ | Default is no. | ||
+ | |||
+ | ==== server_header ==== | ||
+ | |||
+ | The body of Server header field generated by OpenSER when it sends a request as UAS. It defaults to " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | < | ||
+ | server_header=" | ||
+ | </ | ||
+ | |||
+ | Please note that you have to add the header name " | ||
+ | |||
+ | < | ||
+ | My Company SIP Proxy | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== server_signature ==== | ||
+ | |||
+ | This parameter controls the " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | | ||
+ | |||
+ | If it is enabled (default=yes) a header is generated as in the following example: | ||
+ | |||
+ | | ||
+ | ==== sip_warning ==== | ||
+ | |||
+ | Can be 0 (default value) or 1. If set to 1 a ' | ||
+ | The header contains several details that help troubleshooting using the network traffic dumps. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | sip_warning=0 | ||
+ | |||
+ | ==== tcp_children ==== | ||
+ | |||
+ | 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 " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | tcp_children=4 | ||
+ | |||
+ | ==== tcp_accept_aliases ==== | ||
+ | |||
+ | ==== tcp_send_timeout ==== | ||
+ | |||
+ | Time in seconds after a TCP connection will be closed if it is not available | ||
+ | for writing in this interval (and OpenSER wants to send something on it). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | tcp_send_timeout=3 | ||
+ | |||
+ | ==== tcp_connect_timeout ==== | ||
+ | |||
+ | Time in seconds before an ongoing attempt to connect will be aborted. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | tcp_connect_timeout=5 | ||
+ | |||
+ | |||
+ | |||
+ | ==== tcp_connection_lifetime ==== | ||
+ | |||
+ | Lifetime in seconds for TCP sessions. TCP sessions which are inactive for > | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | tcp_connection_lifetime=3600 | ||
+ | |||
+ | ==== tcp_max_connections ==== | ||
+ | |||
+ | 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 | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | tcp_max_connections=4096 | ||
+ | |||
+ | ==== tcp_poll_method ==== | ||
+ | |||
+ | 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: | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | tcp_poll_method=select | ||
+ | |||
+ | ==== tls_ca_list ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_certificate ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_ciphers_list ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_domain ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_handshake_timeout ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_log ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_method ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_port_no ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_private_key ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_require_certificate ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_send_timeout ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tls_verify ==== | ||
+ | |||
+ | See http:// | ||
+ | |||
+ | ==== tos ==== | ||
+ | |||
+ | The TOS (Type Of Service) to be used for the sent IP packages (both TCP and UDP). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | tos=IPTOS_LOWDELAY | ||
+ | tos=0x10 | ||
+ | tos=IPTOS_RELIABILITY | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== user uid ==== | ||
+ | |||
+ | The user id to run OpenSER (OpenSER will suid to it). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | user=" | ||
+ | |||
+ | |||
+ | ==== user_agent_header ==== | ||
+ | |||
+ | The body of User-Agent header field generated by OpenSER when it sends a request as UAC. It defaults to " | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | < | ||
+ | user_agent_header=" | ||
+ | </ | ||
+ | |||
+ | Please note that you have to include the header name " | ||
+ | < | ||
+ | My Company SIP Proxy | ||
+ | </ | ||
+ | |||
+ | ==== wdir ==== | ||
+ | |||
+ | The working directory used by OpenSER at runtime. You might find it usefull when come to generating core files :) | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | | ||
+ | or | ||
+ | | ||
+ | |||
+ | ===== Core Functions ===== | ||
+ | |||
+ | Functions exported by core that can be used in route blocks. | ||
+ | |||
+ | ==== add_local_rport() ==== | ||
+ | |||
+ | Add ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | add_local_rport() | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== append_branch() ==== | ||
+ | |||
+ | Similarly to t_fork_to, it extends destination set by a new entry. The difference is that current URI is taken as new entry. | ||
+ | |||
+ | Without parameter, the function copies the current URI into a new branch. Thus, leaving the main branch (the URI) for further manipulation. | ||
+ | |||
+ | With a parameter, the function copies the URI in the parameter into a new branch. Thus, the current URI is not manipulated. | ||
+ | |||
+ | Example of usage: | ||
+ | < | ||
+ | # if someone calls B, the call should be forwarded to C too. | ||
+ | # | ||
+ | if (method==" | ||
+ | { | ||
+ | # copy the current branch (branches[0]) into | ||
+ | # a new branch (branches[1]) | ||
+ | append_branch(); | ||
+ | # all URI manipulation functions work on branches[0] | ||
+ | # thus, URI manipulation does not touch the | ||
+ | # appended branch (branches[1]) | ||
+ | seturi(" | ||
+ | | ||
+ | # now: branch 0 = C@domain | ||
+ | # branch 1 = B@xx.xx.xx.xx | ||
+ | | ||
+ | # and if you need a third destination ... | ||
+ | | ||
+ | # copy the current branch (branches[0]) into | ||
+ | # a new branch (branches[2]) | ||
+ | append_branch(); | ||
+ | | ||
+ | # all URI manipulation functions work on branches[0] | ||
+ | # thus, URI manipulation does not touch the | ||
+ | # appended branch (branches[1-2]) | ||
+ | seturi(" | ||
+ | | ||
+ | # now: branch 0 = D@domain | ||
+ | # branch 1 = B@xx.xx.xx.xx | ||
+ | # branch 2 = C@domain | ||
+ | | ||
+ | t_relay(); | ||
+ | exit; | ||
+ | }; | ||
+ | |||
+ | # You could also use append_branch(" | ||
+ | | ||
+ | | ||
+ | if(method==" | ||
+ | # append a new branch with the second destination | ||
+ | append_branch(" | ||
+ | # now: branch 0 = B@xx.xx.xx.xx | ||
+ | # now: branch 1 = C@domain | ||
+ | |||
+ | t_relay(); | ||
+ | exit; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== break() ==== | ||
+ | |||
+ | Since v0.10.0-dev3, | ||
+ | |||
+ | ' | ||
+ | |||
+ | ==== drop() ==== | ||
+ | |||
+ | Stop the execution of the configuration script and alter the implicit action which is done afterwards. | ||
+ | |||
+ | If the function is called in a ' | ||
+ | |||
+ | If the function is called in a ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | onreply_route { | ||
+ | if(status==" | ||
+ | drop(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | ==== exit() ==== | ||
+ | |||
+ | Stop the execution of the configuration script -- it has the same behaviour as return(0). It does not affect the implicit action to be taken after script execution. | ||
+ | |||
+ | route { | ||
+ | if (route(2)) { | ||
+ | xlog(" | ||
+ | } else { | ||
+ | xlog(" | ||
+ | }; | ||
+ | } | ||
+ | |||
+ | route[2] { | ||
+ | if (is_method(" | ||
+ | return(1); | ||
+ | } else if (is_method(" | ||
+ | return(-1); | ||
+ | } else if (is_method(" | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | }; | ||
+ | } | ||
+ | |||
+ | ==== force_rport() ==== | ||
+ | Force_rport() adds the rport parameter to the first Via header. Thus, openser will add the received IP port to the top most via header in the SIP message, even if the client does not indicate support for rport. This enables subsequent SIP messages to return to the proper port later on in a SIP transaction. | ||
+ | |||
+ | The rport parameter is defined in RFC 3581. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | force_rport(); | ||
+ | |||
+ | ==== force_send_socket([proto: | ||
+ | |||
+ | Force OpenSER to send the message from the specified socket (it _must_ be one of the sockets OpenSER listens on). If the protocol doesn' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | force_send_socket(10.10.10.10: | ||
+ | |||
+ | |||
+ | |||
+ | ==== force_tcp_alias([port]) ==== | ||
+ | |||
+ | |||
+ | Adds a tcp port alias for the current connection (if tcp). Useful if you want to send all the traffic 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 Via header as the alias. When the " | ||
+ | |||
+ | ==== forward(destination) ==== | ||
+ | |||
+ | Forward the SIP request to the given destination in stateless mode. This has the format of [proto: | ||
+ | If proto or port are not specified, NAPTR and SRV lookups will be used to determine them (if possible). | ||
+ | |||
+ | If destination parameter is missing, the forward will be done based on RURI. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | forward(" | ||
+ | #or | ||
+ | forward(); | ||
+ | |||
+ | |||
+ | ==== isdsturiset() ==== | ||
+ | |||
+ | Test if the dst_uri field (next hop address) is set. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(isdsturiset()) { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | |||
+ | ==== isflagset(int) ==== | ||
+ | |||
+ | Test if a message (or transaction) flag is set for current processed request/ | ||
+ | |||
+ | For more see [[utils: | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(isflagset(3)) { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== isbflagset([branch_idx, | ||
+ | |||
+ | Test if a flag is set for a specific branch (if the flag value is 1). The value of the " | ||
+ | |||
+ | For more about script flags, see [[utils: | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(isbflagset(1, | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== issflagset(flag_idx) ==== | ||
+ | |||
+ | Test if a script flag is set (if the flag value is 1). The value of the " | ||
+ | |||
+ | For more about script flags, see [[utils: | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(issflagset(2)) { | ||
+ | log(" | ||
+ | }; | ||
+ | |||
+ | ==== log([level, | ||
+ | |||
+ | Write text message to standard error terminal or syslog. You can specify the log level as first parameter. | ||
+ | |||
+ | For more see: http:// | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | log(" | ||
+ | |||
+ | |||
+ | ==== prefix(string) ==== | ||
+ | |||
+ | Add the string parameter in front of username in R-URI. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | prefix(" | ||
+ | |||
+ | |||
+ | ==== pv_printf(pv, | ||
+ | |||
+ | Prints the formatted ' | ||
+ | |||
+ | 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(...). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | pv_printf(" | ||
+ | pv_printf(" | ||
+ | |||
+ | ==== next_branches() ==== | ||
+ | |||
+ | it inherits the functionality of next_contacts() from LCR; get (based on q value) the next contact(s) to be used in sequential forking. Returns true only if a new contact was got to be used. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if (next_branches()) { | ||
+ | t_relay(); | ||
+ | } | ||
+ | |||
+ | ==== return(int) ==== | ||
+ | |||
+ | The return() function allows you to return any integer value from a called route() block. | ||
+ | You can test the value returned by a route using [[devel# | ||
+ | |||
+ | return(0) is same as [[devel# | ||
+ | |||
+ | In bool expressions: | ||
+ | |||
+ | * Negative and ZERO is FALSE | ||
+ | * Positive is TRUE | ||
+ | |||
+ | Example usage: | ||
+ | |||
+ | < | ||
+ | route { | ||
+ | if (route(2)) { | ||
+ | xlog(" | ||
+ | } else { | ||
+ | xlog(" | ||
+ | }; | ||
+ | } | ||
+ | </ | ||
+ | < | ||
+ | route[2] { | ||
+ | if (is_method(" | ||
+ | return(1); | ||
+ | } else if (is_method(" | ||
+ | return(-1); | ||
+ | } else { | ||
+ | return(0); | ||
+ | }; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== resetdsturi() ==== | ||
+ | |||
+ | Set the value of dst_uri filed to NULL. dst_uri field is usually set after loose_route() or lookup(" | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | resetdsturi(); | ||
+ | |||
+ | ==== resetflag(int) ==== | ||
+ | |||
+ | Reset a flag for current processed message (set the value to 0). The value of the parameter can be in range of 0..31. | ||
+ | |||
+ | For more see http:// | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | resetflag(3); | ||
+ | |||
+ | ==== resetbflag([branch_idx, | ||
+ | |||
+ | Reset a flag for a specific branch (set flag to value 0). The value of the " | ||
+ | |||
+ | For more about script flags, see [[utils: | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | resetbflag(1, | ||
+ | # or | ||
+ | resetbflag(3); | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== resetsflag(flag_idx) ==== | ||
+ | |||
+ | Reset a script flag (set flag to value 0). The value of the " | ||
+ | |||
+ | For more about script flags, see [[utils: | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | resetsflag(2); | ||
+ | |||
+ | ==== revert_uri() ==== | ||
+ | |||
+ | Set the R-URI to the value of the R-URI as it was when the request was received by server (undo all changes of R-URI). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | revert_uri(); | ||
+ | |||
+ | ==== rewritehost() sethost() ==== | ||
+ | |||
+ | Rewrite the domain part of the R-URI with the value of function' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewritehost(" | ||
+ | |||
+ | ==== rewritehostport() sethostport() ==== | ||
+ | |||
+ | Rewrite the domain part and port of the R-URI with the value of function' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewritehostport(" | ||
+ | |||
+ | ==== rewriteuser(string) setuser(string) ==== | ||
+ | |||
+ | Rewrite the user part of the R-URI with the value of function' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewriteuser(" | ||
+ | |||
+ | ==== rewriteuserpass() setuserpass() ==== | ||
+ | |||
+ | Rewrite the password part of the R-URI with the value of function' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewriteuserpass(" | ||
+ | |||
+ | ==== rewriteport() setport() ==== | ||
+ | |||
+ | Rewrites/ | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewriteport(" | ||
+ | |||
+ | ==== rewriteuri(str) seturi(str) ==== | ||
+ | |||
+ | Rewrite the request URI. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | rewriteuri(" | ||
+ | |||
+ | |||
+ | ==== send(destination) ==== | ||
+ | |||
+ | Send the original SIP message to a specific destination in stateless mode. This is definied as [proto: | ||
+ | |||
+ | Parameter is mandatory and has string format. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | | ||
+ | |||
+ | ==== serialize_branches() ==== | ||
+ | |||
+ | It inherits the functionality of load_contacts() from LCR; gets all parallel branches and convert them into AVPs for serial forking; numerical parameter ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | ==== set_advertised_address(ip|string) ==== | ||
+ | |||
+ | Same as ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | set_advertised_address(" | ||
+ | |||
+ | ==== set_advertised_port(int) ==== | ||
+ | |||
+ | Same as ' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | set_advertised_port(5080); | ||
+ | |||
+ | |||
+ | ==== setdebug([level]) ==== | ||
+ | |||
+ | Changes the debug level of the current process from script. If called without the parameter then the debug level of the current process will be reset to the global level. If the debug level of the current process is changed then changing the global debug level (using MI function) does not affect it, so be careful and make sure to reset the process debug level when you are done. This function is very helpful if you are tracing and debugging only a specific piece of code. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | debug= -1 # errors only | ||
+ | ..... | ||
+ | { | ||
+ | ...... | ||
+ | setdebug(4); | ||
+ | uac_replace_from(....); | ||
+ | setdebug(); # reset the debug level of the current process to the global level | ||
+ | ....... | ||
+ | } | ||
+ | |||
+ | ==== setdsturi(string) ==== | ||
+ | |||
+ | Explicitely set the dst_uri field to the value of the paramater. The parameter has to be a valid SIP URI. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | setdsturi(" | ||
+ | |||
+ | ==== setflag(int) ==== | ||
+ | |||
+ | Set a flag for current processed message. The value of the parameter can be in range of 0..31. The flags are used to mark the message for special processing (e.g., accounting) or to keep some state (e.g., message authenticated). | ||
+ | |||
+ | For more see http:// | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | setflag(3); | ||
+ | |||
+ | |||
+ | ==== setbflag([branch_idx, | ||
+ | |||
+ | Set a flag for a specific branch (set flag to value 1). The value of the " | ||
+ | |||
+ | For more about script flags, see [[utils: | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | setbflag(1, | ||
+ | # or | ||
+ | setbflag(3); | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== setsflag(flag_idx) ==== | ||
+ | |||
+ | Set a script flag (set flag to value 0). The value of the " | ||
+ | |||
+ | For more about script flags, see [[utils: | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | setsflag(2); | ||
+ | |||
+ | ==== strip(int) ==== | ||
+ | |||
+ | Strip the first N-th characters from username of R-URI (N is the value of the parameter). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | strip(3); | ||
+ | |||
+ | ==== strip_tail(int) ==== | ||
+ | |||
+ | Strip the last N-th characters from username of R-URI (N is the value of the parameter). | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | strip_tail(3); | ||
+ | |||
+ | |||
+ | |||
+ | ===== Core MI Functions == | ||
+ | |||
+ | ==== debug [level] ===== | ||
+ | |||
+ | Gets or sets value of debug core variable. | ||
+ | |||
+ | Examples of usage: | ||
+ | |||
+ | openserctl fifo debug | ||
+ | openserctl fifo debug 1 | ||
+ | |||
+ | |||
+ | ===== Routing Blocks ===== | ||
+ | |||
+ | ==== route ==== | ||
+ | |||
+ | Request routing block. It contains a set of actions to be taken for SIP requests. | ||
+ | |||
+ | The main ' | ||
+ | |||
+ | 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. | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | route { | ||
+ | | ||
+ | # send reply for each options request | ||
+ | sl_send_reply(" | ||
+ | exit(); | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | route[1] { | ||
+ | # forward according to uri | ||
+ | | ||
+ | } | ||
+ | |||
+ | Note that if a ' | ||
+ | |||
+ | ==== branch_route ==== | ||
+ | |||
+ | Request' | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | route { | ||
+ | lookup(" | ||
+ | t_on_branch(" | ||
+ | if(!t_relay()) { | ||
+ | sl_send_reply(" | ||
+ | } | ||
+ | } | ||
+ | branch_route[1] { | ||
+ | if(uri=~" | ||
+ | # discard branches that go to 10.10.10.10 | ||
+ | drop(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | ==== failure_route ==== | ||
+ | |||
+ | Failed transaction routing block. It contains a set of actions to be taken each transaction that received only negative replies (>=300) for all branches. The ' | ||
+ | |||
+ | Note that in ' | ||
+ | |||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | route { | ||
+ | lookup(" | ||
+ | t_on_failure(" | ||
+ | if(!t_relay()) { | ||
+ | sl_send_reply(" | ||
+ | } | ||
+ | } | ||
+ | failure_route[1] { | ||
+ | if(is_method(" | ||
+ | # call failed - relay to voice mail | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | ==== onreply_route ==== | ||
+ | |||
+ | |||
+ | Reply routing block. It contains a set of actions to be taken for SIP replies. | ||
+ | |||
+ | The main ' | ||
+ | |||
+ | Certain ' | ||
+ | |||
+ | route { | ||
+ | lookup(" | ||
+ | t_on_reply(" | ||
+ | if(!t_relay()) { | ||
+ | sl_send_reply(" | ||
+ | } | ||
+ | } | ||
+ | onreply_route[1] { | ||
+ | if(status=~" | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | ==== error_route ==== | ||
+ | |||
+ | 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. | ||
+ | |||
+ | In error_route, | ||
+ | * $(err.class) - the class of error (now is ' | ||
+ | * $(err.level) - severity level for the error | ||
+ | * $(err.info) - text describing the error | ||
+ | * $(err.rcode) - recommended reply code | ||
+ | * $(err.rreason) - recommended reply reason phrase | ||
+ | |||
+ | < | ||
+ | error_route { | ||
+ | | ||
+ | info=$(err.info) rcode=$(err.rcode) rreason=$(err.rreason) ---\n" | ||
+ | | ||
+ | | ||
+ | exit; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Routing Constructs ===== | ||
+ | |||
+ | Different constructs that help to select specific actions to be executed. | ||
+ | |||
+ | |||
+ | |||
+ | ==== if ==== | ||
+ | |||
+ | IF-ELSE statement | ||
+ | |||
+ | Prototype: | ||
+ | |||
+ | < | ||
+ | if(expr) { | ||
+ | | ||
+ | } else { | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The ' | ||
+ | |||
+ | The logical operators that can be used in ' | ||
+ | |||
+ | * == - equal | ||
+ | * != - not equal | ||
+ | * =~ - regular expression matching | ||
+ | * !~ - regular expression not-matching | ||
+ | * > - greater | ||
+ | * >= - greater or equal | ||
+ | * < - less | ||
+ | * <= - less or equal | ||
+ | * && - logical AND | ||
+ | * || - logical OR | ||
+ | * ! - logical NOT | ||
+ | * [ ... ] - test operator - inside can be any arithmetic expression | ||
+ | |||
+ | Example of usage: | ||
+ | |||
+ | if(is_method(" | ||
+ | { | ||
+ | log(" | ||
+ | } else { | ||
+ | log(" | ||
+ | } | ||
+ | |||
+ | |||
+ | ==== switch ==== | ||
+ | |||
+ | SWITCH statement - it can be used to test the value of a pseudo-variable. | ||
+ | |||
+ | IMPORTANT NOTE: ' | ||
+ | |||
+ | |||
+ | Example of usage: | ||
+ | < | ||
+ | route { | ||
+ | route(1); | ||
+ | switch($retcode) | ||
+ | { | ||
+ | case -1: | ||
+ | log(" | ||
+ | break; | ||
+ | case 1: | ||
+ | log(" | ||
+ | break; | ||
+ | case 2: | ||
+ | case 3: | ||
+ | log(" | ||
+ | break; | ||
+ | default: | ||
+ | log(" | ||
+ | } | ||
+ | |||
+ | # switch of R-URI username | ||
+ | switch($rU) | ||
+ | { | ||
+ | case " | ||
+ | log(" | ||
+ | break; | ||
+ | case " | ||
+ | log(" | ||
+ | break; | ||
+ | case " | ||
+ | case " | ||
+ | log(" | ||
+ | break; | ||
+ | default: | ||
+ | log(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | route[1]{ | ||
+ | if(is_method(" | ||
+ | { | ||
+ | return(-1); | ||
+ | }; | ||
+ | if(is_method(" | ||
+ | return(1); | ||
+ | } | ||
+ | if(is_method(" | ||
+ | return(2); | ||
+ | } | ||
+ | if(is_method(" | ||
+ | return(3); | ||
+ | } | ||
+ | return(-2); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | NOTE: take care while using ' | ||
+ | |||
+ | |||
+ | ==== while ==== | ||
+ | |||
+ | while statement | ||
+ | |||
+ | Example of usage: | ||
+ | | ||
+ | $var(i) = 0; | ||
+ | while($var(i) < 10) | ||
+ | { | ||
+ | xlog(" | ||
+ | $var(i) = $var(i) + 1; | ||
+ | } | ||
+ | |||
+ | ===== Script Operations ===== | ||
+ | |||
+ | Starting with 1.2.0, assignments together with string and arithmetic operations can be done directly in configuration file. | ||
+ | |||
+ | |||
+ | ==== Assignment ==== | ||
+ | |||
+ | Assignments can be done like in C, via ' | ||
+ | * AVPs - to set the value of an AVP | ||
+ | * script variables ($var(...)) - to set the value of a script variable | ||
+ | * $ru - to set R-URI | ||
+ | * $rd - to set domain part of R-URI | ||
+ | * $rU - to set user part of R-URI | ||
+ | * $du - to set dst URI | ||
+ | * $fs - to set send socket | ||
+ | * $br - to set branch | ||
+ | |||
+ | < | ||
+ | $var(a) = 123; | ||
+ | </ | ||
+ | |||
+ | There is a special assign operator ': | ||
+ | |||
+ | < | ||
+ | $avp(i:3) := 123; | ||
+ | </ | ||
+ | |||
+ | ==== String operations ==== | ||
+ | |||
+ | For strings, ' | ||
+ | |||
+ | < | ||
+ | $var(a) = " | ||
+ | $var(b) = " | ||
+ | </ | ||
+ | |||
+ | ==== Arithmetic operations ==== | ||
+ | |||
+ | For numbers, one can use: | ||
+ | |||
+ | * + : plus | ||
+ | * - : minus | ||
+ | * / : divide | ||
+ | * * : multiply | ||
+ | * % : modulo | ||
+ | * | : bitwise OR | ||
+ | * * : bitwise AND | ||
+ | * ^ : bitwise XOR | ||
+ | * ~ : bitwise NOT | ||
+ | |||
+ | Example: | ||
+ | |||
+ | < | ||
+ | $var(a) = 4 + ( 7 & ( ~2 ) ); | ||
+ | </ | ||
+ | |||
+ | NOTE: to ensure the priority of operands in expression evaluations do use __parenthesis__. | ||
+ | |||
+ | Arithmetic expressions can be used in condition expressions via test operator ' [ ... ] '. | ||
+ | |||
+ | < | ||
+ | if( [ $var(a) & 4 ] ) | ||
+ | log(" | ||
+ | </ | ||
+ | |||
+ | ===== Core Cookbook Stuff ===== | ||
+ | |||
+ | {{indexmenu> | ||
+ | |||
+ | [[http:// | ||