]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
presence issues for dialog_info
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 2 Sep 2010 21:01:50 +0000 (16:01 -0500)
committerBrian West <brian@freeswitch.org>
Thu, 2 Sep 2010 21:02:04 +0000 (16:02 -0500)
src/mod/endpoints/mod_sofia/sofia_presence.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index d548683c9d07e266880b332dd779b6e3e15b566f..73d930314b55034bbd17346d77d669921bdd562b 100644 (file)
@@ -565,34 +565,32 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                                probe_euser = (p + 1);
                        }
 
-                       
-
-
                        if (probe_euser && probe_host && (profile = sofia_glue_find_profile(probe_host))) {
                                sql = switch_mprintf("select status,rpid from sip_dialogs where sip_from_user='%q' and sip_from_host='%q'", probe_euser, probe_host);
                                sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_dialog_callback, &dh);
                                switch_safe_free(sql);
 
 
-                               sql = switch_mprintf("select sip_registrations.sip_user, '%q', sip_registrations.status, "
+                               sql = switch_mprintf("select sip_registrations.sip_user, sip_registrations.orig_server_host, sip_registrations.status, "
                                                                         "sip_registrations.rpid,'', sip_dialogs.uuid, sip_dialogs.state, sip_dialogs.direction, "
                                                                         "sip_dialogs.sip_to_user, sip_dialogs.sip_to_host, sip_presence.status,sip_presence.rpid,sip_presence.open_closed,"
                                                                         "'%q','%q' "
 
                                                                         "from sip_registrations left join sip_dialogs on "
                                                                         "(sip_dialogs.sip_from_user = sip_registrations.sip_user "
-                                                                        "and sip_dialogs.sip_from_host = sip_registrations.sip_host) "
+                                                                        "and (sip_dialogs.sip_from_host = sip_registrations.orig_server_host or "
+                                                                        "sip_dialogs.sip_from_host = sip_registrations.sip_host) ) "
 
                                                                         
                                                                         "left join sip_presence on "
-                                                                        "(sip_registrations.sip_user=sip_presence.sip_user and sip_registrations.sip_host=sip_presence.sip_host and "
+                                                                        "(sip_registrations.sip_user=sip_presence.sip_user and sip_registrations.orig_server_host=sip_presence.sip_host and "
                                                                         "sip_registrations.profile_name=sip_presence.profile_name) "
                                                                         "where sip_registrations.sip_user='%q' and "
-                                                                        "(sip_registrations.sip_host='%q' or sip_registrations.presence_hosts like '%%%q%%')",
-                                                                        probe_host, dh.status, dh.rpid, probe_euser, probe_host, probe_host);
+                                                                        "(sip_registrations.orig_server_host='%q' or sip_registrations.sip_host='%q' "
+                                                                        "or sip_registrations.presence_hosts like '%%%q%%')",
+                                                                        dh.status, dh.rpid, probe_euser, probe_host, probe_host, probe_host);
                                switch_assert(sql);
                                
-
                                if (mod_sofia_globals.debug_presence > 0) {
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s START_PRESENCE_PROBE_SQL\n", profile->name);
                                }
@@ -622,6 +620,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                                sofia_glue_release_profile(profile);
                                switch_safe_free(sql);
                        }
+                                                
 
                        switch_safe_free(probe_user);
                }
@@ -961,7 +960,7 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
        switch_event_header_t *hp;
 
        if (argc > 5) {
-               uuid = switch_str_nil(argv[5]);
+               uuid = argv[5];
                state = switch_str_nil(argv[6]);
                direction = switch_str_nil(argv[7]);
                if (argc > 8) {
@@ -998,12 +997,13 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
                }
 
                if (zstr(state)) {
-                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", SOFIA_CHAT_PROTO);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_HANGUP");
-                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "resubscribe");
+                       //switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", "resubscribe");
                } else {
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_ROUTING");
-                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", uuid);
+                       if (uuid) {
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", uuid);
+                       }
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "answer-state", state);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "astate", state);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-call-direction", direction);
@@ -1327,10 +1327,11 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
                                                                  "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" "
                                                                  "version=\"%s\" state=\"%s\" entity=\"%s\">\n",
                                                                  version,
-                                                                 !strcasecmp(answer_state, "resubscribe") ? "partial" : "full", clean_id);
+                                                                 zstr(uuid) ? "partial" : "full", clean_id);
                }
 
