[asterisk-commits] seanbright: branch seanbright/resolve-shadow-warnings r115071 - in /team/sean...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 1 14:38:06 CDT 2008


Author: seanbright
Date: Thu May  1 14:38:06 2008
New Revision: 115071

URL: http://svn.digium.com/view/asterisk?view=rev&rev=115071
Log:
Merged revisions 115021 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
r115021 | russell | 2008-05-01 15:05:36 -0400 (Thu, 01 May 2008) | 9 lines

Merge changes from team/russell/smdi-msg-searching

This commit adds some new features to the SMDI_MSG_RETRIEVE() dialplan function.
Previously, this function only allowed searching by the forwarding station.
I have added some options to allow you to also search for messages in the queue
by the message desk terminal ID, as well as the message desk number.

This originally came up as a suggestion on the asterisk-dev mailing list.

........

Modified:
    team/seanbright/resolve-shadow-warnings/   (props changed)
    team/seanbright/resolve-shadow-warnings/CHANGES
    team/seanbright/resolve-shadow-warnings/doc/smdi.txt
    team/seanbright/resolve-shadow-warnings/res/res_smdi.c

Propchange: team/seanbright/resolve-shadow-warnings/
------------------------------------------------------------------------------
    automerge = in soviet russia, road forks you!

Propchange: team/seanbright/resolve-shadow-warnings/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu May  1 14:38:06 2008
@@ -1,1 +1,1 @@
-/trunk:1-115020
+/trunk:1-115069

Modified: team/seanbright/resolve-shadow-warnings/CHANGES
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/CHANGES?view=diff&rev=115071&r1=115070&r2=115071
==============================================================================
--- team/seanbright/resolve-shadow-warnings/CHANGES (original)
+++ team/seanbright/resolve-shadow-warnings/CHANGES Thu May  1 14:38:06 2008
@@ -10,6 +10,10 @@
  * Added two new dialplan functions from libspeex for audio gain control and 
    denoise, AGC() and DENOISE(). Both functions can be applied to the tx and 
    rx directions of a channel from the dialplan.
+ * The SMDI_MSG_RETRIEVE function now has the ability to search for SMDI messages
+   based on other parameters.  The default is still to search based on the
+   forwarding station ID.  However, there are new options that allow you to search
+   based on the message desk terminal ID, or the message desk number.
 
 Zaptel channel driver (chan_zap) Changes
 ----------------------------------------

Modified: team/seanbright/resolve-shadow-warnings/doc/smdi.txt
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/doc/smdi.txt?view=diff&rev=115071&r1=115070&r2=115071
==============================================================================
--- team/seanbright/resolve-shadow-warnings/doc/smdi.txt (original)
+++ team/seanbright/resolve-shadow-warnings/doc/smdi.txt Thu May  1 14:38:06 2008
@@ -13,10 +13,10 @@
 
 *CLI> core show function SMDI_MSG_RETRIEVE
 
-  -= Info about function 'SMDI_MSG_RETRIEVE' =-
+  -= Info about function 'SMDI_MSG_RETRIEVE' =- 
 
 [Syntax]
-SMDI_MSG_RETRIEVE(<smdi port>,<station>[,timeout])
+SMDI_MSG_RETRIEVE(<smdi port>,<search key>[,timeout[,options]])
 
 [Synopsis]
 Retrieve an SMDI message.
@@ -29,6 +29,14 @@
 the global SMDI message queue, and can not be accessed by any other Asterisk
 channels.  The timeout for this function is optional, and the default is
 3 seconds.  When providing a timeout, it should be in milliseconds.
+   The default search is done on the forwarding station ID.  However, if
+you set one of the search key options in the options field, you can change
+this behavior.
+   Options:
+     t - Instead of searching on the forwarding station, search on the message
+         desk terminal.
+     n - Instead of searching on the forwarding station, search on the message
+         desk number.
 
 
 *CLI> core show function SMDI_MSG

Modified: team/seanbright/resolve-shadow-warnings/res/res_smdi.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/res/res_smdi.c?view=diff&rev=115071&r1=115070&r2=115071
==============================================================================
--- team/seanbright/resolve-shadow-warnings/res/res_smdi.c (original)
+++ team/seanbright/resolve-shadow-warnings/res/res_smdi.c Thu May  1 14:38:06 2008
@@ -364,8 +364,13 @@
 	return msg;
 }
 
