[asterisk-commits] rmudgett: branch rmudgett/external_mwi r404400 - /team/rmudgett/external_mwi/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Dec 19 22:08:19 CST 2013


Author: rmudgett
Date: Thu Dec 19 22:08:17 2013
New Revision: 404400

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=404400
Log:
Review feeedback changes.

* Renamed AMI MWI actions to remove External.

* Made external MWI CLI commands conditional for debugging purposes.

* Removed the word "external" from the MWI CLI commands.

* Reverted the res_sorcery_astdb regex fix.

* Updated external MWI API doxygen comments from review feedback.

Modified:
    team/rmudgett/external_mwi/res/res_mwi_external.c
    team/rmudgett/external_mwi/res/res_mwi_external_ami.c
    team/rmudgett/external_mwi/res/res_sorcery_astdb.c

Modified: team/rmudgett/external_mwi/res/res_mwi_external.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/external_mwi/res/res_mwi_external.c?view=diff&rev=404400&r1=404399&r2=404400
==============================================================================
--- team/rmudgett/external_mwi/res/res_mwi_external.c (original)
+++ team/rmudgett/external_mwi/res/res_mwi_external.c Thu Dec 19 22:08:17 2013
@@ -65,6 +65,12 @@
 
 /* ------------------------------------------------------------------- */
 
+/*!
+ * Define to include CLI commands to manipulate the external MWI mailboxes.
+ * Useful for testing the module functionality.
+ */
+//#define MWI_DEBUG_CLI		1
+
 #define MWI_ASTDB_PREFIX	"mwi_external"
 #define MWI_MAILBOX_TYPE	"mailboxes"
 
@@ -367,8 +373,6 @@
  *
  * \param mailbox_id The mailbox name.
  * \param folder The folder to look in.  Default is INBOX if not provided.
- *
- * \note If requesting INBOX then the returned count is INBOX + Urgent.
  *
  * \return The number of messages in the mailbox folder (zero or more).
  */
@@ -408,8 +412,7 @@
  * \brief Determines if the given folder has messages.
  * \since 13.0.0
  *
- * \param mailboxes Comma or & delimited list of mailboxes (user at context).
- *          If no context is found, uses 'default' for the context.
+ * \param mailboxes Comma or & delimited list of mailboxes.
  * \param folder The folder to look in.  Default is INBOX if not provided.
  *
  * \retval 1 if the folder has one or more messages.
@@ -464,13 +467,12 @@
  * \brief Gets the number of messages that exist for the mailbox list.
  * \since 13.0.0
  *
- * \param mailboxes Comma or space delimited list of mailboxes (user at context).
- *          If no context is found, uses 'default' for the context.
+ * \param mailboxes Comma or space delimited list of mailboxes.
  * \param newmsgs Where to put the count of new messages. (Can be NULL)
  * \param oldmsgs Where to put the count of old messages. (Can be NULL)
  *
  * \details
- * Simultaneously determines the count of new + urgent and old
+ * Simultaneously determines the count of new and old
  * messages.  The total messages would then be the sum of these.
  *
  * \retval 0 on success
@@ -516,8 +518,7 @@
  * \brief Gets the number of messages that exist for the mailbox list.
  * \since 13.0.0
  *
- * \param mailboxes Comma or space delimited list of mailboxes (user at context).
- *          If no context is found, uses 'default' for the context.
+ * \param mailboxes Comma or space delimited list of mailboxes.
  * \param urgentmsgs Where to put the count of urgent messages. (Can be NULL)
  * \param newmsgs Where to put the count of new messages. (Can be NULL)
  * \param oldmsgs Where to put the count of old messages. (Can be NULL)
@@ -580,13 +581,14 @@
 	return ret;
 }
 
-static char *handle_mwi_external_delete_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+#if defined(MWI_DEBUG_CLI)
+static char *handle_mwi_delete_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "mwi external delete all";
+		e->command = "mwi delete all";
 		e->usage =
-			"Usage: mwi external delete all\n"
+			"Usage: mwi delete all\n"
 			"       Delete all external MWI mailboxes.\n";
 		return NULL;
 	case CLI_GENERATE:
@@ -597,64 +599,70 @@
 	ast_cli(a->fd, "Deleted all external MWI mailboxes.\n");
 	return CLI_SUCCESS;
 }
