i have defined two routes:
route [TEST_ROUTE_MINUS_ONE] { return (-1); }
route [TEST_ROUTE_PLUS_ONE] { return (1); }
and then test them with these statements:
if (route(TEST_ROUTE_MINUS_ONE) == -1) { xlog("L_INFO", "TEST_ROUTE returned -1\n"); }
if (!route(TEST_ROUTE_MINUS_ONE)) { xlog("L_INFO", "TEST_ROUTE returned failure\n"); }
if (route(TEST_ROUTE_PLUS_ONE) == 1) { xlog("L_INFO", "TEST_ROUTE returned 1\n"); }
if (route(TEST_ROUTE_PLUS_ONE)) { xlog("L_INFO", "TEST_ROUTE returned success\n"); }
can someone explain, why i get only three lines to syslog?
Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_MINUS_ONE returned failure Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_PLUS_ONE returned 1 Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_PLUS_ONE returned success
-- juha
Hello,
cannot test it for now personally, but what you get if you do:
route(TEST_ROUTE_MINUS_ONE);
$var(r) = $rc;
xlog("returned code by route minus one is: $var(r)\n");
Maybe this will give some leads I can follow in the code...
Cheers, Daniel
On 12/10/11 3:16 PM, Juha Heinanen wrote:
i have defined two routes:
route [TEST_ROUTE_MINUS_ONE] { return (-1); }
route [TEST_ROUTE_PLUS_ONE] { return (1); }
and then test them with these statements:
if (route(TEST_ROUTE_MINUS_ONE) == -1) { xlog("L_INFO", "TEST_ROUTE returned -1\n"); } if (!route(TEST_ROUTE_MINUS_ONE)) { xlog("L_INFO", "TEST_ROUTE returned failure\n"); } if (route(TEST_ROUTE_PLUS_ONE) == 1) { xlog("L_INFO", "TEST_ROUTE returned 1\n"); } if (route(TEST_ROUTE_PLUS_ONE)) { xlog("L_INFO", "TEST_ROUTE returned success\n"); }
can someone explain, why i get only three lines to syslog?
Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_MINUS_ONE returned failure Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_PLUS_ONE returned 1 Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_PLUS_ONE returned success
-- juha
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Daniel-Constantin Mierla writes:
cannot test it for now personally, but what you get if you do:
route(TEST_ROUTE_MINUS_ONE);
$var(r) = $rc;
xlog("returned code by route minus one is: $var(r)\n");
Maybe this will give some leads I can follow in the code...
daniel,
i correctly get:
Dec 12 11:42:37 sip /usr/sbin/sip-proxy[1308]: ERROR: returned code by route minus one is: -1
so it is only the test
if (route(TEST_ROUTE_MINUS_ONE) == -1) ...
that fails.
-- juha
Hello,
On 12/12/11 10:45 AM, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
cannot test it for now personally, but what you get if you do:
route(TEST_ROUTE_MINUS_ONE);
$var(r) = $rc;
xlog("returned code by route minus one is: $var(r)\n");
Maybe this will give some leads I can follow in the code...
daniel,
i correctly get:
Dec 12 11:42:37 sip /usr/sbin/sip-proxy[1308]: ERROR: returned code by route minus one is: -1
so it is only the test
if (route(TEST_ROUTE_MINUS_ONE) == -1) ...
that fails.
ok, so looks like IF with a mod function returning negative needs investigation. I will look over it soon.
Cheers, Daniel
Hello,
I checked the code and this behaviour is practically due to special meaning of return codes from functions exported to config file, ie,: - <0 is false - >0 is true
route(x) call is returning the code from route block itself, but then the interpreter converts the codes < 0 to 0 (so the condition is false in C) and the codes > 0 to 1 (so the condition is C is true).
Thus, no matter what code you return from a subroute, you have to compare against 0 (for negative return code) or 1 (for positive return code).
Solutions/alternatives:
1) $var(r) = route(x);
.. and then compare $var(r)
2) route(x); $var(r) = $rc;
.. and then compare $var(r)
3) doing it in the if:
if(($var(r) = route(x)) && ($var(r) == -1)) { ... }
The assignment which is done first in the IF expression will return true if the assignment operation is successful.
Cheers, Daniel
just replace -1 with the return code you want to test against On 12/12/11 11:29 AM, Daniel-Constantin Mierla wrote:
Hello,
On 12/12/11 10:45 AM, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
cannot test it for now personally, but what you get if you do:
route(TEST_ROUTE_MINUS_ONE);
$var(r) = $rc;
xlog("returned code by route minus one is: $var(r)\n");
Maybe this will give some leads I can follow in the code...
daniel,
i correctly get:
Dec 12 11:42:37 sip /usr/sbin/sip-proxy[1308]: ERROR: returned code by route minus one is: -1
so it is only the test
if (route(TEST_ROUTE_MINUS_ONE) == -1) ...
that fails.
ok, so looks like IF with a mod function returning negative needs investigation. I will look over it soon.
Cheers, Daniel
Daniel-Constantin Mierla writes:
Thus, no matter what code you return from a subroute, you have to compare against 0 (for negative return code) or 1 (for positive return code).
Solutions/alternatives:
is it not an alternative to fix to change the current implementation so that the real return code of route block could be tested?
-- juha
On 12/13/11 1:03 PM, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
Thus, no matter what code you return from a subroute, you have to compare against 0 (for negative return code) or 1 (for positive return code).
Solutions/alternatives:
is it not an alternative to fix to change the current implementation so that the real return code of route block could be tested?
coding wise might not be a lot, thus I haven't analyzed all the cases where functions are evaluated by return code, but it will impact and break config file as it used to be so far, for example:
route[x] { return -1; }
if(route(x)) will be true, since if(-1) is true in C All conditions with functions have to be changed in:
if( f()<0 ) for false cases if( f(x) > 0) for true cases
At this moment I cannot say for sure if there can be done some workaround to get return code and keep old behavior, at first sight seems unlikely.
Cheers, Daniel
Daniel-Constantin Mierla writes:
coding wise might not be a lot, thus I haven't analyzed all the cases where functions are evaluated by return code, but it will impact and break config file as it used to be so far, for example:
route[x] { return -1; }
if(route(x)) will be true, since if(-1) is true in C
i meant get rid of C interpretation when if evaluates the condition, i.e., do not covert condition to anything, but just test if condition is < 0 for false and > 0 for true.
-- juha
On 12/13/11 1:25 PM, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
coding wise might not be a lot, thus I haven't analyzed all the cases where functions are evaluated by return code, but it will impact and break config file as it used to be so far, for example:
route[x] { return -1; }
if(route(x)) will be true, since if(-1) is true in C
i meant get rid of C interpretation when if evaluates the condition, i.e., do not covert condition to anything, but just test if condition is < 0 for false and> 0 for true.
This is what happens actually:
if(route(x) == 1) is seen by interpreter as:
if(left_expression == 1)
then left_expression is evaluated as you say above: - < 0 is false => this is 0 is C - > 0 is true => this is 1 in C
Since left_expression can be complex (include sub expressions), there has to be propagation to false/true. For example you can have in the left expression (2<1) or variables with such values.
Anyhow, if you have some ideas, you can play with functions in lvalue.c, rvalue.c and action.c
Cheers, Daniel
I had a similar problem with avp_db_query
if (avp_db_query(...) == -2) { xlog("..."); }
did not work, but
$var(r) = avp_db_query(....); if ($var(r) == -2) { xlog("..."); }
did work.
/Morten
On Sat, Dec 10, 2011 at 3:16 PM, Juha Heinanen jh@tutpro.com wrote:
i have defined two routes:
route [TEST_ROUTE_MINUS_ONE] { return (-1); }
route [TEST_ROUTE_PLUS_ONE] { return (1); }
and then test them with these statements:
if (route(TEST_ROUTE_MINUS_ONE) == -1) { xlog("L_INFO", "TEST_ROUTE returned -1\n"); }
if (!route(TEST_ROUTE_MINUS_ONE)) { xlog("L_INFO", "TEST_ROUTE returned failure\n"); }
if (route(TEST_ROUTE_PLUS_ONE) == 1) { xlog("L_INFO", "TEST_ROUTE returned 1\n"); }
if (route(TEST_ROUTE_PLUS_ONE)) { xlog("L_INFO", "TEST_ROUTE returned success\n"); }
can someone explain, why i get only three lines to syslog?
Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_MINUS_ONE returned failure Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_PLUS_ONE returned 1 Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_PLUS_ONE returned success
-- juha
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Hello,
On 12/12/11 11:15 AM, Morten Isaksen wrote:
I had a similar problem with avp_db_query
if (avp_db_query(...) == -2) { xlog("..."); }
did not work, but
$var(r) = avp_db_query(....); if ($var(r) == -2) { xlog("..."); }
did work.
indeed, this is a solution. As stated in the previous email, inside an IF expression, the return code from functions exported to config are converted to 0 if return code is < 0 and to 1 if the return code is >0 to match in C the special meaning of return codes in the config file.
Cheers, Daniel
/Morten
On Sat, Dec 10, 2011 at 3:16 PM, Juha Heinanenjh@tutpro.com wrote:
i have defined two routes:
route [TEST_ROUTE_MINUS_ONE] { return (-1); }
route [TEST_ROUTE_PLUS_ONE] { return (1); }
and then test them with these statements:
if (route(TEST_ROUTE_MINUS_ONE) == -1) { xlog("L_INFO", "TEST_ROUTE returned -1\n"); } if (!route(TEST_ROUTE_MINUS_ONE)) { xlog("L_INFO", "TEST_ROUTE returned failure\n"); } if (route(TEST_ROUTE_PLUS_ONE) == 1) { xlog("L_INFO", "TEST_ROUTE returned 1\n"); } if (route(TEST_ROUTE_PLUS_ONE)) { xlog("L_INFO", "TEST_ROUTE returned success\n"); }
can someone explain, why i get only three lines to syslog?
Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_MINUS_ONE returned failure Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_PLUS_ONE returned 1 Dec 10 16:14:56 sip /usr/sbin/sip-proxy[16099]: INFO: TEST_ROUTE_PLUS_ONE returned success
-- juha
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users