From 8aa9fac0e338e76643fcf856b709914d0f1dc525 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 9 Sep 2019 05:43:50 +0000 Subject: [PATCH] allow header removal when sending to AOR we want to send some headers (default is P-* and R-*) to carriers but not to devices --- kamailio/default.cfg | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index edb4aa7..20d44d2 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -151,6 +151,9 @@ modparam("rr", "enable_full_lr", RR_FULL_LR) modparam("rr", "enable_double_rr", RR_DOUBLE_RR) modparam("rr", "force_send_socket", RR_FORCE_SOCKET) +######## Kamailio dialog module ######## +loadmodule "dialog.so" + ######## Max-Forward processor module ######## loadmodule "maxfwd.so" modparam("maxfwd", "max_limit", 50) @@ -593,6 +596,11 @@ route[PREPARE_INITIAL_REQUESTS] exit(); } + if(is_method("INVITE")) + { + dlg_manage(); + } + if (is_method("UPDATE")) { xlog("L_WARN", "$ci|end|update outside dialog not allowed\n"); send_reply("403", "Dialog does not exist"); @@ -685,6 +693,12 @@ route[INTERNAL_TO_EXTERNAL_RELAY] } #!endif + if (dlg_isflagset(FLT_AOR)) { + if($sel(cfg_get.kazoo.aor_strip_headers) == 1) { + xlog("L_INFO", "$ci|log|INTERNAL TO EXTERNAL AOR REMOVE HDR\n"); + remove_hf_re($sel(cfg_get.kazoo.aor_strip_headers_regex)); + } + } t_on_reply("EXTERNAL_REPLY"); @@ -770,6 +784,13 @@ onreply_route[INTERNAL_REPLY] setflag(FLAG_SESSION_PROGRESS); } + if (dlg_isflagset(FLT_AOR)) { + if($sel(cfg_get.kazoo.aor_strip_headers) == 1) { + xlog("L_INFO", "$ci|log|INTERNAL TO EXTERNAL REPLY AOR REMOVE HDR\n"); + remove_hf_re($sel(cfg_get.kazoo.aor_strip_headers_regex)); + } + } + if ($rs < 300) { xlog("L_INFO", "$ci|pass|$T_req($si):$T_req($sp)\n"); } @@ -880,6 +901,16 @@ onsend_route { } } + +#!trydef STRIP_HEADERS_TO_AOR 1 +#!trydef STRIP_HEADERS_TO_AOR_REGEX "^P-.*|^R-.*" + +kazoo.aor_strip_headers = STRIP_HEADERS_TO_AOR desc "should we remove headers when sending to AOR" +kazoo.aor_strip_headers_regex = STRIP_HEADERS_TO_AOR_REGEX desc "regex used to remove headers before sending to AOR" + +#!trydef AOR_NOT_SUBSCRIBED_APPEND_REASON +#!trydef AOR_NOT_SUBSCRIBED_REASON Reason: Q.850; cause=20;text="Subscriber Absent" + route[ROUTE_TO_AOR] { if ($hdr(X-KAZOO-AOR) == $null) { @@ -887,22 +918,26 @@ route[ROUTE_TO_AOR] } xlog("L_INFO", "$ci|log|using AOR $hdr(X-KAZOO-AOR)\n"); + dlg_setflag(FLT_AOR); if ($hdr(X-KAZOO-INVITE-FORMAT) == "contact") { if(lookup("location", "$hdr(X-KAZOO-AOR)") > 0){ xlog("L_INFO", "$ci|end|routing to contact $ru\n"); + $avp(aor) = $hdr(X-KAZOO-AOR); handle_ruri_alias(); } else { xlog("L_INFO", "$ci|end|lookup for AOR $hdr(X-KAZOO-AOR) failed\n"); - sl_send_reply("410", "Not registered"); + append_to_reply("$def(AOR_NOT_SUBSCRIBED_REASON)\r\n"); + sl_send_reply("480", "Not registered"); exit; } } else if (reg_fetch_contacts("location", "$hdr(X-KAZOO-AOR)", "callee")) { $du = $(ulc(callee=>received)); $fs = $(ulc(callee=>socket)); xlog("L_INFO", "$ci|log|routing $hdr(X-KAZOO-AOR) to $du via $fs\n"); - + $avp(aor) = $hdr(X-KAZOO-AOR); } else { xlog("L_INFO", "$ci|end|user is not registered\n"); + append_to_reply("$def(AOR_NOT_SUBSCRIBED_REASON)\r\n"); sl_send_reply("410", "Not registered"); exit; }