Script enhancemets

OpenSIPS trunk (future 1.9) just got better with some awesome script
enhancements:

1) *Flags with name*, thanks to Liviu Chircu
Message, script and branch flags have now alphanumerical names, instead
of numerical ID (as so far). Now you can simply do:
setflag(DO_SIPTRACE);
or
issflagset(SRC_IS_GW);
The migration to named flags affects all flag related functions and the
module parameters used for defining flags (like flag to enable sip
tracing, etc).
This change is 100% backward compatible, but you will get some warning
about deprecation of the ID based flags.

2) *Script tracing*, also thanks to Liviu Chircu
With script tracing, you can better understand the flow of execution in
the OpenSIPS script. Moreover, you can also trace the values of
pseudo-variables, as script execution progresses.
The blocks of the script where script tracing is enabled will print a
line for each individual action that is done (e.g. assignments,
conditional tests, module functions, core functions, etc.). Multiple
pseudo-variables can be monitored by specifying a pv_format string (e.g.
"$ru---$avp(var1)"). The current value of the format will be printed
along with each line.
Script tracing can be enabled with: script_trace(log_level,
pv_format_string[, info_string])
Ex:
[line 578][me][module consume_credentials] -> (INVITE from
127.0.0.1 , ruri=sip:111111 at opensips.org)
[line 581][me][core setsflag] -> (INVITE from 127.0.0.1,
ruri=sip:111111 at opensips.org)
[line 583][me][assign equal] -> (INVITE from 127.0.0.1,
ruri=sip:111111 at opensips.org)
[line 592][me][core if] -> (INVITE from 127.0.0.1 ,
ruri=sip:tester at opensips.org)
[line 585][me][module is_avp_set] -> (INVITE from 127.0.0.1,
ruri=sip:tester at opensips.org)
[line 589][me][core if] -> (INVITE from 127.0.0.1,
ruri=sip:tester at opensips.org)
[line 586][me][module is_method] -> (INVITE from 127.0.0.1,
ruri=sip:tester at opensips.org)
[line 587][me][module trace_dialog] -> (INVITE 127.0.0.1,
ruri=sip:tester at opensips.org)
[line 590][me][core setflag] -> (INVITE from 127.0.0.1,
ruri=sip:tester at opensips.org)

See: http://www.opensips.org/Resources/DocsCoreFcn#toc146

3) *Routes with parameters*, thanks to Razvan Crainea
When calling a script route, some extra parameters can be attached
(example: route(ROUTE_NAME, 1);), that can be later retrieved from
within the route using the a type of '$param' pseudo variable.
You can push up to 7 parameters which can be strings, numbers or variables.
Ex:

route[tester] {
if ($param(1) > $param(2) )
xlog("test $param(3) failed \n");
send_reply("403",Forbidden);
exit;
}
}

....
route(tester, $avp(calls), 10, "max call limit");
....

See: http://www.opensips.org/Resources/DocsCoreFcn#toc145
http://www.opensips.org/Resources/DocsCoreVar#toc56

Posted by Bogdan-Andrei Iancu 2013-01-21