Documentation |
Documentation.Script-Tran-2-4 HistoryHide minor edits - Show changes to output September 27, 2019, at 09:13 AM
by
- Changed lines 15-17 from:
Intuitively, a '''Transformation''' is 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. Example of using different kind of variables in '''OpenSIPS script''': to:
Intuitively, a '''Transformation''' is a function that is applied to a variable(script variable, pseudo-variable, AVP, static string) to get a special value from it. The input value is not altered. Examples of using different kinds of variables in '''OpenSIPS script''': June 14, 2019, at 06:54 PM
by
- Changed lines 86-87 from:
!!!!{s.len} to:
[[#s.len]] !!!!{s.len} [[#s.len|🔗]] Changed lines 99-100 from:
!!!!{s.int} to:
[[#s.int]] !!!!{s.int} [[#s.int|🔗]] Changed lines 111-112 from:
!!!!{s.md5} to:
[[#s.md5]] !!!!{s.md5} [[#s.md5|🔗]] Changed lines 120-121 from:
!!!!{s.substr,offset,length} to:
[[#s.substr]] !!!!{s.substr,offset,length} [[#s.substr|🔗]] Changed lines 131-132 from:
!!!!{s.select,index,separator} to:
[[#s.select]] !!!!{s.select,index,separator} [[#s.select|🔗]] Changed lines 145-146 from:
!!!!{s.encode.hexa} to:
[[#s.encode.hexa]] !!!!{s.encode.hexa} [[#s.encode.hexa|🔗]] Changed lines 150-151 from:
!!!!{s.decode.hexa} to:
[[#s.decode.hexa]] !!!!{s.decode.hexa} [[#s.decode.hexa|🔗]] Changed lines 156-157 from:
!!!!{s.escape.common} to:
[[#s.escape.common]] !!!!{s.escape.common} [[#s.escape.common|🔗]] Changed lines 162-163 from:
!!!!{s.unescape.common} to:
[[#s.unescape.common]] !!!!{s.unescape.common} [[#s.unescape.common|🔗]] Changed lines 168-169 from:
!!!!{s.escape.user} to:
[[#s.escape.user]] !!!!{s.escape.user} [[#s.escape.user|🔗]] Changed lines 173-174 from:
!!!!{s.unescape.user} to:
[[#s.unescape.user]] !!!!{s.unescape.user} [[#s.unescape.user|🔗]] Changed lines 179-180 from:
!!!!{s.escape.param} to:
[[#s.escape.param]] !!!!{s.escape.param} [[#s.escape.param|🔗]] Changed lines 185-186 from:
!!!!{s.unescape.param} to:
[[#s.unescape.param]] !!!!{s.unescape.param} [[#s.unescape.param|🔗]] Changed lines 190-191 from:
!!!!{s.tolower} to:
[[#s.tolower]] !!!!{s.tolower} [[#s.tolower|🔗]] Changed lines 196-197 from:
!!!!{s.toupper} to:
[[#s.toupper]] !!!!{s.toupper} [[#s.toupper|🔗]] Changed lines 201-202 from:
!!!!{s.index} to:
[[#s.index]] !!!!{s.index} [[#s.index|🔗]] Changed lines 229-230 from:
!!!!{s.rindex} to:
[[#s.rindex]] !!!!{s.rindex} [[#s.rindex|🔗]] Changed lines 244-245 from:
!!!!{s.fill.left, tok, len} to:
[[#s.fill.left]] !!!!{s.fill.left, tok, len} [[#s.fill.left|🔗]] Changed lines 262-263 from:
!!!!{s.fill.right, tok, len} to:
[[#s.fill.right]] !!!!{s.fill.right, tok, len} [[#s.fill.right|🔗]] Changed lines 276-277 from:
!!!!{s.width, len} to:
[[#s.width]] !!!!{s.width, len} [[#s.width|🔗]] Changed lines 291-292 from:
!!!!{s.trim} to:
[[#s.trim]] !!!!{s.trim} [[#s.trim|🔗]] Changed lines 302-303 from:
!!!!{s.trimr} to:
[[#s.trimr]] !!!!{s.trimr} [[#s.trimr|🔗]] Changed lines 313-314 from:
!!!!{s.triml} to:
[[#s.triml]] !!!!{s.triml} [[#s.triml|🔗]] Changed lines 324-325 from:
!!!!{s.dec2hex} to:
[[#s.dec2hex]] !!!!{s.dec2hex} [[#s.dec2hex|🔗]] Changed lines 329-330 from:
!!!!{s.hex2dec} to:
[[#s.hex2dec]] !!!!{s.hex2dec} [[#s.hex2dec|🔗]] Changed lines 334-335 from:
!!!!{s.b64encode} to:
[[#s.b64encode]] !!!!{s.b64encode} [[#s.b64encode|🔗]] Changed lines 344-345 from:
!!!!{s.b64decode} to:
[[#s.b64decode]] !!!!{s.b64decode} [[#s.b64decode|🔗]] Changed lines 354-355 from:
!!!!{s.xor,secret} to:
[[#s.xor]] !!!!{s.xor,secret} [[#s.xor|🔗]] Changed lines 371-372 from:
!!!!{uri.user} to:
[[#uri.user]] !!!!{uri.user} [[#uri.user|🔗]] Changed lines 376-377 from:
!!!!{uri.host} to:
[[#uri.host]] !!!!{uri.host} [[#uri.host|🔗]] Changed lines 383-384 from:
!!!!{uri.passwd} to:
[[#uri.passwd]] !!!!{uri.passwd} [[#uri.passwd|🔗]] Changed lines 388-389 from:
!!!!{uri.port} to:
[[#uri.port]] !!!!{uri.port} [[#uri.port|🔗]] Changed lines 393-394 from:
!!!!{uri.params} to:
[[#uri.params]] !!!!{uri.params} [[#uri.params|🔗]] Changed lines 398-399 from:
!!!!{uri.param,name} to:
[[#uri.param]] !!!!{uri.param,name} [[#uri.param|🔗]] Changed lines 403-404 from:
!!!!{uri.headers} to:
[[#uri.headers]] !!!!{uri.headers} [[#uri.headers|🔗]] Changed lines 408-409 from:
!!!!{uri.transport} to:
[[#uri.transport]] !!!!{uri.transport} [[#uri.transport|🔗]] Changed lines 413-414 from:
!!!!{uri.ttl} to:
[[#uri.ttl]] !!!!{uri.ttl} [[#uri.ttl|🔗]] Changed lines 418-419 from:
!!!!{uri.uparam} to:
[[#uri.uparam]] !!!!{uri.uparam} [[#uri.uparam|🔗]] Changed lines 423-424 from:
!!!!{uri.maddr} to:
[[#uri.maddr]] !!!!{uri.maddr} [[#uri.maddr|🔗]] Changed lines 428-429 from:
!!!!{uri.method} to:
[[#uri.method]] !!!!{uri.method} [[#uri.method|🔗]] Changed lines 433-434 from:
!!!!{uri.lr} to:
[[#uri.lr]] !!!!{uri.lr} [[#uri.lr|🔗]] Changed lines 438-439 from:
!!!!{uri.r2} to:
[[#uri.r2]] !!!!{uri.r2} [[#uri.r2|🔗]] Changed lines 443-444 from:
!!!!{uri.schema} to:
[[#uri.schema]] !!!!{uri.schema} [[#uri.schema|🔗]] Changed lines 460-461 from:
!!!!{via.name} to:
[[#via.name]] !!!!{via.name} [[#via.name|🔗]] Changed lines 465-466 from:
!!!!{via.version} to:
[[#via.version]] !!!!{via.version} [[#via.version|🔗]] Changed lines 470-471 from:
!!!!{via.transport} to:
[[#via.transport]] !!!!{via.transport} [[#via.transport|🔗]] Changed lines 475-476 from:
!!!!{via.host} to:
[[#via.host]] !!!!{via.host} [[#via.host|🔗]] Changed lines 482-483 from:
!!!!{via.port} to:
[[#via.port]] !!!!{via.port} [[#via.port|🔗]] Changed lines 487-488 from:
!!!!{via.comment} to:
[[#via.comment]] !!!!{via.comment} [[#via.comment|🔗]] Changed lines 492-493 from:
!!!!{via.params} to:
[[#via.params]] !!!!{via.params} [[#via.params|🔗]] Changed lines 497-498 from:
!!!!{via.param,name} to:
[[#via.param]] !!!!{via.param,name} [[#via.param|🔗]] Changed lines 502-503 from:
!!!!{via.branch} to:
[[#via.branch]] !!!!{via.branch} [[#via.branch|🔗]] Changed lines 507-508 from:
!!!!{via.received} to:
[[#via.received]] !!!!{via.received} [[#via.received|🔗]] Changed lines 512-513 from:
!!!!{via.rport} to:
[[#via.rport]] !!!!{via.rport} [[#via.rport|🔗]] Changed lines 524-525 from:
!!!!{param.value,name} to:
[[#param.value]] !!!!{param.value,name} [[#param.value|🔗]] Changed lines 536-537 from:
!!!!{param.exist,name} to:
[[#param.exist]] !!!!{param.exist,name} [[#param.exist|🔗]] Changed lines 548-549 from:
!!!!{param.valueat,index} to:
[[#param.valueat]] !!!!{param.valueat,index} [[#param.valueat|🔗]] Changed lines 560-561 from:
!!!!{param.name,index} to:
[[#param.name]] !!!!{param.name,index} [[#param.name|🔗]] Changed lines 572-573 from:
!!!!{param.count} to:
[[#param.count]] !!!!{param.count} [[#param.count|🔗]] Changed lines 591-592 from:
!!!!{nameaddr.name} to:
[[#nameaddr.name]] !!!!{nameaddr.name} [[#nameaddr.name|🔗]] Changed lines 601-602 from:
!!!!{nameaddr.uri} to:
[[#nameaddr.uri]] !!!!{nameaddr.uri} [[#nameaddr.uri|🔗]] Changed lines 611-612 from:
!!!!{nameaddr.len} to:
[[#nameaddr.len]] !!!!{nameaddr.len} [[#nameaddr.len|🔗]] Changed lines 617-618 from:
!!!!{nameaddr.param,param_name} to:
[[#nameaddr.param]] !!!!{nameaddr.param,param_name} [[#nameaddr.param|🔗]] Changed lines 626-627 from:
!!!!{nameaddr.params} to:
[[#nameaddr.params]] !!!!{nameaddr.params} [[#nameaddr.params|🔗]] Changed lines 639-640 from:
!!!!{ip.pton} to:
[[#ip.pton]] !!!!{ip.pton} [[#ip.pton|🔗]] Changed lines 648-649 from:
!!!!{ip.ntop} to:
[[#ip.ntop]] !!!!{ip.ntop} [[#ip.ntop|🔗]] Changed lines 657-658 from:
!!!!{ip.isip} to:
[[#ip.isip]] !!!!{ip.isip} [[#ip.isip|🔗]] Changed lines 667-668 from:
!!!!{ip.family} to:
[[#ip.family]] !!!!{ip.family} [[#ip.family|🔗]] Changed lines 675-676 from:
!!!!{ip.resolve} to:
[[#ip.resolve]] !!!!{ip.resolve} [[#ip.resolve|🔗]] Changed lines 689-690 from:
!!!!{csv.count} to:
[[#csv.count]] !!!!{csv.count} [[#csv.count|🔗]] Changed lines 697-698 from:
!!!!{csv.value} to:
[[#csv.value]] !!!!{csv.value} [[#csv.value|🔗]] Changed lines 711-712 from:
!!!!{sdp.line} to:
[[#sdp.line]] !!!!{sdp.line} [[#sdp.line|🔗]] Changed lines 733-734 from:
!!!!{re.subst,reg_exp} to:
[[#re.subst]] !!!!{re.subst,reg_exp} [[#re.subst|🔗]] Changed line 773 from:
@] to:
@] April 24, 2019, at 01:13 PM
by
- Changed line 21 from:
if($fU==$tU) { to:
if ($fU == $tU) { April 24, 2019, at 01:10 PM
by
- Changed lines 25-26 from:
# r-uri username based processing switch($ruri.user) { to:
# Request-URI username based processing switch ($rU) { Changed lines 37-45 from:
# assign integer value to an AVP $avp(i:11) = 1; #assing string value to an AVP $avp(i:22) = "opensips"; # write ruri in an AVP $avp(i:33) = $ruri; to:
# assign an integer value to an variable $var(gw_count) = 1; # assign a string value to an AVP $avp(server) = "opensips"; # store the Request-URI in a variable $var(ru_backup) = $ru; Changed lines 47-48 from:
$var(x) = "sip:" + $fU +"@" + $td; to:
$var(x) = "sip:" + $fU + "@" + $td; April 23, 2019, at 06:43 PM
by
- Changed line 594 from:
Returns 1 or 0, if the string provided is a valid IP or not. to:
Returns 1 if the string provided is a valid IPv4 or IPv6 address, otherwise 0. April 03, 2018, at 05:05 PM
by
- Changed line 15 from:
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. to:
Intuitively, a '''Transformation''' is 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. July 04, 2017, at 04:46 PM
by
- Changed line 64 from:
Many transformations can be applied in the same time to a variable. to:
Multiple transformations can be applied to a variable at the same time. July 03, 2017, at 05:23 PM
by
- Added lines 72-73:
All transformations, unless otherwise specified, will return NULL in case of error or unsuccessful operation (e.g looking for an nonexistent parameter in an URI with the "{uri.param,name}" transformation). Also, NULL is accepted as input for transformations in order to support chaining with a previous one that would return NULL. Changed lines 130-131 from:
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. to:
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. Note that if a field is empty, an empty string will be returned and not NULL. Changed line 189 from:
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. to:
Searches for one string within another starting at the beginning of the first string. Returns starting index of the string found or NULL if not found. Changed line 209 from:
if ($(var(strtosearch){s.index, $var(str)}) >=0) to:
if ($(var(strtosearch){s.index, $var(str)}) != NULL) Changed line 216 from:
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. to:
Searches for one string within another starting at the end of the first string. Returns starting index of the string found or NULL if not found. June 21, 2016, at 03:56 PM
by
- Changed line 314 from:
$(var(in){s.base64encode}) => "AgMEBSFAIyVeJio=" to:
$(var(in){s.b64encode}) => "AgMEBSFAIyVeJio=" Changed line 323 from:
$(var(in){s.base64encode}) => "\x2\x3\x4\x5!@#%^&*" to:
$(var(in){s.b64decode}) => "\x2\x3\x4\x5!@#%^&*" June 21, 2016, at 02:26 PM
by
- Changed lines 308-309 from:
!!!!{s.base64encode} to:
!!!!{s.b64encode} Changed line 317 from:
!!!!{s.base64decode} to:
!!!!{s.b64decode} March 29, 2016, at 01:54 PM
by
- Changed lines 102-103 from:
$var(x) = "1234"; if($(var(x){s.int})==1234) { to:
$var(dur) = "2868.12 sec"; if ($(var(dur){s.int}) < 3600) { March 29, 2016, at 01:52 PM
by
- Changed line 99 from:
Return integer value of a string-represented number to:
Converts the initial part of the given string to an integer value. Returns 0 if there were no digits at all. March 28, 2016, at 05:35 PM
by
- Added lines 324-332:
@] !!!!{s.xor,secret} Performs one or more logical XOR operations with (a part of) the "secret" string parameter and the input string, depending on the lengths of the two strings. [@ $var(in) = "aaaaaabbbbbb"; $(var(in){s.xor,x}) => "!/>^P!/>^P!^U2^Q!^U2^Q" March 28, 2016, at 05:28 PM
by - March 28, 2016, at 05:28 PM
by
- Deleted lines 184-191:
!!!!{s.dec2hex} Converts a decimal(base 10) number to hexadecimal (in base 16), represented as string. !!!!{s.hex2dec} Converts a hexadecimal number (base 16) represented as string to decimal (base 10). Added lines 298-323:
@] !!!!{s.dec2hex} Converts a decimal(base 10) number to hexadecimal (in base 16), represented as string. !!!!{s.hex2dec} Converts a hexadecimal number (base 16) represented as string to decimal (base 10). !!!!{s.base64encode} Represents binary input data in an ASCII string format. [@ $var(in) = "\x2\x3\x4\x5!@#%^&*"; $(var(in){s.base64encode}) => "AgMEBSFAIyVeJio=" @] !!!!{s.base64decode} Assumes input is a Base64 string and decodes as many characters as possible. [@ $var(in) = "AgMEBSFAIyVeJio="; $(var(in){s.base64encode}) => "\x2\x3\x4\x5!@#%^&*" July 28, 2015, at 01:01 PM
by
- Added lines 276-305:
@] !!!!{s.trim} Strips any leading or trailing whitespace from the input string. Trimmed characters are " " (space), \t (tab), \n (newline) and \r (carriage return). [@ $var(in) = "\t \n input string \r "; $(var(in){s.trim}) => "input string" @] !!!!{s.trimr} Strips any trailing whitespace from the input string. Trimmed characters are " " (space), \t (tab), \n (newline) and \r (carriage return). [@ $var(in) = "\t \n input string \r "; $(var(in){s.trimr}) => "\t \n input string" @] !!!!{s.triml} Strips any leading whitespace from the input string. Trimmed characters are " " (space), \t (tab), \n (newline) and \r (carriage return). [@ $var(in) = "\t \n input string \r "; $(var(in){s.triml}) => "input string \r " June 02, 2015, at 04:56 PM
by
- Changed line 273 from:
$(var(in){s.width, 0}) => "transformation" to:
$(var(in){s.width, 14}) => "transformation" June 02, 2015, at 04:56 PM
by
- Changed lines 234-235 from:
!!!!{s.fill.left} to:
!!!!{s.fill.left, tok, len} Changed lines 251-252 from:
!!!!{s.fill.right} to:
!!!!{s.fill.right, tok, len} Changed lines 264-265 from:
'''Note''': currently optimized for speed. Does not support pseudo-variable parameters or successive "s.fill" cascading. to:
!!!!{s.width, len} Truncates or expands the input to the given ''len''. Expanding is done to the right with the space character ' '. Truncating is done in a similar manner, from the right. Examples: Fills a string to the right with a char/string until the given final length is reached. The initial string is returned if its length is greater or equal to the given final length. If used on pseudo-variables containing integers, it will convert them to strings. [@ $var(in) = "transformation"; $(var(in){s.width, 0}) => "transformation" $(var(in){s.width, 16}) => "transformation " $(var(in){s.width, 9}) => "transform" @] March 13, 2015, at 07:08 PM
by
- Added lines 331-334:
!!!!{uri.schema} Returns the schema part of the given URI. January 26, 2015, at 12:27 PM
by
- Changed line 10 from:
||[[Script-Flags-2-4|Prev]] || [[Modules-2-4|Next]]|| to:
||[[Script-Flags-2-4|Prev]] || [[Script-Async-2-4|Next]]|| October 10, 2014, at 01:26 PM
by
- Changed line 2 from:
(:title Script Transformations - ver 1.12 :) to:
(:title Script Transformations - 2.4:) October 10, 2014, at 01:23 PM
by
- Changed lines 615-616 from:
* The length of the value of parameter at postion 1 (remember 0 is first position, 1 is second position) to:
* The length of the value of parameter at position 1 (remember 0 is first position, 1 is second position) Changed line 626 from:
xlog("This is an un-registrationn"); to:
xlog("This is an un-registration"); October 10, 2014, at 01:16 PM
by
- Changed line 4 from:
(:allVersions Script-Tran 2.4:) to:
(:allVersions Script-Tran 2.4:) September 30, 2014, at 04:17 PM
by
- Deleted lines 237-238:
'''Note''': currently optimized for speed. Does not support pseudo-variable parameters or successive "s.fill" cascading. Added lines 247-250:
'''Note''': currently optimized for speed. Does not support pseudo-variable parameters or successive "s.fill" cascading. Deleted lines 254-255:
'''Note''': currently optimized for speed. Does not support pseudo-variable parameters or successive "s.fill" cascading. Added lines 263-266:
'''Note''': currently optimized for speed. Does not support pseudo-variable parameters or successive "s.fill" cascading. September 30, 2014, at 04:16 PM
by
- Added lines 238-239:
'''Note''': currently optimized for speed. Does not support pseudo-variable parameters or successive "s.fill" cascading. Added lines 252-253:
'''Note''': currently optimized for speed. Does not support pseudo-variable parameters or successive "s.fill" cascading. September 30, 2014, at 04:08 PM
by
- Added lines 231-256:
@] !!!!{s.fill.left} Fills a string to the left with a char/string until the given final length is reached. The initial string is returned if its length is greater or equal to the given final length. [@ $var(in) = "485"; (also works for integer PVs) $(var(in){s.fill.left, 0, 3}) => 485 $(var(in){s.fill.left, 0, 6}) => 000485 $(var(in){s.fill.left, abc, 8}) => bcabc485 @] !!!!{s.fill.right} Fills a string to the right with a char/string until the given final length is reached. The initial string is returned if its length is greater or equal to the given final length. [@ $var(in) = 485; (also works for string PVs) $(var(in){s.fill.right, 0, 3}) => 485 $(var(in){s.fill.right, 0, 6}) => 485000 $(var(in){s.fill.right, abc, 8}) => 485abcab March 20, 2014, at 08:46 PM
by
- Added lines 1-593:
!!!!!Documentation -> [[Documentation.Manuals|Manuals]] -> [[Documentation.Manual-2-4|Manual 2.4]] -> Script Transformations (:title Script Transformations - ver 1.12 :) ---- (:allVersions Script-Tran 2.4:) \\ || %color=#185662%[+'''Script Transformations v2.4 '''+]%% || ||[[Script-Flags-2-4|Prev]] || [[Modules-2-4|Next]]|| ---- (:toc-float Table of Content:) 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. Example of using different kind of variables in '''OpenSIPS script''': [@ # check if username in From header is equal with username in To header if($fU==$tU) { ... } # r-uri username based processing switch($ruri.user) { case "1234": ... break; case "5678": ... break; default: ... } # assign integer value to an AVP $avp(i:11) = 1; #assing string value to an AVP $avp(i:22) = "opensips"; # write ruri in an AVP $avp(i:33) = $ruri; # concat "sip:" + From username + "@" + To domain in a script variable x $var(x) = "sip:" + $fU +"@" + $td; @] 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...). 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 '''')''''. Example: [@ # the length of From URI ($fu is pseudo-variable for From URI) $(fu{s.len}) @] Many transformations can be applied in the same time to a variable. [@ # the length of escaped 'Test' header body $(hdr(Test){s.escape.common}{s.len}) @] 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. %red%IMPORTANT%%: To learn what variables can be used with transformations see [[Documentation/Script-CoreVar|Scripting variables list]]. !!!String Transformations The name of these transformation starts with 's.'. They are intended to apply string operations to variables. Available transformations in this class: !!!!{s.len} Return strlen of variable value [@ $var(x) = "abc"; if($(var(x){s.len}) == 3) { ... } @] !!!!{s.int} Return integer value of a string-represented number [@ $var(x) = "1234"; if($(var(x){s.int})==1234) { ... } @] !!!!{s.md5} Return md5 over variable value [@ xlog("MD4 over From username: $(fU{s.md5})"); @] !!!!{s.substr,offset,length} 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. Example: [@ $var(x) = "abcd"; $(var(x){s.substr,1,0}) = "bcd" @] !!!!{s.select,index,separator} 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. Example: [@ $var(x) = "12,34,56"; $(var(x){s.select,1,,}) => "34" ; $var(x) = "12,34,56"; $(var(x){s.select,-2,,}) => "34" @] !!!!{s.encode.hexa} Return encoding in hexa of variable's value !!!!{s.decode.hexa} Return decoding from hexa of variable's value !!!!{s.escape.common} 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). !!!!{s.unescape.common} Return unescaped string of variable's value. Reverse of above transformation. !!!!{s.escape.user} 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. !!!!{s.unescape.user} Return unescaped string of variable's value, changing '%hexa' to character code. Reverse of above transformation. !!!!{s.escape.param} 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. !!!!{s.unescape.param} Return unescaped string of variable's value, changing '%hexa' to character code. Reverse of above transformation. !!!!{s.tolower} Return string with lower case ASCII letters. !!!!{s.toupper} Return string with upper case ASCII letters. !!!!{s.dec2hex} Converts a decimal(base 10) number to hexadecimal (in base 16), represented as string. !!!!{s.hex2dec} Converts a hexadecimal number (base 16) represented as string to decimal (base 10). !!!!{s.index} 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. [@ $var(strtosearch) = 'onetwothreeone'; $var(str) = 'one'; # Search the string starting at 0 index $(var(strtosearch){s.index, $var(str)}) # will return 0 $(var(strtosearch){s.index, $var(str), 0}) # Same as above $(var(strtosearch){s.index, $var(str), 3}) # returns 11 # Negative offset $(var(strtosearch){s.index, $var(str), -11}) # Same as above # Negative wrapping offset $(var(strtosearch){s.index, $var(str), -25}) # Same as above #Test for existence of string in another if ($(var(strtosearch){s.index, $var(str)}) >=0) xlog("found $var(sstr) in $var(strtosearch)"); @] !!!!{s.rindex} 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. [@ $(var(strtosearch){s.rindex, $var(str)}) # will return 11 $(var(strtosearch){s.rindex, $var(str), -3}) # will return 11 $(var(strtosearch){s.rindex, $var(str), 11}) # will return 11 $(var(strtosearch){s.rindex, $var(str), -4}) # will return 0 @] !!!URI Transformations 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. Available transformations in this class: !!!!{uri.user} Returns the user part of the URI schema. !!!!{uri.host} (same as '''{uri.domain}''') Returns the domain part of the URI schema. !!!!{uri.passwd} Returns the password part of the URI schema. !!!!{uri.port} Returns the port of the URI schema. !!!!{uri.params} Returns all the URI parameters into a single string. !!!!{uri.param,name} Returns the value of URI parameter with name "name" !!!!{uri.headers} Returns URI headers. !!!!{uri.transport} Returns the value of transport URI parameter. !!!!{uri.ttl} Returns the value of ttl URI parameter. !!!!{uri.uparam} Returns the value of user URI parameter !!!!{uri.maddr} Returns the value of maddr URI parameter. !!!!{uri.method} Returns the value of method URI parameter. !!!!{uri.lr} Returns the value of lr URI parameter. !!!!{uri.r2} Returns the value of r2 URI parameter. !!!VIA Transformations 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). Examples: $var(upstreamtransport) = $(hdr(Via)[1]{via.transport}{s.tolower}); $var(upstreamip) = $(hdr(Via)[1]{via.param,received}); $var(clientport) = $(hdr(Via)[-1]{via.param,rport}); Available transformations in this class: !!!!{via.name} Returns the @@protocol-name@@ (of RFC3261 BNF), generally @@SIP@@. !!!!{via.version} Returns the @@protocol-version@@ (of RFC3261 BNF), generally @@2.0@@. !!!!{via.transport} Returns the @@transport@@ (of RFC3261 BNF), e.g., @@UDP@@, @@TCP@@, @@TLS@@. This is the transport protocol used to send the request message. !!!!{via.host} (same as @@{via.domain}@@) 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. !!!!{via.port} 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. !!!!{via.comment} 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. !!!!{via.params} 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. !!!!{via.param,name} Returns the value of Via header parameter with name @@name@@. Typical parameters include @@branch@@, @@rport@@ and @@received@@. !!!!{via.branch} Returns the value of the branch parameter in the VIA header. !!!!{via.received} Returns the value of the received parameter in the VIA header, if any. !!!!{via.rport} Returns the value of the rport parameter in the VIA header, if any. !!!Parameters List Transformations 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. Available transformations in this class: !!!!{param.value,name} Returns the value of parameter 'name' Example: [@ "a=1;b=2;c=3"{param.value,c} = "3" @] 'name' can be a variable !!!!{param.exist,name} 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. Example: [@ "a=0;b=2;ob;c=3"{param.exist,ob}; # returns 1 "a=0;b=2;ob;c=3"{param.exist,a}; # returns 1 "a=0;b=2;ob;c=3"{param.exist,foo}; # returns 0 @] !!!!{param.valueat,index} Returns the value of parameter at position give by 'index' (0-based index) Example: [@ "a=1;b=2;c=3"{param.valueat,1} = "2" @] 'index' can be a variable !!!!{param.name,index} Returns the name of parameter at position 'index'. Example: [@ "a=1;b=2;c=3"{param.name,1} = "b" @] !!!!{param.count} Returns the number of parameters in the list. Example: [@ "a=1;b=2;c=3"{param.count} = 3 @] !!!Name-address Transformations 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. Available transformations in this class: !!!!{nameaddr.name} Returns the value of display name Example: [@ '"test" <sip:test@opensips.org>' {nameaddr.name} = "test" @] !!!!{nameaddr.uri} Returns the value of URI Example: [@ '"test" <sip:test@opensips.org>' {nameaddr.uri} = sip:test@opensips.org @] !!!!{nameaddr.len} Returns the length of the entire name-addr part from the value. !!!!{nameaddr.param,param_name} Returns the value of the parameter with name param_name. Example: [@ '"test" <sip:test@opensips.org>;tag=dat43h' {nameaddr.param,tag} = dat43h @] !!!!{nameaddr.params} Returns all the parameters and their corresponding values. Example: [@ '"test" <sip:test@opensips.org>;tag=dat43h;private=yes' {nameaddr.params} = "tag=dat43h;private=yes" @] !!!IP Transformations The name of the transformation starts with 'ip.'. Available transformations in this class: !!!!{ip.pton} Returns a binary representation of a string represented IP. Example: [@ "192.468.2.434" {ip.pton} returns a 4 byte binary representation of the IP provided @] !!!!{ip.ntop} Returns a string representation of the binary IP provided Example: [@ "192.468.2.434"{ip.pton}{ip.ntop} = "192.468.2.434" @] !!!!{ip.isip} Returns 1 or 0, if the string provided is a valid IP or not. Example: [@ "192.468.2.434" {ip.isip} = 1 "192.468.2.434.1" {ip.isip} = 0 @] !!!!{ip.family} Returns INET or INET6 if the binary IP representation provided is IPv4 or IPv6. Example: [@ "192.468.2.434" {ip.pton}{ip.family} = "INET" @] !!!!{ip.resolve} Returns the resolved IP address coresponding to the string domain provided. Transformation has no effect if a string IP is provided. Example: [@ "opensips.org" {ip.resolve} = "78.46.64.50" @] !!!CSV Transformations 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. Available transformations in this class: !!!!{csv.count} Returns the number of entries in the provided CSV. Example: [@ "a,b,c" {csv.count} = 3 @] !!!!{csv.value} Returns the entry at the specified positions. Indexing starts from 0. Example: [@ "a,b,c" {csv.value,2} = c @] !!!SDP Transformations 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. Available transformations in this class: !!!!{sdp.line} 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: [@ if (is_method("INVITE")) { $var(aline) = $(rb{sdp.line,a,1}); xlog("The second a line in the SDP body is $var(aline)\n"); } if (is_method("INVITE")) { $var(mline) = $(rb{sdp.line,m}); xlog("The first m line in the SDP body is $var(mline)\n"); } @] !!!Regular Expression Transformations The name of the transformation starts with "re.". The input can be any string. !!!!{re.subst,reg_exp} The reg_exp parameter can either be a plain string or a variable. The format of the reg_exp is : /posix_match_expression/replacement_expression/flags The flags can be i - match ignore case s - match within multi-lines strings g - replace all matches Example: [@ $var(reg_input)="abc"; $var(reg) = "/a/A/g"; xlog("Applying reg exp $var(reg) to $var(reg_input) : $(var(reg_input){re.subst,$var(reg)})\n"); ... ... xlog("Applying reg /b/B/g to $var(reg_input) : $(var(reg_input){re.subst,/b/B/g})\n"); @] !!!Examples Within a variable, many transformation can be applied, being executed from left to right. * The length of the value of parameter at postion 1 (remember 0 is first position, 1 is second position) [@ $var(x) = "a=1;b=22;c=333"; $(var(x){param.value,$(var(x){param.name,1})}{s.len}) = 2 @] * Test if whether is un-registration or not [@ if(is_method("REGISTER") && is_present_hf("Expires") && $(hdr(Expires){s.int})==0) xlog("This is an un-registrationn"); @] |
Page last modified on September 27, 2019, at 09:13 AM