looks like it is not currently possible to use a variable as avp index. for example, statements
$var(tmp) = "i:10"; $avp($var(tmp)) = "value"; xlog("L_INFO", "Avp has value $avp(i:10)\n");
produce to syslog
INFO: Avp has value <null>
but if i write xlog like this
xlog("L_INFO", "Avp has value $avp($var(tmp))\n");
i get
INFO: Avp has value value
does this mean that avp name is "$var(tmp)" or what?
anyway, i want to be able to assign values to avps using dynamically calculated avp names. if that is not currently possible, would be it ok as a first aid, if i add to some utils module a function that takes a param list (p1=v2;p2=v2;...) as argument and assigns avps based on it?
-- juha
Hello,
if that is an integer id for avp, then use:
$var(tmp) = 10;
As you wrote is taken as avp with a string name represented by "i:10".
Daniel
On 9/8/10 8:13 AM, Juha Heinanen wrote:
looks like it is not currently possible to use a variable as avp index. for example, statements
$var(tmp) = "i:10"; $avp($var(tmp)) = "value"; xlog("L_INFO", "Avp has value $avp(i:10)\n");
produce to syslog
INFO: Avp has value<null>
but if i write xlog like this
xlog("L_INFO", "Avp has value $avp($var(tmp))\n");
i get
INFO: Avp has value value
does this mean that avp name is "$var(tmp)" or what?
anyway, i want to be able to assign values to avps using dynamically calculated avp names. if that is not currently possible, would be it ok as a first aid, if i add to some utils module a function that takes a param list (p1=v2;p2=v2;...) as argument and assigns avps based on it?
-- 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:
if that is an integer id for avp, then use:
$var(tmp) = 10;
As you wrote is taken as avp with a string name represented by "i:10".
daniel,
thanks for the info. it seems to be missing from avp wiki page:
http://sip-router.org/wiki/cookbooks/pseudo-variables/devel
which states:
AVPs
$(avp(id)[N]) - represents the value of N-th AVP identified by 'id'. The 'id' can be: * "[si]:name" - name is the id of an AVP; 's' and 'i' specifies if the id is string or integer. If missing, it is considered to be string. * "name" - the name is an AVP alias $(avp(id)[0]) can be written in shorter form as $avp(id) and $avp(s:name) as $name.
and gives impression that avp name 10 is same as s:10. also, the page does not tell that avp id can be a variable or perhaps even an expression.
a util function that takes a param list as argument and assigns avps based on it would still be useful. i'll try to write one unless someone figures out a better way to achieve the same. the application that i have in mind is one where proxy receives from another proxy a param list in a header and assigns avps based on it. without such a function a complex loop structure would be needed.
-- juha