]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_voicemail: rework vm_boxcount api and add an optional profile parameter
authorMathieu Rene <mrene@avgs.ca>
Tue, 12 May 2009 04:58:32 +0000 (04:58 +0000)
committerMathieu Rene <mrene@avgs.ca>
Tue, 12 May 2009 04:58:32 +0000 (04:58 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13283 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_voicemail/mod_voicemail.c

index 30eee87ecfeac5a06231fb07a6fcc477e198fcd5..4ff1b616aaf9bb9320bb97c7fb63151a1d398ab5 100644 (file)
@@ -3210,43 +3210,62 @@ SWITCH_STANDARD_APP(voicemail_function)
        
 }
 
-#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_STANDARD_API(boxcount_api_function)
                        }
                        switch_mutex_unlock(globals.mutex);
                }
-
-               switch_safe_free(dup);
        }
 
        if (!strcasecmp(how, "saved")) {
@@ -3271,6 +3288,8 @@ SWITCH_STANDARD_API(boxcount_api_function)
                stream->write_function(stream, "%d", total_new_messages);
        }
 
+done:
+       switch_safe_free(dup);
        return SWITCH_STATUS_SUCCESS;
 }