Merge branch 'master' into smgmaster

Conflicts:
	build/modules.conf.in
This commit is contained in:
Moises Silva committed 2011-06-16 13:43:37 -04:00
commit 2a9046fdb8
608 files changed
+33546 -20511

No files matched your search

+124 -27
View File
@@ -37,6 +37,7 @@
/*************************************************************************************************************************************************************/
#include "mod_sofia.h"
#include "sofia-sip/sip_extra.h"
SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown);
SWITCH_MODULE_DEFINITION(mod_sofia, mod_sofia_load, mod_sofia_shutdown, NULL);
@@ -523,6 +524,12 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
char *cid = generate_pai_str(tech_pvt);
if (sip_cause > 299) {
switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38);
switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_REQ);
switch_channel_set_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_FAIL);
}
nua_respond(tech_pvt->nh, sip_cause, sip_status_phrase(sip_cause),
TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)),
TAG_IF(cid, SIPTAG_HEADER_STR(cid)), TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)), TAG_END());
@@ -568,9 +575,31 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
const char *val;
const char *b_sdp = NULL;
int is_proxy = 0;
int is_3pcc = 0;
char *sticky = NULL;
const char *call_info = switch_channel_get_variable(channel, "presence_call_info_full");
if(sofia_test_flag(tech_pvt, TFLAG_3PCC_INVITE)) {
// SNARK: complete hack to get final ack sent when a 3pcc invite has been passed from the other leg in bypass_media mode.
// This code handles the pass_indication sent after the 3pcc ack is received by the other leg in the is_3pcc && is_proxy case below.
// Is there a better place to hang this...?
b_sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE);
sofia_glue_tech_set_local_sdp(tech_pvt, b_sdp, SWITCH_TRUE);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY nomedia - sending ack\n");
nua_ack(tech_pvt->nh,
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
SOATAG_RTP_SELECT(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"),
TAG_IF(sofia_test_pflag(tech_pvt->profile, PFLAG_DISABLE_100REL), NUTAG_INCLUDE_EXTRA_SDP(1)),
TAG_END());
sofia_clear_flag(tech_pvt, TFLAG_3PCC_INVITE); // all done
return SWITCH_STATUS_SUCCESS;
}
if (sofia_test_flag(tech_pvt, TFLAG_ANS) || switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
return SWITCH_STATUS_SUCCESS;
}
@@ -578,8 +607,9 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
b_sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE);
is_proxy = (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA));
is_3pcc = (sofia_test_pflag(tech_pvt->profile, PFLAG_3PCC_PROXY) && sofia_test_flag(tech_pvt, TFLAG_3PCC));
if (b_sdp && is_proxy) {
if (b_sdp && is_proxy && !is_3pcc) {
sofia_glue_tech_set_local_sdp(tech_pvt, b_sdp, SWITCH_TRUE);
if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
@@ -590,23 +620,35 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
}
} else {
/* This if statement check and handles the 3pcc proxy mode */
if (sofia_test_pflag(tech_pvt->profile, PFLAG_3PCC_PROXY) && sofia_test_flag(tech_pvt, TFLAG_3PCC)) {
if (is_3pcc) {
if(!is_proxy) {
tech_pvt->num_codecs = 0;
sofia_glue_tech_prepare_codecs(tech_pvt);
tech_pvt->local_sdp_str = NULL;
sofia_glue_tech_choose_port(tech_pvt, 0);
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
} else {
sofia_glue_tech_set_local_sdp(tech_pvt, b_sdp, SWITCH_TRUE);
if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
sofia_glue_tech_patch_sdp(tech_pvt);
if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
}
}
/* Send the 200 OK */
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
char *extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_RESPONSE_HEADER_PREFIX);
if (sofia_use_soa(tech_pvt)) {
nua_respond(tech_pvt->nh, SIP_200_OK,
TAG_IF(is_proxy, NUTAG_AUTOANSWER(0)),
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_REUSE_REJECTED(1), TAG_IF(is_proxy, SOATAG_RTP_SELECT(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)),
TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
@@ -638,6 +680,14 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
/* Regain lock on sofia */
switch_mutex_lock(tech_pvt->sofia_mutex);
if(is_proxy) {
sofia_clear_flag(tech_pvt, TFLAG_3PCC_HAS_ACK);
sofia_clear_flag(tech_pvt, TFLAG_3PCC);
// This sends the message to the other leg that causes it to call the TFLAG_3PCC_INVITE code at the start of this function.
// Is there another message it would be better to hang this on though?
switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_ANSWER);
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n");
return SWITCH_STATUS_SUCCESS;
}
@@ -1344,7 +1394,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
case SWITCH_MESSAGE_INDICATE_JITTER_BUFFER:
{
if (switch_rtp_ready(tech_pvt->rtp_session)) {
int len, maxlen = 0, qlen = 0, maxqlen = 50, max_drift = 0;
int len = 0, maxlen = 0, qlen = 0, maxqlen = 50, max_drift = 0;
if (msg->string_arg) {
char *p, *q;
@@ -1625,7 +1675,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
ip = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
port = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
if (ip && port) {
sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), msg->string_arg, 1);
sofia_glue_set_local_sdp(tech_pvt, ip, (switch_port_t)atoi(port), msg->string_arg, 1);
}
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
@@ -1665,7 +1715,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
port = switch_channel_get_variable(other_channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
switch_core_session_rwunlock(other_session);
if (ip && port) {
sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), NULL, 1);
sofia_glue_set_local_sdp(tech_pvt, ip, (switch_port_t)atoi(port), NULL, 1);
}
}
@@ -1684,6 +1734,10 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
switch_channel_get_name(channel), msg->string_arg);
sofia_glue_tech_set_local_sdp(tech_pvt, msg->string_arg, SWITCH_TRUE);
if(zstr(tech_pvt->local_sdp_str)) {
sofia_set_flag(tech_pvt, TFLAG_3PCC_INVITE);
}
sofia_set_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
switch_channel_set_flag(channel, CF_REQ_MEDIA);
sofia_glue_do_invite(session);
@@ -2182,6 +2236,23 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
}
if (sofia_test_pflag(tech_pvt->profile, PFLAG_3PCC_PROXY) && sofia_test_flag(tech_pvt, TFLAG_3PCC)) {
/* Unlock the session signal to allow the ack to make it in */
// Maybe we should timeout?
switch_mutex_unlock(tech_pvt->sofia_mutex);
while (switch_channel_ready(channel) && !sofia_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) {
switch_cond_next();
}
/* Regain lock on sofia */
switch_mutex_lock(tech_pvt->sofia_mutex);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n");
sofia_clear_flag(tech_pvt, TFLAG_3PCC);
sofia_clear_flag(tech_pvt, TFLAG_3PCC_HAS_ACK);
switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_ANSWER);
}
} else {
nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
@@ -3208,6 +3279,19 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
goto done;
}
if (!strcasecmp(argv[1], "check_sync")) {
if (argc > 2) {
sofia_reg_check_call_id(profile, argv[2]);
stream->write_function(stream, "+OK syncing all registrations matching specified call_id\n");
} else {
sofia_reg_check_sync(profile);
stream->write_function(stream, "+OK syncing all registrations\n");
}
goto done;
}
if (!strcasecmp(argv[1], "flush_inbound_reg")) {
int reboot = 0;
@@ -3879,22 +3963,23 @@ SWITCH_STANDARD_API(sofia_function)
switch_status_t status = SWITCH_STATUS_SUCCESS;
sofia_command_t func = NULL;
int lead = 1;
const char *usage_string = "USAGE:\n"
static const char usage_string[] = "USAGE:\n"
"--------------------------------------------------------------------------------\n"
"sofia help\n"
"sofia profile <profile_name> [[start|stop|restart|rescan]|"
"flush_inbound_reg [<call_id>|<[user]@domain>] [reboot]|"
"[register|unregister] [<gateway name>|all]|"
"killgw <gateway name>|"
"[stun-auto-disable|stun-enabled] [true|false]]|"
"siptrace <on|off>|"
"watchdog <on|off>\n"
"sofia status|xmlstatus profile <name> [ reg <contact str> ] | [ pres <pres str> ] | [ user <user@domain> ]\n"
"sofia status|xmlstatus gateway <name>\n"
"sofia global siptrace <on|off>\n"
" watchdog <on|off>\n\n"
"sofia profile <name> [start | stop | restart | rescan]\n"
" flush_inbound_reg [<call_id> | <[user]@domain>] [reboot]\n"
" check_sync [<call_id> | <[user]@domain>]\n"
" [register | unregister] [<gateway name> | all]\n"
" killgw <gateway name>\n"
" [stun-auto-disable | stun-enabled] [true | false]]\n"
" siptrace <on|off>\n"
" watchdog <on|off>\n\n"
"sofia <status|xmlstatus> profile <name> [reg <contact str>] | [pres <pres str>] | [user <user@domain>]\n"
"sofia <status|xmlstatus> gateway <name>\n\n"
"sofia loglevel <all|default|tport|iptsec|nea|nta|nth_client|nth_server|nua|soa|sresolv|stun> [0-9]\n"
"sofia tracelevel <console|alert|crit|err|warning|notice|info|debug>\n"
"sofia global siptrace <on|off>|"
"watchdog <on|off>\n"
"sofia tracelevel <console|alert|crit|err|warning|notice|info|debug>\n\n"
"sofia help\n"
"--------------------------------------------------------------------------------\n";
if (zstr(cmd)) {
@@ -4080,6 +4165,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
char *not_const = NULL;
int cid_locked = 0;
switch_channel_t *o_channel = NULL;
sofia_gateway_t *gateway_ptr = NULL;
*new_session = NULL;
@@ -4119,7 +4205,6 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
if (!strncasecmp(profile_name, "gateway/", 8)) {
char *gw, *params;
sofia_gateway_t *gateway_ptr = NULL;
if (!(gw = strchr(profile_name, '/'))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid URL\n");
@@ -4147,8 +4232,6 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Gateway is down!\n");
cause = SWITCH_CAUSE_NETWORK_OUT_OF_ORDER;
gateway_ptr->ob_failed_calls++;
sofia_reg_release_gateway(gateway_ptr);
gateway_ptr = NULL;
goto error;
}
@@ -4475,6 +4558,14 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
} else {
sofia_clear_flag(ctech_pvt, TFLAG_ENABLE_SOA);
}
/* SNARK: lets copy this across so we can see if we're the other leg of 3PCC + bypass_media... */
if (sofia_test_flag(ctech_pvt, TFLAG_3PCC) && (switch_channel_test_flag(o_channel, CF_PROXY_MODE) || switch_channel_test_flag(o_channel, CF_PROXY_MEDIA))) {
sofia_set_flag(tech_pvt, TFLAG_3PCC_INVITE);
sofia_set_flag(tech_pvt, TFLAG_LATE_NEGOTIATION);
} else {
sofia_clear_flag(tech_pvt, TFLAG_3PCC_INVITE);
}
}
if (switch_channel_test_flag(o_channel, CF_PROXY_MEDIA)) {
@@ -4494,6 +4585,10 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
goto done;
error:
if (gateway_ptr) {
sofia_reg_release_gateway(gateway_ptr);
}
if (nsession) {
switch_core_session_destroy(&nsession);
}
@@ -4730,7 +4825,7 @@ static void general_event_handler(switch_event_t *event)
id = switch_mprintf("sip:%s@%s", user, host);
switch_assert(id);
for (m = list->head; m; m = m->next) {
contact = sofia_glue_get_url_from_contact(m->val, 0);
@@ -4743,10 +4838,9 @@ static void general_event_handler(switch_event_t *event)
nua_message(nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR(ct),
TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), TAG_IF(!zstr(subject), SIPTAG_SUBJECT_STR(subject)), TAG_END());
free(id);
}
free(id);
switch_console_free_matches(&list);
sofia_glue_release_profile(profile);
@@ -4892,6 +4986,8 @@ static void general_event_handler(switch_event_t *event)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "EVENT_TRAP: IP change detected\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "IP change detected [%s]->[%s] [%s]->[%s]\n", old_ip4, new_ip4, old_ip6, new_ip6);
strncpy(mod_sofia_globals.guess_ip, new_ip4, sizeof(mod_sofia_globals.guess_ip));
switch_mutex_lock(mod_sofia_globals.hash_mutex);
if (mod_sofia_globals.profile_hash) {
for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -5181,6 +5277,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
switch_console_set_complete("add sofia profile ::sofia::list_profiles restart");
switch_console_set_complete("add sofia profile ::sofia::list_profiles flush_inbound_reg");
switch_console_set_complete("add sofia profile ::sofia::list_profiles check_sync");
switch_console_set_complete("add sofia profile ::sofia::list_profiles register ::sofia::list_profile_gateway");
switch_console_set_complete("add sofia profile ::sofia::list_profiles unregister ::sofia::list_profile_gateway");
switch_console_set_complete("add sofia profile ::sofia::list_profiles killgw ::sofia::list_profile_gateway");