Hello,

using global custom parameters is a bit complex, because they cannot be referred by a dynamic name.

Creating a loop is not possible, you will have to put all the options one after the other, using an if condition to see if it is set, like:

if($sel(cfg_get.asterisk1.bindip)!=$null && $sel(cfg_get.asterisk1.bindip)!="") {
    $var(astip) = $sel(cfg_get.asterisk1.bindip);
    if($sel(cfg_get.asterisk1.bindport)!=$null && $sel(cfg_get.asterisk1.bindport)!="") {
          $var(astport) = $sel(cfg_get.asterisk1.bindport);
    } else {
           $var(astport) = 5060;
   }
   route(REGFWD);
}

Then do the same for asterisk2, ...

The route[REGFWD] has to be updated to use $var(astip) and $var(astport) instead of using $sel(...).

Perhaps i better to use hash table (because you can get the key dynamic) or global avps in this case.

For example with a hash table named ast:

$var(i) = 1;
while($sht(ast=>ip$var(i))!= $null) {
    $var(i) = $var(i) + 1;
    $var(astip) = $sht(ast=>ip$var(i));
    if($sht(ast=>port$var(i))!=$null) {
          $var(astport) = $sht(ast=>port$var(i));
    } else {
           $var(astport) = 5060;
   }
   route(REGFWD);
}

In the hash table 'ast' you need to add pairs like: (ip1, "1.2.3.4"), (port1, "5060"), (ip2, "2.2.3.4"), (port2, "5060"), ...

More about hash tables in config in the readme of htable module.

Cheers,
Daniel

On 15/08/14 11:29, ANTHONY HESNAUX wrote:
hello everybody,

I would like loop in kamailio.cfg because I want register soft phone on all asterisk system so I have this configuration

but also if I want add another asterisk system

my Kamailio.cfg

#!define WITH_ASTERISK
#!define WITH_CLUST_AST


#!ifdef WITH_ASTERISK
asterisk.bindip = "asterisk.home.fr" desc "Asterisk IP Address"
asterisk.bindport = "5080" desc "Asterisk Port"
kamailio.bindip = « kamailio.home.fr" desc "kamailio IP Address"
kamailio.bindport = "5060" desc "Kamailio Port"
#!endif

#!ifdef WITH_CLUST_AST
#!define HOST 2
asterisk1.bindip = "192.168.0.10" desc « Asterisk - 1 - IP Address"
asterisk1.bindport = "5080" desc "Asterisk Port"
asterisk2.bindip = "192.168.0.20" desc « Asterisk - 2 - IP Address"
asterisk2.bindport = "5080" desc "Asterisk Port"
#!endif




# Forward REGISTER to Asterisk
route[REGFWD] {
        if(!is_method("REGISTER"))
        {
                return;
        }

        $var(rip) = $sel(cfg_get.asterisk1.bindip);
        $uac_req(method)="REGISTER";
        $uac_req(ruri)="sip:" + $var(rip) + ":" + $sel(cfg_get.asterisk1.bindport);
        $uac_req(furi)="sip:" + $au + "@" + $var(rip);
        $uac_req(turi)="sip:" + $au + "@" + $var(rip);
        $uac_req(hdrs)="Contact: <sip:" + $au + "@"
                                + $sel(cfg_get.kamailio.bindip)
                                + ":" + $sel(cfg_get.kamailio.bindport) + ">\r\n";
        if($sel(contact.expires) != $null)
                $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) + "\r\n";
        else
                $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $hdr(Expires) + "\r\n";
        uac_req_send();

$var(rip) = $sel(cfg_get.asterisk2.bindip);
        $uac_req(method)="REGISTER";
        $uac_req(ruri)="sip:" + $var(rip) + ":" + $sel(cfg_get.asterisk2.bindport);
        $uac_req(furi)="sip:" + $au + "@" + $var(rip);
        $uac_req(turi)="sip:" + $au + "@" + $var(rip);
        $uac_req(hdrs)="Contact: <sip:" + $au + "@"
                                + $sel(cfg_get.kamailio.bindip)
                                + ":" + $sel(cfg_get.kamailio.bindport) + ">\r\n";
        if($sel(contact.expires) != $null)
                $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) + "\r\n";
        else
                $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $hdr(Expires) + "\r\n";
        uac_req_send();

}
#!endif
 

thank you for your help

anthony


_______________________________________________
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

-- 
Daniel-Constantin Mierla
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Next Kamailio Advanced Trainings 2014 - http://www.asipto.com
Sep 22-25, Berlin, Germany