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 } }
Is that somehow possible?
Any hint or idea is appreciated!
Best regards, Bernhard Suttner
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 } }
Is that somehow possible?
Any hint or idea is appreciated!
Best regards, Bernhard Suttner
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
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; }
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?
Best regards, Bernhard
-----Ursprüngliche Nachricht----- Von: sr-users-bounces@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@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; }
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@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@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; }
On 11/02/2010 12:01 PM, Daniel-Constantin Mierla wrote:
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).
That is true. I forgot about that. That still means he could insert the IPs in backward order, though, doesn't it?
On 11/2/10 5:13 PM, Alex Balashov wrote:
On 11/02/2010 12:01 PM, Daniel-Constantin Mierla wrote:
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).
That is true. I forgot about that. That still means he could insert the IPs in backward order, though, doesn't it?
yes, it inserts them in backward order.
Cheers, Daniel
Hi,
thanks @ all. I will try out the AVP method.
Best regards, Bernhard
-----Ursprüngliche Nachricht----- Von: Daniel-Constantin Mierla [mailto:miconda@gmail.com] Gesendet: Dienstag, 2. November 2010 17:16 An: Alex Balashov Cc: Bernhard Suttner; sr-users@lists.sip-router.org Betreff: Re: [SR-Users] loop through variables
On 11/2/10 5:13 PM, Alex Balashov wrote:
On 11/02/2010 12:01 PM, Daniel-Constantin Mierla wrote:
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).
That is true. I forgot about that. That still means he could insert the IPs in backward order, though, doesn't it?
yes, it inserts them in backward order.
Cheers, Daniel
On 11/2/10 5:52 PM, Bernhard Suttner wrote:
Hi,
thanks @ all. I will try out the AVP method.
beware that normally the avps are persistent per transaction. Meaning that when the transaction processing (or the message in stateless mode) is done, avps are removed automatically.
There are global avps coming from ser 2.0 (therefore you have to use version 3.0+) where the name has to contain 'g.' prefix - $avp(g.foo)
Cheers, Daniel
Best regards, Bernhard
-----Ursprüngliche Nachricht----- Von: Daniel-Constantin Mierla [mailto:miconda@gmail.com] Gesendet: Dienstag, 2. November 2010 17:16 An: Alex Balashov Cc: Bernhard Suttner; sr-users@lists.sip-router.org Betreff: Re: [SR-Users] loop through variables
On 11/2/10 5:13 PM, Alex Balashov wrote:
On 11/02/2010 12:01 PM, Daniel-Constantin Mierla wrote:
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).
That is true. I forgot about that. That still means he could insert the IPs in backward order, though, doesn't it?
yes, it inserts them in backward order.
Cheers, Daniel
Ok. Thx. And where could I add the global variables (the configured routers)? I would like to have them in the global section (like the mod_param).
-----Ursprüngliche Nachricht----- Von: Daniel-Constantin Mierla [mailto:miconda@gmail.com] Gesendet: Dienstag, 2. November 2010 17:57 An: Bernhard Suttner Cc: sr-users@lists.sip-router.org Betreff: Re: [SR-Users] loop through variables
On 11/2/10 5:52 PM, Bernhard Suttner wrote:
Hi,
thanks @ all. I will try out the AVP method.
beware that normally the avps are persistent per transaction. Meaning that when the transaction processing (or the message in stateless mode) is done, avps are removed automatically.
There are global avps coming from ser 2.0 (therefore you have to use version 3.0+) where the name has to contain 'g.' prefix - $avp(g.foo)
Cheers, Daniel
Best regards, Bernhard
-----Ursprüngliche Nachricht----- Von: Daniel-Constantin Mierla [mailto:miconda@gmail.com] Gesendet: Dienstag, 2. November 2010 17:16 An: Alex Balashov Cc: Bernhard Suttner; sr-users@lists.sip-router.org Betreff: Re: [SR-Users] loop through variables
On 11/2/10 5:13 PM, Alex Balashov wrote:
On 11/02/2010 12:01 PM, Daniel-Constantin Mierla wrote:
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).
That is true. I forgot about that. That still means he could insert the IPs in backward order, though, doesn't it?
yes, it inserts them in backward order.
Cheers, Daniel
The module permissions with the function allow_source_address is exactly what I want to do. Check where the call is coming from and do something special to it. Thanks a lot for that great module (and of course to 3.1 and to the nice help which I got here :-)
Best regards, Bernhard
-----Ursprüngliche Nachricht----- Von: Daniel-Constantin Mierla [mailto:miconda@gmail.com] Gesendet: Dienstag, 2. November 2010 17:57 An: Bernhard Suttner Cc: sr-users@lists.sip-router.org Betreff: Re: [SR-Users] loop through variables
On 11/2/10 5:52 PM, Bernhard Suttner wrote:
Hi,
thanks @ all. I will try out the AVP method.
beware that normally the avps are persistent per transaction. Meaning that when the transaction processing (or the message in stateless mode) is done, avps are removed automatically.
There are global avps coming from ser 2.0 (therefore you have to use version 3.0+) where the name has to contain 'g.' prefix - $avp(g.foo)
Cheers, Daniel
Best regards, Bernhard
-----Ursprüngliche Nachricht----- Von: Daniel-Constantin Mierla [mailto:miconda@gmail.com] Gesendet: Dienstag, 2. November 2010 17:16 An: Alex Balashov Cc: Bernhard Suttner; sr-users@lists.sip-router.org Betreff: Re: [SR-Users] loop through variables
On 11/2/10 5:13 PM, Alex Balashov wrote:
On 11/02/2010 12:01 PM, Daniel-Constantin Mierla wrote:
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).
That is true. I forgot about that. That still means he could insert the IPs in backward order, though, doesn't it?
yes, it inserts them in backward order.
Cheers, Daniel
Bernhard Suttner writes:
# 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 } }
Is that somehow possible?
Any hint or idea is appreciated!
check if htable module would help you.
-- juha