git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6971 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-12-24 18:26:39 +00:00
parent 6cd5f4de00
commit d14909d41d
2 changed files with 104 additions and 52 deletions

View File

@ -84,7 +84,7 @@ static switch_status_t sofia_on_init(switch_core_session_t *session)
tech_pvt->read_frame.buflen = SWITCH_RTP_MAX_BUF_LEN; tech_pvt->read_frame.buflen = SWITCH_RTP_MAX_BUF_LEN;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SOFIA INIT\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA INIT\n", switch_channel_get_name(channel));
if (switch_channel_test_flag(channel, CF_BYPASS_MEDIA)) { if (switch_channel_test_flag(channel, CF_BYPASS_MEDIA)) {
sofia_glue_tech_absorb_sdp(tech_pvt); sofia_glue_tech_absorb_sdp(tech_pvt);
} }
@ -112,7 +112,47 @@ static switch_status_t sofia_on_ring(switch_core_session_t *session)
tech_pvt = (private_object_t *) switch_core_session_get_private(session); tech_pvt = (private_object_t *) switch_core_session_get_private(session);
switch_assert(tech_pvt != NULL); switch_assert(tech_pvt != NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SOFIA RING\n"); switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA RING\n", switch_channel_get_name(channel));
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t sofia_on_reset(switch_core_session_t *session)
{
switch_channel_t *channel = NULL;
private_object_t *tech_pvt = NULL;
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
tech_pvt = (private_object_t *) switch_core_session_get_private(session);
switch_assert(tech_pvt != NULL);
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA RESET\n", switch_channel_get_name(channel));
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t sofia_on_hibernate(switch_core_session_t *session)
{
switch_channel_t *channel = NULL;
private_object_t *tech_pvt = NULL;
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
tech_pvt = (private_object_t *) switch_core_session_get_private(session);
switch_assert(tech_pvt != NULL);
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA HIBERNATE\n", switch_channel_get_name(channel));
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -128,7 +168,8 @@ static switch_status_t sofia_on_execute(switch_core_session_t *session)
tech_pvt = (private_object_t *) switch_core_session_get_private(session); tech_pvt = (private_object_t *) switch_core_session_get_private(session);
switch_assert(tech_pvt != NULL); switch_assert(tech_pvt != NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SOFIA EXECUTE\n"); switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA EXECUTE\n", switch_channel_get_name(channel));
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -206,7 +247,10 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_audio_port); switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_audio_port);
} }
if (switch_test_flag(tech_pvt, TFLAG_SIP_HOLD)) { cause = switch_channel_get_cause(channel);
#if 0
if (switch_test_flag(tech_pvt, TFLAG_SIP_HOLD) && cause != SWITCH_CAUSE_ATTENDED_TRANSFER) {
const char *buuid; const char *buuid;
switch_core_session_t *bsession; switch_core_session_t *bsession;
switch_channel_t *bchannel; switch_channel_t *bchannel;
@ -232,8 +276,8 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD); switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
} }
#endif
cause = switch_channel_get_cause(channel);
sip_cause = hangup_cause_to_sip(cause); sip_cause = hangup_cause_to_sip(cause);
sofia_glue_deactivate_rtp(tech_pvt); sofia_glue_deactivate_rtp(tech_pvt);
@ -1495,7 +1539,10 @@ switch_state_handler_table_t sofia_event_handlers = {
/*.on_execute */ sofia_on_execute, /*.on_execute */ sofia_on_execute,
/*.on_hangup */ sofia_on_hangup, /*.on_hangup */ sofia_on_hangup,
/*.on_loopback */ sofia_on_loopback, /*.on_loopback */ sofia_on_loopback,
/*.on_transmit */ sofia_on_transmit /*.on_transmit */ sofia_on_transmit,
/*.on_hold */ NULL,
/*.on_hibernate*/ sofia_on_hibernate,
/*.on_reset*/ sofia_on_reset
}; };
static switch_status_t sofia_manage(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen) static switch_status_t sofia_manage(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)

View File

