[Users] Re: [Devel] test return code in config file
Bogdan-Andrei Iancu
bogdan at voice-system.ro
Wed Jun 29 16:15:24 CEST 2005
Hi Klaus,
Klaus Darilion wrote:
> Can this be used to exit from a route block to avoid the workaround
> using flags, e.g.:
>
> route {
> route(1);
> if (retcode == 99) break;
> ...
> }
>
> route[1] {
> if (security check fails) {
> return(99);
> }
> ... do some things;
> }
>
yes - you can do this now.
>
> Is there a differnce between
> return(0);
> and
> break;
> ?
>
just to clarify a little bit - the return code convention is like this:
if a function returns 0, the entire script execution will be stopped. If
is a negative value -> false; if positive ->true.
Now, return(0) returns with code 0 -> is the same as exit -> it will
terminated the script execution.
on the other hand, break is used to terminate only the current route (is
similar to return(1) )
regards,
Bogdan
> regards,
> klaus
> Daniel-Constantin Mierla wrote:
>
>> Hello,
>>
>> there is a new variable in configuration file 'retcode' that can be
>> used to test against an integer the value returned by last invoked
>> function or route. In the case of routes that uses return, it is the
>> returned value. The changes were done yesterday, so the pserver CVS
>> head is now synchronized.
>>
>> It is similar to $? from bash ($? can be used also in configuration
>> file, having the same meaning as 'retcode'). Take care when you are
>> testing this value, it can be easily misleading. For example:
>>
>>
>> route[1] {
>> if(method=="INVITE")
>> return(1);
>> return(2);
>> }
>>
>> route {
>>
>> route(1);
>> if(retcode==2)
>> {
>> log("The request is a REGISTER\n");
>> };
>> if(retcode==1)
>> {
>> ...
>> };
>>
>> }
>>
>> In case of REGISTER, the 'log' function is executed and the value of
>> retcode is changed. The proper scripting is:
>> route {
>>
>> route(1);
>> if(retcode==2)
>> {
>> log("The request is a REGISTER\n");
>> } else if(retcode==1)
>> {
>> ...
>> };
>> }
>>
>> I have updated the docuwiki for 'return()' and added 'retcode' there,
>> too.
>>
>> http://www.openser.org/dokuwiki/doku.php?id=openser_core_cookbook#return_int
>>
>> http://www.openser.org/dokuwiki/doku.php?id=openser_core_cookbook#retcode
>>
>>
>> Regards,
>> Daniel
>
More information about the sr-users
mailing list