From bcff5928395d3dea747fcef368362bae77fdc895 Mon Sep 17 00:00:00 2001
From: Richard Mudgett <rmudgett@digium.com>
Date: Sat, 18 Jul 2009 04:17:01 +0000
Subject: [PATCH] Merged 207316 from
 https://origsvn.digium.com/svn/asterisk/be/branches/C.2-...

..........
r207316 | rmudgett | 2009-07-17 23:05:05 -0500 (Fri, 17 Jul 2009) | 20 lines

Fixed incoming calls being matched to MSNs without type-of-number prefix added.

For an incoming ISDN call the dialed.number is incorrectly matched against
the configured MSNs in misdn.conf.  The numbers passed to the dialplan
include the configured prefix for the dialed.number_type, whereas the
check against the configured MSNs (to decide if the call is accepted at
all), is executed without the configured prefix.

e.g., dialed.number = 241168020, TON = national, configured national
prefix is "0".  (This is the TON which is used by ISDN providers in the
Netherlands.)

In chan_misdn.c:cb_events() in case EVENT_SETUP the call to
misdn_cfg_is_msn_valid() uses the unnormalized number 241168020, but 57
lines later the call to read_config() adds the prefix, and the
dialed.number is now 0241168020, which is then used in the dialplan.
misdn_cfg_is_msn_valid() must use the normalized number, too.

JIRA ABE-1912


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@207318 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 CHANGES               |  3 ++-
 channels/chan_misdn.c | 23 +++++++++++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/CHANGES b/CHANGES
index 0fa0835fe5..dd6dfe0a5d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -120,7 +120,8 @@ mISDN channel driver (chan_misdn) changes
     used by the rest of the system.
   * Made use the nationalprefix and internationalprefix misdn.conf
     parameters to prefix any received number from the ISDN link if that
-    number has the corresponding Type-Of-Number.
+    number has the corresponding Type-Of-Number.  NOTE:  This includes
+    comparing the incoming call's dialed number against the MSN list.
   * Added the following new parameters: unknownprefix, netspecificprefix,
     subscriberprefix, and abbreviatedprefix in misdn.conf to prefix any
     received number from the ISDN link if that number has the corresponding
diff --git a/channels/chan_misdn.c b/channels/chan_misdn.c
index 3a5a5b4f15..8f9d5fb0b4 100644
--- a/channels/chan_misdn.c
+++ b/channels/chan_misdn.c
@@ -9390,6 +9390,26 @@ static void misdn_facility_ie_handler(enum event_e event, struct misdn_bchannel
 	}
 }
 
+/*!
+ * \internal
+ * \brief Determine if the given dialed party matches our MSN.
+ * \since 1.6.3
+ *
+ * \param port ISDN port
+ * \param dialed Dialed party information of incoming call.
+ *
+ * \retval non-zero if MSN is valid.
+ * \retval 0 if MSN invalid.
+ */
+static int misdn_is_msn_valid(int port, const struct misdn_party_dialing *dialed)
+{
+	char number[sizeof(dialed->number)];
+
+	ast_copy_string(number, dialed->number, sizeof(number));
+	misdn_add_number_prefix(port, dialed->number_type, number, sizeof(number));
+	return misdn_cfg_is_msn_valid(port, number);
+}
+
 /************************************************************/
 /*  Receive Events from isdn_lib  here                     */
 /************************************************************/
@@ -9640,7 +9660,6 @@ cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data)
 	case EVENT_SETUP:
 	{
 		struct chan_list *ch = find_chan_by_bc(cl_te, bc);
-		int msn_valid = misdn_cfg_is_msn_valid(bc->port, bc->dialed.number);
 		struct ast_channel *chan;
 		int exceed;
 		int ai;
@@ -9657,7 +9676,7 @@ cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data)
 			}
 		}
 
-		if (!bc->nt && ! msn_valid) {
+		if (!bc->nt && !misdn_is_msn_valid(bc->port, &bc->dialed)) {
 			chan_misdn_log(1, bc->port, " --> Ignoring Call, its not in our MSN List\n");
 			return RESPONSE_IGNORE_SETUP; /*  Ignore MSNs which are not in our List */
 		}
-- 
GitLab