Thanks for the feedback. Corey, thanks for the work on the library.

Meanwhile I implemented the workaround: let Kamailio forward the request to an Asterisk server which does the lookup and responds with a 302 redirect to (Transfer()) the proper Asterisk server.

Using SIP for the query has the advantage that the query is handled asynchronous inside Kamailio. For INVITEs it is quite easy (as they are handled in the Asterisk dialplan of the Asterisk server which does the DUNDI query). But it was a bit more complicated than expected as I also have to do the lookups also for REGISTERs, SUBSCRIBE .... Therefore I implemented a "hack" in Kamailio, faking another INVITE transaction while putting the original transcation on hold. (yes there are plenty of hacks you can do in Kamailio).

Basically it works but I have not tested it in detail. If you are interested take a look at the Kamailio config below.

regards
Klaus


dundi.host = "1.2.3.4:5060" desc "Asterisk which performs the DUNDI query. Host:Port" dundi.deftarget = "2.3.4.5:5160" desc "Default Asterisk server if DUNDI lookup failed. Host:Port"


route[RELAY_TO_DUNDI] {
        $var(dundicache) = $sht(dundicache=>$tU);
        if( $var(dundicache) == 0) {
xlogl("L_INFO","$tU not found in cache, quering Dundi-Asterisk for DUNDI lookup...");
                if(t_suspend()) {
# build a new transaction, use From and To URI to store
                        # the transaction identifiers
xlogl("L_INFO","transaction suspended [$T(id_index):$T(id_label)]\n");
                        $uac_req(method)="INVITE";
$uac_req(ruri)="sip:" + $tU + "@" + $sel(cfg_get.dundi.host);
                        $uac_req(furi)="sip:" + $T(id_index) + "@proxy";
                        $uac_req(turi)="sip:" + $T(id_label) + "@proxy";
                        $uac_req(callid)=$(mb{s.md5});
                        uac_req_send();
                        exit;
                } else {
xlogl("L_ERR","Failed to suspend transaction ... 500");
                        send_reply("500","Failed to suspend transaction");
                        exit;
                }
        } else if( $var(dundicache) == "unknown" ) {
xlogl("L_INFO","$tU found in cache but unknown, sending to $(sel(cfg_get.dundi.deftarget))");
                $du="sip:" + $sel(cfg_get.dundi.deftarget);
        } else {
xlogl("L_INFO","$tU found in cache, sending to $var(dundicache)");
                $du="sip:" + $var(dundicache);
        }
        add_contact_alias();

        if (!t_relay()) {
                sl_reply_error();
        }
        exit;
}


event_route [tm:local-request] {
        # Handle locally generated requests
xlogl("L_INFO", "local-request: Routing locally generated $rm to <$ru>:");
        t_on_reply("REPLY_DUNDI");
        # 2 seconds prober timeout
        t_set_fr(0, 2000);
}
onreply_route[REPLY_DUNDI] {
        xlogl("L_INFO","REPLY_DUNDI: response received from $si:");

        $var(index) = $(fU{s.int});
        $var(label) = $(tU{s.int});
        if (t_check_status("3[0-9][0-9]")) {
# this reply route is only executed for DUNDI responses, thus, no need to check the source
                $var(target)= @msg.header.Contact[0].nameaddr.uri.host;
xlogl("L_INFO","REPLY_DUNDI: Tindex=$var(index), Tlabel=$var(label), target=$var(target)");
                $sht(dundicache=>$fU:$tU)=$var(target);
                t_continue("$var(index)", "$var(label)", "AFTER_DUNDI");
        } else {
                xlogl("L_ERR", "Unexpected response from Dundi server");
                t_continue("$var(index)", "$var(label)", "AFTER_DUNDI");
        }

}

route[AFTER_DUNDI] {
xlogl("L_INFO","AFTER_DUNDI: transaction $T(id_index):$T(id_label) continues ....");
        $var(target) = $sht(dundicache=>$T(id_index):$T(id_label));
        if ($(var(target){s.len}) > 1) {
                $du = "sip:" + $var(target);
                $ru = $ou;
xlogl("L_INFO", "Got redirect from Dundi server, target is $ru, sending to $du");
                $sht(dundicache=>$tU)=$var(target);
                r_relay();
                exit;
        } else {
xlogl("L_ERROR","AFTER_DUNDI: no target found ... using default");
                $du="sip:" + $sel(cfg_get.dundi.deftarget);
                $ru = $ou;
                $sht(dundicache=>$tU)="unknown";
                r_relay();
                exit;
        }
        exit;
}






--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
  http://lists.digium.com/mailman/listinfo/asterisk-dev

Reply via email to