[asterisk-commits] rmudgett: branch rmudgett/external_mwi r403699 - in /team/rmudgett/external_m...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 11 18:45:59 CST 2013


Author: rmudgett
Date: Wed Dec 11 18:45:53 2013
New Revision: 403699

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403699
Log:
voicemail, mwi: Convert ast_app_messagecount() to take a mailbox_id string.

Modified:
    team/rmudgett/external_mwi/apps/app_voicemail.c
    team/rmudgett/external_mwi/funcs/func_vmcount.c
    team/rmudgett/external_mwi/include/asterisk/app.h
    team/rmudgett/external_mwi/main/app.c
    team/rmudgett/external_mwi/res/res_mwi_external.c

Modified: team/rmudgett/external_mwi/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/external_mwi/apps/app_voicemail.c?view=diff&rev=403699&r1=403698&r2=403699
==============================================================================
--- team/rmudgett/external_mwi/apps/app_voicemail.c (original)
+++ team/rmudgett/external_mwi/apps/app_voicemail.c Wed Dec 11 18:45:53 2013
@@ -2503,15 +2503,29 @@
 
 /*!
  * \brief Gets the number of messages that exist in a mailbox folder.
- * \param context
- * \param mailbox
+ * \param mailbox_id
  * \param folder
  * 
  * This method is used when IMAP backend is used.
  * \return The number of messages in this mailbox folder (zero or more).
  */
