if (profile->pres_type) {
char *sql;
+ time_t now;
+
const char *presence_id = switch_channel_get_variable(nchannel, "presence_id");
const char *presence_data = switch_channel_get_variable(nchannel, "presence_data");
presence_data = switch_event_get_header(var_event, "presence_data");
}
- sql = switch_mprintf("insert into sip_dialogs (uuid,presence_id,presence_data,profile_name,hostname) "
- "values ('%q', '%q', '%q', '%q', '%q')", switch_core_session_get_uuid(nsession),
- switch_str_nil(presence_id), switch_str_nil(presence_data), profile->name, mod_sofia_globals.hostname);
+ now = switch_epoch_time_now(NULL);
+ sql = switch_mprintf("insert into sip_dialogs (uuid,presence_id,presence_data,profile_name,hostname,rcd) "
+ "values ('%q', '%q', '%q', '%q', '%q', %ld)", switch_core_session_get_uuid(nsession),
+ switch_str_nil(presence_id), switch_str_nil(presence_data), profile->name, mod_sofia_globals.hostname, (long) now);
sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
switch_safe_free(sql);
}
profile->contact_user = SOFIA_DEFAULT_CONTACT_USER;
sofia_set_pflag(profile, PFLAG_PASS_CALLEE_ID);
sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
- sofia_set_pflag(profile, PFLAG_SQL_IN_TRANS);
sofia_set_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER);
+ sofia_set_pflag(profile, PFLAG_SQL_IN_TRANS);
+
profile->shutdown_type = "false";
profile->local_network = "localnet.auto";
sofia_set_flag(profile, TFLAG_ENABLE_SOA);
const char *presence_id = switch_channel_get_variable(channel, "presence_id");
char *full_contact = "";
char *p = NULL;
-
+ time_t now;
+
if (sip->sip_contact) {
full_contact = sip_header_as_string(nua_handle_home(tech_pvt->nh), (void *) sip->sip_contact);
}
if (call_info && (p = strchr(call_info, ';'))) {
p++;
}
+
+ now = switch_epoch_time_now(NULL);
+
sql = switch_mprintf("insert into sip_dialogs "
"(call_id,uuid,sip_to_user,sip_to_host,sip_to_tag,sip_from_user,sip_from_host,sip_from_tag,contact_user,"
- "contact_host,state,direction,user_agent,profile_name,hostname,contact,presence_id,presence_data,call_info) "
- "values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
+ "contact_host,state,direction,user_agent,profile_name,hostname,contact,presence_id,presence_data,call_info,rcd) "
+ "values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
call_id,
switch_core_session_get_uuid(session),
to_user, to_host, to_tag, from_user, from_host, from_tag, contact_user,
contact_host, astate, "outbound", user_agent,
profile->name, mod_sofia_globals.hostname, switch_str_nil(full_contact),
- switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(p));
+ switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(p), (long) now);
switch_assert(sql);
sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
const char *presence_id = switch_channel_get_variable(channel, "presence_id");
char *full_contact = "";
char *p = NULL;
-
+ time_t now;
if (sip->sip_contact) {
full_contact = sip_header_as_string(nua_handle_home(tech_pvt->nh), (void *) sip->sip_contact);
}
}
+ now = switch_epoch_time_now(NULL);
sql = switch_mprintf("insert into sip_dialogs "
"(call_id,uuid,sip_to_user,sip_to_host,sip_to_tag,sip_from_user,sip_from_host,sip_from_tag,contact_user,"
- "contact_host,state,direction,user_agent,profile_name,hostname,contact,presence_id,presence_data,call_info) "
- "values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
+ "contact_host,state,direction,user_agent,profile_name,hostname,contact,presence_id,presence_data,call_info,rcd) "
+ "values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
call_id,
tech_pvt->sofia_private->uuid,
to_user, to_host, to_tag, dialog_from_user, dialog_from_host, from_tag,
contact_user, contact_host, "confirmed", "inbound", user_agent,
profile->name, mod_sofia_globals.hostname, switch_str_nil(full_contact),
- switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(p));
+ switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(p), now);
switch_assert(sql);
" status VARCHAR(255),\n"
" rpid VARCHAR(255),\n"
" sip_to_tag VARCHAR(255),\n"
- " sip_from_tag VARCHAR(255)\n"
+ " sip_from_tag VARCHAR(255),\n"
+ " rcd INTEGER not null default 0\n"
");\n";
char sub_sql[] =
free(test_sql);
- test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and version < 0 and orig_proto like '%%' and network_ip like '%%' and network_port like '%%'",
+ test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' "
+ "and (version < 0 or orig_proto like '%%' or network_ip like '%%' or network_port like '%%')",
mod_sofia_globals.hostname);
switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_subscriptions", sub_sql);
free(test_sql);
- test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and expires <> -9999 or rpid='' or sip_from_tag=''", mod_sofia_globals.hostname);
+ test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and (expires <> -9999 or rpid='' or sip_from_tag='' || rcd > 0)",
+ mod_sofia_globals.hostname);
switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_dialogs", dialog_sql);
char status[512];
char rpid[512];
char presence_id[1024];
+ int hits;
};
struct resub_helper {
switch_set_string(helper->status, argv[0]);
switch_set_string(helper->rpid, argv[1]);
switch_set_string(helper->presence_id, argv[2]);
+ helper->hits++;
}
return -1;
char *probe_user = NULL, *probe_euser, *probe_host, *p;
struct dialog_helper dh = { { 0 } };
+ //DUMP_EVENT(event);
+
if (!proto || strcasecmp(proto, SOFIA_CHAT_PROTO) != 0) {
return;
}
if (probe_euser && probe_host && (profile = sofia_glue_find_profile(probe_host))) {
sql = switch_mprintf("select status,rpid,presence_id from sip_dialogs "
- "where ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q')",
+ "where ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') order by rcd desc",
probe_euser, probe_host, probe_euser, probe_host);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_dialog_callback, &dh);
char *sql = NULL;
char *euser = NULL, *user = NULL, *host = NULL;
char *call_info = switch_event_get_header(event, "presence-call-info");
+ char *presence_source = switch_event_get_header(event, "presence-source");
char *call_info_state = switch_event_get_header(event, "presence-call-info-state");
switch_console_callback_match_t *matches;
call_info, call_info_state, mod_sofia_globals.hostname, euser, host, euser, host, call_info);
}
+ //printf("WTF %s\n", sql);
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "STATE SQL %s\n", sql);
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
}
- sql = switch_mprintf("select status,rpid,presence_id from sip_dialogs where ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q')",
+ sql = switch_mprintf("select status,rpid,presence_id from sip_dialogs "
+ "where ((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') order by rcd desc",
euser, host, euser, host);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_dialog_callback, &dh);
switch_safe_free(sql);
+
+
+ if (dh.hits && presence_source && (!strcasecmp(presence_source, "register") || switch_stristr("register", status))) {
+ goto done;
+ }
+
if ((sql = switch_mprintf("select distinct sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
"sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
event->event_id == SWITCH_EVENT_PRESENCE_IN ? "IN" : "OUT", profile->name);
}
-#if 0
+#if 1
if (event) {
const char *refresh = switch_event_get_header(event, "refresh");
if (switch_true(refresh)) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Force-Direction", "inbound");
}
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "resub", "true");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", status);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
//const char *force_direction = switch_str_nil(switch_event_get_header(helper->event, "force-direction"));
const char *uuid = switch_str_nil(switch_event_get_header(helper->event, "unique-id"));
const char *event_status = switch_str_nil(switch_event_get_header(helper->event, "status"));
+ const char *resub = switch_str_nil(switch_event_get_header(helper->event, "resub"));
const char *force_event_status = switch_str_nil(switch_event_get_header(helper->event, "force-status"));
const char *astate = switch_str_nil(switch_event_get_header(helper->event, "astate"));
const char *answer_state = switch_str_nil(switch_event_get_header(helper->event, "answer-state"));
ct = "application/dialog-info+xml";
}
- if (!zstr(astate) && !zstr(uuid) && helper && helper->stream.data && strcmp(helper->last_uuid, uuid)) {
+ if (!zstr(astate) && !zstr(uuid) &&
+ helper && helper->stream.data && strcmp(helper->last_uuid, uuid) && strcasecmp(astate, "terminated") && strchr(uuid, '-')) {
helper->stream.write_function(&helper->stream, "update sip_dialogs set state='%s' where uuid='%s';", astate, uuid);
-
+ //printf("WTF update sip_dialogs set state='%s' where uuid='%s';\n", astate, uuid);
switch_copy_string(helper->last_uuid, uuid, sizeof(helper->last_uuid));
}
switch_set_string(status_line, status);
if (in) {
- const char *direction = switch_event_get_header(helper->event, "Caller-Direction");
- const char *op, *what = "Ring";
-
- if (direction && !strcasecmp(direction, "outbound")) {
- op = switch_event_get_header(helper->event, "Other-Leg-Caller-ID-Number");
- } else {
- op = switch_event_get_header(helper->event, "Caller-Callee-ID-Number");
- }
-
- if (zstr(op)) {
- op = switch_event_get_header(helper->event, "Caller-Destination-Number");
- }
+ open = "open";
- if (direction) {
- what = strcasecmp(direction, "outbound") ? "Call" : "Ring";
- }
+ if (switch_false(resub)) {
- if (!strcmp(astate, "early")) {
- if (zstr(op)) {
- switch_snprintf(status_line, sizeof(status_line), "%sing", what);
+ const char *direction = switch_event_get_header(helper->event, "Caller-Direction");
+ const char *op, *what = "Ring";
+
+ if (direction && !strcasecmp(direction, "outbound")) {
+ op = switch_event_get_header(helper->event, "Other-Leg-Caller-ID-Number");
} else {
- switch_snprintf(status_line, sizeof(status_line), "%s %s", what, op);
+ op = switch_event_get_header(helper->event, "Caller-Callee-ID-Number");
}
- rpid = "on-the-phone";
- force_status = 1;
-
- } else if (!strcmp(astate, "confirmed")) {
if (zstr(op)) {
- switch_snprintf(status_line, sizeof(status_line), "On The Phone");
- } else {
- switch_snprintf(status_line, sizeof(status_line), "Talk %s", op);
+ op = switch_event_get_header(helper->event, "Caller-Destination-Number");
}
- rpid = "on-the-phone";
- force_status = 1;
- }
+ if (direction) {
+ what = strcasecmp(direction, "outbound") ? "Call" : "Ring";
+ }
- open = "open";
+ if (!strcmp(astate, "early")) {
+ if (!zstr(op)) {
+ //switch_snprintf(status_line, sizeof(status_line), "%sing", what);
+ //} else {
+ switch_snprintf(status_line, sizeof(status_line), "%s %s", what, op);
+ }
- if (!strcmp(status, "hold")) {
- rpid = "on-the-phone";
- switch_snprintf(status_line, sizeof(status_line), "Hold %s", op);
- force_status = 1;
- }
+ rpid = "on-the-phone";
+ force_status = 1;
+
+ } else if (!strcmp(astate, "confirmed")) {
+ if (!zstr(op)) {
+ //switch_snprintf(status_line, sizeof(status_line), "On The Phone");
+ //} else {
+ switch_snprintf(status_line, sizeof(status_line), "Talk %s", op);
+ }
+ rpid = "on-the-phone";
+ force_status = 1;
+ }
+
+
+
+ if (!strcmp(status, "hold")) {
+ rpid = "on-the-phone";
+ if (!zstr(op)) {
+ switch_snprintf(status_line, sizeof(status_line), "Hold %s", op);
+ force_status = 1;
+ }
+ }
+ }
} else {
open = "closed";
}
}
- if (helper->event){
+ if (!is_dialog && helper->event && !switch_stristr("registered", status_line)){
const char *uuid = switch_event_get_header_nil(helper->event, "unique-id");
-
- if (!zstr(uuid) && strchr(uuid, '-')) {
+ const char *register_source = switch_event_get_header_nil(helper->event, "register-source");
+
+ if (!zstr(uuid) && strchr(uuid, '-') && !zstr(status_line) && !zstr(rpid) && (zstr(register_source) || strcasecmp(register_source, "register"))) {
char *sql = switch_mprintf("update sip_dialogs set rpid='%q',status='%q' where uuid='%q'", rpid, status_line, uuid);
+ //printf("WTF %s\n", sql);
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
}
if (!strcasecmp(event, "line-seize")) {
char *full_call_info = NULL;
char *p;
+ switch_time_t now;
if (sip->sip_call_info) {
full_call_info = sip_header_as_string(nh->nh_home, (void *) sip->sip_call_info);
}
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, switch_epoch_time_now(NULL) + exp_delta);
+ now = switch_epoch_time_now(NULL);
+ sql = switch_mprintf("insert into sip_dialogs (sip_from_user,sip_from_host,call_info,call_info_state,hostname,expires,rcd) "
+ "values ('%q','%q','%q','seized','%q',%ld,%ld)",
+ to_user, to_host, switch_str_nil(p), mod_sofia_globals.hostname, switch_epoch_time_now(NULL) + exp_delta, (long)now);
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SEIZE SQL %s\n", sql);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
switch_event_fire(&event);
}
-#else
+
if (sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER) ||
(reg_count == 1 && sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER))) {
(sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", "Unregistered");
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-source", "register");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
switch_event_fire(&event);
}
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, sub_host);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event_type", "presence");
+ switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "presence-source", "register");
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
switch_event_fire(&s_event);
}
if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "login", profile->name);
+ switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "presence-source", "register");
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, sub_host);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "rpid", "unknown");
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "status", "Registered");