wait for reply of refer

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10471 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2008-11-20 02:07:59 +00:00
parent ca60095ee2
commit 412fc926ea
6 changed files with 100 additions and 3 deletions
+11
View File
@@ -1120,6 +1120,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
case SWITCH_MESSAGE_INDICATE_DEFLECT:
{
char ref_to[128] = "";
const char *var;
if (!strstr(msg->string_arg, "sip:")) {
const char *format = strchr(tech_pvt->profile->sipip, ':') ? "sip:%s@[%s]" : "sip:%s@%s";
@@ -1128,6 +1129,16 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
switch_set_string(ref_to, msg->string_arg);
}
nua_refer(tech_pvt->nh, SIPTAG_REFER_TO_STR(ref_to), SIPTAG_REFERRED_BY_STR(tech_pvt->contact_url), TAG_END());
switch_mutex_unlock(tech_pvt->sofia_mutex);
sofia_wait_for_reply(tech_pvt, 9999, 300);
switch_mutex_lock(tech_pvt->sofia_mutex);
if ((var = switch_channel_get_variable(tech_pvt->channel, "sip_refer_reply"))) {
msg->string_reply = strdup(var);
switch_set_flag(msg, SCSMF_FREE_STRING_REPLY);
} else {
msg->string_reply = "no reply";
}
}
break;
+2
View File
@@ -513,6 +513,7 @@ struct private_object {
switch_size_t last_ts;
uint32_t check_frames;
uint32_t mismatch_count;
nua_event_t want_event;
};
struct callback_t {
@@ -717,3 +718,4 @@ void sofia_glue_restart_all_profiles(void);
void sofia_glue_toggle_hold(private_object_t *tech_pvt, int sendonly);
const char * sofia_state_string(int state);
switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force);
void sofia_wait_for_reply(struct private_object *tech_pvt, nua_event_t event, uint32_t timeout);
+43 -2
View File
@@ -83,6 +83,7 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status,
nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
{
switch_channel_t *channel = NULL;
private_object_t *tech_pvt = NULL;
/* make sure we have a proper event */
if (!sip || !sip->sip_event) {
@@ -94,14 +95,35 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status,
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
return;
}
if (session) {
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
tech_pvt = switch_core_session_get_private(session);
switch_assert(tech_pvt != NULL);
}
if (!strcasecmp(sip->sip_event->o_type, "refer")) {
if (session && channel && tech_pvt) {
if (sip->sip_payload && sip->sip_payload->pl_data) {
if (!switch_stristr("100", sip->sip_payload->pl_data)) {
switch_channel_set_variable(channel, "sip_refer_reply", sip->sip_payload->pl_data);
if (tech_pvt->want_event == 9999) {
tech_pvt->want_event = 0;
}
}
}
}
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
}
/* make sure we have a proper "talk" event */
if (!session || strcasecmp(sip->sip_event->o_type, "talk")) {
goto error;
}
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
if (!switch_channel_test_flag(channel, CF_OUTBOUND)) {
switch_channel_answer(channel);
switch_channel_set_variable(channel, "auto_answer_destination", switch_channel_get_variable(channel, "destination_number"));
@@ -109,6 +131,7 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status,
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
return;
}
error:
nua_respond(nh, 481, "Subscription Does Not Exist", NUTAG_WITH_THIS(nua), TAG_END());
@@ -160,6 +183,18 @@ void sofia_handle_sip_r_message(int status, sofia_profile_t *profile, nua_handle
{
}
void sofia_wait_for_reply(struct private_object *tech_pvt, nua_event_t event, uint32_t timeout)
{
time_t exp = switch_timestamp(NULL) + timeout;
tech_pvt->want_event = event;
while(switch_channel_ready(tech_pvt->channel) && tech_pvt->want_event && switch_timestamp(NULL) < exp) {
switch_yield(100000);
}
}
void sofia_event_callback(nua_event_t event,
int status,
char const *phrase,
@@ -336,6 +371,10 @@ void sofia_event_callback(nua_event_t event,
done:
if (tech_pvt && tech_pvt->want_event && event == tech_pvt->want_event) {
tech_pvt->want_event = 0;
}
switch (event) {
case nua_i_subscribe:
break;
@@ -586,6 +625,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("include-session-description")),
TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("presence.winfo")),
TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("message-summary")),
NUTAG_ALLOW_EVENTS("refer"),
SIPTAG_SUPPORTED_STR(supported), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END());
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set params for %s\n", profile->name);
@@ -2940,6 +2980,7 @@ static void launch_nightmare_xfer(nightmare_xfer_helper_t *nhelper)
}
/*---------------------------------------*/
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[])
{
/* Incoming refer */