mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-29 06:34:19 +00:00
xmas presence 2009
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16053 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
f2b9cbf23e
commit
88a21f40f2
7 files changed
+644
-246
No files matched your search
@@ -211,7 +211,7 @@ char *generate_pai_str(switch_core_session_t *session)
|
||||
callee_number = switch_core_session_sprintf(session, "sip:%s@%s", callee_number, tech_pvt->profile->sipip);
|
||||
}
|
||||
|
||||
header = (tech_pvt->cid_type == CID_TYPE_RPID) ? "Remote-Party-ID" : "P-Asserted-Identity";
|
||||
header = (tech_pvt->cid_type == CID_TYPE_RPID && !switch_stristr("aastra", ua)) ? "Remote-Party-ID" : "P-Asserted-Identity";
|
||||
|
||||
if (!zstr(callee_name) && !zstr(callee_number)) {
|
||||
if (switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote)) {
|
||||
@@ -394,6 +394,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
|
||||
}
|
||||
|
||||
if (switch_channel_test_flag(channel, CF_ANSWERED) || sofia_test_flag(tech_pvt, TFLAG_ANS)) {
|
||||
const char *call_info = switch_channel_get_variable(channel, "presence_call_info");
|
||||
if (!tech_pvt->got_bye) {
|
||||
switch_channel_set_variable(channel, "sip_hangup_disposition", "send_bye");
|
||||
}
|
||||
@@ -401,6 +402,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
|
||||
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
|
||||
nua_bye(tech_pvt->nh,
|
||||
TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)),
|
||||
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
|
||||
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
|
||||
TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)),
|
||||
TAG_END());
|
||||
@@ -472,6 +474,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
|
||||
const char *b_sdp = NULL;
|
||||
int is_proxy = 0;
|
||||
char *sticky = NULL;
|
||||
const char *call_info = switch_channel_get_variable(channel, "presence_call_info");
|
||||
|
||||
if (sofia_test_flag(tech_pvt, TFLAG_ANS) || switch_channel_test_flag(channel, CF_OUTBOUND)) {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
@@ -508,6 +511,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
|
||||
nua_respond(tech_pvt->nh, SIP_200_OK,
|
||||
SIPTAG_CONTACT_STR(tech_pvt->profile->url),
|
||||
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
|
||||
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
|
||||
SOATAG_REUSE_REJECTED(1),
|
||||
SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
|
||||
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
|
||||
@@ -519,6 +523,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
|
||||
NUTAG_MEDIA_ENABLE(0),
|
||||
SIPTAG_CONTACT_STR(tech_pvt->profile->url),
|
||||
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
|
||||
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
|
||||
SIPTAG_CONTENT_TYPE_STR("application/sdp"),
|
||||
SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
|
||||
TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
|
||||
@@ -1443,6 +1448,14 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
|
||||
SIPTAG_PAYLOAD_STR(message), TAG_END());
|
||||
} else if ((ua && (switch_stristr("polycom", ua)))) {
|
||||
snprintf(message, sizeof(message), "P-Asserted-Identity: \"%s\" <%s>", name, number);
|
||||
sofia_set_flag_locked(tech_pvt, TFLAG_UPDATING_DISPLAY);
|
||||
nua_update(tech_pvt->nh,
|
||||
TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)),
|
||||
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
|
||||
TAG_END());
|
||||
} else if ((ua && (switch_stristr("aastra", ua)))) {
|
||||
snprintf(message, sizeof(message), "P-Asserted-Identity: \"%s\" <sip:%s@%s>", name, number, tech_pvt->profile->sipip);
|
||||
|
||||
sofia_set_flag_locked(tech_pvt, TFLAG_UPDATING_DISPLAY);
|
||||
nua_update(tech_pvt->nh,
|
||||
TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)),
|
||||
@@ -1683,9 +1696,12 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
|
||||
if (!switch_channel_test_flag(channel, CF_RING_READY) && !sofia_test_flag(tech_pvt, TFLAG_BYE) &&
|
||||
!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED)) {
|
||||
char *extra_header = sofia_glue_get_extra_headers(channel, SOFIA_SIP_PROGRESS_HEADER_PREFIX);
|
||||
const char *call_info = switch_channel_get_variable(channel, "presence_call_info");
|
||||
|
||||
nua_respond(tech_pvt->nh, SIP_180_RINGING,
|
||||
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
|
||||
SIPTAG_HEADER_STR(generate_pai_str(session)),
|
||||
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
|
||||
TAG_IF(!zstr(extra_header), SIPTAG_HEADER_STR(extra_header)),
|
||||
TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
|
||||
SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
|
||||
@@ -1701,6 +1717,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
|
||||
{
|
||||
char *sticky = NULL;
|
||||
const char *val = NULL;
|
||||
const char *call_info = switch_channel_get_variable(channel, "presence_call_info");
|
||||
|
||||
if (sofia_test_pflag(tech_pvt->profile, PFLAG_3PCC_PROXY) && sofia_test_flag(tech_pvt, TFLAG_3PCC)) {
|
||||
sofia_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
|
||||
@@ -1774,6 +1791,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
|
||||
|
||||
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
|
||||
char *extra_header = sofia_glue_get_extra_headers(channel, SOFIA_SIP_PROGRESS_HEADER_PREFIX);
|
||||
|
||||
if (sofia_use_soa(tech_pvt)) {
|
||||
nua_respond(tech_pvt->nh,
|
||||
SIP_183_SESSION_PROGRESS,
|
||||
@@ -1785,6 +1803,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
|
||||
SOATAG_ORDERED_USER(1),
|
||||
SOATAG_ADDRESS(tech_pvt->adv_sdp_audio_ip),
|
||||
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"),
|
||||
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
|
||||
TAG_IF(!zstr(extra_header), SIPTAG_HEADER_STR(extra_header)),
|
||||
TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
|
||||
SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
|
||||
@@ -1799,6 +1818,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
|
||||
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
|
||||
SIPTAG_CONTENT_TYPE_STR("application/sdp"),
|
||||
SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
|
||||
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
|
||||
TAG_IF(!zstr(extra_header), SIPTAG_HEADER_STR(extra_header)),
|
||||
TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
|
||||
SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
|
||||
|
||||
@@ -522,6 +522,7 @@ struct sofia_profile {
|
||||
uint32_t timer_t4;
|
||||
char *contact_user;
|
||||
char *local_network;
|
||||
uint32_t trans_timeout;
|
||||
};
|
||||
|
||||
struct private_object {
|
||||
|
||||
@@ -284,6 +284,7 @@ void sofia_handle_sip_i_bye(switch_core_session_t *session, int status,
|
||||
switch_channel_t *channel;
|
||||
private_object_t *tech_pvt;
|
||||
char *extra_headers;
|
||||
const char *call_info = NULL;
|
||||
#ifdef MANUAL_BYE
|
||||
int cause;
|
||||
char st[80] = "";
|
||||
@@ -295,12 +296,12 @@ void sofia_handle_sip_i_bye(switch_core_session_t *session, int status,
|
||||
channel = switch_core_session_get_channel(session);
|
||||
tech_pvt = switch_core_session_get_private(session);
|
||||
|
||||
|
||||
#ifdef MANUAL_BYE
|
||||
status = 200;
|
||||
phrase = "OK";
|
||||
|
||||
sofia_set_flag_locked(tech_pvt, TFLAG_BYE);
|
||||
call_info = switch_channel_get_variable(channel, "presence_call_info");
|
||||
|
||||
if (sip->sip_reason && sip->sip_reason->re_protocol &&
|
||||
(!strcasecmp(sip->sip_reason->re_protocol, "Q.850")
|
||||
@@ -328,7 +329,8 @@ void sofia_handle_sip_i_bye(switch_core_session_t *session, int status,
|
||||
|
||||
switch_channel_hangup(channel, cause);
|
||||
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua),
|
||||
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
|
||||
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
|
||||
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
|
||||
|
||||
switch_safe_free(extra_headers);
|
||||
|
||||
@@ -948,7 +950,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread
|
||||
|
||||
while ((mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING)) || qsize) {
|
||||
if (sofia_test_pflag(profile, PFLAG_SQL_IN_TRANS)) {
|
||||
if (qsize > 0 && (qsize >= 500 || ++loop_count >= 500)) {
|
||||
if (qsize > 0 && (qsize >= 1024 || ++loop_count >= profile->trans_timeout)) {
|
||||
switch_size_t newlen;
|
||||
uint32_t itterations = 0;
|
||||
switch_size_t len = 0;
|
||||
@@ -2449,6 +2451,8 @@ switch_status_t config_sofia(int reload, char *profile_name)
|
||||
goto done;
|
||||
}
|
||||
|
||||
profile->trans_timeout = 500;
|
||||
|
||||
profile->auto_rtp_bugs = RTP_BUG_CISCO_SKIP_MARK_BIT_2833 | RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833;
|
||||
|
||||
profile->pool = pool;
|
||||
@@ -2910,7 +2914,14 @@ switch_status_t config_sofia(int reload, char *profile_name)
|
||||
sofia_clear_pflag(profile, PFLAG_PASS_CALLEE_ID);
|
||||
}
|
||||
} else if (!strcasecmp(var, "sql-in-transactions")) {
|
||||
int tmp = atoi(val);
|
||||
|
||||
if (switch_true(val)) {
|
||||
tmp = 500;
|
||||
}
|
||||
|
||||
if (tmp > 0) {
|
||||
profile->trans_timeout = tmp;
|
||||
sofia_set_pflag(profile, PFLAG_SQL_IN_TRANS);
|
||||
} else {
|
||||
sofia_clear_pflag(profile, PFLAG_SQL_IN_TRANS);
|
||||
@@ -3376,6 +3387,8 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
|
||||
char network_ip[80];
|
||||
int network_port = 0;
|
||||
switch_caller_profile_t *caller_profile = NULL;
|
||||
char *call_info = NULL;
|
||||
|
||||
|
||||
sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
|
||||
|
||||
@@ -3402,7 +3415,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
|
||||
} else if (sip->sip_server && sip->sip_server->g_string) {
|
||||
switch_channel_set_variable(channel, "sip_user_agent", sip->sip_server->g_string);
|
||||
}
|
||||
|
||||
|
||||
sofia_glue_set_extra_headers(channel, sip, SOFIA_SIP_PROGRESS_HEADER_PREFIX);
|
||||
|
||||
sofia_update_callee_id(session, profile, sip, SWITCH_FALSE);
|
||||
@@ -3428,6 +3441,11 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
|
||||
return;
|
||||
}
|
||||
|
||||
if (sip->sip_call_info) {
|
||||
call_info = sip_header_as_string(profile->home, (void *) sip->sip_call_info);
|
||||
switch_channel_set_variable(channel, "presence_call_info", call_info);
|
||||
}
|
||||
|
||||
if ((br = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
|
||||
switch_xml_t root = NULL, domain = NULL;
|
||||
switch_core_session_t *a_session;
|
||||
@@ -3648,20 +3666,25 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
|
||||
|
||||
sql = switch_mprintf("insert into sip_dialogs "
|
||||
"(call_id,uuid,sip_to_user,sip_to_host,sip_from_user,sip_from_host,contact_user,"
|
||||
"contact_host,state,direction,user_agent,profile_name,hostname,contact,presence_id, presence_data) "
|
||||
"values('%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) "
|
||||
"values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
|
||||
call_id,
|
||||
switch_core_session_get_uuid(session),
|
||||
to_user, to_host, from_user, from_host, 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(presence_id), switch_str_nil(presence_data), switch_str_nil(call_info));
|
||||
|
||||
switch_assert(sql);
|
||||
|
||||
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
|
||||
|
||||
}
|
||||
|
||||
if (call_info) {
|
||||
su_free(profile->home, call_info);
|
||||
}
|
||||
|
||||
} else if (status == 200 && (profile->pres_type)) {
|
||||
char *sql = NULL;
|
||||
const char *presence_data = switch_channel_get_variable(channel, "presence_data");
|
||||
@@ -5240,6 +5263,8 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
|
||||
char acl_token[512] = "";
|
||||
sofia_transport_t transport;
|
||||
const char *gw_name = NULL;
|
||||
char *call_info_str = NULL;
|
||||
nua_handle_t *bnh = NULL;
|
||||
|
||||
profile->ib_calls++;
|
||||
|
||||
@@ -5799,12 +5824,11 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
|
||||
}
|
||||
|
||||
if ((call_info = sip_call_info(sip))) {
|
||||
char *tmp = sip_header_as_string(profile->home, (void *) call_info);
|
||||
call_info_str = sip_header_as_string(nh->nh_home, (void *) call_info);
|
||||
if (call_info->ci_params && (msg_params_find(call_info->ci_params , "answer-after=0"))) {
|
||||
switch_channel_set_variable(channel, "sip_auto_answer_detected", "true");
|
||||
}
|
||||
switch_channel_set_variable(channel, "sip_call_info", tmp);
|
||||
su_free(profile->home, tmp);
|
||||
switch_channel_set_variable(channel, "sip_call_info", call_info_str);
|
||||
}
|
||||
|
||||
if (profile->pres_type) {
|
||||
@@ -5857,79 +5881,97 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
|
||||
}
|
||||
}
|
||||
|
||||
if (sip->sip_replaces) {
|
||||
nua_handle_t *bnh;
|
||||
if ((bnh = nua_handle_by_replaces(nua, sip->sip_replaces))) {
|
||||
sofia_private_t *b_private = NULL;
|
||||
if ((b_private = nua_handle_magic(bnh))) {
|
||||
switch_core_session_t *b_session = NULL;
|
||||
if ((b_session = switch_core_session_locate(b_private->uuid))) {
|
||||
switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
|
||||
const char *uuid;
|
||||
int one_leg = 1;
|
||||
private_object_t *b_tech_pvt = NULL;
|
||||
const char *app = switch_channel_get_variable(b_channel, SWITCH_CURRENT_APPLICATION_VARIABLE);
|
||||
const char *data = switch_channel_get_variable(b_channel, SWITCH_CURRENT_APPLICATION_DATA_VARIABLE);
|
||||
|
||||
if (app && data && !strcasecmp(app, "conference")) {
|
||||
destination_number = switch_core_session_sprintf(b_session, "answer,conference:%s", data);
|
||||
dialplan = "inline";
|
||||
} else {
|
||||
if (switch_core_session_check_interface(b_session, sofia_endpoint_interface)) {
|
||||
b_tech_pvt = switch_core_session_get_private(b_session);
|
||||
}
|
||||
if (call_info_str) {
|
||||
char *sql;
|
||||
char cid[512] = "";
|
||||
char *str;
|
||||
|
||||
if ((uuid = switch_channel_get_variable(b_channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
|
||||
one_leg = 0;
|
||||
} else {
|
||||
uuid = switch_core_session_get_uuid(b_session);
|
||||
}
|
||||
|
||||
if (uuid) {
|
||||
switch_core_session_t *c_session = NULL;
|
||||
int do_conf = 0;
|
||||
|
||||
uuid = switch_core_session_strdup(b_session, uuid);
|
||||
|
||||
if ((c_session = switch_core_session_locate(uuid))) {
|
||||
switch_channel_t *c_channel = switch_core_session_get_channel(c_session);
|
||||
private_object_t *c_tech_pvt = NULL;
|
||||
|
||||
if (switch_core_session_check_interface(c_session, sofia_endpoint_interface)) {
|
||||
c_tech_pvt = switch_core_session_get_private(c_session);
|
||||
}
|
||||
|
||||
|
||||
if (!one_leg &&
|
||||
(!b_tech_pvt || !sofia_test_flag(b_tech_pvt, TFLAG_SIP_HOLD)) &&
|
||||
(!c_tech_pvt || !sofia_test_flag(c_tech_pvt, TFLAG_SIP_HOLD))) {
|
||||
char *ext = switch_core_session_sprintf(b_session, "conference:%s@sla+flags{mintwo}", uuid);
|
||||
|
||||
switch_channel_set_flag(c_channel, CF_REDIRECT);
|
||||
switch_ivr_session_transfer(b_session, ext, "inline", NULL);
|
||||
switch_ivr_session_transfer(c_session, ext, "inline", NULL);
|
||||
switch_channel_clear_flag(c_channel, CF_REDIRECT);
|
||||
do_conf = 1;
|
||||
}
|
||||
switch_core_session_rwunlock(c_session);
|
||||
}
|
||||
|
||||
if (do_conf) {
|
||||
destination_number = switch_core_session_sprintf(b_session, "answer,conference:%s@sla+flags{mintwo}", uuid);
|
||||
} else {
|
||||
destination_number = switch_core_session_sprintf(b_session, "answer,intercept:%s", uuid);
|
||||
}
|
||||
|
||||
dialplan = "inline";
|
||||
}
|
||||
}
|
||||
switch_core_session_rwunlock(b_session);
|
||||
}
|
||||
if (sip->sip_to && sip->sip_to->a_url) {
|
||||
sql = switch_mprintf("select call_id from sip_dialogs where call_info='%q' and sip_from_user='%q' and sip_from_host='%q'",
|
||||
call_info_str, sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host);
|
||||
|
||||
if ((str = sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, cid, sizeof(cid)))) {
|
||||
bnh = nua_handle_by_call_id(nua, str);
|
||||
}
|
||||
nua_handle_unref(bnh);
|
||||
|
||||
free(sql);
|
||||
}
|
||||
}
|
||||
|
||||
if (sip->sip_replaces) {
|
||||
bnh = nua_handle_by_replaces(nua, sip->sip_replaces);
|
||||
}
|
||||
|
||||
if (bnh) {
|
||||
sofia_private_t *b_private = NULL;
|
||||
if ((b_private = nua_handle_magic(bnh))) {
|
||||
switch_core_session_t *b_session = NULL;
|
||||
|
||||
if ((b_session = switch_core_session_locate(b_private->uuid))) {
|
||||
switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
|
||||
const char *uuid;
|
||||
int one_leg = 1;
|
||||
private_object_t *b_tech_pvt = NULL;
|
||||
const char *app = switch_channel_get_variable(b_channel, SWITCH_CURRENT_APPLICATION_VARIABLE);
|
||||
const char *data = switch_channel_get_variable(b_channel, SWITCH_CURRENT_APPLICATION_DATA_VARIABLE);
|
||||
|
||||
if (app && data && !strcasecmp(app, "conference")) {
|
||||
destination_number = switch_core_session_sprintf(b_session, "answer,conference:%s", data);
|
||||
dialplan = "inline";
|
||||
} else {
|
||||
if (switch_core_session_check_interface(b_session, sofia_endpoint_interface)) {
|
||||
b_tech_pvt = switch_core_session_get_private(b_session);
|
||||
}
|
||||
|
||||
if ((uuid = switch_channel_get_variable(b_channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
|
||||
one_leg = 0;
|
||||
} else {
|
||||
uuid = switch_core_session_get_uuid(b_session);
|
||||
}
|
||||
|
||||
if (uuid) {
|
||||
switch_core_session_t *c_session = NULL;
|
||||
int do_conf = 0;
|
||||
uuid = switch_core_session_strdup(b_session, uuid);
|
||||
|
||||
if ((c_session = switch_core_session_locate(uuid))) {
|
||||
switch_channel_t *c_channel = switch_core_session_get_channel(c_session);
|
||||
private_object_t *c_tech_pvt = NULL;
|
||||
|
||||
if (switch_core_session_check_interface(c_session, sofia_endpoint_interface)) {
|
||||
c_tech_pvt = switch_core_session_get_private(c_session);
|
||||
}
|
||||
|
||||
|
||||
if (!one_leg &&
|
||||
(!b_tech_pvt || !sofia_test_flag(b_tech_pvt, TFLAG_SIP_HOLD)) &&
|
||||
(!c_tech_pvt || !sofia_test_flag(c_tech_pvt, TFLAG_SIP_HOLD))) {
|
||||
char *ext = switch_core_session_sprintf(b_session, "conference:%s@sla+flags{mintwo}", uuid);
|
||||
|
||||
switch_channel_set_flag(c_channel, CF_REDIRECT);
|
||||
switch_ivr_session_transfer(b_session, ext, "inline", NULL);
|
||||
switch_ivr_session_transfer(c_session, ext, "inline", NULL);
|
||||
switch_channel_clear_flag(c_channel, CF_REDIRECT);
|
||||
do_conf = 1;
|
||||
}
|
||||
switch_core_session_rwunlock(c_session);
|
||||
}
|
||||
|
||||
if (do_conf) {
|
||||
destination_number = switch_core_session_sprintf(b_session, "answer,conference:%s@sla+flags{mintwo}", uuid);
|
||||
} else {
|
||||
destination_number = switch_core_session_sprintf(b_session, "answer,intercept:%s", uuid);
|
||||
}
|
||||
|
||||
dialplan = "inline";
|
||||
}
|
||||
}
|
||||
switch_core_session_rwunlock(b_session);
|
||||
}
|
||||
}
|
||||
nua_handle_unref(bnh);
|
||||
}
|
||||
|
||||
check_decode(displayname, session);
|
||||
tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
|
||||
from_user,
|
||||
@@ -6074,20 +6116,26 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
|
||||
full_contact = sip_header_as_string(nua_handle_home(tech_pvt->nh), (void *) sip->sip_contact);
|
||||
}
|
||||
|
||||
if (call_info_str) {
|
||||
switch_channel_set_variable(channel, "presence_call_info", call_info_str);
|
||||
}
|
||||
|
||||
|
||||
sql = switch_mprintf("insert into sip_dialogs "
|
||||
"(call_id,uuid,sip_to_user,sip_to_host,sip_from_user,sip_from_host,contact_user,"
|
||||
"contact_host,state,direction,user_agent,profile_name,hostname,contact,presence_id,presence_data) "
|
||||
"values('%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) "
|
||||
"values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
|
||||
call_id,
|
||||
tech_pvt->sofia_private->uuid,
|
||||
to_user, to_host, dialog_from_user, dialog_from_host,
|
||||
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(presence_id), switch_str_nil(presence_data), switch_str_nil(call_info_str));
|
||||
|
||||
switch_assert(sql);
|
||||
|
||||
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
|
||||
|
||||
}
|
||||
|
||||
if (is_nat) {
|
||||
|
||||
@@ -3806,7 +3806,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
|
||||
" hostname VARCHAR(255),\n"
|
||||
" contact VARCHAR(255),\n"
|
||||
" presence_id VARCHAR(255),\n"
|
||||
" presence_data VARCHAR(255)\n"
|
||||
" presence_data VARCHAR(255),\n"
|
||||
" call_info VARCHAR(255)\n"
|
||||
");\n";
|
||||
|
||||
char sub_sql[] =
|
||||
@@ -3880,7 +3881,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
|
||||
"create index sr_sip_realm on sip_registrations (sip_realm)",
|
||||
"create index ss_call_id on sip_subscriptions (call_id)",
|
||||
"create index ss_hostname on sip_subscriptions (hostname)",
|
||||
"create index ss_hostname on sip_subscriptions (network_ip)",
|
||||
"create index ss_network_ip on sip_subscriptions (network_ip)",
|
||||
"create index ss_sip_user on sip_subscriptions (sip_user)",
|
||||
"create index ss_sip_host on sip_subscriptions (sip_host)",
|
||||
"create index ss_presence_hosts on sip_subscriptions (presence_hosts)",
|
||||
@@ -3890,11 +3891,13 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
|
||||
"create index ss_sub_to_host on sip_subscriptions (sub_to_host)",
|
||||
"create index sd_uuid on sip_dialogs (uuid)",
|
||||
"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 sp_hostname on sip_presence (hostname)",
|
||||
"create index sa_nonce on sip_authentication (nonce)",
|
||||
"create index sa_hostname on sip_authentication (hostname)",
|
||||
"create index ssa_hostname on sip_shared_appearance_subscriptions (hostname)",
|
||||
"create index ssa_hostname on sip_shared_appearance_subscriptions (network_ip)",
|
||||
"create index ssa_network_ip on sip_shared_appearance_subscriptions (network_ip)",
|
||||
"create index ssa_subscriber on sip_shared_appearance_subscriptions (subscriber)",
|
||||
"create index ssa_profile_name on sip_shared_appearance_subscriptions (profile_name)",
|
||||
"create index ssa_aor on sip_shared_appearance_subscriptions (aor)",
|
||||
@@ -3959,14 +3962,14 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
|
||||
}
|
||||
|
||||
free(test_sql);
|
||||
test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and contact like '%%'", mod_sofia_globals.hostname);
|
||||
test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and call_info like '%%'", 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_odbc_handle_exec(odbc_dbh, dialog_sql, NULL);
|
||||
}
|
||||
|
||||
test_sql = switch_mprintf("delete from sip_presence where hostname='%q'", mod_sofia_globals.hostname);
|
||||
test_sql = switch_mprintf("delete from sip_presence where hostname='%q' ", 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_presence", NULL);
|
||||
@@ -4026,11 +4029,11 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
|
||||
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 contact like '%%'", mod_sofia_globals.hostname);
|
||||
test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and call_info like '%%'", mod_sofia_globals.hostname);
|
||||
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_dialogs", dialog_sql);
|
||||
free(test_sql);
|
||||
|
||||
test_sql = switch_mprintf("delete from sip_presence where hostname='%q'", mod_sofia_globals.hostname);
|
||||
test_sql = switch_mprintf("delete from sip_presence where hostname='%q' ", mod_sofia_globals.hostname);
|
||||
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_presence", pres_sql);
|
||||
free(test_sql);
|
||||
|
||||
@@ -4061,7 +4064,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
|
||||
NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists ssd_hostname on sip_shared_appearance_dialogs (hostname)",
|
||||
NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists ssd_hostname on sip_shared_appearance_dialogs (network_ip)",
|
||||
switch_core_db_exec(db, "create index if not exists ssd_network_ip on sip_shared_appearance_dialogs (network_ip)",
|
||||
NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists ssd_contact_str on sip_shared_appearance_dialogs (contact_str)",
|
||||
NULL, NULL, NULL);
|
||||
@@ -4089,7 +4092,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
|
||||
|
||||
switch_core_db_exec(db, "create index if not exists ss_call_id on sip_subscriptions (call_id)", NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists ss_hostname on sip_subscriptions (hostname)", NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists ss_hostname on sip_subscriptions (network_ip)", NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists ss_network_ip on sip_subscriptions (network_ip)", NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists ss_sip_user on sip_subscriptions (sip_user)", NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists ss_sip_host on sip_subscriptions (sip_host)", NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists ss_presence_hosts on sip_subscriptions (presence_hosts)", NULL, NULL, NULL);
|
||||
@@ -4100,9 +4103,10 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
|
||||
|
||||
switch_core_db_exec(db, "create index if not exists sd_uuid on sip_dialogs (uuid)", NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists sd_hostname on sip_dialogs (hostname)", NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists sd_hostname on sip_dialogs (contact)", NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists sd_hostname on sip_dialogs (presence_id)", NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists sd_hostname on sip_dialogs (presence_data)", NULL, NULL, NULL);
|
||||
switch_core_db_exec(db, "create index if not exists sd_contact on sip_dialogs (contact)", NULL, NULL, NULL);
|
||||
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 sp_hostname on sip_presence (hostname)", NULL, NULL, NULL);
|
||||
|
||||
@@ -4500,12 +4504,13 @@ switch_status_t sofia_glue_send_notify(sofia_profile_t *profile, const char *use
|
||||
nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
|
||||
|
||||
nua_notify(nh,
|
||||
NUTAG_NEWSUB(1),
|
||||
TAG_IF(dst->route_uri, NUTAG_PROXY(route_uri)), TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
|
||||
TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
|
||||
SIPTAG_EVENT_STR(event),
|
||||
SIPTAG_CONTENT_TYPE_STR(contenttype),
|
||||
SIPTAG_PAYLOAD_STR(body), TAG_END());
|
||||
NUTAG_NEWSUB(1),
|
||||
TAG_IF(dst->route_uri, NUTAG_PROXY(route_uri)), TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
|
||||
TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
|
||||
TAG_IF(event, SIPTAG_EVENT_STR(event)),
|
||||
TAG_IF(contenttype, SIPTAG_CONTENT_TYPE_STR(contenttype)),
|
||||
TAG_IF(body, SIPTAG_PAYLOAD_STR(body)),
|
||||
TAG_END());
|
||||
|
||||
switch_safe_free(contact);
|
||||
switch_safe_free(route_uri);
|
||||
|
||||
@@ -41,6 +41,12 @@ static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char
|
||||
static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, char **columnNames);
|
||||
static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char **columnNames);
|
||||
static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames);
|
||||
static int broadsoft_sla_callback(void *pArg, int argc, char **argv, char **columnNames);
|
||||
|
||||
struct resub_helper {
|
||||
sofia_profile_t *profile;
|
||||
switch_event_t *event;
|
||||
};
|
||||
|
||||
struct presence_helper {
|
||||
sofia_profile_t *profile;
|
||||
@@ -201,16 +207,18 @@ void sofia_presence_cancel(void)
|
||||
|
||||
void sofia_presence_establish_presence(sofia_profile_t *profile)
|
||||
{
|
||||
|
||||
struct resub_helper h = { 0 };
|
||||
h.profile = profile;
|
||||
|
||||
if (sofia_glue_execute_sql_callback(profile, profile->ireg_mutex,
|
||||
"select sip_user,sip_host,'Registered','unknown','' from sip_registrations",
|
||||
sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
|
||||
sofia_presence_resub_callback, &h) != SWITCH_TRUE) {
|
||||
return;
|
||||
}
|
||||
|
||||
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, profile) != SWITCH_TRUE) {
|
||||
"where proto='ext' or proto='user' or proto='conf'", sofia_presence_resub_callback, &h) != SWITCH_TRUE) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -380,8 +388,13 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
|
||||
char *status = switch_event_get_header(event, "status");
|
||||
char *event_type = switch_event_get_header(event, "event_type");
|
||||
char *alt_event_type = switch_event_get_header(event, "alt_event_type");
|
||||
//char *event_subtype = switch_event_get_header(event, "event_subtype");
|
||||
char *sql = NULL;
|
||||
char *euser = NULL, *user = NULL, *host = NULL;
|
||||
char *call_info = switch_event_get_header(event, "presence-call-info");
|
||||
char *call_info_state = switch_event_get_header(event, "presence-call-info-state");
|
||||
struct resub_helper h = { 0 };
|
||||
|
||||
|
||||
if (!mod_sofia_globals.running) {
|
||||
return;
|
||||
@@ -534,7 +547,8 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s DUMP PRESENCE_PROBE_SQL:\n%s\n", profile->name, sql);
|
||||
}
|
||||
|
||||
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_resub_callback, profile);
|
||||
h.profile = profile;
|
||||
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_resub_callback, &h);
|
||||
if (mod_sofia_globals.debug_presence > 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END_PRESENCE_PROBE_SQL\n\n", profile->name);
|
||||
}
|
||||
@@ -574,6 +588,53 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (call_info) {
|
||||
sql = switch_mprintf("select sip_subscriptions.call_id,sip_subscriptions.expires,'%q',3, sip_dialogs.state,sip_dialogs.call_info, "
|
||||
"sip_subscriptions.sub_to_host,'%q',event "
|
||||
"from sip_subscriptions left join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user "
|
||||
"and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host "
|
||||
"where sip_subscriptions.hostname='%q' "
|
||||
"and sub_to_user='%q' and sub_to_host='%q' "
|
||||
"and (event='call-info' or event='line-seize') and sip_dialogs.call_info='%q'",
|
||||
call_info,
|
||||
call_info_state,
|
||||
mod_sofia_globals.hostname,
|
||||
euser,
|
||||
host,
|
||||
call_info
|
||||
);
|
||||
|
||||
if (mod_sofia_globals.debug_presence > 1) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
|
||||
}
|
||||
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_callback, profile);
|
||||
switch_safe_free(sql);
|
||||
|
||||
|
||||
|
||||
sql = switch_mprintf("select sip_subscriptions.call_id,sip_subscriptions.expires,'',3, sip_dialogs.state,sip_dialogs.call_info, "
|
||||
"sip_subscriptions.sub_to_host,'',event "
|
||||
"from sip_subscriptions inner join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user "
|
||||
"and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host "
|
||||
"where sip_subscriptions.hostname='%q' "
|
||||
"and sub_to_user='%q' and sub_to_host='%q' "
|
||||
"and event='call-info' and sip_dialogs.call_info!='%q'",
|
||||
mod_sofia_globals.hostname,
|
||||
euser,
|
||||
host,
|
||||
call_info
|
||||
);
|
||||
|
||||
if (mod_sofia_globals.debug_presence > 1) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"PRES SQL %s\n", sql);
|
||||
}
|
||||
|
||||
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_callback, profile);
|
||||
switch_safe_free(sql);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ((sql = switch_mprintf(
|
||||
|
||||
"select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
|
||||
@@ -815,7 +876,8 @@ static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, ch
|
||||
|
||||
static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
{
|
||||
sofia_profile_t *profile = (sofia_profile_t *) pArg;
|
||||
struct resub_helper *h = (struct resub_helper *) pArg;
|
||||
sofia_profile_t *profile = h->profile;
|
||||
char *user = argv[0];
|
||||
char *host = argv[1];
|
||||
char *status = argv[2];
|
||||
@@ -828,6 +890,7 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
|
||||
char *direction = NULL;
|
||||
switch_event_t *event;
|
||||
char to_buf[128] = "";
|
||||
switch_event_header_t *hp;
|
||||
|
||||
if (argc > 5) {
|
||||
uuid = switch_str_nil(argv[5]);
|
||||
@@ -878,6 +941,15 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-call-direction", direction);
|
||||
}
|
||||
|
||||
if (h->event) {
|
||||
for (hp = h->event->headers; hp; hp = hp->next) {
|
||||
if (!strncasecmp(hp->name, "fwd-", 4)) {
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, hp->name + 4, hp->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch_event_fire(&event);
|
||||
}
|
||||
|
||||
@@ -1391,6 +1463,114 @@ static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int broadsoft_sla_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
{
|
||||
char *call_id = argv[0];
|
||||
char *expires = argv[1];
|
||||
char *header = argv[2];
|
||||
char *onoff = argv[3];
|
||||
char *state = NULL;
|
||||
char *call_info = NULL;
|
||||
char *call_info_state = NULL;
|
||||
char *event = NULL;
|
||||
char *host = NULL;
|
||||
sofia_profile_t *profile = (sofia_profile_t *) pArg;
|
||||
nua_handle_t *nh;
|
||||
char sstr[128] = "", expires_str[128] = "";
|
||||
time_t exptime = 3600;
|
||||
int on = atoi(onoff);
|
||||
char buf[512] = "";
|
||||
const char *r_state = "idle";
|
||||
int i;
|
||||
|
||||
if (mod_sofia_globals.debug_presence > 1) {
|
||||
for(i = 0; i < argc; i++) {
|
||||
printf("COL [%s]=[%s]\n", columnNames[i], argv[i]);
|
||||
}
|
||||
printf("\non=%d\n\n", on);
|
||||
}
|
||||
|
||||
if (on >= 2 && argc >= 7) {
|
||||
state = argv[4];
|
||||
call_info = argv[5];
|
||||
host = argv[6];
|
||||
call_info_state = argv[7];
|
||||
if (argc > 8) event = argv[8];
|
||||
} else {
|
||||
call_info = header;
|
||||
}
|
||||
|
||||
if (zstr(event)) {
|
||||
event = "call-info";
|
||||
}
|
||||
|
||||
if (expires) {
|
||||
long tmp = atol(expires);
|
||||
exptime = tmp - switch_epoch_time_now(NULL);
|
||||
}
|
||||
|
||||
if (exptime > 0) {
|
||||
switch_snprintf(sstr, sizeof(sstr), "active;expires=%u", (unsigned)exptime);
|
||||
} else {
|
||||
switch_snprintf(sstr, sizeof(sstr), "terminated;reason=noresource");
|
||||
}
|
||||
|
||||
switch_snprintf(expires_str, sizeof(expires_str), "%u", (unsigned)exptime);
|
||||
|
||||
if (zstr(call_info)) {
|
||||
call_info = header;
|
||||
}
|
||||
|
||||
if (on == 3) {
|
||||
if (!zstr(call_info_state)) {
|
||||
r_state = call_info_state;
|
||||
} else if (!zstr(argv[4])) {
|
||||
r_state = "active";
|
||||
} else {
|
||||
r_state = "idle";
|
||||
}
|
||||
} else if (on) {
|
||||
r_state = "seized";
|
||||
}
|
||||
|
||||
|
||||
if (zstr(call_info)) {
|
||||
switch_snprintf(buf, sizeof(buf), "<sip:%s>;apperance-index=*", host);
|
||||
call_info = buf;
|
||||
}
|
||||
|
||||
if (mod_sofia_globals.debug_presence > 1) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[%s][%s][%s][%s]\n", event, call_info, call_id, r_state);
|
||||
}
|
||||
|
||||
if (!strcasecmp(event, "line-seize") && (nh = nua_handle_by_call_id(profile->nua, call_id))) {
|
||||
if (strcasecmp(r_state, "seized")) {
|
||||
char *new_header = switch_mprintf("%s;appearance-state=%s", call_info, r_state);
|
||||
nua_notify(nh,
|
||||
SIPTAG_EXPIRES_STR("0"),
|
||||
SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"),
|
||||
SIPTAG_EVENT_STR("line-seize"), SIPTAG_CALL_INFO_STR(new_header), TAG_END());
|
||||
switch_safe_free(new_header);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (profile && call_id && call_info && (nh = nua_handle_by_call_id(profile->nua, call_id))) {
|
||||
char *new_header = switch_mprintf("%s;appearance-state=%s", call_info, r_state);
|
||||
|
||||
nua_notify(nh,
|
||||
TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)),
|
||||
SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
|
||||
SIPTAG_EVENT_STR("call-info"), SIPTAG_CALL_INFO_STR(new_header), TAG_END());
|
||||
|
||||
switch_safe_free(new_header);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sofia_presence_handle_sip_i_subscribe(int status,
|
||||
char const *phrase,
|
||||
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
|
||||
@@ -1456,7 +1636,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
|
||||
display = "\"user\"";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
display = "\"user\"";
|
||||
}
|
||||
|
||||
@@ -1494,6 +1674,13 @@ void sofia_presence_handle_sip_i_subscribe(int status,
|
||||
}
|
||||
}
|
||||
|
||||
if (is_nat && profile->local_network && switch_check_network_list_ip(network_ip, profile->local_network)) {
|
||||
if (profile->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP %s is on local network, not seting NAT mode.\n", network_ip);
|
||||
}
|
||||
is_nat = NULL;
|
||||
}
|
||||
|
||||
if (is_nat) {
|
||||
contact_host = network_ip;
|
||||
switch_snprintf(new_port, sizeof(new_port), ":%d", network_port);
|
||||
@@ -1514,7 +1701,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
|
||||
ipv6 ? "]" : "",
|
||||
new_port,
|
||||
contact->m_url->url_params,
|
||||
is_nat ? ";fs_nat" : "");
|
||||
is_nat ? ";fs_nat=yes" : "");
|
||||
} else {
|
||||
contact_str = switch_mprintf("%s <sip:%s@%s%s%s%s>%s",
|
||||
display,
|
||||
@@ -1523,7 +1710,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
|
||||
contact_host,
|
||||
ipv6 ? "]" : "",
|
||||
new_port,
|
||||
is_nat ? ";fs_nat" : "");
|
||||
is_nat ? ";fs_nat=yes" : "");
|
||||
}
|
||||
|
||||
|
||||
@@ -1743,8 +1930,134 @@ void sofia_presence_handle_sip_i_subscribe(int status,
|
||||
TAG_IF(sticky, NUTAG_PROXY(sticky)), TAG_END());
|
||||
|
||||
switch_safe_free(sticky);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (sub_state == nua_substate_terminated) {
|
||||
char *full_call_info = NULL;
|
||||
|
||||
if (sip->sip_call_info) {
|
||||
full_call_info = sip_header_as_string(profile->home, (void *) sip->sip_call_info);
|
||||
}
|
||||
|
||||
nua_notify(nh,
|
||||
SIPTAG_EXPIRES_STR("0"),
|
||||
SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
|
||||
TAG_IF(full_call_info, SIPTAG_CALL_INFO_STR(full_call_info)),
|
||||
TAG_END());
|
||||
|
||||
|
||||
if (!strcasecmp(event, "line-seize")) {
|
||||
if (full_call_info) {
|
||||
sql = switch_mprintf("select call_id,expires,'%q',0 from sip_subscriptions where hostname='%q' "
|
||||
"and sub_to_user='%q' and sub_to_host='%q' "
|
||||
"and event='call-info' and contact != '%q'",
|
||||
full_call_info,
|
||||
mod_sofia_globals.hostname,
|
||||
to_user,
|
||||
to_host,
|
||||
contact_str
|
||||
);
|
||||
if (mod_sofia_globals.debug_presence > 1) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "UNSEIZE SQL %s\n", sql);
|
||||
}
|
||||
|
||||
sofia_glue_execute_sql_callback(profile, NULL, sql, broadsoft_sla_callback, profile);
|
||||
switch_safe_free(sql);
|
||||
}
|
||||
}
|
||||
|
||||
if (full_call_info) {
|
||||
su_free(profile->home, full_call_info);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
if (!strcasecmp(event, "line-seize")) {
|
||||
char *full_call_info = NULL;
|
||||
|
||||
if (sip->sip_call_info) {
|
||||
full_call_info = sip_header_as_string(profile->home, (void *) sip->sip_call_info);
|
||||
}
|
||||
|
||||
|
||||
nua_notify(nh,
|
||||
SIPTAG_EXPIRES_STR(exp_delta_str),
|
||||
SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
|
||||
SIPTAG_EVENT_STR("line-seize"), SIPTAG_CALL_INFO_STR(full_call_info), TAG_END());
|
||||
|
||||
if (full_call_info) {
|
||||
sql = switch_mprintf("select sip_subscriptions.call_id,sip_subscriptions.expires,'%q',4, sip_dialogs.state,sip_dialogs.call_info, "
|
||||
"sip_subscriptions.sub_to_host,'','call-info' "
|
||||
"from sip_subscriptions left join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user "
|
||||
"and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host "
|
||||
"where sip_subscriptions.hostname='%q' "
|
||||
"and sub_to_user='%q' and sub_to_host='%q' "
|
||||
"and event='call-info'and sip_subscriptions.contact != '%q'",
|
||||
full_call_info,
|
||||
mod_sofia_globals.hostname,
|
||||
to_user,
|
||||
to_host,
|
||||
contact_str
|
||||
);
|
||||
|
||||
if (mod_sofia_globals.debug_presence > 1) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SEIZE SQL %s\n", sql);
|
||||
}
|
||||
|
||||
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_callback, profile);
|
||||
switch_safe_free(sql);
|
||||
su_free(profile->home, full_call_info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!strcasecmp(event, "call-info")) {
|
||||
|
||||
#if 0
|
||||
int x = 0;
|
||||
for (x = 1; x < 5; x++) {
|
||||
char tmp[128] = "";
|
||||
|
||||
switch_snprintf(tmp, sizeof(tmp), "<sip:%s>;apperance-index=%d;appearance-state=idle", to_host, x);
|
||||
nua_notify(nh,
|
||||
SIPTAG_EXPIRES_STR(exp_delta_str),
|
||||
SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
|
||||
SIPTAG_EVENT_STR("call-info"), SIPTAG_CALL_INFO_STR(tmp), TAG_END());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
sql = switch_mprintf("select sip_subscriptions.call_id,sip_subscriptions.expires,'',2, sip_dialogs.state,sip_dialogs.call_info, "
|
||||
"sip_subscriptions.sub_to_host "
|
||||
"from sip_subscriptions inner join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user "
|
||||
"and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host "
|
||||
"where sip_subscriptions.hostname='%q' "
|
||||
"and sub_to_user='%q' and sub_to_host='%q' "
|
||||
"and event='call-info' and sip_subscriptions.contact != '%q'",
|
||||
mod_sofia_globals.hostname,
|
||||
to_user,
|
||||
to_host,
|
||||
contact_str
|
||||
);
|
||||
|
||||
if (mod_sofia_globals.debug_presence > 1) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CALL-INFO SQL %s\n", sql);
|
||||
}
|
||||
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_callback, profile);
|
||||
switch_safe_free(sql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
sent_reply++;
|
||||
|
||||
@@ -1758,14 +2071,16 @@ void sofia_presence_handle_sip_i_subscribe(int status,
|
||||
|
||||
switch_safe_free(sstr);
|
||||
|
||||
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 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);
|
||||
|
||||
switch_safe_free(sql);
|
||||
if (!strcasecmp(event, "message-summary")) {
|
||||
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' 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);
|
||||
|
||||
switch_safe_free(sql);
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
||||
|
||||
Reference in new issue
Block a user