-static int messagecount(const char *context, const char *mailbox, const char *folder)
-{
+static int messagecount(const char *mailbox_id, const char *folder)
+{
+	char *context;
+	char *mailbox;
+
+	if (ast_strlen_zero(mailbox_id)) {
+		return 0;
+	}
+	context = ast_strdupa(mailbox_id);
+	mailbox = strsep(&context, "@");
+	if (ast_strlen_zero(mailbox)) {
+		return 0;
+	}
+	if (ast_strlen_zero(context)) {
+		context = "default";
+	}
+
 	if (ast_strlen_zero(folder) || !strcmp(folder, "INBOX")) {
 		return __messagecount(context, mailbox, "INBOX") + __messagecount(context, mailbox, "Urgent");
 	} else {
@@ -2534,8 +2548,11 @@
 	STRING str;
 	int ret; /* for better error checking */
 	char *imap_flags = NIL;
-	int msgcount = (messagecount(vmu->context, vmu->mailbox, "INBOX") + messagecount(vmu->context, vmu->mailbox, "Old"));
+	int msgcount;
 	int box = NEW_FOLDER;
+
+	snprintf(mailbox, sizeof(mailbox), "%s@%s", vmu->mailbox, vmu->context);
+	msgcount = messagecount(mailbox, "INBOX") + messagecount(mailbox, "Old");
 
 	/* Back out early if this is a greeting and we don't want to store greetings in IMAP */
 	if (msgnum < 0) {
@@ -5613,16 +5630,17 @@
 
 /*!
  * \brief Gets the number of messages that exist in a mailbox folder.
- * \param context
- * \param mailbox
+ * \param mailbox_id
  * \param folder
  * 
  * This method is used when ODBC backend is used.
  * \return The number of messages in this mailbox folder (zero or more).
  */
-static int messagecount(const char *context, const char *mailbox, const char *folder)
+static int messagecount(const char *mailbox_id, const char *folder)
 {
 	struct odbc_obj *obj = NULL;
+	char *context;
+	char *mailbox;
 	int nummsgs = 0;
 	int res;
 	SQLHSTMT stmt = NULL;
@@ -5631,8 +5649,16 @@
 	struct generic_prepare_struct gps = { .sql = sql, .argc = 0 };
 
 	/* If no mailbox, return immediately */
+	if (ast_strlen_zero(mailbox_id)) {
+		return 0;
+	}
+	context = ast_strdupa(mailbox_id);
+	mailbox = strsep(&context, "@");
 	if (ast_strlen_zero(mailbox)) {
 		return 0;
+	}
+	if (ast_strlen_zero(context)) {
+		context = "default";
 	}
 
 	if (ast_strlen_zero(folder)) {
@@ -5682,16 +5708,16 @@
  * This invokes the messagecount(). Here we are interested in the presence of messages (> 0) only, not the actual count.
  * \return 1 if the folder has one or more messages. zero otherwise.
  */
-static int has_voicemail(const char *mailbox, const char *folder)
-{
-	char tmp[256], *tmp2 = tmp, *box, *context;
-	ast_copy_string(tmp, mailbox, sizeof(tmp));
-	while ((context = box = strsep(&tmp2, ",&"))) {
-		strsep(&context, "@");
-		if (ast_strlen_zero(context))
-			context = "default";
-		if (messagecount(context, box, folder))
+static int has_voicemail(const char *mailboxes, const char *folder)
+{
+	char *parse;
+	char *mailbox;
+
+	parse = ast_strdupa(mailboxes);
+	while ((mailbox = strsep(&parse, ",&"))) {
+		if (messagecount(mailbox, folder)) {
 			return 1;
+		}
 	}
 	return 0;
 }
@@ -5779,8 +5805,23 @@
 #endif
 #if !(defined(IMAP_STORAGE) || defined(ODBC_STORAGE))
 
-static int messagecount(const char *context, const char *mailbox, const char *folder)
-{
+static int messagecount(const char *mailbox_id, const char *folder)
+{
+	char *context;
+	char *mailbox;
+
+	if (ast_strlen_zero(mailbox_id)) {
+		return 0;
+	}
+	context = ast_strdupa(mailbox_id);
+	mailbox = strsep(&context, "@");
+	if (ast_strlen_zero(mailbox)) {
+		return 0;
+	}
+	if (ast_strlen_zero(context)) {
+		context = "default";
+	}
+
 	return __has_voicemail(context, mailbox, folder, 0) + (folder && strcmp(folder, "INBOX") ? 0 : __has_voicemail(context, mailbox, "Urgent", 0));
 }
 
@@ -12052,8 +12093,13 @@
 		} else if (!strncasecmp(arg.attribute, "tz", 2)) {
 			ast_copy_string(buf, vmu->zonetag, len);
 		} else if (!strncasecmp(arg.attribute, "count", 5)) {
+			char *mailbox_id;
+
+			mailbox_id = ast_alloca(strlen(mailbox) + strlen(context) + 2);
+			sprintf(mailbox_id, "%s@%s", mailbox, context);/* Safe */
+
 			/* If mbxfolder is empty messagecount will default to INBOX */
-			res = messagecount(context, mailbox, arg.folder);
+			res = messagecount(mailbox_id, arg.folder);
 			if (res < 0) {
 				ast_log(LOG_ERROR, "Unable to retrieve message count for mailbox %s\n", arg.mailbox_context);
 				return -1;
@@ -13921,9 +13967,9 @@
 
 		new = old = urgent = 0;
 		for (j = 0; j < 3; j++) {
-			if (ast_app_messagecount(testcontext, testmailbox, folders[j]) != expected_results[i][9 + j]) {
+			if (ast_app_messagecount(testspec, folders[j]) != expected_results[i][9 + j]) {
 				ast_test_status_update(test, "messagecount(%s, %s) returned %d and we expected %d\n",
-					testspec, folders[j], ast_app_messagecount(testcontext, testmailbox, folders[j]), expected_results[i][9 + j]);
+					testspec, folders[j], ast_app_messagecount(testspec, folders[j]), expected_results[i][9 + j]);
 				res = AST_TEST_FAIL;
 			}
 		}

Modified: team/rmudgett/external_mwi/funcs/func_vmcount.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/external_mwi/funcs/func_vmcount.c?view=diff&rev=403699&r1=403698&r2=403699
==============================================================================
--- team/rmudgett/external_mwi/funcs/func_vmcount.c (original)
+++ team/rmudgett/external_mwi/funcs/func_vmcount.c Wed Dec 11 18:45:53 2013
@@ -49,27 +49,21 @@
 			Count the voicemails in a specified mailbox.
 		</synopsis>
 		<syntax>
-			<parameter name="vmbox" required="true" argsep="@">
-				<argument name="vmbox" required="true" />
-				<argument name="context" required="false">
-					<para>If not specified, defaults to <literal>default</literal>.</para>
-				</argument>
-			</parameter>
+			<parameter name="vmbox" required="true" />
 			<parameter name="folder" required="false">
 				<para>If not specified, defaults to <literal>INBOX</literal></para>
 			</parameter>
 		</syntax>
 		<description>
 			<para>Count the number of voicemails in a specified mailbox, you could also specify 
-			the <replaceable>context</replaceable> and the mailbox <replaceable>folder</replaceable>.</para>
-			<para>Example: <literal>exten => s,1,Set(foo=${VMCOUNT(125)})</literal></para>
+			the mailbox <replaceable>folder</replaceable>.</para>
+			<para>Example: <literal>exten => s,1,Set(foo=${VMCOUNT(125 at default)})</literal></para>
 		</description>
 	</function>
  ***/
 
 static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
 {
-	char *context;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(vmbox);
 		AST_APP_ARG(folder);
@@ -82,19 +76,15 @@
 
 	AST_STANDARD_APP_ARGS(args, argsstr);
 
-	if (strchr(args.vmbox, '@')) {
-		context = args.vmbox;
-		args.vmbox = strsep(&context, "@");
-	} else {
-		context = "default";
+	if (ast_strlen_zero(args.vmbox)) {
+		return -1;
 	}
 
 	if (ast_strlen_zero(args.folder)) {
 		args.folder = "INBOX";
 	}
 
-/* BUGBUG likely need to fix this to just pass a mailbox string and separate user and context */
-	snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
+	snprintf(buf, len, "%d", ast_app_messagecount(args.vmbox, args.folder));
 	
 	return 0;
 }

Modified: team/rmudgett/external_mwi/include/asterisk/app.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/external_mwi/include/asterisk/app.h?view=diff&rev=403699&r1=403698&r2=403699
==============================================================================
--- team/rmudgett/external_mwi/include/asterisk/app.h (original)
+++ team/rmudgett/external_mwi/include/asterisk/app.h Wed Dec 11 18:45:53 2013
@@ -382,16 +382,14 @@
 /*!
  * \brief Gets the number of messages that exist in a mailbox folder.
  *
- * \param context The context part of user at context.  Uses 'default' if not provided.
- * \param user The user part of user at context.
+ * \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 this mailbox folder (zero or more).
- */
-typedef int (ast_messagecount_fn)(const char *context, const char *user, const char *folder);
+ * \note If requesting INBOX then the returned count is INBOX + Urgent.
+ *
+ * \return The number of messages in the mailbox folder (zero or more).
+ */
+typedef int (ast_messagecount_fn)(const char *mailbox_id, const char *folder);
 
 /*!
  * \brief Play a recorded user name for the mailbox.
@@ -657,14 +655,16 @@
 int ast_app_sayname(struct ast_channel *chan, const char *mailbox, const char *context);
 
 /*!
- * \brief Check number of messages in a given context, mailbox, and folder
- * \since 1.4
- * \param[in] context Mailbox context
- * \param[in] mailbox Mailbox number
- * \param[in] folder Mailbox folder
- * \return Number of messages in the given context, mailbox, and folder.  If folder is NULL, folder "INBOX" is assumed.  If folder is "INBOX", includes number of messages in the "Urgent" folder.
- */
-int ast_app_messagecount(const char *context, const char *mailbox, const char *folder);
+ * \brief Get the number of messages in a given mailbox folder
+ *
+ * \param[in] mailbox_id Mailbox name
+ * \param[in] 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).
+ */
+int ast_app_messagecount(const char *mailbox_id, const char *folder);
 
 /*!
  * \brief Return name of folder, given an id

Modified: team/rmudgett/external_mwi/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/external_mwi/main/app.c?view=diff&rev=403699&r1=403698&r2=403699
==============================================================================
--- team/rmudgett/external_mwi/main/app.c (original)
+++ team/rmudgett/external_mwi/main/app.c Wed Dec 11 18:45:53 2013
@@ -576,11 +576,11 @@
 	return res;
 }
 
-int ast_app_messagecount(const char *context, const char *mailbox, const char *folder)
+int ast_app_messagecount(const char *mailbox_id, const char *folder)
 {
 	int res = 0;
 
-	VM_API_CALL(res, messagecount, (context, mailbox, folder));
+	VM_API_CALL(res, messagecount, (mailbox_id, folder));
 	return res;
 }
 

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=403699&r1=403698&r2=403699
==============================================================================
--- team/rmudgett/external_mwi/res/res_mwi_external.c (original)
+++ team/rmudgett/external_mwi/res/res_mwi_external.c Wed Dec 11 18:45:53 2013
@@ -365,22 +365,18 @@
  * \brief Gets the number of messages that exist in a mailbox folder.
  * \since 13.0.0
  *
- * \param context The context part of user at context.  Uses 'default' if not provided.
- * \param user The user part of user at context.
+ * \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 this mailbox folder (zero or more).
- */
-static int mwi_messagecount(const char *context, const char *user, const char *folder)
+ * \note If requesting INBOX then the returned count is INBOX + Urgent.
+ *
+ * \return The number of messages in the mailbox folder (zero or more).
+ */
+static int mwi_messagecount(const char *mailbox_id, const char *folder)
 {
 	const struct ast_mwi_mailbox_object *mailbox;
 	int num_msgs;
 	enum folder_map which_folder;
-/* BUGBUG need to change the mwi_messagecount() signature to take mailbox_id instead of user and context */
-	const char *mailbox_id = user;
 
 	which_folder = mwi_folder_map(folder);
 	if (which_folder == FOLDER_INVALID) {




More information about the asterisk-commits mailing list