diff --git a/apps/dsm/DSM.cpp b/apps/dsm/DSM.cpp index 7f050b46..fc299a91 100644 --- a/apps/dsm/DSM.cpp +++ b/apps/dsm/DSM.cpp @@ -35,6 +35,7 @@ #include "AmUriParser.h" #include "DSMDialog.h" #include "DSMChartReader.h" +#include "AmSipHeaders.h" #include #include @@ -57,8 +58,9 @@ DSMFactory* DSMFactory::instance() string DSMFactory::InboundStartDiag; string DSMFactory::OutboundStartDiag; -bool DSMFactory::MonSelectUseCaller = true; -bool DSMFactory::MonSelectUseCallee = true; + +MonSelectType DSMFactory::MonSelectCaller; +MonSelectType DSMFactory::MonSelectCallee; map DSMFactory::config; bool DSMFactory::RunInviteEvent; @@ -230,11 +232,29 @@ int DSMFactory::onLoad() SetParamVariables = cfg.getParameter("set_param_variables")=="yes"; - if (cfg.getParameter("monitor_select_use_caller")=="no") - MonSelectUseCaller = false; + string cfg_usecaller = cfg.getParameter("monitor_select_use_caller"); + if (cfg_usecaller.empty() || cfg_usecaller=="from") + MonSelectCaller = MonSelect_FROM; + else if (cfg_usecaller=="no") + MonSelectCaller = MonSelect_NONE; + else if (cfg_usecaller=="pai") + MonSelectCaller = MonSelect_PAI; + else { + ERROR("monitor_select_use_caller value '%s' not understood\n", + cfg_usecaller.c_str()); + } - if (cfg.getParameter("monitor_select_use_callee")=="no") - MonSelectUseCallee = false; + string cfg_usecallee = cfg.getParameter("monitor_select_use_callee"); + if (cfg_usecallee.empty() || cfg_usecallee=="ruri") + MonSelectCallee = MonSelect_RURI; + else if (cfg_usecallee=="no") + MonSelectCallee = MonSelect_NONE; + else if (cfg_usecallee=="from") + MonSelectCallee = MonSelect_FROM; + else { + ERROR("monitor_select_use_callee value '%s' not understood\n", + cfg_usecallee.c_str()); + } return 0; } @@ -296,30 +316,58 @@ AmSession* DSMFactory::onInvite(const AmSipRequest& req) if (InboundStartDiag=="$(mon_select)") { #ifdef USE_MONITORING + if (NULL == MONITORING_GLOBAL_INTERFACE) { + ERROR("using $(mon_select) but monitoring not loaded\n"); + throw AmSession::Exception(488, "Not Acceptable Here"); + } + AmArg di_args, ret; - if (MonSelectUseCaller) { + if (MonSelectCaller != MonSelect_NONE) { AmUriParser from_parser; - from_parser.uri = req.from_uri; + if (MonSelectCaller == MonSelect_FROM) + from_parser.uri = req.from_uri; + else { + size_t end; + string pai = getHeader(req.hdrs, SIP_HDR_P_ASSERTED_IDENTITY); + if (!from_parser.parse_contact(pai, 0, end)) { + ERROR("Failed to parse "SIP_HDR_P_ASSERTED_IDENTITY " '%s'\n", + pai.c_str()); + throw AmSession::Exception(488, "Not Acceptable Here"); + } + } + if (!from_parser.parse_uri()) { - DBG("failed to parse from_uri '%s'\n", req.from_uri.c_str()); + DBG("failed to parse caller uri '%s'\n", from_parser.uri.c_str()); throw AmSession::Exception(488, "Not Acceptable Here"); } - if (NULL == MONITORING_GLOBAL_INTERFACE) { - ERROR("using $(mon_select) but monitoring not loaded\n"); - throw AmSession::Exception(488, "Not Acceptable Here"); - } - AmArg caller_filter; caller_filter.push("caller"); caller_filter.push(from_parser.uri_user); DBG(" && looking for caller=='%s'\n", from_parser.uri_user.c_str()); di_args.push(caller_filter); } - if (MonSelectUseCallee) { + + + if (MonSelectCallee != MonSelect_NONE) { AmArg callee_filter; callee_filter.push("callee"); - callee_filter.push(req.user); + if (MonSelectCallee == MonSelect_RURI) + callee_filter.push(req.user); + else { + AmUriParser to_parser; + size_t end; + if (!to_parser.parse_contact(req.to, 0, end)) { + ERROR("Failed to parse To '%s'\n", req.to.c_str()); + throw AmSession::Exception(488, "Not Acceptable Here"); + } + if (!to_parser.parse_uri()) { + DBG("failed to parse callee uri '%s'\n", to_parser.uri.c_str()); + throw AmSession::Exception(488, "Not Acceptable Here"); + } + callee_filter.push(to_parser.uri_user); + } + DBG(" && looking for callee=='%s'\n", req.user.c_str()); di_args.push(callee_filter); } diff --git a/apps/dsm/DSM.h b/apps/dsm/DSM.h index 6a796ff2..b4fabfb0 100644 --- a/apps/dsm/DSM.h +++ b/apps/dsm/DSM.h @@ -42,6 +42,14 @@ using std::string; #include +enum MonSelectType { + MonSelect_NONE, + MonSelect_RURI, + MonSelect_TO, + MonSelect_FROM, + MonSelect_PAI +}; + class DSMDialog; class DSMModule; /** \brief Factory for announcement sessions */ @@ -56,8 +64,9 @@ class DSMFactory static string InboundStartDiag; static string OutboundStartDiag; - static bool MonSelectUseCaller; - static bool MonSelectUseCallee; + + static MonSelectType MonSelectCaller; + static MonSelectType MonSelectCallee; static DSMFactory* _instance; DSMFactory(const string& _app_name); diff --git a/apps/dsm/etc/dsm.conf b/apps/dsm/etc/dsm.conf index b34092c3..cf8257cf 100644 --- a/apps/dsm/etc/dsm.conf +++ b/apps/dsm/etc/dsm.conf @@ -46,21 +46,27 @@ load_prompts=/usr/local/etc/sems/etc/dsm_in_prompts.conf,/usr/local/etc/sems/etc # #set_param_variables=yes -# monitor_select_use_caller=[yes|no] +# monitor_select_use_caller=[no|from|pai] # # for $(mon_select) application selection from monitoring: -# select application by caller? (caller==remote_uri.user) +# select application by caller? +# from: caller==remote_uri.user (From URI user part) +# pai: caller==P-Asserted-Identity user part +# no: caller not regarded # -# Default:yes +# Default: from # #monitor_select_use_caller=no -# monitor_select_use_callee=[yes|no] +# monitor_select_use_callee=[no|ruri|to] # # for $(mon_select) application selection from monitoring: -# select application by callee? (callee==r_uri.user) +# select application by callee? +# ruri: callee==r_uri.user (request URI user part) +# to: callee==local_uri.user (To URI user part) +# no: callee not regarded # -# Default:yes +# Default: ruri # #monitor_select_use_callee=no