diff --git a/freeswitch/sip_profiles/sipinterface_1.xml b/freeswitch/sip_profiles/sipinterface_1.xml index 987e115..6aa36c6 100644 --- a/freeswitch/sip_profiles/sipinterface_1.xml +++ b/freeswitch/sip_profiles/sipinterface_1.xml @@ -43,7 +43,7 @@ - + diff --git a/kamailio/dispatcher.list b/kamailio/dispatcher.list index d50f425..cf724b4 100644 --- a/kamailio/dispatcher.list +++ b/kamailio/dispatcher.list @@ -1 +1,2 @@ # setit(integer) destination(sip uri) flags (integer, optional) +1 sip:127.0.0.1:11000 0 diff --git a/kamailio/kamailio.cfg b/kamailio/kamailio.cfg index 0152a50..cc770ec 100644 --- a/kamailio/kamailio.cfg +++ b/kamailio/kamailio.cfg @@ -17,9 +17,9 @@ ####### Global Parameters ######### fork = yes -children = 16 -#group = -#user = +children = 25 +group = kamailio +user = kamailio server_signature = no server_header = "Server: Kazoo" user_agent_header = "User-Agent: Kazoo" @@ -48,9 +48,6 @@ listen = tcp:127.0.0.1:5080 listen = udp:127.0.0.1:5080 listen = tcp:127.0.0.1:7000 listen = udp:127.0.0.1:7000 - -#listen = tcp:127.0.0.1:5065 -#listen = udp:127.0.0.1:5065 tos = IPTOS_LOWDELAY ####### TCP Parameters ######### @@ -106,18 +103,16 @@ disable_sctp = yes ####### Modules Section ######## mpath="/usr/lib64/kamailio/modules/" - ####### Flags ####### flags FLAG_INTERNALLY_SOURCED: 1, -# FLAG_ITSP_SOURCED: 2, - FLAG_ASSOCIATE_SERVER: 3, - FLAG_SKIP_NAT_CORRECTION: 4; + FLAG_ASSOCIATE_SERVER: 2, + FLAG_SKIP_NAT_CORRECTION: 3, + FLAG_ASSOCIATE_USER: 4; #!define FLB_NATB 6 #!define FLB_NATSIPPING 7 - ######## Kamailio core extensions module ######## loadmodule "kex.so" @@ -163,19 +158,10 @@ modparam("path", "use_received", 0) ######## Generic Hash Table container in shared memory ######## loadmodule "htable.so" -#modparam("htable", "htable", "associations=>size=14;") -modparam("htable", "htable", "a=>size=10;") - -/* -######## Memcached connector module ######## -loadmodule "memcached.so" -modparam("memcached", "servers", "localhost:11211") -modparam("memcached", "expire", 10800) -modparam("memcached", "mode", 0) -modparam("memcached", "timeout", 10000) -*/ - -######## Module holding Pseudo-Variables ######## +modparam("htable", "htable", "associations=>size=10;") +modparam("htable", "htable", "auth_cache=>size=10;") + +######## Pseudo-Variables module ######## loadmodule "pv.so" ######## Advanced logger module ######## @@ -185,12 +171,9 @@ loadmodule "xlog.so" loadmodule "mi_fifo.so" modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo") -####### Different config utilities ######## -loadmodule "cfgutils.so" - -####### Dispatcher Module Parameters ######## +####### Dispatcher module ######## loadmodule "dispatcher.so" -modparam("dispatcher", "list_file", "/etc/kazoo/kamailio/dispatcher.list") +modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list") modparam("dispatcher", "flags", 2) modparam("dispatcher", "use_default", 0) modparam("dispatcher", "force_dst", 1) @@ -208,35 +191,36 @@ modparam("dispatcher", "ds_probing_threshhold", 3) modparam("dispatcher", "ds_probing_mode", 1) modparam("dispatcher", "ds_ping_reply_codes", "501,403,404,400,200") -######## Uac_redirect ######## +######## UAC Redirection module ######## loadmodule "uac_redirect.so" - -####### db_kazoo registrar modules ########## +####### Kazoo Integration module ########## loadmodule "db_kazoo.so" +# FIXME: uncomment the next line and set the correct hostname that should be advertised to Kazoo +#modparam("db_kazoo", "node_hostname", "kamailio.kazoo.com") +# If you want a certain fs_path to be sent Kazoo, uncomment the next line and set the right value +#modparam("db_kazoo", "register_fs_path", "127.0.0.1:5060") + +####### Authentication Interface module ########## loadmodule "auth.so" loadmodule "auth_db.so" - -# ----- registrar modules ----- -loadmodule "usrloc.so" -loadmodule "registrar.so" - -modparam("auth_db|usrloc", "db_url", "kazoo://guest:guest@127.0.0.1:5672/callmgr") modparam("auth_db", "use_domain", 1) modparam("auth_db", "version_table", 0) modparam("auth_db", "calculate_ha1", 1) modparam("auth_db", "password_column", "password") modparam("auth_db", "load_credentials", "$avp(password)=password") - -/* enable DB persistency for location entries */ +####### User Location Implementation module ########## +loadmodule "usrloc.so" modparam("usrloc", "db_mode", 1) modparam("usrloc", "db_update_as_insert", 1) modparam("usrloc", "use_domain", 1) modparam("usrloc", "nat_bflag", FLB_NATB) +####### SIP Registrar implementation module ########## +loadmodule "registrar.so" -######## NAT traversal module - signaling functions ######## +######## NAT Traversal module - signaling functions ######## loadmodule "nathelper.so" modparam("nathelper|registrar", "received_avp", "$avp(AVP_RECV_PARAM)") modparam("nathelper", "natping_interval", 30) @@ -246,9 +230,13 @@ modparam("nathelper", "sipping_bflag", FLB_NATSIPPING) modparam("nathelper", "sipping_from", "sip:sipcheck@127.0.0.1") #modparam("nathelper", "natping_socket", "127.0.0.1:5060") +####### Common Module Parameters ########## +modparam("auth_db|usrloc", "db_url", "kazoo://guest:guest@127.0.0.1:5672/callmgr") + ####### Routing Logic ######## -route { +route +{ # log the basic info regarding this call xlog("L_INFO", "$ci|start|recieved $oP request $rm $ou"); xlog("L_INFO", "$ci|log|source $si:$sp"); @@ -257,8 +245,6 @@ route { route(SANITY_CHECK); - route(SET_LOGGING_FLAGS); - route(CLASSIFY_SOURCE); route(HANDLE_OPTIONS); @@ -280,7 +266,8 @@ route { route(EXTERNAL_TO_INTERNAL_RELAY); } -route[SANITY_CHECK] { +route[SANITY_CHECK] +{ if (!mf_process_maxfwd_header("10")) { xlog("L_WARN", "$ci|end|max-forward limit reached"); sl_send_reply("483", "Too Many Hops"); @@ -293,43 +280,19 @@ route[SANITY_CHECK] { } } -route[SET_LOGGING_FLAGS] { - return(); -} - route[CLASSIFY_SOURCE] { - if (ds_is_from_list("1") || ds_is_from_list("3")) - { + if (ds_is_from_list("1") || ds_is_from_list("3")) { xlog("L_INFO", "$ci|log|originated from internal sources"); setflag(FLAG_INTERNALLY_SOURCED); - } - else - { + } else { xlog("L_INFO", "$ci|log|originated from external sources"); } } -/* -route[CLASSIFY_SOURCE] { - switch($mct($si)) { - case "itsp": - xlog("L_INFO", "$ci|log|message is from ITSP"); - setflag(FLAG_ITSP_SOURCED); - break; - case "kazoo": - xlog("L_INFO", "$ci|log|message is from KAZOO"); - setflag(FLAG_INTERNALLY_SOURCED); - break; - default: - xlog("L_INFO", "$ci|log|message is from an unknown source"); - break; - } -} -*/ - -route[HANDLE_OPTIONS] { +route[HANDLE_OPTIONS] +{ if (is_method("OPTIONS")) { if (isflagset(FLAG_INTERNALLY_SOURCED)) { route(INTERNAL_TO_EXTERNAL_RELAY); @@ -340,33 +303,21 @@ route[HANDLE_OPTIONS] { } } -# Called on in-dialog requests -# If the request in an Invite for on hold from external to internal, -# associate the contact with the media server -route[MAYBE_ASSOCIATE_USER] { - # if Invite for on hold, we need to associate the contact URI with the next hop - - if (is_method("INVITE") && !isflagset(FLAG_INTERNALLY_SOURCED) && is_audio_on_hold()) { - $var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host}); - xlog("L_INFO", "$ci|log|associate user $var(contact_uri):$si:$sp with media server $du\n"); - $sht(associations=>$var(contact_uri))= $du; - } - -} - -route[HANDLE_IN_DIALOG_REQUESTS] { +route[HANDLE_IN_DIALOG_REQUESTS] +{ if (has_totag()) { if (loose_route()) { xlog("L_INFO", "$ci|log|loose_route in-dialog message"); - - route(MAYBE_ASSOCIATE_USER); - + # Called on in-dialog requests + # If the request in an Invite for on hold from external to internal, + # associate the contact with the media server + # if Invite for on hold, we need to associate the contact URI with the next hop + if (is_method("INVITE") && !isflagset(FLAG_INTERNALLY_SOURCED) && is_audio_on_hold()) { + setflag(FLAG_ASSOCIATE_USER); + } route(RELAY); } else if (isflagset(FLAG_INTERNALLY_SOURCED)) { xlog("L_INFO", "$ci|log|relay internally sourced in-dialog message without loose_route"); - if(is_method("INVITE")) { - xlog("L_INFO", "$ci|log|re-associate $ci with media server $si:$sp"); - } route(RELAY); } else if (t_check_trans()) { xlog("L_INFO", "$ci|log|allow message for a known transaction"); @@ -379,7 +330,8 @@ route[HANDLE_IN_DIALOG_REQUESTS] { } } - route[PREPARE_INITIAL_REQUESTS] { +route[PREPARE_INITIAL_REQUESTS] +{ if (is_method("CANCEL")) { if (t_check_trans()) { route(RELAY); @@ -402,73 +354,43 @@ route[HANDLE_IN_DIALOG_REQUESTS] { } if (is_method("REGISTER")) { - - if (nat_uac_test("3")) { - xlog("L_INFO", "Nated contact\n"); -# setflag(FLB_NATSIPPING); - force_rport(); - setbflag(FLB_NATB); - setbflag(FLB_NATSIPPING); - - fix_nated_register(); - } - # authenticate requests - # check iif we have the password in cache - if ( is_present_hf("Authorization") ) { - if ( $sht(a=>$Au) != $null ) { - xlog("L_INFO", "Found stored password for $Au, $sht(a=>$Au)\n"); - if (!pv_auth_check("$fd", "$sht(a=>$Au)", "0", "0")) { - xlog("L_INFO", "Authentication did not work with stored password\n"); - - ## RABBITMQ - Credentials fetch - if (!auth_check("$fd", "subscriber", "1")) { - auth_challenge("$fd", "0"); - exit; - } else { - xlog("Credential fetch $avp(password)\n"); - # xlog("au=$au, ad = $ad, aU=$aU, Au= $Au\n"); - $sht(a=>$Au) = $avp(password); - } - } - } else { - ## RABBITMQ - Credentials fetch - if (!auth_check("$fd", "subscriber", "1")) { - auth_challenge("$fd", "0"); - exit; - } else { - xlog("L_INFO", "Credential fetch $avp(password)\n"); - # xlog("au=$Au, ad = $ad, aU=$aU, Au= $Au\n"); - $sht(a=>$Au) = $avp(password); - } - } - } else { - auth_challenge("$fd", "0"); - exit; - } - - - # user authenticated - remove auth header - consume_credentials(); - -# if (!add_path_received()) { - # sl_send_reply("503", "Internal path befuddlement"); - # # route(CLEANUP_DIALOG); - # exit(); - # } - - save("location"); - exit; - /* - if (is_method("REGISTER")) { - if (!add_path_received()) { - sl_send_reply("503", "Internal path befuddlement"); - # route(CLEANUP_DIALOG); - exit(); + if (is_present_hf("Authorization")) { + if ($sht(auth_cache=>$Au) != $null && pv_auth_check("$fd", "$sht(auth_cache=>$Au)", "0", "0")) { + xlog("L_INFO", "$ci|log|Authenticated $Au via cached SIP creds\n"); + } else { + ## RABBITMQ - Credentials fetch + if (!auth_check("$fd", "subscriber", "1")) { + auth_challenge("$fd", "0"); + xlog("L_INFO", "$ci|log|Issued new auth challenge to failed registration attempt\n"); + exit; + } else { + xlog("$ci|log|Caching SIP credentials for $Au\n"); + $sht(auth_cache=>$Au) = $avp(password); + } + } + } else { + auth_challenge("$fd", "0"); + xlog("L_INFO", "$ci|log|Issued new auth challenge to new registration attempt\n"); + exit; } - */ - } else { - if (!is_method("MESSAGE")) - record_route(); + + # user authenticated - remove auth header + consume_credentials(); + + if (nat_uac_test("3")) { + xlog("L_INFO", "$ci|log|Correcting NATed contact in registration\n"); + force_rport(); + + setbflag(FLB_NATB); + setbflag(FLB_NATSIPPING); + + fix_nated_register(); + } + + save("location"); + exit; + } else if (!is_method("MESSAGE")) { + record_route(); } } @@ -476,127 +398,85 @@ route[HANDLE_IN_DIALOG_REQUESTS] { # If prefered route defined, reorder the destionations route[FIND_ROUTES] { - if (is_method("REGISTER")) - { - # alg 2 = hash(To URI) - # To URI is actually AOR - to help with nounce reusage at reRegister - if (!ds_select_dst("3", "2") && !ds_select_dst("1", "2")) - { - xlog("L_ERR", "$ci|end|no servers avaliable"); + # alg 0 = hash(Callid) + if (!ds_select_dst("1", "0")) { + xlog("L_ERR", "$ci|end|no servers avaliable"); - sl_send_reply("480", "All servers busy"); + sl_send_reply("480", "All servers busy"); - exit; - } + exit; } - else - { - # alg 0 = hash(Callid) - if (!ds_select_dst("1", "0")) - { - xlog("L_ERR", "$ci|end|no servers avaliable"); - - sl_send_reply("480", "All servers busy"); - - exit; - } - - # Handle the case when a prefered route is set - $var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host}); - if ($sht(associations=>$var(contact_uri)) != $null) - { - $var(prefered_route) = $sht(associations=>$var(contact_uri)); + # Handle the case when a prefered route is set + $var(contact_uri) = @from.uri.user + "@" + @from.uri.host; + if ($sht(associations=>$var(contact_uri)) != $null) { + $var(prefered_route) = $sht(associations=>$var(contact_uri)); - xlog("L_INFO", "$ci|log|should route to $var(prefered_route)"); - - route(REORDER_ROUTES); - } + xlog("L_INFO", "$ci|log|should route to $var(prefered_route)"); + route(REORDER_ROUTES); } } -route[REORDER_ROUTES] { - # if the dispatcher list does not start with - # the the prefered route, reorder the list so that it does - - if ($(avp(ds_dst)[0]) != $var(prefered_route)) - { - # create a index var for our loop (arrays are start at 0 and this is a count) - $var(i) = $avp(ds_cnt) - 1; - - # loop over the dispatcher list - while($var(i) > 0) - { - # if this element in the dispatch list is the same - # as the call destination - if($(avp(ds_dst)[$var(i)]) == $var(prefered_route)) - { - # replace it with the first element of the list - $(avp(ds_dst)[$(var(i))]) = $(avp(ds_dst)[0]); - - # break out of the loop - $var(i) = -1; - } - - $var(i) = $var(i) - 1; +route[REORDER_ROUTES] +{ + $var(i) = 0; + $var(found) = 0; + while($(avp(ds_dst)[$var(i)]) != $null) { + if($(avp(ds_dst)[$var(i)]) != $var(prefered_route)) { + $avp(tmp_ds_dst) = $(avp(ds_dst)[$var(i)]); + } else { + $var(found) = 1; } - # handles the case were we only have two servers - # and the one that we are locked to has failed - if ($var(i) >= 0) - { + $var(i) = $var(i) + 1; + } + + if ($var(found)) { + xlog("L_INFO", "$ci|log|re-ordering the dispatcher list to keep associated server first"); - xlog("L_INFO", "$ci|log|associated media server is inactive, moving to $rd"); + $(avp(ds_dst)[*]) = $null; - $sht(associations=>$var(contact_uri)) = "sip:$rd:$rp"; + $var(i) = 0; + while($(avp(tmp_ds_dst)[$var(i)]) != $null) { + $avp(ds_dst) = $(avp(tmp_ds_dst)[$var(i)]); - xlog("L_INFO", "$ci|log|associated contact $var(contact_uri) with media server sip:$rd:$rp"); + $var(i) = $var(i) + 1; } - # the server we are locked to is in the active server list from then - # dispatcher so re-arrange the list to try it first - else - { - xlog("L_INFO", "$ci|log|re-ordering the dispatcher list to keep associated server first"); + $avp(ds_dst) = $var(prefered_route); + $du = $var(prefered_route); - # set the first element of the list to the destination - $(avp(ds_dst)[0]) = $var(prefered_route); - - # set the domain for this request (server IP to route to) - $rd = $(var(prefered_route){uri.host}); + $(avp(tmp_ds_dst)[*]) = $null; + } else { + xlog("L_INFO", "$ci|log|associated media server is inactive, moving to $rd"); - # set the port for this request (server IP to route to) - $rp = $(var(prefered_route){uri.port}); - } + $sht(associations=>$var(contact_uri)) = $null; } } - - - route[HANDLE_MOVE_REQUEST] { - if (is_method("INVITE") && $rU == "*6683*" && $sht(associations=>$var(contact_uri)) != $null ) - { - $var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host}); + if (is_method("INVITE") && $rU == "*6683*") { + $var(contact_uri) = @from.uri.user + "@" + @from.uri.host; - xlog("L_INFO", "$ci|log|remove association for user $var(contact_uri):$si:$sp - with media server $sht(associations=>$var(contact_uri))\n"); + if ($sht(associations=>$var(contact_uri)) != $null) { + xlog("L_INFO", "$ci|log|remove association for user $var(contact_uri) + with media server $sht(associations=>$var(contact_uri))\n"); - $sht(associations=>$var(contact_uri))= $null; + $sht(associations=>$var(contact_uri)) = $null; + } - # TODO - does the test expect smth like $rd:$rp as reason? send_reply("503", "Removed association"); + + xlog("L_INFO", "$ci|log|removed association for user $var(contact_uri) + with media server $sht(associations=>$var(contact_uri))\n"); exit; } } -route[RELAY] { -# if (is_method("CANCEL") || is_method("BYE")) { -# route(CLEANUP_DIALOG); -# } - +route[RELAY] +{ if (isflagset(FLAG_INTERNALLY_SOURCED)) { route(INTERNAL_TO_EXTERNAL_RELAY); } else { @@ -606,22 +486,19 @@ route[RELAY] { exit(); } -route[INTERNAL_TO_EXTERNAL_RELAY] { +route[INTERNAL_TO_EXTERNAL_RELAY] +{ remove_hf("X-AUTH-IP"); t_on_reply("EXTERNAL_REPLY"); t_set_fr(0, 10000); - route(LOG_DESTINATION); - -# xlog("L_INFO", "$ci|log|associate call-id $ci with sip:$sip:$sp"); -# $sht(associations=>$ci) = "sip:" + $si + ":" + $sp; - t_relay(); } -route[EXTERNAL_TO_INTERNAL_RELAY] { +route[EXTERNAL_TO_INTERNAL_RELAY] +{ if (!isflagset(FLAG_INTERNALLY_SOURCED)) { route(NAT_TEST_AND_CORRECT); } @@ -634,14 +511,11 @@ route[EXTERNAL_TO_INTERNAL_RELAY] { t_set_fr(0, 1000); - route(LOG_DESTINATION); - t_relay(); } - - -route[LOG_DESTINATION] { +route[LOG_DESTINATION] +{ if (isdsturiset()) { $var(port) = $dp; $var(domain) = $dd; @@ -657,7 +531,8 @@ route[LOG_DESTINATION] { xlog("L_INFO", "$ci|pass|$var(domain):$var(port)"); } -route[NAT_TEST_AND_CORRECT] { +route[NAT_TEST_AND_CORRECT] +{ if (is_present_hf("Record-Route")) { $var(i) = $rr_count; while($var(i) > 0) { @@ -685,49 +560,39 @@ route[NAT_TEST_AND_CORRECT] { } } -onreply_route[EXTERNAL_REPLY] { +onreply_route[EXTERNAL_REPLY] +{ xlog("L_INFO", "$ci|log|external reply $T_reply_code"); route(NAT_TEST_AND_CORRECT); - -# if (is_method("INVITE") && t_check_status("200")) { -# $var(user) = $(ct{tobody.user}) + "@" + $(ct{tobody.host}); -# xlog("L_INFO", "$ci|log|associate user $var(user):$si:$sp with media server"); -# $sht(associations=>$var(user)) = $avp(AVP_ASSOCIATED_SERVER); -# } - } - onreply_route[INTERNAL_REPLY] { # this route handles replies that are comming from our media server xlog("L_INFO", "$ci|start|recieved internal reply $T_reply_code $rr"); xlog("L_INFO", "$ci|log|source $si:$sp"); - if ($rs < 300) - { + if ($rs < 300) { xlog("L_INFO", "$ci|pass|$T_req($si):$T_req($sp)"); } # change 6xx to 4xx - if (t_check_status("6[0-9][0-9]")) - { + if (t_check_status("6[0-9][0-9]")) { $var(new_code) = "4" + $(T_reply_code{s.substr,1,0}); change_reply_status("$var(new_code)", "$rr"); } } -failure_route[INTERNAL_FAULT] +failure_route[INTERNAL_FAULT] { # this branch handles failures (>=300) to our media servers, # which we can sometimes overcome by routing to another server # if the failure cause was due to the transaction being # cancelled then we are complete - if (t_is_canceled()) - { + if (t_is_canceled()) { xlog("L_INFO", "$ci|log|transaction was cancelled"); exit; @@ -735,14 +600,11 @@ failure_route[INTERNAL_FAULT] # if the failure case was something that we should recover # from then try to find a new media server - if (t_check_status("(401)|(407)")) - { + if (t_check_status("(401)|(407)")) { xlog("L_INFO", "$ci|log|failure route ignoring auth reply $T_reply_code $rr"); exit; - } - else if (t_check_status("403")) - { + } else if (t_check_status("403")) { xlog("L_INFO", "$ci|log|failure route overriding reply code 403 with 503"); xlog("L_INFO", "$ci|pass|$si:$sp"); @@ -750,9 +612,7 @@ failure_route[INTERNAL_FAULT] send_reply("503", "Error: Services Unavailable. Try Later"); exit; - } - else if (t_check_status("402")) - { + } else if (t_check_status("402")) { xlog("L_INFO", "$ci|log|failure route overriding reply code 402 with 486"); xlog("L_INFO", "$ci|pass|$si:$sp"); @@ -760,14 +620,11 @@ failure_route[INTERNAL_FAULT] send_reply("486", "Insufficient Funds"); exit; - } - else if (t_check_status("(4[0-9][0-9])|(5[0-9][0-9])")) - { + } else if (t_check_status("(4[0-9][0-9])|(5[0-9][0-9])")) { xlog("L_INFO", "$ci|start|received failure reply $T_reply_code $rr"); # try to find a new media server to send the call to - if ($avp(route_attempts) < 3 && ds_next_domain()) - { + if ($avp(route_attempts) < 3 && ds_next_domain()) { xlog("L_INFO", "$ci|log|attempting retry $avp(route_attempts) of failed request"); xlog("L_INFO", "$ci|log|routing call to next media server $rd:$rp"); @@ -782,46 +639,31 @@ failure_route[INTERNAL_FAULT] route(EXTERNAL_TO_INTERNAL_RELAY); $avp(route_attempts) = $avp(route_attempts) + 1; - } - else if (t_check_status("404")) - { + } else if (t_check_status("404")) { xlog("L_ERR", "$ci|log|no other media servers avaliable, sending 486"); send_reply("486", "Not found"); exit; - } - else - { + } else { xlog("L_ERR", "$ci|log|no other media servers avaliable"); exit; } - } - else if (t_check_status("302")) - { + } else if (t_check_status("302")) { ## TODO - test this - get_redirects("*"); - - route(EXTERNAL_TO_INTERNAL_RELAY); - - /* - if( $(hdr(X-Redirect-Server)) && $(ct.fields(uri)) ) - { - $var(redirect_host) = $(hdr(X-Redirect-Server){uri.host}); + ## get_redirects("*"); - $var(redirect_port) = $(hdr(X-Redirect-Server){uri.port}); + if($T_rpl($hdr(X-Redirect-Server)) != $null) { + $var(contact_uri) = @from.uri.user + "@" + @from.uri.host; - cache_store("local", "$(ct.fields(uri))", "sip:$var(redirect_host):$var(redirect_port)", 60); + $sht(associations=>$var(contact_uri)) = $T_rpl($hdr(X-Redirect-Server)); - xlog("L_INFO", "$ci|log|stored redirect mapping for $(ct.fields(uri)) to sip:$var(redirect_host):$var(redirect_port)"); + xlog("L_INFO", "$ci|log|stored redirect mapping for $var(contact_uri) to $T_rpl($hdr(X-Redirect-Server))"); remove_hf("X-Redirect-Server"); } - */ - } - else - { + } else { xlog("L_INFO", "$ci|log|failure route ignoring reply $T_reply_code $rr"); exit; @@ -831,114 +673,13 @@ failure_route[INTERNAL_FAULT] } onsend_route { - xlog("L_INFO", "$ci|pass|$sndfrom(ip):$sndfrom(port) -> $sndto(ip):$sndto(port)"); -} - - -## Not used routes -/* -# Take the routes from memcached -# Write them in an AVP -# Randomize -route[LOAD_KAZOO_ROUTES] { - $var(routes) = $mct(available_kazoo_routes); - route(LOAD_ROUTES); - - $var(randomizer_pos) = $avp(AVP_ROUTE_CNT); - route(RANDOMIZE_ROUTES); - - if (!isflagset(FLAG_ITSP_SOURCED) && is_method("REGISTER|INVITE|SUBSCRIBE")) { - setflag(FLAG_ASSOCIATE_SERVER); - } -} - -route[LOAD_ROUTES] { - if ($var(routes) == $null) { - return(-1); - } - - $var(i) = 0; - $var(route) = $(var(routes){s.select,$var(i),;}); - while($(var(route){s.len}) > 0) { - $var(i) = $var(i) + 1; - $avp($var(i)) = $var(route); - $var(route) = $(var(routes){s.select,$var(i),;}); - } - $avp(AVP_ROUTE_CNT) = $var(i); - - return(1); -} - -# No longer used -route[NEXT_ROUTE] { - if ($avp(AVP_ROUTE_CNT) <= 0) { - return(-1); - } - - $var(domain) = $(avp($avp(AVP_ROUTE_CNT)){uri.host}); - $var(port) = $(avp($avp(AVP_ROUTE_CNT)){uri.port}); - - $avp(AVP_ROUTE_CNT) = $avp(AVP_ROUTE_CNT) - 1; - - if ($(var(domain){s.len}) <= 0) { - route(NEXT_ROUTE); - } - - if ($(var(port){s.len}) <= 4) { - $var(port) = "5060"; - } - - $du = "sip:" + $var(domain) + ":" + $var(port); - - xlog("L_INFO", "$ci|log|associate call-id $ci with $du"); - $sht(associations=>$ci) = $du; - - return(1); -} - -route[RANDOMIZE_ROUTES] { - if ($var(randomizer_pos) <= 0) { - return(); - } - - $var(random_pos) = ($RANDOM mod $var(randomizer_pos) + 1); - - if ($var(random_pos) != $var(randomizer_pos)) { - $var(route) = $avp($var(randomizer_pos)); - $avp($var(randomizer_pos)) = $avp($var(random_pos)); - $avp($var(random_pos)) = $var(route); - } - - $var(randomizer_pos) = $var(randomizer_pos) - 1; - route(RANDOMIZE_ROUTES); -} - -route[LOG_ROUTES] { - $var(i) = $avp(AVP_ROUTE_CNT); - while($var(i) > 0) { - $var(value) = $avp($var(i)); - xlog("L_INFO", "$ci|log|route $var(i): $var(value)"); - $var(i) = $var(i) - 1; + if (isflagset(FLAG_ASSOCIATE_USER)) { + $var(contact_uri) = @from.uri.user + "@" + @from.uri.host; + xlog("L_INFO", "$ci|log|associate user $var(contact_uri) with media server sip:$sndto(ip):$sndto(port)\n"); + $sht(associations=>$var(contact_uri))= "sip:" + $sndto(ip) + ":" + $sndto(port); } -} -route[CLEANUP_DIALOG] { - xlog("L_INFO", "$ci|log|remove any association for $ci"); - sht_rm_name_re("associations=>$ci"); - return(); + xlog("L_INFO", "$ci|pass|$sndfrom(ip):$sndfrom(port) -> $sndto(ip):$sndto(port)"); } -route[MAYBE_ASSOCIATE_SERVER] { - if (isflagset(FLAG_ASSOCIATE_SERVER) && defined $avp(AVP_ASSOCIATED_SERVER)) { - xlog("L_INFO", "$ci|log|associate call-id $ci with $avp(AVP_ASSOCIATED_SERVER)"); - $sht(associations=>$ci) = $avp(AVP_ASSOCIATED_SERVER); - - if (is_method("INVITE")) { - $var(user) = $(ct{tobody.user}) + "@" + $si; - xlog("L_INFO", "$ci|log|associate user $var(user) with $avp(AVP_ASSOCIATED_SERVER)"); - $sht(associations=>$var(user)) = $avp(AVP_ASSOCIATED_SERVER); - } - } -} -*/ ## vim:set tabstop=4 softtabstop=4 shiftwidth=4 expandtab