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
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; }
Is there a differnce between return(0); and break; ?
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
Devel mailing list Devel@openser.org http://openser.org/cgi-bin/mailman/listinfo/devel
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
Bogdan-Andrei Iancu wrote:
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) )
Are you sure? AFAIK break; return 0 If return(0) also returns 0, then it is like break and only exits from the current route block.
If your statement is correct, it is possible to exit ser.cfg from any route block by return(0)? I didn't knew that.
regards, klaus
On 06/29/05 18:36, Klaus Darilion wrote:
Bogdan-Andrei Iancu wrote:
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) )
Are you sure?
yes.
AFAIK break; return 0
that happens in ser, but has changed in openser to keep the compatibility -- in ser, break exists from current route and if(route()) is always true if there was a break.
This is a bug is ser because many functions exported for use in config rely that when returning 0, no further processing takes place (e.g., t_newtran() returns 0 if detects retransmission and if the t_newtran() is used in other route than 0, the retransmissions are processed).
So, in openser, 'break' is return(1) and there is also 'exit' which is return(0).
If return(0) also returns 0, then it is like break and only exits from the current route block.
If your statement is correct, it is possible to exit ser.cfg from any route block by return(0)?
yes, you can exit cfg from any route -- you can use also 'exit' which is more appropriate as name.
I didn't knew that.
It is written in the file with changes from ser to openser, but maybe not that obviously.
Regards, Daniel
regards, klaus
cool - I recently reviewed ser's code to add an "exit" command myself :-)
Conclusion for myself: break; leaves current route block, identical to return(1) exit; leaves entire script, identical to return(0)
regards, klaus
Daniel-Constantin Mierla wrote:
On 06/29/05 18:36, Klaus Darilion wrote:
Bogdan-Andrei Iancu wrote:
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) )
Are you sure?
yes.
AFAIK break; return 0
that happens in ser, but has changed in openser to keep the compatibility -- in ser, break exists from current route and if(route()) is always true if there was a break.
This is a bug is ser because many functions exported for use in config rely that when returning 0, no further processing takes place (e.g., t_newtran() returns 0 if detects retransmission and if the t_newtran() is used in other route than 0, the retransmissions are processed).
So, in openser, 'break' is return(1) and there is also 'exit' which is return(0).
If return(0) also returns 0, then it is like break and only exits from the current route block.
If your statement is correct, it is possible to exit ser.cfg from any route block by return(0)?
yes, you can exit cfg from any route -- you can use also 'exit' which is more appropriate as name.
I didn't knew that.
It is written in the file with changes from ser to openser, but maybe not that obviously.
Regards, Daniel
regards, klaus