@ -1462,6 +1462,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
if (br_b) { if (br_b) {
switch_ivr_uuid_bridge(br_a, br_b); switch_ivr_uuid_bridge(br_a, br_b);
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER"); switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_channel_hangup(channel, SWITCH_CAUSE_ATTENDED_TRANSFER); switch_channel_hangup(channel, SWITCH_CAUSE_ATTENDED_TRANSFER);
} else { } else {
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER_ERROR"); switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER_ERROR");
@ -1763,6 +1764,7 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"), nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END()); NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END());
switch_clear_flag_locked(b_tech_pvt, TFLAG_SIP_HOLD);
switch_channel_hangup(channel_b, SWITCH_CAUSE_ATTENDED_TRANSFER); switch_channel_hangup(channel_b, SWITCH_CAUSE_ATTENDED_TRANSFER);
} else { } else {
if (!br_a && !br_b) { if (!br_a && !br_b) {
@ -1786,8 +1788,11 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t
t_session = switch_core_session_locate(br_a); t_session = switch_core_session_locate(br_a);
hup_channel = channel_b; hup_channel = channel_b;
} else { } else {
private_object_t *h_tech_pvt = (private_object_t *) switch_core_session_get_private(b_session);
t_session = switch_core_session_locate(br_b); t_session = switch_core_session_locate(br_b);
hup_channel = channel_a; hup_channel = channel_a;
switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_clear_flag_locked(h_tech_pvt, TFLAG_SIP_HOLD);
switch_channel_hangup(channel_b, SWITCH_CAUSE_ATTENDED_TRANSFER); switch_channel_hangup(channel_b, SWITCH_CAUSE_ATTENDED_TRANSFER);
} }
@ -1936,9 +1941,10 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t
struct private_object *tech_pvt = NULL; struct private_object *tech_pvt = NULL;
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
/* placeholder for string searching */ /* placeholder for string searching */
char *signal_ptr; const char *signal_ptr;
const char *rec_header; const char *rec_header;
switch_dtmf_t dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION };
if (session) { if (session) {
/* Get the channel */ /* Get the channel */
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
@ -1952,55 +1958,47 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t
/* Barf if we didn't get it */ /* Barf if we didn't get it */
switch_assert(tech_pvt != NULL); switch_assert(tech_pvt != NULL);
if (sip && sip->sip_content_type && sip->sip_content_type->c_type && sip->sip_content_type->c_subtype &&
sip->sip_payload && sip->sip_payload->pl_data) {
if (!strcasecmp(sip->sip_content_type->c_type, "dtmf") && !strcasecmp(sip->sip_content_type->c_subtype, "relay")) {
/* Try and find signal information in the payload */
if ((signal_ptr = switch_stristr("Signal=", sip->sip_payload->pl_data))) {
/* move signal_ptr where we need it (right past Signal=) */
signal_ptr = signal_ptr + 7;
dtmf.digit = *signal_ptr;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Bad signal\n");
goto fail;
}
if (sip && sip->sip_payload && sip->sip_payload->pl_data) { if ((signal_ptr = switch_stristr("Duration=", sip->sip_payload->pl_data))) {
switch_dtmf_t dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION }; int tmp;
signal_ptr += 8;
/* Try and find signal information in the payload */ if ((tmp = atoi(signal_ptr)) < 0) {
if ((signal_ptr = strstr(sip->sip_payload->pl_data, "Signal="))) { tmp = SWITCH_DEFAULT_DTMF_DURATION;
/* move signal_ptr where we need it (right past Signal=) */ }
signal_ptr = signal_ptr + 7; dtmf.duration = tmp;
}
} else if (!strcasecmp(sip->sip_content_type->c_type, "application") && !strcasecmp(sip->sip_content_type->c_subtype, "dtmf")) {
dtmf.digit = *sip->sip_payload->pl_data;
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Bad signal\n"); goto fail;
return;
} }
if (dtmf.digit) {
/* queue it up */
switch_channel_queue_dtmf(channel, &dtmf);
/* unknown info type */ /* print debug info */
if (!signal_ptr) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INFO DTMF(%c)\n", dtmf.digit);
sip_from_t const *from = sip->sip_from;
/* print in the logs if something comes through we don't understand */ /* Send 200 OK response */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown INFO Recieved: %s%s" URL_PRINT_FORMAT "[%s]\n", nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
from->a_display ? from->a_display : "",
from->a_display ? " " : "",
URL_PRINT_ARGS(from->a_url),
sip->sip_payload->pl_data);
/* Send 415 Unsupported Media response */
nua_respond(nh, SIP_415_UNSUPPORTED_MEDIA, NUTAG_WITH_THIS(nua), TAG_END());
return;
}
dtmf.digit = *signal_ptr;
if ((signal_ptr = strstr(sip->sip_payload->pl_data, "Duration="))) {
int tmp;
signal_ptr += 8;
if ((tmp = atoi(signal_ptr)) < 0) {
tmp = SWITCH_DEFAULT_DTMF_DURATION;
}
dtmf.duration = tmp;
}
/* queue it up */
switch_channel_queue_dtmf(channel, &dtmf);
/* print debug info */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INFO DTMF(%c)\n", dtmf.digit);
/* Send 200 OK response */
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
return; return;
} else {
goto fail;
}
} }
if ((rec_header = sofia_glue_get_unknown_header(sip, "record"))) { if ((rec_header = sofia_glue_get_unknown_header(sip, "record"))) {
@ -2037,6 +2035,13 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t
} }
} }
return;
fail:
nua_respond(nh, 488, "Unsupported Request", NUTAG_WITH_THIS(nua), TAG_END());
} }