-
-static char *handle_mwi_external_delete_like(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+#endif	/* defined(MWI_DEBUG_CLI) */
+
+#if defined(MWI_DEBUG_CLI)
+static char *handle_mwi_delete_like(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	const char *regex;
 
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "mwi external delete like";
+		e->command = "mwi delete like";
 		e->usage =
-			"Usage: mwi external delete like <pattern>\n"
+			"Usage: mwi delete like <pattern>\n"
 			"       Delete external MWI mailboxes matching a regular expression.\n";
 		return NULL;
 	case CLI_GENERATE:
 		return NULL;
 	}
 
-	if (a->argc != 5) {
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
 	}
-	regex = a->argv[4];
+	regex = a->argv[3];
 
 	ast_mwi_mailbox_delete_by_regex(regex);
 	ast_cli(a->fd, "Deleted external MWI mailboxes matching '%s'.\n", regex);
 	return CLI_SUCCESS;
 }
-
-static char *handle_mwi_external_delete_mailbox(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+#endif	/* defined(MWI_DEBUG_CLI) */
+
+#if defined(MWI_DEBUG_CLI)
+static char *handle_mwi_delete_mailbox(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	const char *mailbox_id;
 
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "mwi external delete mailbox";
+		e->command = "mwi delete mailbox";
 		e->usage =
-			"Usage: mwi external delete mailbox <mailbox_id>\n"
+			"Usage: mwi delete mailbox <mailbox_id>\n"
 			"       Delete a specific external MWI mailbox.\n";
 		return NULL;
 	case CLI_GENERATE:
-		if (a->pos == 4) {
+		if (a->pos == 3) {
 			return complete_mailbox(a->word, a->n);
 		}
 		return NULL;
 	}
 
-	if (a->argc != 5) {
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
 	}
-	mailbox_id = a->argv[4];
+	mailbox_id = a->argv[3];
 
 	ast_mwi_mailbox_delete(mailbox_id);
 	ast_cli(a->fd, "Deleted external MWI mailbox '%s'.\n", mailbox_id);
 
 	return CLI_SUCCESS;
 }
+#endif	/* defined(MWI_DEBUG_CLI) */
 
 #define FORMAT_MAILBOX_HDR "%6s %6s %s\n"
 #define FORMAT_MAILBOX_ROW "%6u %6u %s\n"
 
+#if defined(MWI_DEBUG_CLI)
 /*!
  * \internal
  * \brief Print a mailbox list line to CLI.
@@ -670,7 +678,9 @@
 	ast_cli(cli_fd, FORMAT_MAILBOX_ROW, mailbox->msgs_new, mailbox->msgs_old,
 		ast_sorcery_object_get_id(mailbox));
 }
-
+#endif	/* defined(MWI_DEBUG_CLI) */
+
+#if defined(MWI_DEBUG_CLI)
 /*!
  * \internal
  * \brief List all mailboxes in the given container.
@@ -694,19 +704,21 @@
 	}
 	ao2_iterator_destroy(&iter);
 }
+#endif	/* defined(MWI_DEBUG_CLI) */
 
 #undef FORMAT_MAILBOX_HDR
 #undef FORMAT_MAILBOX_ROW
 
-static char *handle_mwi_external_list_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+#if defined(MWI_DEBUG_CLI)
+static char *handle_mwi_list_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ao2_container *mailboxes;
 
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "mwi external list all";
+		e->command = "mwi list all";
 		e->usage =
-			"Usage: mwi external list all\n"
+			"Usage: mwi list all\n"
 			"       List all external MWI mailboxes.\n";
 		return NULL;
 	case CLI_GENERATE:
@@ -722,27 +734,29 @@
 	ao2_ref(mailboxes, -1);
 	return CLI_SUCCESS;
 }
