[asterisk-commits] rmudgett: branch rmudgett/mcid r253458 - in /team/rmudgett/mcid: ./ channels/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 18 14:25:51 CDT 2010


Author: rmudgett
Date: Thu Mar 18 14:25:48 2010
New Revision: 253458

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=253458
Log:
Implement MCID AMI event from libpri MCID request event.

Modified:
    team/rmudgett/mcid/CHANGES
    team/rmudgett/mcid/channels/sig_pri.c
    team/rmudgett/mcid/channels/sig_pri.h
    team/rmudgett/mcid/configure.ac
    team/rmudgett/mcid/include/asterisk/channel.h
    team/rmudgett/mcid/main/channel.c

Modified: team/rmudgett/mcid/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/mcid/CHANGES?view=diff&rev=253458&r1=253457&r2=253458
==============================================================================
--- team/rmudgett/mcid/CHANGES (original)
+++ team/rmudgett/mcid/CHANGES Thu Mar 18 14:25:48 2010
@@ -323,6 +323,7 @@
    dialing option.  Dial(DAHDI/g1/[extension]/K(<keypad_digits>))
    Access any received keypad digits in SETUP message by: ${CHANNEL(keypad_digits)}
    (requires latest LibPRI)
+ * Added Malicious Call ID (MCID) event to the AMI call event class.
 
 Asterisk Manager Interface
 --------------------------

Modified: team/rmudgett/mcid/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/mcid/channels/sig_pri.c?view=diff&rev=253458&r1=253457&r2=253458
==============================================================================
--- team/rmudgett/mcid/channels/sig_pri.c (original)
+++ team/rmudgett/mcid/channels/sig_pri.c Thu Mar 18 14:25:48 2010
@@ -1450,6 +1450,98 @@
 	return 0;
 }
 
+#if defined(HAVE_PRI_MCID)
+/*!
+ * \internal
+ * \brief Append the given party id to the event string.
+ * \since 1.8
+ *
+ * \param msg Event message string being built.
+ * \param prefix Prefix to add to the party id lines.
+ * \param party Party information to encode.
+ *
+ * \return Nothing
+ */
+static void sig_pri_event_party_id(struct ast_str **msg, const char *prefix, struct ast_party_id *party)
+{
+	ast_str_append(msg, 0, "%s/Presentation: %d (%s)\r\n", prefix,
+		party->number_presentation,
+		ast_named_caller_presentation(party->number_presentation));
+	ast_str_append(msg, 0, "%s/Number: %s\r\n", prefix, S_OR(party->number, ""));
+	ast_str_append(msg, 0, "%s/TON: %d\r\n", prefix, party->number_type);
+	ast_str_append(msg, 0, "%s/Name: %s\r\n", prefix, S_OR(party->name, ""));
+#if defined(HAVE_PRI_SUBADDR)
+	if (party->subaddress.valid) {
+		static const char subaddress[] = "Subaddress";
+
+		ast_str_append(msg, 0, "%s/%s: %s\r\n", prefix, subaddress,
+			S_OR(party->subaddress.str, ""));
+		ast_str_append(msg, 0, "%s/%s/Type: %d\r\n", prefix, subaddress,
+			party->subaddress.type);
+		ast_str_append(msg, 0, "%s/%s/Odd: %d\r\n", prefix, subaddress,
+			party->subaddress.odd_even_indicator);
+	}
+#endif	/* defined(HAVE_PRI_SUBADDR) */
+}
+#endif	/* defined(HAVE_PRI_MCID) */
+
+#if defined(HAVE_PRI_MCID)
+/*!
+ * \internal
+ * \brief Handle the MCID event.
+ * \since 1.8
+ *
+ * \param pri sig_pri PRI control structure.
+ * \param mcid MCID event parameters.
+ * \param owner Asterisk channel associated with the call.
+ * NULL if Asterisk no longer has the ast_channel struct.
+ *
+ * \note Assumes the pri->lock is already obtained.
+ * \note Assumes the owner channel lock is already obtained if still present.
+ *
+ * \return Nothing
+ */
+static void sig_pri_mcid_event(struct sig_pri_pri *pri, const struct pri_subcmd_mcid_req *mcid, struct ast_channel *owner)
+{
+	struct ast_channel *chans[1];
+	struct ast_str *msg;
+	struct ast_party_id party;
+
+	msg = ast_str_create(4096);
+	if (!msg) {
+		return;
+	}
+
+	if (owner) {
+		/* The owner channel is present. */
+		ast_str_append(&msg, 0, "Channel: %s\r\n", owner->name);
+		ast_str_append(&msg, 0, "UniqueID: %s\r\n", owner->uniqueid);
+
+		sig_pri_event_party_id(&msg, "CallerID", &owner->connected.id);
+	} else {
+		/*
+		 * Since we no longer have an owner channel,
+		 * we have to use the caller information supplied by libpri.
+		 */
+		ast_party_id_init(&party);
+		sig_pri_party_id_convert(&party, &mcid->originator, pri);
+		sig_pri_event_party_id(&msg, "CallerID", &party);
+		ast_party_id_free(&party);
+	}
+
+	/* Always use libpri's called party information. */
+	ast_party_id_init(&party);
+	sig_pri_party_id_convert(&party, &mcid->answerer, pri);
+	sig_pri_event_party_id(&msg, "Called", &party);
+	ast_party_id_free(&party);
+
+	chans[0] = owner;
+	ast_manager_event_multichan(EVENT_FLAG_CALL, "MCID", owner ? 1 : 0, chans, "%s",
+		ast_str_buffer(msg));
+	ast_free(msg);
+}
+#endif	/* defined(HAVE_PRI_MCID) */
+
 /*!
  * \internal
  * \brief Obtain the sig_pri owner channel lock if the owner exists.
@@ -1652,6 +1744,21 @@
 			}
 			break;
 #endif	/* defined(HAVE_PRI_CALL_REROUTING) */
