" contact VARCHAR(255),\n"
" presence_id VARCHAR(255),\n"
" presence_data VARCHAR(255),\n"
- " call_info VARCHAR(255),\n"
- " call_info_state VARCHAR(255)\n"
+ " call_info VARCHAR(255),\n"
+ " call_info_state VARCHAR(255),\n"
+ " expires INTEGER default 0\n"
");\n";
char sub_sql[] =
"create index sd_hostname on sip_dialogs (hostname)",
"create index sd_presence_data on sip_dialogs (presence_data)",
"create index sd_call_info on sip_dialogs (call_info)",
- "create index sd_call_info on sip_dialogs (call_info_state)",
+ "create index sd_call_info_state on sip_dialogs (call_info_state)",
+ "create index sd_expires on sip_dialogs (expires)",
"create index sp_hostname on sip_presence (hostname)",
"create index sa_nonce on sip_authentication (nonce)",
"create index sa_hostname on sip_authentication (hostname)",
}
free(test_sql);
- test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and call_info_state like '%%'", mod_sofia_globals.hostname);
+ test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and expires > 0", mod_sofia_globals.hostname);
if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_dialogs", NULL);
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_subscriptions", sub_sql);
free(test_sql);
- test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and call_info_state like '%%'", mod_sofia_globals.hostname);
+ test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and expires > 0", mod_sofia_globals.hostname);
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_dialogs", dialog_sql);
free(test_sql);
switch_core_db_exec(db, "create index if not exists sd_presence_id on sip_dialogs (presence_id)", NULL, NULL, NULL);
switch_core_db_exec(db, "create index if not exists sd_presence_data on sip_dialogs (presence_data)", NULL, NULL, NULL);
switch_core_db_exec(db, "create index if not exists sd_call_info on sip_dialogs (call_info)", NULL, NULL, NULL);
- switch_core_db_exec(db, "create index if not exists sd_call_info on sip_dialogs (call_info_state)", NULL, NULL, NULL);
+ switch_core_db_exec(db, "create index if not exists sd_call_info_state on sip_dialogs (call_info_state)", NULL, NULL, NULL);
+ switch_core_db_exec(db, "create index if not exists sd_expires on sip_dialogs (expires)", NULL, NULL, NULL);
switch_core_db_exec(db, "create index if not exists sp_hostname on sip_presence (hostname)", NULL, NULL, NULL);
}
}
+void sofia_glue_execute_sql_now(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic)
+{
+ sofia_glue_actually_execute_sql(profile, *sqlp, profile->ireg_mutex);
+ if (sql_already_dynamic) {
+ switch_safe_free(*sqlp);
+ }
+ *sqlp = NULL;
+}
+
switch_cache_db_handle_t *sofia_glue_get_db_handle(sofia_profile_t *profile)
{
if ((sql = switch_mprintf(
"select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
"full_via,expires,user_agent,accept,profile_name,network_ip"
- ",-1,'unavailable','unavailable' from sip_subscriptions where event='presence' and hostname='%q'",
+ ",-1,'unavailable','unavailable' from sip_subscriptions where expires > -1 and event='presence' and hostname='%q'",
mod_sofia_globals.hostname))) {
switch_mutex_lock(mod_sofia_globals.hash_mutex);
for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
if (sofia_glue_execute_sql_callback(profile, profile->ireg_mutex,
"select sub_to_user,sub_to_host,'Online','unknown',proto from sip_subscriptions "
- "where proto='ext' or proto='user' or proto='conf'", sofia_presence_resub_callback, &h) != SWITCH_TRUE) {
+ "where expires > -1 and proto='ext' or proto='user' or proto='conf'",
+ sofia_presence_resub_callback, &h) != SWITCH_TRUE) {
return;
}
}
if (for_everyone) {
sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
"full_via,expires,user_agent,accept,profile_name,network_ip"
- ",'%q','%q' from sip_subscriptions where event='message-summary' "
+ ",'%q','%q' from sip_subscriptions where expires > -1 and event='message-summary' "
"and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%')",
stream.data, host, user, host, host);
} else if (sub_call_id) {
sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
"full_via,expires,user_agent,accept,profile_name,network_ip"
- ",'%q','%q' from sip_subscriptions where event='message-summary' "
+ ",'%q','%q' from sip_subscriptions where expires > -1 and event='message-summary' "
"and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%' and call_id='%q')",
stream.data, host, user, host, host, sub_call_id);
}
"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 "
"sip_subscriptions.profile_name=sip_presence.profile_name) "
- "where sip_subscriptions.event='presence' and sip_subscriptions.full_from like '%%%q%%'",
+ "where sip_subscriptions.expires > -1 and sip_subscriptions.event='presence' and sip_subscriptions.full_from like '%%%q%%'",
switch_str_nil(status), switch_str_nil(rpid), from);
} else {
sql = switch_mprintf(
"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 "
"sip_subscriptions.profile_name=sip_presence.profile_name) "
- "where sip_subscriptions.event='presence'", switch_str_nil(status), switch_str_nil(rpid));
+ "where sip_subscriptions.expires > -1 and sip_subscriptions.event='presence'", switch_str_nil(status), switch_str_nil(rpid));
}
switch_assert(sql != NULL);
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "STATE SQL %s\n", sql);
}
- sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
- switch_safe_free(sql);
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+ if (mod_sofia_globals.debug_sla > 1) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PROCESS PRESENCE EVENT\n");
+ }
+
sync_sla(profile, euser, host, SWITCH_TRUE, SWITCH_TRUE);
}
"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 "
"sip_subscriptions.profile_name=sip_presence.profile_name) "
- "where (event='%q' or event='%q') and sub_to_user='%q' "
+ "where sip_subscriptions.expires > -1 and (event='%q' or event='%q') and sub_to_user='%q' "
"and (sub_to_host='%q' or presence_hosts like '%%%q%%') "
"and (sip_subscriptions.profile_name = '%q' or sip_subscriptions.presence_hosts != sip_subscriptions.sub_to_host)",
switch_str_nil(status), switch_str_nil(rpid), host, event_type, alt_event_type, euser, host, host, profile->name))) {
if (unseize) {
sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event "
"from sip_subscriptions "
- "where hostname='%q' "
+ "where expires > -1 and hostname='%q' "
"and sub_to_user='%q' and sub_to_host='%q' "
"and (event='call-info' or event='line-seize')",
mod_sofia_globals.hostname,
} else {
sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event "
"from sip_subscriptions "
- "where hostname='%q' "
+ "where expires > -1 and hostname='%q' "
"and sub_to_user='%q' and sub_to_host='%q' "
"and (event='call-info')",
mod_sofia_globals.hostname,
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql);
}
- sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
}
}
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' or (contact='%q' and event='%q')", call_id, contact_str, event);
-
- sql = switch_mprintf("delete from sip_subscriptions where call_id='%q' "
+ sql = switch_mprintf("update sip_subscriptions set expires=-1 where call_id='%q' "
"or (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' "
"and contact='%q')",
contact_str);
} else {
- sql = switch_mprintf("delete from sip_subscriptions where "
+ sql = switch_mprintf("update sip_subscriptions set expires=-1 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'",
proto, from_user, from_host, to_user, to_host, event, mod_sofia_globals.hostname);
}
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,
//sofia_test_pflag(profile, PFLAG_MULTIREG) ? switch_epoch_time_now(NULL) + exp_delta : exp_delta * -1,
- (long)switch_epoch_time_now(NULL) + exp_delta,
+ (long)switch_epoch_time_now(NULL) + (exp_delta * 2),
full_agent, accept, profile->name,mod_sofia_globals.hostname, network_port, network_ip);
switch_assert(sql != NULL);
}
- sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
- switch_safe_free(sql);
-
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
sstr = switch_mprintf("active;expires=%ld", exp_delta);
}
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, exp_delta);
+ nua_dialog_usage_set_refresh_range(nh->nh_ds->ds_usage, exp_delta * 2, exp_delta * 2);
}
-
+
nua_respond(nh, SIP_202_ACCEPTED,
SIPTAG_CONTACT_STR(contactstr),
NUTAG_WITH_THIS(nua),
SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
SIPTAG_EXPIRES_STR(exp_delta_str),
TAG_IF(sticky, NUTAG_PROXY(sticky)), TAG_END());
-
+
switch_safe_free(sticky);
}
if (!strcasecmp(event, "line-seize")) {
- sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_TRUE);
+ if (mod_sofia_globals.debug_sla > 1) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CANCEL LINE SEIZE\n");
+ }
+
+ sql = switch_mprintf("delete from sip_dialogs where sip_from_user='%q' and sip_from_host='%q' and call_info_state='seized'",
+ to_user,
+ to_host
+ );
+
+
+ if (mod_sofia_globals.debug_sla > 1) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql);
+ }
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+
+ sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE);
}
su_free(profile->home, full_call_info);
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql);
}
- sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
-
- sql = switch_mprintf("insert into sip_dialogs (sip_from_user,sip_from_host,call_info,call_info_state,hostname) "
- "values ('%q','%q','%q','seized','%q')",
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+
+ sql = switch_mprintf("insert into sip_dialogs (sip_from_user,sip_from_host,call_info,call_info_state,hostname,expires) "
+ "values ('%q','%q','%q','seized','%q',%ld)",
to_user,
to_host,
switch_str_nil(p),
- mod_sofia_globals.hostname
+ mod_sofia_globals.hostname,
+ switch_epoch_time_now(NULL) + exp_delta
);
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SEIZE SQL %s\n", sql);
}
- sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
- switch_safe_free(sql);
- sync_sla(profile, to_user, to_host, SWITCH_TRUE, SWITCH_FALSE);
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+ sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE);
su_free(profile->home, full_call_info);
}
- }
-
-
-
- if (!strcasecmp(event, "call-info")) {
+ } else if (!strcasecmp(event, "call-info")) {
sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE);
}
-
}
-
-
sent_reply++;
if ((sql = switch_mprintf(
"select proto,sip_user,'%q',sub_to_user,sub_to_host,event,contact,call_id,full_from,"
"full_via,expires,user_agent,accept,profile_name,network_ip"
- " from sip_subscriptions where event='message-summary' and sip_user='%q' "
+ " from sip_subscriptions where expires > -1 and event='message-summary' and sip_user='%q' "
"and (sip_host='%q' or presence_hosts like '%%%q%%')",
to_host, to_user, to_host, to_host))) {
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_reg_callback, profile);