From 589502d3d998d18d846f635961e1e28c17ffd893 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Oct 2010 14:04:06 -0500 Subject: [PATCH] FS-2747 --- src/mod/endpoints/mod_sofia/sofia_glue.c | 5 +++-- src/mod/endpoints/mod_sofia/sofia_presence.c | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 42b8b5e80b..5e633e0d79 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -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); diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 333f31b91d..d9b3de0a8b 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -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"; }