+#if defined(HAVE_PRI_MCID)
+		case PRI_SUBCMD_MCID_REQ:
+			sig_pri_lock_owner(pri, chanpos);
+			owner = pri->pvts[chanpos]->owner;
+			sig_pri_mcid_event(pri, &subcmd->u.mcid_req, owner);
+			if (owner) {
+				ast_channel_unlock(owner);
+			}
+			break;
+#endif	/* defined(HAVE_PRI_MCID) */
+#if defined(HAVE_PRI_MCID)
+		case PRI_SUBCMD_MCID_RSP:
+			/* Ignore for now. */
+			break;
+#endif	/* defined(HAVE_PRI_MCID) */
 		default:
 			ast_debug(2,
 				"Unknown call subcommand(%d) in %s event on channel %d/%d on span %d.\n",
@@ -3965,8 +4072,14 @@
 		}
 #endif
 	}
+
 	/* Assume primary is the one we use */
 	pri->pri = pri->dchans[0];
+
+#if defined(HAVE_PRI_MCID)
+	pri_mcid_enable(pri->pri, 1);
+#endif	/* defined(HAVE_PRI_MCID) */
+
 	pri->resetpos = -1;
 	if (ast_pthread_create_background(&pri->master, NULL, pri_dchannel, pri)) {
 		for (i = 0; i < NUM_DCHANS; i++) {

Modified: team/rmudgett/mcid/channels/sig_pri.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/mcid/channels/sig_pri.h?view=diff&rev=253458&r1=253457&r2=253458
==============================================================================
--- team/rmudgett/mcid/channels/sig_pri.h (original)
+++ team/rmudgett/mcid/channels/sig_pri.h Thu Mar 18 14:25:48 2010
@@ -29,6 +29,10 @@
 #include "asterisk/frame.h"
 #include <libpri.h>
 #include <dahdi/user.h>
+#if defined(PRI_SUBCMD_MCID_REQ)
+/* BUGBUG the HAVE_PRI_MCID line is to be removed when the mcid branch is merged to trunk and the configure script is updated. */
+#define HAVE_PRI_MCID 1
+#endif	/* defined(PRI_SUBCMD_MCID_REQ) */
 
 enum sig_pri_tone {
 	SIG_PRI_TONE_RINGTONE = 0,

Modified: team/rmudgett/mcid/configure.ac
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/mcid/configure.ac?view=diff&rev=253458&r1=253457&r2=253458
==============================================================================
--- team/rmudgett/mcid/configure.ac (original)
+++ team/rmudgett/mcid/configure.ac Thu Mar 18 14:25:48 2010
@@ -335,6 +335,7 @@
 AST_EXT_LIB_SETUP([POPT], [popt], [popt])
 AST_EXT_LIB_SETUP([PORTAUDIO], [PortAudio], [portaudio])
 AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pri])
+AST_EXT_LIB_SETUP_DEPENDENT([PRI_MCID], [ISDN PRI Malicious Call ID], [PRI], [pri])
 AST_EXT_LIB_SETUP_DEPENDENT([PRI_SUBADDR], [ISDN PRI subaddressing], [PRI], [pri])
 AST_EXT_LIB_SETUP_DEPENDENT([PRI_CALL_HOLD], [ISDN PRI call hold], [PRI], [pri])
 AST_EXT_LIB_SETUP_DEPENDENT([PRI_CALL_REROUTING], [ISDN PRI call rerouting and call deflection], [PRI], [pri])
@@ -1529,6 +1530,7 @@
 AST_EXT_LIB_CHECK([PORTAUDIO], [portaudio], [Pa_GetDeviceCount], [portaudio.h])
 
 AST_EXT_LIB_CHECK([PRI], [pri], [pri_connected_line_update], [libpri.h])
+AST_EXT_LIB_CHECK([PRI_MCID], [pri], [pri_mcid_enable], [libpri.h])
 AST_EXT_LIB_CHECK([PRI_SUBADDR], [pri], [pri_sr_set_called_subaddress], [libpri.h])
 AST_EXT_LIB_CHECK([PRI_CALL_HOLD], [pri], [pri_hold_enable], [libpri.h])
 AST_EXT_LIB_CHECK([PRI_CALL_REROUTING], [pri], [pri_reroute_enable], [libpri.h])

Modified: team/rmudgett/mcid/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/mcid/include/asterisk/channel.h?view=diff&rev=253458&r1=253457&r2=253458
==============================================================================
--- team/rmudgett/mcid/include/asterisk/channel.h (original)
+++ team/rmudgett/mcid/include/asterisk/channel.h Thu Mar 18 14:25:48 2010
@@ -2442,6 +2442,24 @@
 void ast_party_subaddress_free(struct ast_party_subaddress *doomed);
 
 /*!
+ * \brief Initialize the given party id structure.
+ *
+ * \param init Party id structure to initialize.
+ *
+ * \return Nothing
+ */
+void ast_party_id_init(struct ast_party_id *init);
+
+/*!
+ * \brief Destroy the party id contents
+ *
+ * \param doomed The party id to destroy.
+ *
+ * \return Nothing
+ */
+void ast_party_id_free(struct ast_party_id *doomed);
+
+/*!
  * \since 1.8
  * \brief Initialize the given caller structure.
  *

Modified: team/rmudgett/mcid/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/mcid/main/channel.c?view=diff&rev=253458&r1=253457&r2=253458
==============================================================================
--- team/rmudgett/mcid/main/channel.c (original)
+++ team/rmudgett/mcid/main/channel.c Thu Mar 18 14:25:48 2010
@@ -1537,15 +1537,7 @@
 	}
 }
 
-/*!
- * \internal
- * \brief Initialize the given party id structure.
- *
- * \param init Party id structure to initialize.
- *
- * \return Nothing
- */
-static void ast_party_id_init(struct ast_party_id *init)
+void ast_party_id_init(struct ast_party_id *init)
 {
 	init->number = NULL;
 	init->name = NULL;
@@ -1646,15 +1638,7 @@
 	ast_party_subaddress_set(&dest->subaddress, &src->subaddress);
 }
 
-/*!
- * \internal
- * \brief Destroy the party id contents
- *
- * \param doomed The party id to destroy.
- *
- * \return Nothing
- */
-static void ast_party_id_free(struct ast_party_id *doomed)
+void ast_party_id_free(struct ast_party_id *doomed)
 {
 	if (doomed->number) {
 		ast_free(doomed->number);




More information about the asterisk-commits mailing list