mod_voicemail: rework vm_boxcount api and add an optional profile parameter

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13283 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Mathieu Rene 2009-05-12 04:58:32 +00:00
parent 19d9f3db4e
commit 952a3f2374
1 changed files with 43 additions and 24 deletions

View 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) SWITCH_STANDARD_API(boxcount_api_function)
{ {
char *dup; char *dup;
char *how = "new"; const char *how = "new";
int total_new_messages = 0; int total_new_messages = 0;
int total_saved_messages = 0; int total_saved_messages = 0;
int total_new_urgent_messages = 0; int total_new_urgent_messages = 0;
int total_saved_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) { id = dup = strdup(cmd);
switch_hash_index_t *hi;
void *val; if ((p = strchr(dup, '/'))) {
vm_profile_t *profile; *p++ = '\0';
char *id, *domain, *p; id = p;
profilename = dup;
}
if (!strncasecmp(id, "sip:", 4)) {
id += 4;
}
dup = strdup(cmd); if (switch_strlen_zero(id)) {
id = dup; stream->write_function(stream, "%d", 0);
goto done;
}
if (!strncasecmp(cmd, "sip:", 4)) { if ((domain = strchr(id, '@'))) {
id += 4; *domain++ = '\0';
if ((p = strchr(domain, '|'))) {
*p++ = '\0';
how = p;
} }
if (!id) { if (!switch_strlen_zero(profilename)) {
stream->write_function(stream, "%d", 0); if ((profile = get_profile(profilename))) {
free(dup); message_count(profile, id, domain, "inbox", &total_new_messages, &total_saved_messages,
return SWITCH_STATUS_SUCCESS; &total_new_urgent_messages, &total_saved_urgent_messages);
} switch_thread_rwlock_unlock(profile->rwlock);
} else {
if ((domain = strchr(id, '@'))) { stream->write_function(stream, "-ERR No such profile\n");
*domain++ = '\0'; goto done;
if ((p = strchr(domain, '|'))) {
*p++ = '\0';
how = p;
} }
} else {
/* Kept for backwards-compatibility */
switch_hash_index_t *hi;
switch_mutex_lock(globals.mutex); switch_mutex_lock(globals.mutex);
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) { for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
void *val;
switch_hash_this(hi, NULL, NULL, &val); switch_hash_this(hi, NULL, NULL, &val);
profile = (vm_profile_t *) val; profile = (vm_profile_t *) val;
total_new_messages = total_saved_messages = 0; total_new_messages = total_saved_messages = 0;
@ -3255,8 +3274,6 @@ SWITCH_STANDARD_API(boxcount_api_function)
} }
switch_mutex_unlock(globals.mutex); switch_mutex_unlock(globals.mutex);
} }
switch_safe_free(dup);
} }
if (!strcasecmp(how, "saved")) { if (!strcasecmp(how, "saved")) {
@ -3271,6 +3288,8 @@ SWITCH_STANDARD_API(boxcount_api_function)
stream->write_function(stream, "%d", total_new_messages); stream->write_function(stream, "%d", total_new_messages);
} }
done:
switch_safe_free(dup);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }