Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
ref_manual:selects [2009/05/05 00:24]
janakj created
ref_manual:selects [2012/05/24 21:17] (current)
oej
Line 4: Line 4:
 You might ask, why the select framework was introduced at all? The main reason You might ask, why the select framework was introduced at all? The main reason
 was that everytime you wanted to check any part (header, etc.) of the was that everytime you wanted to check any part (header, etc.) of the
-incomming message you had to write new module/new function which did that.+incoming message you had to write new module/new function which did that.
 Moreover this function (due to historic limitations) might get at most two Moreover this function (due to historic limitations) might get at most two
 parameters. If you need more you have to use workaround and set attributes parameters. If you need more you have to use workaround and set attributes
Line 39: Line 39:
 text with the select identifier, so it must be enclosed in double quotes.) text with the select identifier, so it must be enclosed in double quotes.)
 Xlog formatting also support selects as a element while composing the final Xlog formatting also support selects as a element while composing the final
-value - the formatting element is ''%@select.identtifier.as.usual''.+value - the formatting element is ''%@select.identifier.as.usual''.
  
 Return value of the select is text string, but be aware, it might be also Return value of the select is text string, but be aware, it might be also
Line 109: Line 109:
 You can use the select in the conditional expressions like these: You can use the select in the conditional expressions like these:
  
-  * ''if (@select.value) {...}''+  if (@select.value) {...}
  
 the test is true, when the select returns NON-EMPTY string. the test is true, when the select returns NON-EMPTY string.
  
-  * ''if (@select.value=="string") {...}'' +<note> 
-  * ''if ("string"==@select.value{...}''+This way of using select is obsolete and it will generate a warning message on start-up. 
 +For sip-router the if will be true only if it returns a non-empty, non-zero numerical string (e.g. "123"). 
 +The preferred correct ways for sip-router are:
  
-the result is true, when the select is error-free and its return value. +  if (@select.value!="")
-Instead of constant value, you can also use values from $attribute or +
-@yet.another.select+
  
-  * ''if (@select.value!="string") {...}'' +or 
-  * ''if ("string"!=@select.value) {...}''+ 
 +  if (!strempty(@select.value)) 
 + 
 +</note> 
 + 
 + 
 +  if (@select.value=="string") {...} 
 +  if ("string"==@select.value) {...} 
 + 
 +the result is true, when the select is error-free and its return value is equal to "string"
 +Instead of a constant value, you can use any expression (it could involve avps, pvars or other selects). 
 + 
 +  if (@select.value!="string") {...} 
 +  if ("string"!=@select.value) {...}
  
 in this case the test checks whether the two strings are different. If in this case the test checks whether the two strings are different. If
 there is error during the select evaluation, the result is also false. there is error during the select evaluation, the result is also false.
  
- * ''if (@select.value=~"reg.*expr.?") {...}''+  if (@select.value=~"reg.*expr.?") {...}
  
 true, when the string returned by select function matches the regular true, when the string returned by select function matches the regular
 expression. In this case swapping of the left and right values matter, so expression. In this case swapping of the left and right values matter, so
  
- * ''if ("string"=~@select.value) {...}''+  if ("string"=~@select.value) {...}
  
 is true when the "string" matches the regular expression, which is is true when the "string" matches the regular expression, which is
 obtained as select's return value. This is what you usually don't want. obtained as select's return value. This is what you usually don't want.
  
-You can also use the select as the right hand value of the attribute +You can also use the select in any kind of expression, be it in the right hand of an assignment, in an if, while() or switch().
-assignment. A new string-type attribute is created and the result value of +
-the select function call is assigned to this attribute.+
  
-  * ''$attribute=@the.select.you.want''+E.g.: 
 +  $attribute=@the.select.you.want
  
 ===== Selects in Parameters ===== ===== Selects in Parameters =====
Line 158: Line 170:
 are system selects which's identifiers begin with @sys like: are system selects which's identifiers begin with @sys like:
  
- * ''@sys.pid'' + * ''@sys.pid''returns string representation of current process # 
-   returns string representation of current process # + * ''@sys.now''unix timestamp or 
- * ''@sys.now'' + * ''@sys.utc''UTC timestamp if you use different time zones 
-   unix timestamp or + * ''@sys.unique''generates and returns random UUID (type 2)
- * ''@sys.utc'' +
-   UTC timestamp if you use different time zones +
- * ''@sys.unique'' +
-   generates and returns random UUID (type 2)+
  
 ===== Selects in Modules ===== ===== Selects in Modules =====
Line 180: Line 188:
 select, just make sure you have loaded all neccessary modules. select, just make sure you have loaded all neccessary modules.
  
 +
 +===== Select List =====
 +
 +For a list with all the defined selects in the sip-router devel version (master branch), see
 +[[http://sip-router.org/docbook/sip-router/branch/master/select_list/select_list.html]].

Navigation

Wiki

Other

QR Code
QR Code ref_manual:selects (generated for current page)