Hello,
On 11/2/10 3:02 PM, Bernhard Suttner wrote:
Hi,
yeah, that looks like a good solution. But I assume that there should be the similar way
to use the shm or pseudo variables as a array. Maybe someone else does know more about
this way?
the script variables that can hold arrays are AVPs. You can emulate
arrays with htable by constructing an array-like key - what Juha
suggested. I haven't checked/used the memcache module.
What Alex provided for assignment is not working exactly that way,
because an assignment to an AVP always adds at the first position like a
stack (the index is not relevant for avp in the left side of assignment
unless it is '*' and assigned value is null - meaning delete all avps
with that name).
However, as I understand you want to execute some actions based on
source IP. Look at permissions module, with 3.1 you can assign tag value
per ip/network address. This value is returned in config upon matching
and based on it you can do specific operations.
There are other modules that could be used to match based on ip address,
without a need to do a loop in config.
Cheers,
Daniel
Best regards,
Bernhard
-----Ursprüngliche Nachricht-----
Von: sr-users-bounces(a)lists.sip-router.org [mailto:sr-users-bounces@lists.sip-router.org]
Im Auftrag von Alex Balashov
Gesendet: Dienstag, 2. November 2010 14:41
An: sr-users(a)lists.sip-router.org
Betreff: Re: [SR-Users] loop through variables
On 11/02/2010 09:35 AM, Sergey Okhapkin wrote:
htable module should do the trick to you.
On Tuesday 02 November 2010, Bernhard Suttner wrote:
> Hi,
>
> I want something like that:
>
> # define some router to use later in the script (global section)
> Mod_param(router(1), "10.10.10.1")
> mod_param(router(2), "10.10.10.2")
> mod_param(router(3), "10.10.10.3")
> Mod_param(router_count, "3")
>
> within the different routes I want to loop through the routers like that:
>
> $var(i)
> while($(var(i)< $var(router_count)) {
> if ($var(router($var(i)) == src_ip") {
> .. do something
> }
> }
Another option is to push the constants into AVP arrays at startup (I
assume there is some sort of init route at this point, otherwise a
module init event-route):
$(avp(s:routers)[0]) = "10.10.10.1";
$(avp(s:routers)[1]) = "10.10.10.2";
$(avp(s:routers)[2]) = "10.10.10.3";
You can then iterate through them, using is_avp_set() to check if
something exists at the current index/array subscript:
$var(i) = 0;
while(is_avp_set("$(avp(s:routers)[$var(i)])")) {
xlog("L_INFO", "Router is: $(avp(s:routers)[$var(i)])\n";
$var(i) = $var(i) + 1;
}
--
Daniel-Constantin Mierla
http://www.asipto.com