</refactor>

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4955 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-04-17 06:08:39 +00:00
parent c833f03377
commit cf3c9b8889
4 changed files with 104 additions and 90 deletions

View File

@ -300,7 +300,9 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
} }
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0); sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
sofia_glue_activate_rtp(tech_pvt); if (sofia_glue_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
if (tech_pvt->nh) { if (tech_pvt->nh) {
if (tech_pvt->local_sdp_str) { if (tech_pvt->local_sdp_str) {
@ -605,7 +607,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
switch_clear_flag_locked(tech_pvt, TFLAG_NOMEDIA); switch_clear_flag_locked(tech_pvt, TFLAG_NOMEDIA);
tech_pvt->local_sdp_str = NULL; tech_pvt->local_sdp_str = NULL;
if (!switch_rtp_ready(tech_pvt->rtp_session)) { if (!switch_rtp_ready(tech_pvt->rtp_session)) {
sofia_glue_sofia_glue_tech_set_codecs(tech_pvt); sofia_glue_tech_prepare_codecs(tech_pvt);
if ((status = sofia_glue_tech_choose_port(tech_pvt)) != SWITCH_STATUS_SUCCESS) { if ((status = sofia_glue_tech_choose_port(tech_pvt)) != SWITCH_STATUS_SUCCESS) {
return status; return status;
} }
@ -645,8 +647,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
a_tech_pvt->remote_sdp_audio_port = b_tech_pvt->remote_sdp_audio_port; a_tech_pvt->remote_sdp_audio_port = b_tech_pvt->remote_sdp_audio_port;
a_tech_pvt->local_sdp_audio_ip = switch_core_session_strdup(a_session, b_tech_pvt->local_sdp_audio_ip); a_tech_pvt->local_sdp_audio_ip = switch_core_session_strdup(a_session, b_tech_pvt->local_sdp_audio_ip);
a_tech_pvt->local_sdp_audio_port = b_tech_pvt->local_sdp_audio_port; a_tech_pvt->local_sdp_audio_port = b_tech_pvt->local_sdp_audio_port;
sofia_glue_activate_rtp(a_tech_pvt); if (sofia_glue_activate_rtp(a_tech_pvt) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
b_tech_pvt->kick = switch_core_session_strdup(b_session, tech_pvt->xferto); b_tech_pvt->kick = switch_core_session_strdup(b_session, tech_pvt->xferto);
switch_core_session_rwunlock(a_session); switch_core_session_rwunlock(a_session);
} }
@ -708,7 +711,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
return status; return status;
} }
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0); sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
sofia_glue_activate_rtp(tech_pvt); if (sofia_glue_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
if (tech_pvt->local_sdp_str) { if (tech_pvt->local_sdp_str) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ring SDP:\n%s\n", tech_pvt->local_sdp_str); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ring SDP:\n%s\n", tech_pvt->local_sdp_str);
} }
@ -843,7 +848,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
if (!(tech_pvt = (struct private_object *) switch_core_session_alloc(nsession, sizeof(*tech_pvt)))) { if (!(tech_pvt = (struct private_object *) switch_core_session_alloc(nsession, sizeof(*tech_pvt)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Creating Session\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error Creating Session\n");
sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__); sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__);
goto done; goto done;
} }
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(nsession)); switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(nsession));
@ -858,7 +863,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
if (!(gw = strchr(profile_name, '/'))) { if (!(gw = strchr(profile_name, '/'))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__); sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__);
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT; cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
goto done; goto done;
} }
@ -867,7 +872,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
if (!(dest = strchr(gw, '/'))) { if (!(dest = strchr(gw, '/'))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__); sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__);
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT; cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
goto done; goto done;
} }
@ -876,7 +881,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
if (!(gateway_ptr = sofia_reg_find_gateway(gw))) { if (!(gateway_ptr = sofia_reg_find_gateway(gw))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Gateway\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Gateway\n");
sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__); sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__);
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT; cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
goto done; goto done;
} }
@ -892,7 +897,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
} else { } else {
if (!(dest = strchr(profile_name, '/'))) { if (!(dest = strchr(profile_name, '/'))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__); sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__);
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT; cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
goto done; goto done;
} }
@ -900,7 +905,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
if (!(profile = sofia_glue_find_profile(profile_name))) { if (!(profile = sofia_glue_find_profile(profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n");
sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__); sofia_glue_terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__);
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
goto done; goto done;
} }
@ -922,7 +927,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate registered user %s@%s\n", dest, host); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate registered user %s@%s\n", dest, host);
cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION; cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION;
sofia_glue_terminate_session(&nsession, cause, __LINE__); sofia_glue_terminate_session(&nsession, cause, __FILE__, __LINE__);
goto done; goto done;
} }
} else if (!strchr(dest, '@')) { } else if (!strchr(dest, '@')) {
@ -934,7 +939,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate registered user %s@%s\n", dest, profile_name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate registered user %s@%s\n", dest, profile_name);
cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION; cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION;
sofia_glue_terminate_session(&nsession, cause, __LINE__); sofia_glue_terminate_session(&nsession, cause, __FILE__, __LINE__);
goto done; goto done;
} }
} else { } else {

View File

@ -309,6 +309,7 @@ struct private_object {
nua_handle_t *nh; nua_handle_t *nh;
nua_handle_t *nh2; nua_handle_t *nh2;
sip_contact_t *contact; sip_contact_t *contact;
int hangup_status;
}; };
struct callback_t { struct callback_t {
@ -338,25 +339,20 @@ void sofia_glue_deactivate_rtp(private_object_t *tech_pvt);
void sofia_glue_set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, char *sr, int force); void sofia_glue_set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, char *sr, int force);
void sofia_glue_sofia_glue_tech_set_codecs(private_object_t *tech_pvt); void sofia_glue_tech_prepare_codecs(private_object_t *tech_pvt);
void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t *profile, private_object_t *tech_pvt, const char *channame); void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t *profile, private_object_t *tech_pvt, const char *channame);
void sofia_glue_terminate_session(switch_core_session_t **session, switch_call_cause_t cause, int line); void sofia_glue_terminate_session(switch_core_session_t **session, switch_call_cause_t cause, const char *file, int line);
switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt); switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt);
switch_status_t sofia_glue_do_invite(switch_core_session_t *session); switch_status_t sofia_glue_do_invite(switch_core_session_t *session);
uint8_t negotiate_sdp(switch_core_session_t *session, sdp_session_t *sdp); uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *sdp);
void sofia_presence_establish_presence(sofia_profile_t *profile); void sofia_presence_establish_presence(sofia_profile_t *profile);
void sofia_handle_sip_i_state(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, tagi_t tags[]);
void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[]); void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[]);
void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[]); void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[]);