+enum {
+	OPT_SEARCH_TERMINAL = (1 << 0),
+	OPT_SEARCH_NUMBER   = (1 << 1),
+};
+
 static void *smdi_msg_find(struct ast_smdi_interface *iface,
-	enum smdi_message_type type, const char *station)
+	enum smdi_message_type type, const char *search_key, struct ast_flags options)
 {
 	void *msg = NULL;
 
@@ -373,10 +378,35 @@
 
 	switch (type) {
 	case SMDI_MD:
-		msg = ASTOBJ_CONTAINER_FIND(&iface->md_q, station);
+		if (ast_test_flag(&options, OPT_SEARCH_TERMINAL)) {
+			struct ast_smdi_md_message *md_msg = NULL;
+
+			/* Searching by the message desk terminal */
+
+			ASTOBJ_CONTAINER_TRAVERSE(&iface->md_q, !md_msg, do {
+				if (!strcasecmp(iterator->mesg_desk_term, search_key))
+					md_msg = ASTOBJ_REF(iterator);
+			} while (0); );
+
+			msg = md_msg;
+		} else if (ast_test_flag(&options, OPT_SEARCH_NUMBER)) {
+			struct ast_smdi_md_message *md_msg = NULL;
+
+			/* Searching by the message desk number */
+
+			ASTOBJ_CONTAINER_TRAVERSE(&iface->md_q, !md_msg, do {
+				if (!strcasecmp(iterator->mesg_desk_num, search_key))
+					md_msg = ASTOBJ_REF(iterator);
+			} while (0); );
+
+			msg = md_msg;
+		} else {
+			/* Searching by the forwarding station */
+			msg = ASTOBJ_CONTAINER_FIND(&iface->md_q, search_key);
+		}
 		break;
 	case SMDI_MWI:
-		msg = ASTOBJ_CONTAINER_FIND(&iface->mwi_q, station);
+		msg = ASTOBJ_CONTAINER_FIND(&iface->mwi_q, search_key);
 		break;
 	}
 
@@ -384,7 +414,7 @@
 }
 
 static void *smdi_message_wait(struct ast_smdi_interface *iface, int timeout, 
-	enum smdi_message_type type, const char *station)
+	enum smdi_message_type type, const char *search_key, struct ast_flags options)
 {
 	struct timeval start;
 	long diff = 0;
@@ -396,7 +426,7 @@
 
 		lock_msg_q(iface, type);
 
-		if ((msg = smdi_msg_find(iface, type, station))) {
+		if ((msg = smdi_msg_find(iface, type, search_key, options))) {
 			unlock_msg_q(iface, type);
 			return msg;
 		}
@@ -410,7 +440,7 @@
 
 		ast_cond_timedwait(&iface->md_q_cond, &iface->md_q_lock, &ts);
 
-		if ((msg = smdi_msg_find(iface, type, station))) {
+		if ((msg = smdi_msg_find(iface, type, search_key, options))) {
 			unlock_msg_q(iface, type);
 			return msg;
 		}
@@ -431,7 +461,8 @@
 
 struct ast_smdi_md_message *ast_smdi_md_message_wait(struct ast_smdi_interface *iface, int timeout)
 {
-	return smdi_message_wait(iface, timeout, SMDI_MD, NULL);
+	struct ast_flags options = { 0 };
+	return smdi_message_wait(iface, timeout, SMDI_MD, NULL, options);
 }
 
 struct ast_smdi_mwi_message *ast_smdi_mwi_message_pop(struct ast_smdi_interface *iface)
@@ -441,13 +472,15 @@
 
 struct ast_smdi_mwi_message *ast_smdi_mwi_message_wait(struct ast_smdi_interface *iface, int timeout)
 {
-	return smdi_message_wait(iface, timeout, SMDI_MWI, NULL);
+	struct ast_flags options = { 0 };
+	return smdi_message_wait(iface, timeout, SMDI_MWI, NULL, options);
 }
 
 struct ast_smdi_mwi_message *ast_smdi_mwi_message_wait_station(struct ast_smdi_interface *iface, int timeout,
 	const char *station)
 {
-	return smdi_message_wait(iface, timeout, SMDI_MWI, station);
+	struct ast_flags options = { 0 };
+	return smdi_message_wait(iface, timeout, SMDI_MWI, station, options);
 }
 
 struct ast_smdi_interface *ast_smdi_interface_find(const char *iface_name)
@@ -1039,14 +1072,21 @@
 /*! In milliseconds */
 #define SMDI_RETRIEVE_TIMEOUT_DEFAULT 3000
 
+AST_APP_OPTIONS(smdi_msg_ret_options, BEGIN_OPTIONS
+	AST_APP_OPTION('t', OPT_SEARCH_TERMINAL),
+	AST_APP_OPTION('n', OPT_SEARCH_NUMBER),
+END_OPTIONS );
+
 static int smdi_msg_retrieve_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
 	struct ast_module_user *u;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(port);
-		AST_APP_ARG(station);
+		AST_APP_ARG(search_key);
 		AST_APP_ARG(timeout);
+		AST_APP_ARG(options);
 	);
+	struct ast_flags options = { 0 };
 	unsigned int timeout = SMDI_RETRIEVE_TIMEOUT_DEFAULT;
 	int res = -1;
 	char *parse = NULL;
@@ -1072,7 +1112,7 @@
 	parse = ast_strdupa(data);
 	AST_STANDARD_APP_ARGS(args, parse);
 
-	if (ast_strlen_zero(args.port) || ast_strlen_zero(args.station)) {
+	if (ast_strlen_zero(args.port) || ast_strlen_zero(args.search_key)) {
 		ast_log(LOG_ERROR, "Invalid arguments provided to SMDI_MSG_RETRIEVE\n");
 		goto return_error;
 	}
@@ -1080,6 +1120,10 @@
 	if (!(iface = ast_smdi_interface_find(args.port))) {
 		ast_log(LOG_ERROR, "SMDI port '%s' not found\n", args.port);
 		goto return_error;
+	}
+
+	if (!ast_strlen_zero(args.options)) {
+		ast_app_parse_options(smdi_msg_ret_options, &options, NULL, args.options);
 	}
 
 	if (!ast_strlen_zero(args.timeout)) {
@@ -1089,9 +1133,9 @@
 		}
 	}
 
-	if (!(md_msg = smdi_message_wait(iface, timeout, SMDI_MD, args.station))) {
-		ast_log(LOG_WARNING, "No SMDI message retrieved for station '%s' after "
-			"waiting %u ms.\n", args.station, timeout);
+	if (!(md_msg = smdi_message_wait(iface, timeout, SMDI_MD, args.search_key, options))) {
+		ast_log(LOG_WARNING, "No SMDI message retrieved for search key '%s' after "
+			"waiting %u ms.\n", args.search_key, timeout);
 		goto return_error;
 	}
 
@@ -1180,7 +1224,11 @@
 
 	smd = datastore->data;
 
-	if (!strcasecmp(args.component, "station")) {
+	if (!strcasecmp(args.component, "number")) {
+		ast_copy_string(buf, smd->md_msg->mesg_desk_num, len);
+	} else if (!strcasecmp(args.component, "terminal")) {
+		ast_copy_string(buf, smd->md_msg->mesg_desk_term, len);
+	} else if (!strcasecmp(args.component, "station")) {
 		ast_copy_string(buf, smd->md_msg->fwd_st, len);
 	} else if (!strcasecmp(args.component, "callerid")) {
 		ast_copy_string(buf, smd->md_msg->calling_st, len);
@@ -1203,7 +1251,7 @@
 static struct ast_custom_function smdi_msg_retrieve_function = {
 	.name = "SMDI_MSG_RETRIEVE",
 	.synopsis = "Retrieve an SMDI message.",
-	.syntax = "SMDI_MSG_RETRIEVE(<smdi port>,<station>[,timeout])",
+	.syntax = "SMDI_MSG_RETRIEVE(<smdi port>,<search key>[,timeout[,options]])",
 	.desc = 
 	"   This function is used to retrieve an incoming SMDI message.  It returns\n"
 	"an ID which can be used with the SMDI_MSG() function to access details of\n"
@@ -1212,6 +1260,14 @@
 	"the global SMDI message queue, and can not be accessed by any other Asterisk\n"
 	"channels.  The timeout for this function is optional, and the default is\n"
 	"3 seconds.  When providing a timeout, it should be in milliseconds.\n"
+	"   The default search is done on the forwarding station ID.  However, if\n"
+	"you set one of the search key options in the options field, you can change\n"
+	"this behavior.\n"
+	"   Options:\n"
+	"     t - Instead of searching on the forwarding station, search on the message\n"
+	"         desk terminal.\n"
+	"     n - Instead of searching on the forwarding station, search on the message\n"
+	"         desk number.\n"
 	"",
 	.read = smdi_msg_retrieve_read,
 };
@@ -1225,6 +1281,8 @@
 	"pulled from the incoming SMDI message queue using the SMDI_MSG_RETRIEVE()\n"
 	"function.\n"
 	"   Valid message components are:\n"
+	"      number   - The message desk number\n"
+	"      terminal - The message desk terminal\n"
 	"      station  - The forwarding station\n"
 	"      callerid - The callerID of the calling party that was forwarded\n"
 	"      type     - The call type.  The value here is the exact character\n"




More information about the asterisk-commits mailing list