[asterisk-commits] mmichelson: branch mmichelson/trunk-digiumphones r367360 - /team/mmichelson/t...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 22 13:50:24 CDT 2012


Author: mmichelson
Date: Tue May 22 13:50:19 2012
New Revision: 367360

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367360
Log:
Take a lazier approach to adding missing message IDs to voicemails.

Rather than perusing every single voicemail message on startup, we
now do it more-or-less on demand. Whenever a voicemail message
snapshot is created, we will ensure that the message has a message
ID associated with it.

IMAP is still not addressed here because it is a whole other can
of worms and will greatly detract from the clarity of the diff that
will be posted to reviewboard.


Modified:
    team/mmichelson/trunk-digiumphones/apps/app_voicemail.c

Modified: team/mmichelson/trunk-digiumphones/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/apps/app_voicemail.c?view=diff&rev=367360&r1=367359&r2=367360
==============================================================================
--- team/mmichelson/trunk-digiumphones/apps/app_voicemail.c (original)
+++ team/mmichelson/trunk-digiumphones/apps/app_voicemail.c Tue May 22 13:50:19 2012
@@ -11316,81 +11316,27 @@
 	snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]);
 }
 
-static int add_message_ids_folder(struct ast_vm_user *vmu, int folder)
-{
-	struct vm_state vms;
-	int res = 0;
-	memset(&vms, 0, sizeof(vms));
-	ast_copy_string(vms.username, vmu->mailbox, sizeof(vms.username));
-	vms.lastmsg = -1;
-	if (open_mailbox(&vms, vmu, folder)) {
+static int add_message_id(struct ast_config *msg_cfg, char *dir, int msg, char *filename, char *id, size_t id_size)
+{
+	struct ast_variable *var;
+	struct ast_category *cat;
+	generate_random_string(id, id_size);
+
+	var = ast_variable_new("msg_id", id, "");
+	cat = ast_category_get(msg_cfg, "message");
+
+	ast_variable_append(cat, var);
+
+	if (ast_config_text_file_save(filename, msg_cfg, "app_voicemail")) {
+		ast_log(LOG_WARNING, "Unable to update %s to have a message ID\n", filename);
+		ast_config_destroy(msg_cfg);
 		return -1;
 	}
 
-	for (vms.curmsg = 0; vms.curmsg <= vms.lastmsg; ++vms.curmsg) {
-		const char *msg_id;
-		char filename[PATH_MAX];
-		struct ast_config *msg_cfg;
-		struct ast_flags config_flags = { CONFIG_FLAG_NOCACHE };
-		char random_string[33];
-		struct ast_variable *var;
-		struct ast_category *cat;
-
-		make_file(vms.fn, sizeof(vms.fn), vms.curdir, vms.curmsg);
-		snprintf(filename, sizeof(filename), "%s.txt", vms.fn);
-		RETRIEVE(vms.curdir, vms.curmsg, vmu->mailbox, vmu->context);
-		msg_cfg = ast_config_load(filename, config_flags);
-
-		if (!msg_cfg || msg_cfg == CONFIG_STATUS_FILEINVALID) {
-			ast_log(LOG_WARNING, "Unable to open metadata file %s\n", filename);
-			DISPOSE(vms.curdir, vms.curmsg);
-			res = -1;
-			goto done;
-		}
-
-		msg_id = ast_variable_retrieve(msg_cfg, "message", "msg_id");
-
-		if (msg_id) {
-			/* If the message has an ID, nothing further to do. Continue */
-			ast_config_destroy(msg_cfg);
-			DISPOSE(vms.curdir, vms.curmsg);
-			continue;
-		}
-
-		/* We need to create a message ID for this message */
-		generate_random_string(random_string, sizeof(random_string));
-
-		var = ast_variable_new("msg_id", random_string, "");
-		cat = ast_category_get(msg_cfg, "message");
-		ast_variable_append(cat, var);
-		if (ast_config_text_file_save(filename, msg_cfg, "app_voicemail")) {
-			ast_log(LOG_WARNING, "Unable to update %s to have a message ID\n", filename);
-			ast_config_destroy(msg_cfg);
-			DISPOSE(vms.curdir, vms.curmsg);
-			res = -1;
-			goto done;
-		}
 #ifdef ODBC_STORAGE
-		odbc_update_msg_id(vms.curdir, vms.curmsg, random_string);
+	odbc_update_msg_id(dir, msg, id);
 #endif
-	}
-done:
-	return res;
-}
-
-static int add_message_ids(struct ast_vm_user *vmu)
-{
-	int i;
-	int res = 0;
-	for (i = 0; i < ARRAY_LEN(mailbox_folders); ++i)
-	{
-		res = add_message_ids_folder(vmu, i);
-		if (res) {
-			break;
-		}
-	}
-
-	return res;
+	return 0;
 }
 
 static struct ast_vm_user *find_or_create(const char *context, const char *box)
@@ -11427,13 +11373,6 @@
 	
 	ast_copy_string(vmu->context, context, sizeof(vmu->context));
 	ast_copy_string(vmu->mailbox, box, sizeof(vmu->mailbox));
-
-	/* In Asterisk 11, it is required that all voicemail messages have a unique message
-	 * ID associated with them. Let's get that taken care of here
-	 */
-	if (add_message_ids(vmu)) {
-		ast_log(LOG_WARNING, "Unable to add unique message IDs for all messages for voicemail user %s@%s\n", vmu->mailbox, vmu->context);
-	}
 
 	AST_LIST_INSERT_TAIL(&users, vmu, list);
 	
@@ -14647,6 +14586,18 @@
 		/* Fill in the snapshot object */
 		if ((value = ast_variable_retrieve(msg_cfg, "message", "msg_id"))) {
 			ast_string_field_set(msg_snapshot, msg_id, value);
+		} else {
+			/* Message snapshots *really* should have a 
+			 * message ID. Add one to the message config
+			 * if it does not already exist
+			 */
+			char id[33];
+			if (!(add_message_id(msg_cfg, vms->curdir, vms->curmsg,
+							filename, id, sizeof(id)))) {
+				ast_string_field_set(msg_snapshot, msg_id, id);
+			} else {
+				ast_log(LOG_WARNING, "Unable to create a message ID for message %s/%d\n", vms->curdir, vms->curmsg);
+			}
 		}
 		if ((value = ast_variable_retrieve(msg_cfg, "message", "callerid"))) {
 			ast_string_field_set(msg_snapshot, callerid, value);




More information about the asterisk-commits mailing list