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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 1 17:44:39 CDT 2012


Author: mmichelson
Date: Tue May  1 17:44:34 2012
New Revision: 364887

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=364887
Log:
Commit some progress towards setting message IDs on messages that do not have them.

Bamboo is going to throw a tantrum since this does not compile.


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=364887&r1=364886&r2=364887
==============================================================================
--- team/mmichelson/trunk-digiumphones/apps/app_voicemail.c (original)
+++ team/mmichelson/trunk-digiumphones/apps/app_voicemail.c Tue May  1 17:44:34 2012
@@ -11266,6 +11266,71 @@
 	return res;
 }
 
+static int add_message_ids_folder(struct ast_vm_user *vmu, int folder)
+{
+	struct vm_state vms;
+	ast_copy_string(vms.username, vmu->mailbox, sizeof(vms.username));
+	vms.lastmsg = -1;
+	if (open_mailbox(&vms, vmu, folder)) {
+		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];
+
+		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) {
+			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, "");
+		ast_variable_append("message", var);
+		if (ast_config_text_file_save(filename, msg_cfg, "app_voicemail")) {
+			/* EFF */
+		}
+		/* Hmm, what do we actually do here?
+		 * STORE is probably the best choice since we got both the message and its
+		 * metadata. Will it result in duplicates? Do we need to delete the first
+		 * version and then STORE? I'm starting to think that a better idea is to
+		 * implement the idea of just grabbing metadata and adding a macro to update
+		 * said metadata as well. Hard to believe this is the first instance where such
+		 * an operation is needed though...
+		 */
+		/* XXX Get back to this later. */
+	}
+}
+
+static int add_message_ids(struct ast_vm_user *vmu)
+{
+	int i;
+	for (i = 0; i < ARRAY_LEN(mailbox_folders); ++i)
+	{
+		add_message_ids_folder(vmu, mailbox_folders[i]);
+	}
+}
+
 static struct ast_vm_user *find_or_create(const char *context, const char *box)
 {
 	struct ast_vm_user *vmu;
@@ -11300,6 +11365,11 @@
 	
 	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
+	 */
+	add_message_ids(vmu);
 
 	AST_LIST_INSERT_TAIL(&users, vmu, list);
 	




More information about the asterisk-commits mailing list