diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 786d43f2db..b588956262 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1133,6 +1133,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void 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), diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 22abf3786e..265097463b 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -3848,7 +3848,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile) 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 @@ void sofia_glue_actually_execute_sql(sofia_profile_t *profile, switch_bool_t mas } 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,7 +4016,12 @@ void sofia_glue_actually_execute_sql(sofia_profile_t *profile, switch_bool_t mas 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); diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 5093c1adc3..e0fe13fe3c 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -1041,7 +1041,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char * 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 @@ void sofia_presence_handle_sip_i_subscribe(int status, 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 @@ void sofia_presence_handle_sip_i_subscribe(int status, 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 @@ void sofia_presence_handle_sip_i_subscribe(int status, } 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, diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 5769e2df2e..870b3079d0 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -1569,25 +1569,6 @@ void sofia_reg_handle_sip_r_challenge(int status, } -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 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, 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 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, 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);