This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
cookbooks:5.2.x:core [2019/02/22 18:58] henningw [reply_to_via] |
cookbooks:5.2.x:core [2019/10/30 00:22] joelsdc |
||
---|---|---|---|
Line 736: | Line 736: | ||
==== auto_bind_ipv6 ==== | ==== auto_bind_ipv6 ==== | ||
- | When turned on, Kamailio will automatically bind to all IPv6 addresses (much like the default behaviour for IPv4). | + | When turned on, Kamailio will automatically bind to all IPv6 addresses (much like the default behaviour for IPv4). Default value is off. |
Example: | Example: | ||
Line 866: | Line 866: | ||
==== flags ==== | ==== flags ==== | ||
- | **Alias name: bool** | + | SIP message (transaction) flags can have string names. |
+ | The //name// for flags cannot be used for **branch** or **script flags**(*) | ||
+ | |||
+ | |||
+ | <code c> | ||
+ | ... | ||
+ | flags | ||
+ | FLAG_ONE | ||
+ | FLAG_TWO | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | (*) The named flags feature was propagated from the source code merge back in 2008 and is not extensively tested. The recommended way of defining flags is using [[cookbooks: | ||
+ | <code c> | ||
+ | #!define FLAG_NAME FLAG_BIT | ||
+ | </ | ||
==== force_rport ==== | ==== force_rport ==== | ||
Line 982: | Line 998: | ||
==== latency_limit_db ==== | ==== latency_limit_db ==== | ||
- | Limit of latency in ms for db operations. If a db operation executed via DB API v1 takes longer that its value, a message is printed in the logs, showing the first 50 characters of the db query. | + | Limit of latency in us (micro-seconds) |
Line 1397: | Line 1413: | ||
==== pv_buffer_size ==== | ==== pv_buffer_size ==== | ||
- | The size in bytes of internal buffer to print dynamic strings with pseudo-variables inside. The default value is 8192 (8kB). | + | The size in bytes of internal buffer to print dynamic strings with pseudo-variables inside. The default value is 8192 (8kB). Please keep in mind that for xlog messages, there is a dedicated module parameter to set the internal buffer size. |
Example of usage: | Example of usage: | ||
Line 3098: | Line 3114: | ||
} | } | ||
</ | </ | ||
+ | |||
==== onsend_route ==== | ==== onsend_route ==== | ||
Line 3122: | Line 3139: | ||
* msg:len - when used in an onsend_route, | * msg:len - when used in an onsend_route, | ||
- | ==== event_route ==== | ||
- | |||
- | Generic type of route executed when specific events happen. | ||
- | |||
- | Prototype: event_route[groupid: | ||
- | * groupid - should be the name of the module that triggers the event | ||
- | * eventid - some meaningful short text describing the event | ||
- | |||
- | Implementations: | ||
- | |||
- | * **event_route[core: | ||
- | * note that due to forking, other sip workers can get faster to listening for sip traffic | ||
- | |||
- | <code c> | ||
- | event_route[core: | ||
- | xlog(" | ||
- | } | ||
- | </ | ||
- | |||
- | * **event_route[htable: | ||
- | <code c> | ||
- | modparam(" | ||
- | |||
- | event_route[htable: | ||
- | $sht(a=> | ||
- | $sht(a=> | ||
- | } | ||
- | |||
- | request_route { | ||
- | if(is_method(" | ||
- | { | ||
- | switch($rd) { | ||
- | case " | ||
- | lock(" | ||
- | $sht(a=> | ||
- | $sht(a=> | ||
- | unlock(" | ||
- | if($sht(a=> | ||
- | { | ||
- | | ||
- | exit; | ||
- | } | ||
- | break; | ||
- | ... | ||
- | } | ||
- | } | ||
- | } | ||
- | </ | ||
- | * **event_route [tm: | ||
- | <code c> | ||
- | event_route [tm: | ||
- | xlog(" | ||
- | t_set_fr(10000, | ||
- | } | ||
- | </ | ||
- | |||
- | * **event_route [tm: | ||
- | <code c> | ||
- | event_route [tm: | ||
- | xlog(" | ||
- | if (t_check_status(" | ||
- | unregister(" | ||
- | if (t_next_contact_flow()) { | ||
- | t_relay(); | ||
- | } | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | ===== Script Statements ===== | ||
- | |||
- | ==== if ==== | ||
- | IF-ELSE statement | ||
- | |||
- | Prototype: | ||
- | |||
- | < | ||
- | if(expr) { | ||
- | | ||
- | } else { | ||
- | | ||
- | } | ||
- | </ | ||
- | |||
- | The ' | ||
- | |||
- | The logical operators that can be used in ' | ||
- | |||
- | < | ||
- | == equal | ||
- | != not equal | ||
- | =~ regular expression matching: Note: Posix regular expressions will be used, e.g. use [[: | ||
- | !~ regular expression not-matching (NOT PORTED from Kamailio 1.x, use '!(x =~ y)') | ||
- | > | ||
- | >= greater or equal | ||
- | < less | ||
- | <= less or equal | ||
- | && | ||
- | || logical OR | ||
- | ! | ||
- | [ ... ] 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 ===== | ||
- | |||
- | Assignments together with string and arithmetic operations can be done directly in configuration file. | ||
- | ==== Assignment ==== | ||
- | |||
- | Assignments can be done like in C, via ' | ||
- | * Unordered List Item AVPs - to set the value of an AVP | ||
- | * script variables ($var(...)) - to set the value of a script variable | ||
- | * shared variables ($shv(...)) | ||
- | * $ru - to set R-URI | ||
- | * $rd - to set domain part of R-URI | ||
- | * $rU - to set user part of R-URI | ||
- | * $rp - to set the port of R-URI | ||
- | * $du - to set dst URI | ||
- | * $fs - to set send socket | ||
- | * $br - to set branch | ||
- | * $mf - to set message flags value | ||
- | * $sf - to set script flags value | ||
- | * $bf - to set branch flags value | ||
- | |||
- | < | ||
- | $var(a) = 123; | ||
- | </ | ||
- | |||
- | For avp's there a way to remove all values and assign a single value in one statement (in other words, delete existing AVPs with same name, add a new one with the right side value). This replaces the := assignment operator from kamailio < 3.0. | ||
- | < | ||
- | $(avp(i: | ||
- | $(avp(i: | ||
- | </ | ||
- | |||
- | ==== String Operations ==== | ||
- | For strings, ' | ||
- | |||
- | < | ||
- | $var(a) = " | ||
- | $var(b) = " | ||
- | </ | ||
- | ==== Arithmetic Operations ==== | ||
- | |||
- | For numbers, one can use: | ||
- | * + : plus | ||
- | * - : minus | ||
- | * / : divide | ||
- | * * : multiply | ||
- | * % : modulo (Kamailio uses ' | ||
- | * | : 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. | ||
- | |||
- | < | ||
- | if( $var(a) & 4 ) | ||
- | log(" | ||
- | </ | ||
- | |||
- | ===== Operators ===== | ||
- | |||
- | - type casts operators: (int), (str). | ||
- | - string comparison: eq, ne | ||
- | - integer comparison: ieq, ine | ||
- | |||
- | Note: The names are not yet final (use them at your own risk). Future version might use ==/!= only for ints (ieq/ine) and eq/ne for strings (under debate). They are almost equivalent to == or !=, but they force the conversion of their operands (eq to string and ieq to int), allowing among other things better type checking on startup and more optimizations. | ||
- | |||
- | Non equiv. examples: | ||
- | |||
- | 0 == "" | ||
- | |||
- | " | ||
- | |||
- | Note: internally == and != are converted on startup to eq/ | ||
- | |||
- | - Kamailio tries to guess what the user wanted when operators that support multiple types are used on different typed operands. In general convert the right operand to the type of the left operand and then perform the operation. Exception: the left operand is undef. This applies to the following operators: +, == and !=. | ||
- | | ||
- | For +: undef + expr -> undef is converted to string => "" | ||
- | For == and !=: undef == expr -> undef is converted to type_of expr. | ||
- | If expr is undef, then undef == undef is true (internally is converted | ||
- | to string). | ||
- | |||
- | - expression evaluation changes: Kamailio will auto-convert to integer or string in function of the operators: | ||
- | | ||
- | | ||
- | |||
- | - script operators for dealing with empty/ | ||
- | defined expr - returns true if expr is defined, and false if not. | ||
- | Note: only a standalone avp or pvar can be | ||
- | | ||
- | strlen(expr) - returns the lenght of expr evaluated as string. | ||
- | strempty(expr) - returns true if expr evaluates to the empty | ||
- | | ||
- | Example: if (defined $v && !strempty($v)) $len=strlen($v); |