]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-2747
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 1 Oct 2010 19:04:06 +0000 (14:04 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 1 Oct 2010 19:04:06 +0000 (14:04 -0500)
src/mod/endpoints/mod_sofia/sofia_glue.c
src/mod/endpoints/mod_sofia/sofia_presence.c

index 42b8b5e80b24768b6d692c922be1141abd59cdf9..5e633e0d7910ca129375f38406772d03aa3e5626 100644 (file)
@@ -5216,7 +5216,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
                "   profile_name    VARCHAR(255),\n"
                "   hostname        VARCHAR(255),\n"
                "   network_port    VARCHAR(6),\n"
-               "   network_ip      VARCHAR(255)\n"
+               "   network_ip      VARCHAR(255),\n"
+               "   version         INTEGER DEFAULT 0 NOT NULL\n"
                ");\n";
 
        char auth_sql[] =
@@ -5336,7 +5337,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
        free(test_sql);
 
 
-       test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and network_ip like '%%' and network_port like '%%'",
+       test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and version < 0 and network_ip like '%%' and network_port like '%%'",
                                                          mod_sofia_globals.hostname);
        switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_subscriptions", sub_sql);
 
index 333f31b91d6de4c4100ac99497d1a26bb93b902e..d9b3de0a8b9ebd9be6285b334cffa4dbd1b8affd 100644 (file)
@@ -700,7 +700,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                                                                  "sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
                                                                  "sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
                                                                  "sip_subscriptions.accept,sip_subscriptions.profile_name"
-                                                                 ",'%q','%q','%q',sip_presence.status,sip_presence.rpid,sip_presence.open_closed,'%q','%q' "
+                                                                 ",'%q','%q','%q',sip_presence.status,sip_presence.rpid,sip_presence.open_closed,'%q','%q',sip_subscriptions.version "
                                                                  "from sip_subscriptions "
                                                                  "left join sip_presence on "
                                                                  "(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
@@ -743,6 +743,15 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
 
                        sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_presence_sub_callback, &helper);
 
+
+                       sql = switch_mprintf("update sip_subscriptions set version=version+1 where event='dialog' and sub_to_user='%q' "
+                                                                "and (sub_to_host='%q' or presence_hosts like '%%%q%%') "
+                                                                "and (profile_name = '%q' or presence_hosts != sub_to_host)",
+                                                                euser, host, host, profile->name);
+
+                       sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+
+
                        if (mod_sofia_globals.debug_presence > 0) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END_PRESENCE_SQL (%s)\n",
                                                                  event->event_id == SWITCH_EVENT_PRESENCE_IN ? "IN" : "OUT", profile->name);
@@ -1193,7 +1202,8 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
        int kill_handle = 0;
        char expires_str[10] = "";
        char status_line[256] = "";
-
+       char *version = "0";
+       
        //int i;
        
        //for(i = 0; i < argc; i++) {
@@ -1213,6 +1223,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
        if (argc > 20) {
                dialog_status = argv[20];
                dialog_rpid = argv[21];
+               version = argv[22];
        }
 
        in = helper->event && helper->event->event_id == SWITCH_EVENT_PRESENCE_IN;
@@ -1317,8 +1328,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
                }
 
                if (is_dialog) {
-                       char *version = switch_event_get_header(helper->event, "event_count");
-                       if (!version) {
+                       if (zstr(version)) {
                                version = "0";
                        }