[Devel] new features: script variables and pseudo-variables in script

Klaus Darilion klaus.mailinglists at pernau.at
Mon Jan 29 18:03:15 CET 2007


thanks :-)

regards
klaus

Daniel-Constantin Mierla wrote:
> Hello everybody,
> 
> the development version allows now ability to use pseudo-variables 
> directly in configuration file. In addition to old pseudo-variables you 
> know, a new type was introduced: script variables - the format is 
> $var(name) where name can be any string of digits and characters.
> 
> Basically this are variables that can have integer or string values and 
> they can be set directly in the configuration file via 'assign 
> operation. The big advantage is that they are directly referenced at 
> runtime, avoiding searching each access time. They are specific per 
> processes and survive over multiple sip message processing (be sure you 
> set the value before testing it -- e.g., $var(counter) = $var(counter) + 
> 1 at the beginning of main route is a counter of messages processed). 
> The script variables are initialized at startup to '0'. You can shift 
> between value types: e.g., '$var(a)=1; $var(a)="openser";'  is valid.
> 
> The switch statement can be used now with any valid pseudo-variable 
> ('retcode' must be now replaced with '$retcode' to get old behavior).  
> switch($rU) will compare the r-uri username with 'case' values. The case 
> 'values' can be string or integer.
> 
> switch($rU) {
> case "101": xlog("dialed number is 101\n"); break;
> case "102": xlog("dialed number is 102\n"); break;
> default: xlog("dialed number is $rU\n");
> }
> 
> Assignments of script variables, AVPs, R-URI parts (username, domain, 
> and URI) and dst URI can be done as well in script.
> $avp(i:11) = 1; - sets the value of $avp(i:11) to integer '1'
> $avp(i:11) = "1"; - sets the value of $avp(i:11) to string '1'
> $ru = "sip:"+$var(user)+"@"+$fd; - sets the R-URI to string composed 
> from value of variable $var(user) and From URI domain
> 
> '+' can be used to concatenate strings or do arithmetic addition. Other 
> arithmetic operators:
> - '-' - minus
> - '/' - divide
> - '*' - multiply
> - '%' - modulo
> - '|' - bitwise OR
> - '&' - bitwise AND
> - '^' - bitwise XOR
> - '~' - bitwise NOT
> 
> To make sure that the priority of the operators is right, do use 
> parenthesis, it is the best to get expected result:
> $var(a) = 2 + (7&(~4));
> 
> If you want to evaluate arithmetic operations and test the value in 
> conditions, use the test operator ' [ ... ] ' . This is required to 
> convert the result to internal convention for drop, true and false.
> 
> if ( [ $var(a)&4 ] ) {
>   xlog("bit 3 is set in var a");
> }
> 
> Old '*' used to match any port or proto was changed to 'any' to avoid 
> the conflict with multiply operator. Some operations overlap with 
> several avpops functions. Until sure that all cases are covered in 
> script variant, both will go further, avpops version being scheduled for 
> deprecation.
> 
> It was a big lump of changes, help in testing and feedback is very much 
> appreciated.
> 
> Cheers,
> Daniel
> 
> 
> 
> 
> _______________________________________________
> Devel mailing list
> Devel at openser.org
> http://openser.org/cgi-bin/mailman/listinfo/devel


-- 
Klaus Darilion
nic.at




More information about the Devel mailing list