提交 51c22811 authored 作者: Anthony Minessale's avatar Anthony Minessale

FS-2877 FS-2831 FS-2823 FS-3469 some of the patch from 2877 refactored a bit to…

FS-2877 FS-2831 FS-2823 FS-3469 some of the patch from 2877 refactored a bit to be more centralized to sip and some other stuff added on, please test
上级 caa360b6
...@@ -3539,7 +3539,7 @@ switch_status_t config_sofia(int reload, char *profile_name) ...@@ -3539,7 +3539,7 @@ switch_status_t config_sofia(int reload, char *profile_name)
sofia_set_pflag(profile, PFLAG_PASS_CALLEE_ID); sofia_set_pflag(profile, PFLAG_PASS_CALLEE_ID);
sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER); sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
sofia_set_pflag(profile, PFLAG_SQL_IN_TRANS); sofia_set_pflag(profile, PFLAG_SQL_IN_TRANS);
sofia_set_pflag(profile, PFLAG_PRESENCE_ON_REGISTER); sofia_set_pflag(profile, PFLAG_PRESENCE_ON_FIRST_REGISTER);
profile->shutdown_type = "false"; profile->shutdown_type = "false";
profile->local_network = "localnet.auto"; profile->local_network = "localnet.auto";
sofia_set_flag(profile, TFLAG_ENABLE_SOA); sofia_set_flag(profile, TFLAG_ENABLE_SOA);
...@@ -3646,7 +3646,7 @@ switch_status_t config_sofia(int reload, char *profile_name) ...@@ -3646,7 +3646,7 @@ switch_status_t config_sofia(int reload, char *profile_name)
sofia_clear_pflag(profile, PFLAG_PRESENCE_PROBE_ON_REGISTER); sofia_clear_pflag(profile, PFLAG_PRESENCE_PROBE_ON_REGISTER);
} }
} else if (!strcasecmp(var, "send-presence-on-register")) { } else if (!strcasecmp(var, "send-presence-on-register")) {
if (switch_true(val)) { if (switch_true(val) || !strcasecmp(val, "all")) {
sofia_set_pflag(profile, PFLAG_PRESENCE_ON_REGISTER); sofia_set_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
} else if (!strcasecmp(val, "first-only")) { } else if (!strcasecmp(val, "first-only")) {
sofia_clear_pflag(profile, PFLAG_PRESENCE_ON_REGISTER); sofia_clear_pflag(profile, PFLAG_PRESENCE_ON_REGISTER);
...@@ -4964,6 +4964,8 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status ...@@ -4964,6 +4964,8 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
!switch_channel_test_flag(channel, CF_RING_READY)) { !switch_channel_test_flag(channel, CF_RING_READY)) {
const char *from_user = "", *from_host = "", *to_user = "", *to_host = "", *contact_user = "", *contact_host = ""; const char *from_user = "", *from_host = "", *to_user = "", *to_host = "", *contact_user = "", *contact_host = "";
const char *user_agent = "", *call_id = ""; const char *user_agent = "", *call_id = "";
const char *to_tag = "";
const char *from_tag = "";
char *sql = NULL; char *sql = NULL;
if (sip->sip_user_agent) { if (sip->sip_user_agent) {
...@@ -4976,12 +4978,14 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status ...@@ -4976,12 +4978,14 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
if (to) { if (to) {
from_user = switch_str_nil(to->url_user); from_user = switch_str_nil(to->url_user);
from_tag = switch_str_nil(sip->sip_to->a_tag);
} }
if (from) { if (from) {
from_host = switch_str_nil(from->url_host); from_host = switch_str_nil(from->url_host);
to_user = switch_str_nil(from->url_user); to_user = switch_str_nil(from->url_user);
to_host = switch_str_nil(from->url_host); to_host = switch_str_nil(from->url_host);
to_tag = switch_str_nil(sip->sip_from->a_tag);
} }
if (contact) { if (contact) {
...@@ -5003,12 +5007,12 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status ...@@ -5003,12 +5007,12 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
p++; p++;
} }
sql = switch_mprintf("insert into sip_dialogs " sql = switch_mprintf("insert into sip_dialogs "
"(call_id,uuid,sip_to_user,sip_to_host,sip_from_user,sip_from_host,contact_user," "(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) " "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')", "values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
call_id, call_id,
switch_core_session_get_uuid(session), switch_core_session_get_uuid(session),
to_user, to_host, from_user, from_host, contact_user, to_user, to_host, to_tag, from_user, from_host, from_tag, contact_user,
contact_host, astate, "outbound", user_agent, contact_host, astate, "outbound", user_agent,
profile->name, mod_sofia_globals.hostname, switch_str_nil(full_contact), 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));
...@@ -5301,6 +5305,19 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, ...@@ -5301,6 +5305,19 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
status = 183; status = 183;
} }
if (channel && profile->pres_type && ss_state == nua_callstate_ready && status == 200) {
const char* to_tag = "";
char *sql = NULL;
to_tag = switch_str_nil(switch_channel_get_variable(channel, "sip_to_tag"));
sql = switch_mprintf("update sip_dialogs set sip_to_tag='%q' "
"where uuid='%q' and sip_to_tag = ''", to_tag, switch_core_session_get_uuid(session));
if (mod_sofia_globals.debug_presence > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "QUERY SQL %s\n", sql);
}
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
}
if (channel && (status == 180 || status == 183) && switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { if (channel && (status == 180 || status == 183) && switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
const char *val; const char *val;
if ((val = switch_channel_get_variable(channel, "sip_auto_answer")) && switch_true(val)) { if ((val = switch_channel_get_variable(channel, "sip_auto_answer")) && switch_true(val)) {
...@@ -8065,6 +8082,8 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ ...@@ -8065,6 +8082,8 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
const char *dialog_from_user = "", *dialog_from_host = "", *to_user = "", *to_host = "", *contact_user = "", *contact_host = ""; const char *dialog_from_user = "", *dialog_from_host = "", *to_user = "", *to_host = "", *contact_user = "", *contact_host = "";
const char *user_agent = "", *call_id = ""; const char *user_agent = "", *call_id = "";
url_t *from = NULL, *to = NULL, *contact = NULL; url_t *from = NULL, *to = NULL, *contact = NULL;
const char *to_tag = "";
const char *from_tag = "";
char *sql = NULL; char *sql = NULL;
if (sip->sip_to) { if (sip->sip_to) {
...@@ -8088,11 +8107,13 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ ...@@ -8088,11 +8107,13 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
if (to) { if (to) {
to_user = switch_str_nil(to->url_user); to_user = switch_str_nil(to->url_user);
to_host = switch_str_nil(to->url_host); to_host = switch_str_nil(to->url_host);
to_tag = switch_str_nil(sip->sip_to->a_tag);
} }
if (from) { if (from) {
dialog_from_user = switch_str_nil(from->url_user); dialog_from_user = switch_str_nil(from->url_user);
dialog_from_host = switch_str_nil(from->url_host); dialog_from_host = switch_str_nil(from->url_host);
from_tag = switch_str_nil(sip->sip_from->a_tag);
} }
if (contact) { if (contact) {
...@@ -8121,12 +8142,12 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ ...@@ -8121,12 +8142,12 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
sql = switch_mprintf("insert into sip_dialogs " sql = switch_mprintf("insert into sip_dialogs "
"(call_id,uuid,sip_to_user,sip_to_host,sip_from_user,sip_from_host,contact_user," "(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) " "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')", "values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
call_id, call_id,
tech_pvt->sofia_private->uuid, tech_pvt->sofia_private->uuid,
to_user, to_host, dialog_from_user, dialog_from_host, to_user, to_host, to_tag, dialog_from_user, dialog_from_host, from_tag,
contact_user, contact_host, "confirmed", "inbound", user_agent, contact_user, contact_host, "confirmed", "inbound", user_agent,
profile->name, mod_sofia_globals.hostname, switch_str_nil(full_contact), 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));
......
...@@ -5824,7 +5824,9 @@ int sofia_glue_init_sql(sofia_profile_t *profile) ...@@ -5824,7 +5824,9 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
" call_info_state VARCHAR(255),\n" " call_info_state VARCHAR(255),\n"
" expires INTEGER default 0,\n" " expires INTEGER default 0,\n"
" status VARCHAR(255),\n" " status VARCHAR(255),\n"
" rpid VARCHAR(255)\n" " rpid VARCHAR(255),\n"
" sip_to_tag VARCHAR(255),\n"
" sip_from_tag VARCHAR(255)\n"
");\n"; ");\n";
char sub_sql[] = char sub_sql[] =
...@@ -5972,7 +5974,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile) ...@@ -5972,7 +5974,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_subscriptions", sub_sql); switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_subscriptions", sub_sql);
free(test_sql); free(test_sql);
test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and expires <> -9999 or rpid=''", mod_sofia_globals.hostname); test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and expires <> -9999 or rpid='' or from_tag=''", mod_sofia_globals.hostname);
switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_dialogs", dialog_sql); switch_cache_db_test_reactive(dbh, test_sql, "DROP TABLE sip_dialogs", dialog_sql);
......
...@@ -605,8 +605,12 @@ SWITCH_DECLARE(void) switch_channel_perform_presence(switch_channel_t *channel, ...@@ -605,8 +605,12 @@ SWITCH_DECLARE(void) switch_channel_perform_presence(switch_channel_t *channel,
call_info = switch_channel_get_variable(channel, "presence_call_info"); call_info = switch_channel_get_variable(channel, "presence_call_info");
if (switch_event_create(&event, type) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, type) == SWITCH_STATUS_SUCCESS) {
if (!strcasecmp(status, "CS_HANGUP")) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "refresh", "true");
}
switch_channel_event_set_data(channel, event); switch_channel_event_set_data(channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", __FILE__); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "any");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", __FILE__); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", __FILE__);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", id);
if (type == SWITCH_EVENT_PRESENCE_IN) { if (type == SWITCH_EVENT_PRESENCE_IN) {
...@@ -1828,7 +1832,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state( ...@@ -1828,7 +1832,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state(
channel->running_state = state; channel->running_state = state;
if (channel->state == CS_ROUTING || channel->state == CS_HANGUP) { if (state == CS_ROUTING || state == CS_HANGUP) {
switch_channel_presence(channel, "unknown", (const char *) state_names[state], NULL); switch_channel_presence(channel, "unknown", (const char *) state_names[state], NULL);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论