it was easy to write the code that counts the number of record routes in a message. first i though that i can return the count as result of the script function, but that didn't work out because if script function returns 0, it will terminate execution of the script.
so i though to give the function a pvar argument to which the count is stored, e.g.,
rr_count("$var(count)");
so far i have not been able to assign the count to the pvar argument and have already spent three hours on such a simple assignment statement. in pvar.h there is function
int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op, pv_value_t *value);
that sounds like it might do the trick, but there is no documentation on op argument and i have not yet found in sr sources any place there that function is really used. also i have not found in any of sr modules any script function that would assign something to a pvar argument? is there one so that i could take a look or it that an impossible thing to do?
i have tried various versions, such as
pv_val.ri = count; pv_val.flags = PV_VAL_INT; if (_count) { if (pv_set_spec_value(msg, (pv_spec_t *)_count, EQ_T, &pv_val) == 0) {
where _count is pvar fixed up argument of rr_count function, but no luck so far. i just get
Nov 10 05:42:51 localhost /usr/sbin/sip-proxy[27707]: ERROR: pv [pv_svar.c:117]: out of pkg mem! Nov 10 05:42:51 localhost /usr/sbin/sip-proxy[27707]: ERROR: pv [pv_core.c:1620]: error - cannot set svar [tmp]
can anyone help here? if not, i'll have to make rr_count to return the actual count + 1 so that i can return it as result of the rr_count function.
-- juha
there is an example in group module - get_user_group() function.
However, you can do a new pseudo-variable:
$rr_count or so, where get function counts the number of routes.
The you do not need to use a function to set a variable, you can do: $var(x) = $rr_count;
Cheers, Daniel
On 10.11.2009 4:47 Uhr, Juha Heinanen wrote:
it was easy to write the code that counts the number of record routes in a message. first i though that i can return the count as result of the script function, but that didn't work out because if script function returns 0, it will terminate execution of the script.
so i though to give the function a pvar argument to which the count is stored, e.g.,
rr_count("$var(count)");
so far i have not been able to assign the count to the pvar argument and have already spent three hours on such a simple assignment statement. in pvar.h there is function
int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op, pv_value_t *value);
that sounds like it might do the trick, but there is no documentation on op argument and i have not yet found in sr sources any place there that function is really used. also i have not found in any of sr modules any script function that would assign something to a pvar argument? is there one so that i could take a look or it that an impossible thing to do?
i have tried various versions, such as
pv_val.ri = count; pv_val.flags = PV_VAL_INT; if (_count) {
if (pv_set_spec_value(msg, (pv_spec_t *)_count, EQ_T, &pv_val) == 0) {
where _count is pvar fixed up argument of rr_count function, but no luck so far. i just get
Nov 10 05:42:51 localhost /usr/sbin/sip-proxy[27707]: ERROR: pv [pv_svar.c:117]: out of pkg mem! Nov 10 05:42:51 localhost /usr/sbin/sip-proxy[27707]: ERROR: pv [pv_core.c:1620]: error - cannot set svar [tmp]
can anyone help here? if not, i'll have to make rr_count to return the actual count + 1 so that i can return it as result of the rr_count function.
-- juha
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
Daniel-Constantin Mierla writes:
there is an example in group module - get_user_group() function.
daniel,
thanks for the pointer. i'll take a look at it. i don't use that module and thus missed it.
it would still be interesting to know what i'm doing wrong with my try to use pv_set_spec_value:
pv_val.ri = count; pv_val.flags = PV_VAL_INT; if (_count) { if (pv_set_spec_value(msg, (pv_spec_t *)_count, EQ_T, &pv_val) == 0) {
However, you can do a new pseudo-variable: $rr_count or so, where get function counts the number of routes.
yes, at stage two. at this point i want to have all needed functions in nathelper module, so that not too many files need to be patched by those who want to try this feature out.
-- juha
On 10.11.2009 11:51 Uhr, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
there is an example in group module - get_user_group() function.
daniel,
thanks for the pointer. i'll take a look at it. i don't use that module and thus missed it.
it would still be interesting to know what i'm doing wrong with my try to use pv_set_spec_value:
pv_val.ri = count; pv_val.flags = PV_VAL_INT; if (_count) {
if (pv_set_spec_value(msg, (pv_spec_t *)_count, EQ_T, &pv_val) == 0) {
However, you can do a new pseudo-variable: $rr_count or so, where get function counts the number of routes.
yes, at stage two. at this point i want to have all needed functions in nathelper module, so that not too many files need to be patched by those who want to try this feature out.
you have to set:
pv_val.flags = PV_TYPE_INT;
-- hope is ok, since I tried to remember from memory. The errors shows that the type is considered to be string, in your case.
You can add the pv in any of the modules, does not have to be in "pv" module... then you can move it later. There are many modules exporting PVs ... htable, tmx, ...
Cheers, Daniel