]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
message-query-exact-match global param in settings section of voicemail to assume...
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 24 Apr 2009 14:27:19 +0000 (14:27 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 24 Apr 2009 14:27:19 +0000 (14:27 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13138 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_voicemail/mod_voicemail.c

index b2f578ffdc671f226b5daa38925ff6c2626f6988..093ba95f1472855f9352a510888359e27b5f26d2 100644 (file)
@@ -54,6 +54,7 @@ static switch_status_t voicemail_inject(const char *data);
 static struct {
        switch_hash_t *profile_hash;
        int debug;
+       int message_query_exact_match;
        switch_memory_pool_t *pool;
 } globals;
 
@@ -269,6 +270,8 @@ static switch_status_t load_config(void)
 
                        if (!strcasecmp(var, "debug")) {
                                globals.debug = atoi(val);
+                       } else if (!strcasecmp(var, "message-query-exact-match")) {
+                               globals.message_query_exact_match = switch_true(val);
                        }
                }
        }
@@ -3199,19 +3202,40 @@ SWITCH_STANDARD_API(boxcount_api_function)
        return SWITCH_STATUS_SUCCESS;
 }
 
+#define parse_profile() {\
+               total_new_messages = total_saved_messages = 0;                                  \
+               message_count(profile, id, domain, "inbox", &total_new_messages, &total_saved_messages, \
+                                         &total_new_urgent_messages, &total_saved_urgent_messages); \
+               if (total_new_messages || total_saved_messages) {\
+                       if (switch_event_create(&new_event, SWITCH_EVENT_MESSAGE_WAITING) == SWITCH_STATUS_SUCCESS) { \
+                               const char *yn = "no";                                                                  \
+                               if (total_new_messages || total_new_urgent_messages) {  \
+                                       yn = "yes";                                                                                     \
+                               }                                                                                                               \
+                               switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", yn);\
+                               switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", account); \
+                               switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", \
+                                                                               total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages); \
+                               created++;                                                                                              \
+                       }                                                                                                                       \
+               }                                                                                                                               \
+       }
+
+
+
 static void message_query_handler(switch_event_t *event)
 {
        char *account = switch_event_get_header(event, "message-account");
        int created = 0;
        switch_event_t *new_event = NULL;
        char *dup = NULL;
+       int total_new_messages = 0;
+       int total_saved_messages = 0;
+       int total_new_urgent_messages = 0;
+       int total_saved_urgent_messages = 0;
 
        if (account) {
                switch_hash_index_t *hi;
-               int total_new_messages = 0;
-               int total_saved_messages = 0;
-               int total_new_urgent_messages = 0;
-               int total_saved_urgent_messages = 0;
                void *val;
                vm_profile_t *profile;
                char *id, *domain;
@@ -3222,38 +3246,32 @@ static void message_query_handler(switch_event_t *event)
                if (!strncasecmp(account, "sip:", 4)) {
                        id += 4;
                }
-
+               
                if (!id) {
                        free(dup);
                        return;
                }
 
+
                if ((domain = strchr(id, '@'))) {
                        *domain++ = '\0';
-                       for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
-                               switch_hash_this(hi, NULL, NULL, &val);
-                               profile = (vm_profile_t *) val;
-                               total_new_messages = total_saved_messages = 0;
-                               message_count(profile, id, domain, "inbox", &total_new_messages, &total_saved_messages,
-                                                         &total_new_urgent_messages, &total_saved_urgent_messages);
-                               if (total_new_messages || total_saved_messages) {
-                                       if (switch_event_create(&new_event, SWITCH_EVENT_MESSAGE_WAITING) == SWITCH_STATUS_SUCCESS) {
-                                               const char *yn = "no";
-                                               if (total_new_messages || total_new_urgent_messages) {
-                                                       yn = "yes";
-                                               }
-                                               switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", yn);
-                                               switch_event_add_header_string(new_event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", account);
-                                               switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)",
-                                                                                               total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
-                                               created++;
-                                       }
+                       profile = NULL;
+
+                       if (globals.message_query_exact_match) {
+                               if ((profile = (vm_profile_t *) switch_core_hash_find(globals.profile_hash, domain))) {
+                                       parse_profile();
+                               }
+                       } else {
+                               for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+                                       switch_hash_this(hi, NULL, NULL, &val);
+                                       profile = (vm_profile_t *) val;
+                                       parse_profile();
                                }
                        }
                }
-
+               
                switch_safe_free(dup);
-
+               
        }
 
        if (!created) {