substitute variable names within variables

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

substitute variable names within variables

jay1017
Hi,
I define some values using the varset parameters of cfgutils module.
modparam("cfgutils", "varset", "media1=1.2.3.4")
modparam("cfgutils", "varset", "media2=4.3.2.1")
modparam("cfgutils", "varset", "media3=5.6.7.8")

I need a logic to dynamically select the the variables. Say for example:
I select a value from DB and store it in an AVP say $avp(db_val) which I know can be either 1,2 or 3. Based on that value, I need to select among variables media1, media2 or media3.
I need to find a way where I can substitute the avp(db_val) value in the name of the variable. Basically something like this:
$avp(variable_to_be_used) = $var(media$avp(db_val))
So here if $avp(db_val) is 1, avp(variable_to_be_used) becomes $var(media1) which will be 1.2.3.4

Is something like this possible or allowed? Is there an alternative to do something similar dynamically !! I know, I cud have stored those values in DB and retrieved directly but I am looking at this feature for many other purposes too !!

Any help is much appreciated. Thanks,

--- Jayesh

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: substitute variable names within variables

Razvan Crainea-3
Hi, Jayesh!

Unfortunately you can't do this in OpenSIPS. The 'var' pseudo-variable only accepts a constant name, like 'media'. There are some variables, like AVP, that can also receive a variable name ( ex: $avp($avp(name)) ), but note they can only receive a pseudo-variable, not a format ( like $avp(media$avp(name)) ). I think this is only supported in the latest changes to the 'stat' pseudo-variable.
Implementing a generic solution is not that feasible, as it requires changes in both pvar interface and each variable implementation.

Regards,
Răzvan

On 12/27/2012 08:52 PM, Jayesh Nambiar wrote:
Hi,
I define some values using the varset parameters of cfgutils module.
modparam("cfgutils", "varset", "media1=1.2.3.4")
modparam("cfgutils", "varset", "media2=4.3.2.1")
modparam("cfgutils", "varset", "media3=5.6.7.8")

I need a logic to dynamically select the the variables. Say for example:
I select a value from DB and store it in an AVP say $avp(db_val) which I know can be either 1,2 or 3. Based on that value, I need to select among variables media1, media2 or media3.
I need to find a way where I can substitute the avp(db_val) value in the name of the variable. Basically something like this:
$avp(variable_to_be_used) = $var(media$avp(db_val))
So here if $avp(db_val) is 1, avp(variable_to_be_used) becomes $var(media1) which will be 1.2.3.4

Is something like this possible or allowed? Is there an alternative to do something similar dynamically !! I know, I cud have stored those values in DB and retrieved directly but I am looking at this feature for many other purposes too !!

Any help is much appreciated. Thanks,

--- Jayesh


_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users