-               if (strcasecmp(event_status, "Registered")) {
+               //if (strcasecmp(event_status, "Registered")) {
+               if (!zstr(uuid)) {
                        if (!zstr(answer_state)) {
                                astate = answer_state;
                        }
@@ -2237,8 +2238,11 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                                if (switch_event_create(&pevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
                                        switch_event_add_header_string(pevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
                                        switch_event_add_header_string(pevent, SWITCH_STACK_BOTTOM, "login", profile->url);
-                                       switch_event_add_header(pevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
+                                       //switch_event_add_header(pevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
+                                       switch_event_add_header(pevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
+                                       switch_event_add_header(pevent, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, to_host);
                                        switch_event_add_header_string(pevent, SWITCH_STACK_BOTTOM, "event_type", "presence");
+                                       switch_event_add_header_string(pevent, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
                                        switch_event_add_header_string(pevent, SWITCH_STACK_BOTTOM, "event_subtype", "probe");
                                        switch_event_add_header_string(pevent, SWITCH_STACK_BOTTOM, "proto-specific-event-name", event);
                                        switch_event_add_header_string(pevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
index 18df1c439886d0b9330fb16c1e81ed45e8622149..6b90b775fc6b6ae38ee0c3dd1fa27249b9340bbf 100644 (file)
@@ -787,6 +787,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
        const char *from_user = NULL;
        const char *from_host = NULL;
        const char *reg_host = profile->reg_db_domain;
+       const char *sub_host = profile->sub_domain;
        char contact_str[1024] = "";
        int nat_hack = 0;
        uint8_t multi_reg = 0, multi_reg_contact = 0, avoid_multi_reg = 0;
@@ -851,6 +852,9 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
        if (!reg_host) {
                reg_host = to_host;
        }
+       if (!sub_host) {
+               sub_host = to_host;
+       }
 
        if (contact->m_url) {
                const char *port = contact->m_url->url_port;
@@ -1146,11 +1150,14 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                }
 
                if (multi_reg) {
+
+#ifdef DEL_SUBS
                        if (reg_count == 1) {
                                sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q' and contact='%q'", 
-                                                                        to_user, reg_host, contact_str);
+                                                                        to_user, sub_host, contact_str);
                                sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
                        }
+#endif
                                
 
                        if (multi_reg_contact) {
@@ -1160,14 +1167,35 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id);
                        }
                } else {
-                       sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, reg_host);
+#ifdef DEL_SUBS
+                       sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, sub_host);
                        sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+#endif
                        sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, reg_host);
                }
                switch_mutex_lock(profile->ireg_mutex);
                sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 
                switch_find_local_ip(guess_ip4, sizeof(guess_ip4), NULL, AF_INET);
+
+               if (profile->reg_db_domain) {
+                       sofia_profile_t *xprofile;
+
+                       if ((xprofile = sofia_glue_find_profile(to_host))) {
+                               sofia_glue_release_profile(xprofile);
+                       } else {
+
+                               if (sofia_glue_add_profile(switch_core_strdup(profile->pool, to_host), profile) == SWITCH_STATUS_SUCCESS) {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Auto-Adding Alias [%s] for profile [%s]\n", to_host, profile->name);
+                               } else {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Alias [%s] for profile [%s] (already exists)\n",
+                                                                         to_host, profile->name);
+                               }
+                               
+                               
+                       }
+               }
+
                
                sql = switch_mprintf("insert into sip_registrations "
                                                         "(call_id,sip_user,sip_host,presence_hosts,contact,status,rpid,expires,"
@@ -1220,7 +1248,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "user-agent",
                                                                                   (sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
-                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, reg_host);
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", "Registered");
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
                        switch_event_fire(&event);
@@ -1234,8 +1262,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "sip");
                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
-                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, reg_host);
-                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, reg_host);
+                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
+                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, sub_host);
                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", "Registered");
                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_subtype", "probe");
                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
@@ -1253,7 +1281,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "user-agent",
                                                                                   (sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
-                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, reg_host);
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", "Unregistered");
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
                        switch_event_fire(&event);
@@ -1262,7 +1290,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "sip");
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
-                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s+%s@%s", SOFIA_CHAT_PROTO, to_user, reg_host);
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s+%s@%s", SOFIA_CHAT_PROTO, to_user, sub_host);
 
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", "unavailable");
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
@@ -1280,15 +1308,16 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                        if ((p = strchr(icontact + 4, ':'))) {
                                *p = '\0';
                        }
-
+#ifdef DEL_SUBS
                        if (multi_reg_contact) {
                                sql =
-                                       switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q' and contact='%q'", to_user, reg_host, contact_str);
+                                       switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q' and contact='%q'", to_user, sub_host, contact_str);
                        } else {
                                sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", call_id);
                        }
 
                        sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+#endif
 
                        if (multi_reg_contact) {
                                sql =
@@ -1301,10 +1330,11 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
 
                        switch_safe_free(icontact);
                } else {
-                       if ((sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, reg_host))) {
+#ifdef DEL_SUBS
+                       if ((sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, sub_host))) {
                                sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
                        }
-
+#endif
                        if ((sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, reg_host))) {
                                sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
                        }
@@ -1333,15 +1363,26 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                        }
 
 
+#if 0
+                       if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
+                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "login", profile->name);
+                               switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
+                               switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, sub_host);
+                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
+                               switch_event_fire(&s_event);
+                       }
+#else
                        if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
                                switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
                                switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "login", profile->name);
-                               switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, reg_host);
+                               switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
                                switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "rpid", "unknown");
                                switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "status", "Registered");
                                switch_event_fire(&s_event);
-                       }                                       
-
+                       }                               
+#endif
                } else {
                        if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_UNREGISTER) == SWITCH_STATUS_SUCCESS) {
                                switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "profile-name", profile->name);