-
-static char *handle_mwi_external_list_like(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+#endif	/* defined(MWI_DEBUG_CLI) */
+
+#if defined(MWI_DEBUG_CLI)
+static char *handle_mwi_list_like(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ao2_container *mailboxes;
 	const char *regex;
 
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "mwi external list like";
+		e->command = "mwi list like";
 		e->usage =
-			"Usage: mwi external list like <pattern>\n"
+			"Usage: mwi list like <pattern>\n"
 			"       List external MWI mailboxes matching a regular expression.\n";
 		return NULL;
 	case CLI_GENERATE:
 		return NULL;
 	}
 
-	if (a->argc != 5) {
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
 	}
-	regex = a->argv[4];
+	regex = a->argv[3];
 
 	mailboxes = ast_mwi_mailbox_get_by_regex(regex);
 	if (!mailboxes) {
@@ -753,30 +767,32 @@
 	ao2_ref(mailboxes, -1);
 	return CLI_SUCCESS;
 }
-
-static char *handle_mwi_external_show_mailbox(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+#endif	/* defined(MWI_DEBUG_CLI) */
+
+#if defined(MWI_DEBUG_CLI)
+static char *handle_mwi_show_mailbox(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	const struct ast_mwi_mailbox_object *mailbox;
 	const char *mailbox_id;
 
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "mwi external show mailbox";
+		e->command = "mwi show mailbox";
 		e->usage =
-			"Usage: mwi external show mailbox <mailbox_id>\n"
+			"Usage: mwi show mailbox <mailbox_id>\n"
 			"       Show a specific external MWI mailbox.\n";
 		return NULL;
 	case CLI_GENERATE:
-		if (a->pos == 4) {
+		if (a->pos == 3) {
 			return complete_mailbox(a->word, a->n);
 		}
 		return NULL;
 	}
 
-	if (a->argc != 5) {
+	if (a->argc != 4) {
 		return CLI_SHOWUSAGE;
 	}
-	mailbox_id = a->argv[4];
+	mailbox_id = a->argv[3];
 
 	mailbox = ast_mwi_mailbox_get(mailbox_id);
 	if (mailbox) {
@@ -795,8 +811,10 @@
 
 	return CLI_SUCCESS;
 }
-
-static char *handle_mwi_external_update_mailbox(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+#endif	/* defined(MWI_DEBUG_CLI) */
+
+#if defined(MWI_DEBUG_CLI)
+static char *handle_mwi_update_mailbox(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_mwi_mailbox_object *mailbox;
 	const char *mailbox_id;
@@ -805,26 +823,26 @@
 
 	switch (cmd) {
 	case CLI_INIT:
-		e->command = "mwi external update mailbox";
+		e->command = "mwi update mailbox";
 		e->usage =
-			"Usage: mwi external update mailbox <mailbox_id> [<new> [<old>]]\n"
+			"Usage: mwi update mailbox <mailbox_id> [<new> [<old>]]\n"
 			"       Update a specific external MWI mailbox.\n";
 		return NULL;
 	case CLI_GENERATE:
-		if (a->pos == 4) {
+		if (a->pos == 3) {
 			return complete_mailbox(a->word, a->n);
 		}
 		return NULL;
 	}
 
-	if (a->argc < 5 || 7 < a->argc) {
+	if (a->argc < 4 || 6 < a->argc) {
 		return CLI_SHOWUSAGE;
 	}
-	mailbox_id = a->argv[4];
+	mailbox_id = a->argv[3];
 
 	num_new = 0;
-	if (5 < a->argc) {
-		const char *count_new = a->argv[5];
+	if (4 < a->argc) {
+		const char *count_new = a->argv[4];
 
 		if (sscanf(count_new, "%u", &num_new) != 1) {
 			ast_cli(a->fd, "Invalid NewMessages: '%s'.\n", count_new);
@@ -833,8 +851,8 @@
 	}
 
 	num_old = 0;
-	if (6 < a->argc) {
-		const char *count_old = a->argv[6];
+	if (5 < a->argc) {
+		const char *count_old = a->argv[5];
 
 		if (sscanf(count_old, "%u", &num_old) != 1) {
 			ast_cli(a->fd, "Invalid OldMessages: '%s'.\n", count_old);
@@ -858,16 +876,19 @@
 
 	return CLI_SUCCESS;
 }
-
-static struct ast_cli_entry mwi_external_cli[] = {
-	AST_CLI_DEFINE(handle_mwi_external_delete_all, "Delete all external MWI mailboxes"),
-	AST_CLI_DEFINE(handle_mwi_external_delete_like, "Delete external MWI mailboxes matching regex"),
-	AST_CLI_DEFINE(handle_mwi_external_delete_mailbox, "Delete a specific external MWI mailbox"),
-	AST_CLI_DEFINE(handle_mwi_external_list_all, "List all external MWI mailboxes"),
-	AST_CLI_DEFINE(handle_mwi_external_list_like, "List external MWI mailboxes matching regex"),
-	AST_CLI_DEFINE(handle_mwi_external_show_mailbox, "Show a specific external MWI mailbox"),
-	AST_CLI_DEFINE(handle_mwi_external_update_mailbox, "Update a specific external MWI mailbox"),
+#endif	/* defined(MWI_DEBUG_CLI) */
+
+#if defined(MWI_DEBUG_CLI)
+static struct ast_cli_entry mwi_cli[] = {
+	AST_CLI_DEFINE(handle_mwi_delete_all, "Delete all external MWI mailboxes"),
+	AST_CLI_DEFINE(handle_mwi_delete_like, "Delete external MWI mailboxes matching regex"),
+	AST_CLI_DEFINE(handle_mwi_delete_mailbox, "Delete a specific external MWI mailbox"),
+	AST_CLI_DEFINE(handle_mwi_list_all, "List all external MWI mailboxes"),
+	AST_CLI_DEFINE(handle_mwi_list_like, "List external MWI mailboxes matching regex"),
+	AST_CLI_DEFINE(handle_mwi_show_mailbox, "Show a specific external MWI mailbox"),
+	AST_CLI_DEFINE(handle_mwi_update_mailbox, "Update a specific external MWI mailbox"),
 };
+#endif	/* defined(MWI_DEBUG_CLI) */
 
 /*!
  * \internal
@@ -901,7 +922,9 @@
 static int unload_module(void)
 {
 	ast_vm_unregister(vm_table.module_name);
-	ast_cli_unregister_multiple(mwi_external_cli, ARRAY_LEN(mwi_external_cli));
+#if defined(MWI_DEBUG_CLI)
+	ast_cli_unregister_multiple(mwi_cli, ARRAY_LEN(mwi_cli));
+#endif	/* defined(MWI_DEBUG_CLI) */
 	ast_sorcery_observer_remove(mwi_sorcery, MWI_MAILBOX_TYPE, &mwi_observers);
 
 	ast_sorcery_unref(mwi_sorcery);
@@ -914,7 +937,9 @@
 {
 	if (mwi_sorcery_init()
 		|| ast_sorcery_observer_add(mwi_sorcery, MWI_MAILBOX_TYPE, &mwi_observers)
-		|| ast_cli_register_multiple(mwi_external_cli, ARRAY_LEN(mwi_external_cli))
+#if defined(MWI_DEBUG_CLI)
+		|| ast_cli_register_multiple(mwi_cli, ARRAY_LEN(mwi_cli))
+#endif	/* defined(MWI_DEBUG_CLI) */
 		|| ast_vm_register(&vm_table)) {
 		unload_module();
 		return AST_MODULE_LOAD_DECLINE;

Modified: team/rmudgett/external_mwi/res/res_mwi_external_ami.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/external_mwi/res/res_mwi_external_ami.c?view=diff&rev=404400&r1=404399&r2=404400
==============================================================================
--- team/rmudgett/external_mwi/res/res_mwi_external_ami.c (original)
+++ team/rmudgett/external_mwi/res/res_mwi_external_ami.c Thu Dec 19 22:08:17 2013
@@ -33,7 +33,7 @@
 
 
 /*** DOCUMENTATION
-	<manager name="MWIExternalGet" language="en_US">
+	<manager name="MWIGet" language="en_US">
 		<synopsis>
 			Get selected mailboxes with message counts.
 		</synopsis>
@@ -49,10 +49,10 @@
 			<para>Get a list of mailboxes with their message counts.</para>
 		</description>
 	</manager>
-	<managerEvent language="en_US" name="MWIExternalGet">
+	<managerEvent language="en_US" name="MWIGet">
 		<managerEventInstance class="EVENT_FLAG_REPORTING">
 			<synopsis>
-				Raised in response to a MWIExternalGet command.
+				Raised in response to a MWIGet command.
 			</synopsis>
 			<syntax>
 				<parameter name="ActionID" required="false"/>
@@ -67,14 +67,14 @@
 				</parameter>
 			</syntax>
 			<see-also>
-				<ref type="manager">MWIExternalGet</ref>
+				<ref type="manager">MWIGet</ref>
 			</see-also>
 		</managerEventInstance>
 	</managerEvent>
-	<managerEvent language="en_US" name="MWIExternalGetComplete">
+	<managerEvent language="en_US" name="MWIGetComplete">
 		<managerEventInstance class="EVENT_FLAG_REPORTING">
 			<synopsis>
-				Raised in response to a MWIExternalGet command.
+				Raised in response to a MWIGet command.
 			</synopsis>
 			<syntax>
 				<parameter name="ActionID" required="false"/>
@@ -84,23 +84,23 @@
 				</parameter>
 			</syntax>
 			<see-also>
-				<ref type="manager">MWIExternalGet</ref>
+				<ref type="manager">MWIGet</ref>
 			</see-also>
 		</managerEventInstance>
 	</managerEvent>
-	<manager name="MWIExternalDelete" language="en_US">
+	<manager name="MWIDelete" language="en_US">
 		<synopsis>
 			Delete selected mailboxes.
 		</synopsis>
 		<syntax>
 			<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
-			<xi:include xpointer="xpointer(/docs/manager[@name='MWIExternalGet']/syntax/parameter[@name='Mailbox'])" />
+			<xi:include xpointer="xpointer(/docs/manager[@name='MWIGet']/syntax/parameter[@name='Mailbox'])" />
 		</syntax>
 		<description>
 			<para>Delete the specified mailboxes.</para>
 		</description>
 	</manager>
-	<manager name="MWIExternalUpdate" language="en_US">
+	<manager name="MWIUpdate" language="en_US">
 		<synopsis>
 			Update the mailbox message counts.
 		</synopsis>
@@ -212,7 +212,7 @@
 	for (; (mailbox = ao2_iterator_next(&iter)); ast_mwi_mailbox_unref(mailbox)) {
 		++count;
 		astman_append(s,
-			"Event: MWIExternalGet\r\n"
+			"Event: MWIGet\r\n"
 			"Mailbox: %s\r\n"
 			"OldMessages: %u\r\n"
 			"NewMessages: %u\r\n"
@@ -227,7 +227,7 @@
 	ao2_ref(mailboxes, -1);
 
 	astman_append(s,
-		"Event: MWIExternalGetComplete\r\n"
+		"Event: MWIGetComplete\r\n"
 		"EventList: Complete\r\n"
 		"ListItems: %d\r\n"
 		"%s"
@@ -344,9 +344,9 @@
 
 static int unload_module(void)
 {
-	ast_manager_unregister("MWIExternalGet");
-	ast_manager_unregister("MWIExternalDelete");
-	ast_manager_unregister("MWIExternalUpdate");
+	ast_manager_unregister("MWIGet");
+	ast_manager_unregister("MWIDelete");
+	ast_manager_unregister("MWIUpdate");
 
 	/* Must be done last */
 	ast_mwi_external_unref();
@@ -361,9 +361,9 @@
 	ast_mwi_external_ref();
 
 	res = 0;
-	res |= ast_manager_register_xml_core("MWIExternalGet", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, mwi_mailbox_get);
-	res |= ast_manager_register_xml_core("MWIExternalDelete", EVENT_FLAG_CALL, mwi_mailbox_delete);
-	res |= ast_manager_register_xml_core("MWIExternalUpdate", EVENT_FLAG_CALL, mwi_mailbox_update);
+	res |= ast_manager_register_xml_core("MWIGet", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, mwi_mailbox_get);
+	res |= ast_manager_register_xml_core("MWIDelete", EVENT_FLAG_CALL, mwi_mailbox_delete);
+	res |= ast_manager_register_xml_core("MWIUpdate", EVENT_FLAG_CALL, mwi_mailbox_update);
 	if (res) {
 		unload_module();
 		return AST_MODULE_LOAD_DECLINE;

Modified: team/rmudgett/external_mwi/res/res_sorcery_astdb.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/external_mwi/res/res_sorcery_astdb.c?view=diff&rev=404400&r1=404399&r2=404400
==============================================================================
--- team/rmudgett/external_mwi/res/res_sorcery_astdb.c (original)
+++ team/rmudgett/external_mwi/res/res_sorcery_astdb.c Thu Dec 19 22:08:17 2013
@@ -218,15 +218,20 @@
 static void sorcery_astdb_retrieve_regex(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *regex)
 {
 	const char *prefix = data;
-	char family[strlen(prefix) + strlen(type) + 2];
+	char family[strlen(prefix) + strlen(type) + 2], tree[strlen(regex) + 1];
 	RAII_VAR(struct ast_db_entry *, entries, NULL, ast_db_freetree);
 	regex_t expression;
 	struct ast_db_entry *entry;
 
 	snprintf(family, sizeof(family), "%s/%s", prefix, type);
 
-	if (!(entries = ast_db_gettree(family, NULL))
-		|| regcomp(&expression, regex, REG_EXTENDED | REG_NOSUB)) {
+	if (regex[0] == '^') {
+		snprintf(tree, sizeof(tree), "%s%%", regex + 1);
+	} else {
+		tree[0] = '\0';
+	}
+
+	if (!(entries = ast_db_gettree(family, tree)) || regcomp(&expression, regex, REG_EXTENDED | REG_NOSUB)) {
 		return;
 	}
 




More information about the asterisk-commits mailing list