[Freeswitch-svn] [commit] r13283 - freeswitch/trunk/src/mod/applications/mod_voicemail

FreeSWITCH SVN mrene at freeswitch.org
Mon May 11 21:58:32 PDT 2009


Author: mrene
Date: Mon May 11 23:58:32 2009
New Revision: 13283

Log:
mod_voicemail: rework vm_boxcount api and add an optional profile parameter

Modified:
   freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c

Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	Mon May 11 23:58:32 2009
@@ -3210,43 +3210,62 @@
 	
 }
 
-#define BOXCOUNT_SYNTAX "<user>@<domain>[|[new|saved|new-urgent|saved-urgent|all]]"
+#define BOXCOUNT_SYNTAX "[profile/]<user>@<domain>[|[new|saved|new-urgent|saved-urgent|all]]"
 SWITCH_STANDARD_API(boxcount_api_function)
 {
 	char *dup;
-	char *how = "new";
+	const char *how = "new";
 	int total_new_messages = 0;
 	int total_saved_messages = 0;
 	int total_new_urgent_messages = 0;
 	int total_saved_urgent_messages = 0;
+	vm_profile_t *profile;
+	char *id, *domain, *p, *profilename = NULL;
+	
+	if (switch_strlen_zero(cmd)) {
+		stream->write_function(stream, "%d", 0);	
+		return SWITCH_STATUS_SUCCESS;
+	}
 
-	if (cmd) {
-		switch_hash_index_t *hi;
-		void *val;
-		vm_profile_t *profile;
-		char *id, *domain, *p;
-
-		dup = strdup(cmd);
-		id = dup;
+	id = dup = strdup(cmd);
+	
+	if ((p = strchr(dup, '/'))) {
+		*p++ = '\0';
+		id = p;
+		profilename = dup;
+	}
+	
+	if (!strncasecmp(id, "sip:", 4)) {
+		id += 4;
+	}
 
-		if (!strncasecmp(cmd, "sip:", 4)) {
-			id += 4;
-		}
+	if (switch_strlen_zero(id)) {
+		stream->write_function(stream, "%d", 0);
+		goto done;
+	}
 
-		if (!id) {
-			stream->write_function(stream, "%d", 0);
-			free(dup);
-			return SWITCH_STATUS_SUCCESS;
+	if ((domain = strchr(id, '@'))) {
+		*domain++ = '\0';
+		if ((p = strchr(domain, '|'))) {
+			*p++ = '\0';
+			how = p;
 		}
 
-		if ((domain = strchr(id, '@'))) {
-			*domain++ = '\0';
-			if ((p = strchr(domain, '|'))) {
-				*p++ = '\0';
-				how = p;
+		if (!switch_strlen_zero(profilename)) {
+			if ((profile = get_profile(profilename))) {
+				message_count(profile, id, domain, "inbox", &total_new_messages, &total_saved_messages,
+							  &total_new_urgent_messages, &total_saved_urgent_messages);
+				switch_thread_rwlock_unlock(profile->rwlock);
+			} else {
+				stream->write_function(stream, "-ERR No such profile\n");
+				goto done;
 			}
+		} else {
+			/* Kept for backwards-compatibility */
+			switch_hash_index_t *hi;
 			switch_mutex_lock(globals.mutex);
 			for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+				void *val;
 				switch_hash_this(hi, NULL, NULL, &val);
 				profile = (vm_profile_t *) val;
 				total_new_messages = total_saved_messages = 0;
@@ -3255,8 +3274,6 @@
 			}
 			switch_mutex_unlock(globals.mutex);
 		}
-
-		switch_safe_free(dup);
 	}
 
 	if (!strcasecmp(how, "saved")) {
@@ -3271,6 +3288,8 @@
 		stream->write_function(stream, "%d", total_new_messages);
 	}
 
+done:
+	switch_safe_free(dup);
 	return SWITCH_STATUS_SUCCESS;
 }
 



More information about the Freeswitch-svn mailing list