View File

@ -36,6 +36,9 @@
#include "mod_sofia.h" #include "mod_sofia.h"
extern su_log_t tport_log[]; extern su_log_t tport_log[];
static void sofia_handle_sip_i_state(switch_core_session_t *session, 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, tagi_t tags[]);
void sofia_event_callback(nua_event_t event, void sofia_event_callback(nua_event_t event,
int status, int status,
@ -144,7 +147,7 @@ void sofia_event_callback(nua_event_t event,
case nua_i_prack: case nua_i_prack:
break; break;
case nua_i_state: case nua_i_state:
sofia_handle_sip_i_state(status, phrase, nua, profile, nh, sofia_private, sip, tags); sofia_handle_sip_i_state(session, status, phrase, nua, profile, nh, sofia_private, sip, tags);
break; break;
case nua_i_message: case nua_i_message:
sofia_presence_handle_sip_i_message(status, phrase, nua, profile, nh, sofia_private, sip, tags); sofia_presence_handle_sip_i_message(status, phrase, nua, profile, nh, sofia_private, sip, tags);
@ -177,7 +180,18 @@ void sofia_event_callback(nua_event_t event,
done: done:
if (session) { if (session) {
if (tech_pvt->hangup_status) {
if (!switch_core_session_running(session)) {
switch_core_session_rwunlock(session); switch_core_session_rwunlock(session);
switch_core_session_destroy(&session);
} else {
switch_channel_hangup(channel, sofia_glue_sip_cause_to_freeswitch(tech_pvt->hangup_status));
switch_core_session_rwunlock(session);
}
tech_pvt->hangup_status = 0;
} else {
switch_core_session_rwunlock(session);
}
} }
} }
@ -801,7 +815,7 @@ switch_status_t config_sofia(int reload)
} }
void sofia_handle_sip_i_state(int status, static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
char const *phrase, char const *phrase,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]) nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
{ {
@ -810,7 +824,6 @@ void sofia_handle_sip_i_state(int status,
int ss_state = nua_callstate_init; int ss_state = nua_callstate_init;
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
private_object_t *tech_pvt = NULL; private_object_t *tech_pvt = NULL;
switch_core_session_t *session = NULL;
const char *replaces_str = NULL; const char *replaces_str = NULL;
char *uuid; char *uuid;
switch_core_session_t *other_session = NULL; switch_core_session_t *other_session = NULL;
@ -818,16 +831,6 @@ void sofia_handle_sip_i_state(int status,
char st[80] = ""; char st[80] = "";
if (sofia_private) {
if (!switch_strlen_zero(sofia_private->uuid)) {
if (!(session = switch_core_session_locate(sofia_private->uuid))) {
/* too late */
return;
}
}
}
tl_gets(tags, tl_gets(tags,
NUTAG_CALLSTATE_REF(ss_state), NUTAG_CALLSTATE_REF(ss_state),
NUTAG_OFFER_RECV_REF(offer_recv), NUTAG_OFFER_RECV_REF(offer_recv),
@ -916,6 +919,7 @@ void sofia_handle_sip_i_state(int status,
if (sofia_glue_tech_media(tech_pvt, (char *) r_sdp) != SWITCH_STATUS_SUCCESS) { if (sofia_glue_tech_media(tech_pvt, (char *) r_sdp) != SWITCH_STATUS_SUCCESS) {
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); nua_respond(nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
} }
} }
goto done; goto done;
@ -942,19 +946,18 @@ void sofia_handle_sip_i_state(int status,
switch_core_session_thread_launch(session); switch_core_session_thread_launch(session);
goto done; goto done;
} else { } else {
sdp_parser_t *parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0); sdp_parser_t *parser;
sdp_session_t *sdp; sdp_session_t *sdp;
uint8_t match = 0; uint8_t match = 0;
if (tech_pvt->num_codecs) { if (tech_pvt->num_codecs) {
if ((parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
if ((sdp = sdp_session(parser))) { if ((sdp = sdp_session(parser))) {
match = negotiate_sdp(session, sdp); match = sofia_glue_negotiate_sdp(session, sdp);
} }
}
if (parser) {
sdp_parser_free(parser); sdp_parser_free(parser);
} }
}
if (match) { if (match) {
nua_handle_t *bnh; nua_handle_t *bnh;
@ -1023,13 +1026,16 @@ void sofia_handle_sip_i_state(int status,
if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) { if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
goto done; goto done;
} else { } else {
sdp_parser_t *parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0); sdp_parser_t *parser;
sdp_session_t *sdp; sdp_session_t *sdp;
uint8_t match = 0; uint8_t match = 0;
if (tech_pvt->num_codecs) { if (tech_pvt->num_codecs) {
if ((parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
if ((sdp = sdp_session(parser))) { if ((sdp = sdp_session(parser))) {
match = negotiate_sdp(session, sdp); match = sofia_glue_negotiate_sdp(session, sdp);
}
sdp_parser_free(parser);
} }
} }
if (match) { if (match) {
@ -1038,11 +1044,14 @@ void sofia_handle_sip_i_state(int status,
} }
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0); sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
switch_set_flag_locked(tech_pvt, TFLAG_REINVITE); switch_set_flag_locked(tech_pvt, TFLAG_REINVITE);
sofia_glue_activate_rtp(tech_pvt); if (sofia_glue_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Processing Reinvite\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Reinvite RTP Error!\n");
if (parser) { switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
sdp_parser_free(parser);
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Processing Reinvite\n");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Reinvite Codec Error!\n");
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
} }
} }
} }
@ -1055,7 +1064,10 @@ void sofia_handle_sip_i_state(int status,
tech_pvt->nh = tech_pvt->nh2; tech_pvt->nh = tech_pvt->nh2;
tech_pvt->nh2 = NULL; tech_pvt->nh2 = NULL;
if (sofia_glue_tech_choose_port(tech_pvt) == SWITCH_STATUS_SUCCESS) { if (sofia_glue_tech_choose_port(tech_pvt) == SWITCH_STATUS_SUCCESS) {
sofia_glue_activate_rtp(tech_pvt); if (sofia_glue_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cheater Reinvite RTP Error!\n");
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
} }
goto done; goto done;
} }
@ -1091,26 +1103,28 @@ void sofia_handle_sip_i_state(int status,
} }
goto done; goto done;
} else { } else {
sdp_parser_t *parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0); sdp_parser_t *parser;
sdp_session_t *sdp; sdp_session_t *sdp;
uint8_t match = 0; uint8_t match = 0;
if (tech_pvt->num_codecs) { if (tech_pvt->num_codecs) {
if ((parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
if ((sdp = sdp_session(parser))) { if ((sdp = sdp_session(parser))) {
match = negotiate_sdp(session, sdp); match = sofia_glue_negotiate_sdp(session, sdp);
} }
}
if (parser) {
sdp_parser_free(parser); sdp_parser_free(parser);
} }
}
if (match) { if (match) {
switch_set_flag_locked(tech_pvt, TFLAG_ANS); switch_set_flag_locked(tech_pvt, TFLAG_ANS);
if (sofia_glue_tech_choose_port(tech_pvt) == SWITCH_STATUS_SUCCESS) { if (sofia_glue_tech_choose_port(tech_pvt) == SWITCH_STATUS_SUCCESS) {
sofia_glue_activate_rtp(tech_pvt); if (sofia_glue_activate_rtp(tech_pvt) == SWITCH_STATUS_SUCCESS) {
switch_channel_mark_answered(channel); switch_channel_mark_answered(channel);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP Error!\n");
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
goto done; goto done;
} }
} }
@ -1128,25 +1142,26 @@ void sofia_handle_sip_i_state(int status,
case nua_callstate_terminated: case nua_callstate_terminated:
if (session) { if (session) {
if (!switch_test_flag(tech_pvt, TFLAG_BYE)) { if (!switch_test_flag(tech_pvt, TFLAG_BYE)) {
switch_set_flag_locked(tech_pvt, TFLAG_BYE); switch_set_flag_locked(tech_pvt, TFLAG_BYE);
if (switch_test_flag(tech_pvt, TFLAG_NOHUP)) { if (switch_test_flag(tech_pvt, TFLAG_NOHUP)) {
switch_clear_flag_locked(tech_pvt, TFLAG_NOHUP); switch_clear_flag_locked(tech_pvt, TFLAG_NOHUP);
} else { } else {
snprintf(st, sizeof(st), "%d", status); snprintf(st, sizeof(st), "%d", status);
switch_channel_set_variable(channel, "sip_term_status", st); switch_channel_set_variable(channel, "sip_term_status", st);
sofia_glue_terminate_session(&session, sofia_glue_sip_cause_to_freeswitch(status), __LINE__); tech_pvt->hangup_status = status;
} }
} }
if (tech_pvt->sofia_private) { if (tech_pvt->sofia_private) {
if (sofia_private->home) { if (tech_pvt->sofia_private->home) {
su_home_unref(sofia_private->home); su_home_unref(tech_pvt->sofia_private->home);
} }
free(tech_pvt->sofia_private); free(tech_pvt->sofia_private);
tech_pvt->sofia_private = NULL; tech_pvt->sofia_private = NULL;
} }
tech_pvt->nh = NULL; tech_pvt->nh = NULL;
} else if (sofia_private) { } else if (sofia_private) {
if (sofia_private->home) { if (sofia_private->home) {
su_home_unref(sofia_private->home); su_home_unref(sofia_private->home);
@ -1163,9 +1178,7 @@ void sofia_handle_sip_i_state(int status,
done: done:
if (session) { return;
switch_core_session_rwunlock(session);
}
} }
@ -1277,10 +1290,11 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(session, br_b_tech_pvt->remote_sdp_audio_ip); tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(session, br_b_tech_pvt->remote_sdp_audio_ip);
tech_pvt->remote_sdp_audio_port = br_b_tech_pvt->remote_sdp_audio_port; tech_pvt->remote_sdp_audio_port = br_b_tech_pvt->remote_sdp_audio_port;
sofia_glue_activate_rtp(tech_pvt); if (sofia_glue_activate_rtp(tech_pvt) == SWITCH_STATUS_SUCCESS) {
br_b_tech_pvt->kick = switch_core_session_strdup(br_b_session, switch_core_session_get_uuid(session)); br_b_tech_pvt->kick = switch_core_session_strdup(br_b_session, switch_core_session_get_uuid(session));
} else {
switch_channel_hangup(channel_a, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
switch_core_session_rwunlock(br_b_session); switch_core_session_rwunlock(br_b_session);
} }
@ -1586,7 +1600,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
if (!(tech_pvt = (private_object_t *) switch_core_session_alloc(session, sizeof(private_object_t)))) { if (!(tech_pvt = (private_object_t *) switch_core_session_alloc(session, sizeof(private_object_t)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
nua_respond(nh, SIP_503_SERVICE_UNAVAILABLE, TAG_END()); nua_respond(nh, SIP_503_SERVICE_UNAVAILABLE, TAG_END());
sofia_glue_terminate_session(&session, SWITCH_CAUSE_SWITCH_CONGESTION, __LINE__); sofia_glue_terminate_session(&session, SWITCH_CAUSE_SWITCH_CONGESTION, __FILE__, __LINE__);
return; return;
} }
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
@ -1650,7 +1664,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
} }
sofia_glue_attach_private(session, profile, tech_pvt, channel_name); sofia_glue_attach_private(session, profile, tech_pvt, channel_name);
sofia_glue_sofia_glue_tech_set_codecs(tech_pvt); sofia_glue_tech_prepare_codecs(tech_pvt);
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "INBOUND CALL"); switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "INBOUND CALL");

View File

@ -139,7 +139,7 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t por
tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, buf); tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, buf);
} }
void sofia_glue_sofia_glue_tech_set_codecs(private_object_t *tech_pvt) void sofia_glue_tech_prepare_codecs(private_object_t *tech_pvt)
{ {
switch_channel_t *channel; switch_channel_t *channel;
char *abs, *codec_string = NULL; char *abs, *codec_string = NULL;
@ -232,13 +232,13 @@ void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t *
snprintf(name, sizeof(name), "sofia/%s/%s", profile->name, channame); snprintf(name, sizeof(name), "sofia/%s/%s", profile->name, channame);
switch_channel_set_name(channel, name); switch_channel_set_name(channel, name);
//sofia_glue_sofia_glue_tech_set_codecs(tech_pvt); //sofia_glue_tech_prepare_codecs(tech_pvt);
} }
void sofia_glue_terminate_session(switch_core_session_t **session, switch_call_cause_t cause, int line) void sofia_glue_terminate_session(switch_core_session_t **session, switch_call_cause_t cause, const char *file, int line)
{ {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Term called from line: %d\n", line); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Term called from %s line: %d\n", file, line);
if (*session) { if (*session) {
switch_channel_t *channel = switch_core_session_get_channel(*session); switch_channel_t *channel = switch_core_session_get_channel(*session);
struct private_object *tech_pvt = NULL; struct private_object *tech_pvt = NULL;
@ -306,7 +306,7 @@ switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt)
if (tech_pvt->profile->extrtpip) { if (tech_pvt->profile->extrtpip) {
if (sofia_glue_ext_address_lookup(&ip, &sdp_port, tech_pvt->profile->extrtpip, switch_core_session_get_pool(tech_pvt->session)) != if (sofia_glue_ext_address_lookup(&ip, &sdp_port, tech_pvt->profile->extrtpip, switch_core_session_get_pool(tech_pvt->session)) !=
SWITCH_STATUS_SUCCESS) { SWITCH_STATUS_SUCCESS) {
sofia_glue_terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__); sofia_glue_terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
} }
@ -356,7 +356,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
cid_name = (char *) caller_profile->caller_id_name; cid_name = (char *) caller_profile->caller_id_name;
cid_num = (char *) caller_profile->caller_id_number; cid_num = (char *) caller_profile->caller_id_number;
sofia_glue_sofia_glue_tech_set_codecs(tech_pvt); sofia_glue_tech_prepare_codecs(tech_pvt);
if (!tech_pvt->from_str) { if (!tech_pvt->from_str) {
tech_pvt->from_str = switch_core_session_sprintf(tech_pvt->session, "\"%s\" <sip:%s@%s>", tech_pvt->from_str = switch_core_session_sprintf(tech_pvt->session, "\"%s\" <sip:%s@%s>",
@ -609,7 +609,6 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
if (!tech_pvt->rm_encoding) { if (!tech_pvt->rm_encoding) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec with no name?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec with no name?\n");
sofia_glue_terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -622,7 +621,6 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags,
NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
sofia_glue_terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} else { } else {
if (switch_core_codec_init(&tech_pvt->write_codec, if (switch_core_codec_init(&tech_pvt->write_codec,
@ -634,7 +632,6 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE | tech_pvt->profile->codec_flags,
NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
sofia_glue_terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} else { } else {
int ms; int ms;
@ -763,7 +760,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt)
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP REPORTS ERROR: [%s]\n", err); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP REPORTS ERROR: [%s]\n", err);
sofia_glue_terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__); sofia_glue_terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __FILE__, __LINE__);
switch_clear_flag_locked(tech_pvt, TFLAG_IO); switch_clear_flag_locked(tech_pvt, TFLAG_IO);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -787,7 +784,7 @@ switch_status_t sofia_glue_tech_media(private_object_t *tech_pvt, char *r_sdp)
if (tech_pvt->num_codecs) { if (tech_pvt->num_codecs) {
if ((sdp = sdp_session(parser))) { if ((sdp = sdp_session(parser))) {
match = negotiate_sdp(tech_pvt->session, sdp); match = sofia_glue_negotiate_sdp(tech_pvt->session, sdp);
} }
} }
@ -799,7 +796,9 @@ switch_status_t sofia_glue_tech_media(private_object_t *tech_pvt, char *r_sdp)
if (sofia_glue_tech_choose_port(tech_pvt) != SWITCH_STATUS_SUCCESS) { if (sofia_glue_tech_choose_port(tech_pvt) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
sofia_glue_activate_rtp(tech_pvt); if (sofia_glue_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "EARLY MEDIA"); switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "EARLY MEDIA");
switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA); switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
switch_channel_mark_pre_answered(channel); switch_channel_mark_pre_answered(channel);
@ -811,7 +810,7 @@ switch_status_t sofia_glue_tech_media(private_object_t *tech_pvt, char *r_sdp)
uint8_t negotiate_sdp(switch_core_session_t *session, sdp_session_t *sdp) uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *sdp)
{ {
uint8_t match = 0; uint8_t match = 0;
switch_payload_t te = 0, cng_pt = 0; switch_payload_t te = 0, cng_pt = 0;