]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
reduce exponential mwi notifies
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 27 Mar 2009 00:27:07 +0000 (00:27 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 27 Mar 2009 00:27:07 +0000 (00:27 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12801 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index d7041b28e69d186c8f9d513a626dd1ef924297f7..20441886364bb39763664eebff229d69c07d7b9f 100644 (file)
@@ -477,6 +477,8 @@ void sofia_event_callback(nua_event_t event,
                sofia_presence_handle_sip_i_publish(nua, profile, nh, sofia_private, sip, tags);
                break;
        case nua_i_register:
+               //nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(sip->sip_contact), NUTAG_WITH_THIS(nua), TAG_END());
+               //nua_handle_destroy(nh);
                sofia_reg_handle_sip_i_register(nua, profile, nh, sofia_private, sip, tags);
                break;
        case nua_i_state:
index 645e82db2cf2ef76ae020fc3f822fcce50826954..456a7ff131bfd846e56c10812295f6ffb3693e1a 100644 (file)
@@ -283,6 +283,8 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
        switch_event_header_t *hp;
        struct mwi_helper h = { 0 };
        char *pname = NULL;
+       const char *call_id;
+       const char *sub_call_id;
 
        switch_assert(event != NULL);
 
@@ -296,6 +298,9 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
                return;
        }
 
+       call_id = switch_event_get_header(event, "call-id");
+       sub_call_id = switch_event_get_header(event, "sub-call-id");
+
        dup_account = strdup(account);
        switch_assert(dup_account != NULL);
        sofia_glue_get_user_host(dup_account, &user, &host);
@@ -339,30 +344,39 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
 
        stream.write_function(&stream, "\r\n");
        
-       sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
-                                                "full_via,expires,user_agent,accept,profile_name"
-                                                ",'%q','%q' from sip_subscriptions where event='message-summary' "
-                                                "and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%')",
-                                                stream.data, host, user, host, host);
-
-       switch_assert(sql != NULL);
-       sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_mwi_callback, &h);
-       
-       switch_safe_free(sql);
-
-       sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q' from sip_registrations where sip_user='%q' and sip_host='%q'", 
-                                                stream.data, user, host);
-
+       sql = NULL;
+
+       if (sub_call_id) {
+               sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
+                                                        "full_via,expires,user_agent,accept,profile_name"
+                                                        ",'%q','%q' from sip_subscriptions where event='message-summary' "
+                                                        "and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%' and call_id='%q')",
+                                                        stream.data, host, user, host, host, sub_call_id);
+       } else if (!call_id) {
+               sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
+                                                        "full_via,expires,user_agent,accept,profile_name"
+                                                        ",'%q','%q' from sip_subscriptions where event='message-summary' "
+                                                        "and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%')",
+                                                        stream.data, host, user, host, host);
+       }
+
+       if (sql) {
+               sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_mwi_callback, &h);
+               switch_safe_free(sql);
 
+       } else if (call_id) {
+               sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q' "
+                                                        "from sip_registrations where sip_user='%q' and sip_host='%q' and call_id='%q'", 
+                                                        stream.data, user, host, call_id);
+               switch_assert(sql != NULL);
+               sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_mwi_callback2, &h);
+       }
 
-       switch_assert(sql != NULL);
-       sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_mwi_callback2, &h);
 
        switch_safe_free(sql);
-
        switch_safe_free(stream.data);
-
        switch_safe_free(dup_account);
+
        if (profile) {
                sofia_glue_release_profile(profile);
        }
@@ -791,6 +805,7 @@ static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, ch
                if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) {
                        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", user, host);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "VM-Sofia-Profile", profile->name);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "VM-sub-call-id", argv[7]);
                        switch_event_fire(&event);
                }
                return 0;
index 1e3fb0422decce08e72b2ccfdcec13479e24eb83..af18fe154b8eb5d58f9726cb9bec368439f587d2 100644 (file)
@@ -1137,6 +1137,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                        if (switch_event_create(&s_event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) {
                                switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", to_user, reg_host);
                                switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "VM-Sofia-Profile", profile->name);
+                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "VM-Call-ID", call_id);
                        }
                } else {
                        if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_UNREGISTER) == SWITCH_STATUS_SUCCESS) {