i wrote alias_contact() function and seems to work fine. i have not yet written handle_alias(), but tried to first use scripting means for that. that led into trouble with testing is $var has value.
i have this piece of code:
xlog("L_INFO", "R-URI is <$ru>\n"); $var(tmp) = $(ru{uri.param,alias}); xlog("L_INFO", "Alias param is <$var(tmp)>\n"); if ($var(tmp)) { xlog("L_INFO", "Alias param is <$var(tmp)>\n"); $du = $var(tmp); xlog("L_INFO", "Routing in-dialog $rm from <$fu> to <$du>\n"); } else { xlog("L_INFO", "Routing in-dialog $rm from <$fu> to <$ru>\n"); }
and i get to syslog:
Nov 8 12:51:10 localhost /usr/sbin/sip-proxy[4506]: INFO: R-URI is sip:jh_test_fi@192.98.101.10:5074;transport=tcp;alias="192.98.101.10:55375;transport=tcp" Nov 8 12:51:10 localhost /usr/sbin/sip-proxy[4506]: INFO: Alias param is <192.98.101.10:55375;transport=tcp> Nov 8 12:51:10 localhost /usr/sbin/sip-proxy[4506]: INFO: Routing in-dialog BYE from sip:test@as.test.fi to sip:jh_test_fi@192.98.101.10:5074;transport=tcp;alias="192.98.101.10:55375;transport=tcp"
why does the test
if ($var(tmp)) {
fail to figure out that $var(tmp) has value?
-- juha
On Nov 08, 2009 at 12:55, Juha Heinanen jh@tutpro.com wrote:
i wrote alias_contact() function and seems to work fine. i have not yet written handle_alias(), but tried to first use scripting means for that. that led into trouble with testing is $var has value.
i have this piece of code:
xlog("L_INFO", "R-URI is <$ru>\n"); $var(tmp) = $(ru{uri.param,alias}); xlog("L_INFO", "Alias param is <$var(tmp)>\n"); if ($var(tmp)) { xlog("L_INFO", "Alias param is <$var(tmp)>\n"); $du = $var(tmp);
^^^^^^^^ shouldn't it be $du = "sip:" + $var(tmp) ?
xlog("L_INFO", "Routing in-dialog $rm from <$fu> to <$du>\n"); } else { xlog("L_INFO", "Routing in-dialog $rm from <$fu> to <$ru>\n"); }
and i get to syslog:
Nov 8 12:51:10 localhost /usr/sbin/sip-proxy[4506]: INFO: R-URI is sip:jh_test_fi@192.98.101.10:5074;transport=tcp;alias="192.98.101.10:55375;transport=tcp" Nov 8 12:51:10 localhost /usr/sbin/sip-proxy[4506]: INFO: Alias param is <192.98.101.10:55375;transport=tcp> Nov 8 12:51:10 localhost /usr/sbin/sip-proxy[4506]: INFO: Routing in-dialog BYE from sip:test@as.test.fi to sip:jh_test_fi@192.98.101.10:5074;transport=tcp;alias="192.98.101.10:55375;transport=tcp"
why does the test
if ($var(tmp)) {
fail to figure out that $var(tmp) has value?
You should use if ($var(tmp)!=""). if ($var(tmp)) works only for integers. If $var(tmp) is not integer and not a string of the form "1234", it will evaluate to 0 in an integer context. The if() it's an integer context (no boolean context in sr).
Andrei
Andrei Pelinescu-Onciul writes:
$var(tmp) = $(ru{uri.param,alias}); xlog("L_INFO", "Alias param is <$var(tmp)>\n"); if ($var(tmp)) { xlog("L_INFO", "Alias param is <$var(tmp)>\n"); $du = $var(tmp);
^^^^^^^^ shouldn't it be $du = "sip:" + $var(tmp) ?
andrei,
yes, it should have been like that. now handle_alias() takes care of it.
why does the test
if ($var(tmp)) {
fail to figure out that $var(tmp) has value?
You should use if ($var(tmp)!=""). if ($var(tmp)) works only for integers. If $var(tmp) is not integer and not a string of the form "1234", it will evaluate to 0 in an integer context. The if() it's an integer context (no boolean context in sr).
thanks for the explanation. i have to say though that as a normal programmer, i'm not used to such behavior.
in order to avoid programming mistakes like that, could it be possible to produce a error message if such a test is attempted, i.e., test on string valued pvar?
-- juha
On Nov 09, 2009 at 22:58, Juha Heinanen jh@tutpro.com wrote:
Andrei Pelinescu-Onciul writes:
$var(tmp) = $(ru{uri.param,alias}); xlog("L_INFO", "Alias param is <$var(tmp)>\n"); if ($var(tmp)) { xlog("L_INFO", "Alias param is <$var(tmp)>\n"); $du = $var(tmp);
^^^^^^^^ shouldn't it be $du = "sip:" + $var(tmp) ?
andrei,
yes, it should have been like that. now handle_alias() takes care of it.
why does the test
if ($var(tmp)) {
fail to figure out that $var(tmp) has value?
You should use if ($var(tmp)!=""). if ($var(tmp)) works only for integers. If $var(tmp) is not integer and not a string of the form "1234", it will evaluate to 0 in an integer context. The if() it's an integer context (no boolean context in sr).
thanks for the explanation. i have to say though that as a normal programmer, i'm not used to such behavior.
in order to avoid programming mistakes like that, could it be possible to produce a error message if such a test is attempted, i.e., test on string valued pvar?
We could generate an error message, but only at runtime (because we don't know the type of $var(tmp) at script compile time).
Andrei
Andrei Pelinescu-Onciul writes:
We could generate an error message, but only at runtime (because we don't know the type of $var(tmp) at script compile time).
andrei,
run-time would be great. current no-error implementation results in many non-working scripts, where people wonder what is wrong with them.
-- juha
On Nov 10, 2009 at 12:49, Juha Heinanen jh@tutpro.com wrote:
Andrei Pelinescu-Onciul writes:
We could generate an error message, but only at runtime (because we don't know the type of $var(tmp) at script compile time).
andrei,
run-time would be great. current no-error implementation results in many non-working scripts, where people wonder what is wrong with them.
Latest sr_3.0 should have them, as warnings, e.g.: WARNING: <core> [rvalue.c:987]: automatic string to int conversion for "avp_test1" failed WARNING: <core> [rvalue.c:1838]: rval expression conversion to int failed (40,12-40,25) ^^^^^^^^^^^ expression position in the config.
The behaviour can now be controlled by defines.
From rvalue.c:
* RV_STR2INT_VERBOSE_ERR - if a string conversion to int fails, log (L_WARN) * the string that caused it (only the string, not * the expression position). * RV_STR2INT_ERR - if a string conversion to int fails, don't ignore * the error (return error). * RVAL_GET_INT_ERR_WARN - if a conversion to int fails, log a warning with * the expression position. * Depends on RV_STR2INT_ERR. * RVAL_GET_INT_ERR_IGN - if a conversion to int fails, ignore the error * (the result will be 0). Can be combined with * RVAL_GET_INT_ERR_WARN. * Depends on RV_STR2INT_ERR.
By default all of them are on/defined.
This is quite a late change (for sr_3.0), but if something goes wrong it can easily be reverted by commenting all of the 4 defines at the top of rvalue.c.
Andrei
Andrei,
Great news....
Latest sr_3.0 should have them, as warnings, e.g.: WARNING: <core> [rvalue.c:987]: automatic string to int conversion for "avp_test1" failed WARNING: <core> [rvalue.c:1838]: rval expression conversion to int failed (40,12-40,25) ^^^^^^^^^^^ expression position in the config.
Could You clarify the meaning of this 3 number/position expression?
Edson.
On Nov 16, 2009 at 18:19, Edson - Lists 4lists@gmail.com wrote:
Andrei,
Great news....
Latest sr_3.0 should have them, as warnings, e.g.: WARNING: <core> [rvalue.c:987]: automatic string to int conversion for "avp_test1" failed WARNING: <core> [rvalue.c:1838]: rval expression conversion to int failed (40,12-40,25) ^^^^^^^^^^^ expression position in the config.
Could You clarify the meaning of this 3 number/position expression?
(start line, start column - end line, end column).
Andrei