Hello, I 'm new in kamailio.
I have kamailio with dispatcher and two asterisks. Endpoints register to kamailio. Calls beetwen endpoints going through dispatcher to asterisks. Calls to other destination rejected by kamailio with 404. But If i put xlog("AAAA") or xwarn in route[LOCATION] in if (!lookup("location")) block (default kamailio 5.0.2 config) calls to other destination goes through dispatcher to asterisks. I cant't understand WHY? :( (sorry for my bad English)
route[LOCATION] { #!ifdef WITH_SPEEDDIAL # search for short dialing - 2-digit extension if($rU=~"^[0-9][0-9]$") { if(sd_lookup("speed_dial")) { route(SIPOUT); } } #!endif
#!ifdef WITH_ALIASDB # search in DB-based aliases if(alias_db_lookup("dbaliases")) { route(SIPOUT); } #!endif $avp(oexten) = $rU;
if (!lookup("location")) { xwarn("method ($rm) r-uri ($ru)\n"); ################## HERE ########################## $var(rc) = $rc;
route(TOVOICEMAIL); t_newtran(); switch ($var(rc)) { case -1: case -3: send_reply("404", "Not Found"); exit; case -2: send_reply("405", "Method Not Allowed"); exit; } }
# when routing via usrloc, log the missed calls also if (is_method("INVITE")) { setflag(FLT_ACCMISSED); }
if(!ds_is_from_list()) { route(DISPATCH); } route(RELAY); exit; }
Hi Aidar, I believe $rc is the return code of the last function called (ref https://www.kamailio.org/wiki/cookbooks/4.4.x/pseudovariables#rc_-_returned_... https://www.kamailio.org/wiki/cookbooks/4.4.x/pseudovariables#rc_-_returned_code)
In your example you call xwarn() and then test $rc… so by the time you test $rc it is no longer the result of the lookup() function.
Try storing $rc in a $var before calling xwarn() instead and see if it works the way you expect it to:
if (!lookup("location")) { $var(rc) = $rc; xwarn("method ($rm) r-uri ($ru)\n"); ################## HERE ########################## route(TOVOICEMAIL); t_newtran(); switch ($var(rc)) { case -1: case -3: send_reply("404", "Not Found"); exit; case -2: send_reply("405", "Method Not Allowed"); exit; } }
Paul Smith
I understood, thank you! Now I did like that, hope it is right way.
if (!lookup("location")) { $var(rc) = $rc;
switch ($var(rc)) { case -1: xwarn("Contact $rU not registered($var(rc)). Forwarding call to dispatcher"); $rU = "00"+$rU; break; case -3: send_reply("404", "Not Found"); exit; case -2: send_reply("405", "Method Not Allowed"); exit; }
2017-08-04 9:29 GMT+03:00 Paul Smith paul.smith@claritytele.com:
Hi Aidar, I believe $rc is the return code of the last function called (ref https://www.kamailio.org/wiki/cookbooks/4.4.x/ pseudovariables#rc_-_returned_code)
In your example you call xwarn() and then test $rc… so by the time you test $rc it is no longer the result of the lookup() function.
Try storing $rc in a $var before calling xwarn() instead and see if it works the way you expect it to:
if (!lookup("location")) { $var(rc) = $rc; xwarn("method ($rm) r-uri ($ru)\n"); ##################
HERE ##########################
route(TOVOICEMAIL); t_newtran(); switch ($var(rc)) { case -1: case -3: send_reply("404", "Not Found"); exit; case -2: send_reply("405", "Method Not Allowed"); exit; } }
Paul Smith