Revision
15364
Author
anthm
Date
2009-11-04 22:21:08 -0600 (Wed, 04 Nov 2009)

Log Message

make subscriptions time out discarding hack to make them last forever

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (15363 => 15364)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2009-11-05 02:10:10 UTC (rev 15363)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2009-11-05 04:21:08 UTC (rev 15364)
@@ -1133,6 +1133,7 @@
 		nua_set_params(node->nua,
 					   NUTAG_APPL_METHOD("OPTIONS"),
 					   NUTAG_APPL_METHOD("REFER"),
+					   NUTAG_APPL_METHOD("SUBSCRIBE"),
 					   NUTAG_AUTOANSWER(0),
 					   NUTAG_AUTOACK(0),
 					   NUTAG_AUTOALERT(0),

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (15363 => 15364)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	2009-11-05 02:10:10 UTC (rev 15363)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	2009-11-05 04:21:08 UTC (rev 15364)
@@ -3848,7 +3848,7 @@
 		switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_registrations", reg_sql);
 		free(test_sql);
 
-		test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and network_ip!='-1'", mod_sofia_globals.hostname);
+		test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and network_ip!='-1' and network_port!='-1'", mod_sofia_globals.hostname);
 		switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_subscriptions", sub_sql);
 		free(test_sql);
 
@@ -4006,6 +4006,8 @@
 	} else if (profile->odbc_dsn) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
 	} else {
+		char *errmsg;
+
 		if (master) {
 			db = profile->master_db;
 		} else {
@@ -4014,8 +4016,13 @@
 				goto end;
 			}
 		}
-		switch_core_db_persistant_execute(db, sql, 1);
 
+		switch_core_db_exec(db, sql, NULL, NULL, &errmsg);
+		if (errmsg) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n%s\n", errmsg, sql);
+			switch_core_db_free(errmsg);
+		}
+
 		if (!master) {
 			switch_core_db_close(db);
 		}

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (15363 => 15364)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	2009-11-05 02:10:10 UTC (rev 15363)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	2009-11-05 04:21:08 UTC (rev 15364)
@@ -1041,7 +1041,7 @@
 	if (expires) {
 		long tmp = atol(expires);
 		if (tmp > 0) {
-			exptime = tmp - switch_epoch_time_now(NULL) - SUB_OVERLAP;
+			exptime = tmp - switch_epoch_time_now(NULL);// - SUB_OVERLAP;
 		} else {
 			exptime = tmp;
 		}
@@ -1628,7 +1628,7 @@
 		switch_snprintf(exp_delta_str, sizeof(exp_delta_str), "%ld", exp_delta);
 		
 		if (sofia_test_pflag(profile, PFLAG_MULTIREG)) {
-			sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", call_id);
+			sql = switch_mprintf("delete from sip_subscriptions where call_id='%q' or (contact='%q' and and event='%q')", call_id, contact_str, event);
 		} else {
 			sql = switch_mprintf("delete from sip_subscriptions where "
 								 "proto='%q' and sip_user='%q' and sip_host='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q' and hostname='%q'",
@@ -1662,14 +1662,14 @@
 
 			sql = switch_mprintf("insert into sip_subscriptions "
 								 "(proto,sip_user,sip_host,sub_to_user,sub_to_host,presence_hosts,event,contact,call_id,full_from,"
-								 "full_via,expires,user_agent,accept,profile_name,hostname,network_ip) "
-								 "values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld,'%q','%q','%q','%q','%q')",
+								 "full_via,expires,user_agent,accept,profile_name,hostname,network_port,network_ip) "
+								 "values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld,'%q','%q','%q','%q','%d','%q')",
 								 proto, from_user, from_host, to_user, to_host, profile->presence_hosts ? profile->presence_hosts : to_host, 
 								 event, contact_str, call_id, full_from, full_via, 
-								 exp_delta * -1, 
-								 full_agent, accept, profile->name,mod_sofia_globals.hostname, network_ip);
+								 //sofia_test_pflag(profile, PFLAG_MULTIREG) ? switch_epoch_time_now(NULL) + exp_delta : exp_delta * -1,
+								 switch_epoch_time_now(NULL) + exp_delta,
+								 full_agent, accept, profile->name,mod_sofia_globals.hostname, network_port, network_ip);
 								 
-			
 			if (mod_sofia_globals.debug_presence > 0) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s SUBSCRIBE %s@%s %s@%s\n", profile->name, from_user, from_host, to_user, to_host);
 			}
@@ -1723,7 +1723,8 @@
 			}
 
 			if (nh && nh->nh_ds && nh->nh_ds->ds_usage) {
-				nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, exp_delta + SUB_OVERLAP, exp_delta + SUB_OVERLAP);
+				//nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, exp_delta + SUB_OVERLAP, exp_delta + SUB_OVERLAP);
+				nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, exp_delta, exp_delta);
 			}
 
 			nua_respond(nh, SIP_202_ACCEPTED,

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (15363 => 15364)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	2009-11-05 02:10:10 UTC (rev 15363)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	2009-11-05 04:21:08 UTC (rev 15364)
@@ -1569,25 +1569,6 @@
 
 }
 
-static unsigned long get_nc(const char *nc, sip_t const *sip)
-{
-	unsigned long x;
-	const char *ua = NULL;
-
-	if (sip->sip_user_agent) {
-		ua = sip->sip_user_agent->g_string;
-	}
-
-	/* sigh, polycom sends nc in base-10 rather than spec which says base-16*/
-	if (ua && switch_stristr("polycom", ua)) {
-		x = strtoul(nc, 0, 10);
-	} else {
-		x = strtoul(nc, 0, 16);
-	}
-
-	return x;
-}
-
 auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, 
 								sip_authorization_t const *authorization, 
 								sip_t const *sip, 
@@ -1680,10 +1661,7 @@
 	if (zstr(np)) {
 		first = 1;
 		if (nc) {
-			unsigned long x;
-
-			x = get_nc(nc, sip);
-			sql = switch_mprintf("select nonce from sip_authentication where nonce='%q' and last_nc + 1 >= %lu", nonce, x);
+			sql = switch_mprintf("select nonce from sip_authentication where nonce='%q' and last_nc < %lu", nonce, strtoul(nc, 0, 16));
 		} else {
 			sql = switch_mprintf("select nonce from sip_authentication where nonce='%q'", nonce);
 		}
@@ -2079,17 +2057,15 @@
 
 
 	if (nc && cnonce && qop) {
-		unsigned long x;
 		char *sql;
 
-		x = get_nc(nc, sip);
 #if defined(_WIN32) && !defined(_WIN64)
 #define	LL_FMT "ll"
 #else
 #define	LL_FMT "l"
 #endif
 		sql = switch_mprintf("update sip_authentication set expires='%"LL_FMT"u',last_nc=%lu where nonce='%s'", 
-							 switch_epoch_time_now(NULL) + (profile->nonce_ttl ? profile->nonce_ttl : exptime + 10), x, nonce);
+							 switch_epoch_time_now(NULL) + (profile->nonce_ttl ? profile->nonce_ttl : exptime + 10), strtoul(nc, 0, 16), nonce);
 
 		switch_assert(sql != NULL);
 		sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);