}
-SWITCH_STANDARD_APP(reject_function)
+SWITCH_STANDARD_APP(respond_function)
{
switch_core_session_message_t msg = { 0 };
- /* Tell the channel to reject the call */
+ /* Tell the channel to respond the call */
msg.from = __FILE__;
msg.string_arg = data;
- msg.message_id = SWITCH_MESSAGE_INDICATE_REJECT;
+ msg.message_id = SWITCH_MESSAGE_INDICATE_RESPOND;
switch_core_session_receive_message(session, &msg);
}
SWITCH_ADD_APP(app_interface, "detect_speech", "Detect speech", "Detect speech on a channel.", detect_speech_function, DETECT_SPEECH_SYNTAX, SAF_NONE);
SWITCH_ADD_APP(app_interface, "ivr", "Run an ivr menu", "Run an ivr menu.", ivr_application_function, "<menu_name>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "redirect", "Send session redirect", "Send a redirect message to a session.", redirect_function, "<redirect_data>", SAF_SUPPORT_NOMEDIA);
- SWITCH_ADD_APP(app_interface, "reject", "Send session reject", "Send a reject message to a session.", reject_function, "<reject_data>", SAF_SUPPORT_NOMEDIA);
+ SWITCH_ADD_APP(app_interface, "respond", "Send session respond", "Send a respond message to a session.", respond_function, "<respond_data>", SAF_SUPPORT_NOMEDIA);
+ SWITCH_ADD_APP(app_interface, "reject", "Send session reject (depricated)", "Send a respond message to a session.", respond_function, "<respond_data>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "queue_dtmf", "Queue dtmf to be sent", "Queue dtmf to be sent from a session", queue_dtmf_function, "<dtmf_data>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "sched_hangup", SCHED_HANGUP_DESCR, SCHED_HANGUP_DESCR, sched_hangup_function, "[+]<time> [<cause>]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function, "[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
}
nua_respond(tech_pvt->nh, SIP_200_OK,
+ NUTAG_AUTOANSWER(0),
NUTAG_SESSION_TIMER(session_timeout),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
nua_respond(tech_pvt->nh, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR(msg->string_arg), TAG_END());
}
break;
- case SWITCH_MESSAGE_INDICATE_REJECT:
- if (msg->string_arg) {
- int code = 0;
- char *reason = NULL;
-
- if (switch_channel_test_flag(channel, CF_ANSWERED)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call is already answered, Rejecting with hangup\n");
- switch_channel_hangup(channel, SWITCH_CAUSE_CALL_REJECTED);
- } else {
+ case SWITCH_MESSAGE_INDICATE_RESPOND:
+ if (msg->numeric_arg || msg->string_arg) {
+ int code = msg->numeric_arg;
+ const char *reason = NULL;
+ if (code) {
+ reason = msg->string_arg;
+ } else {
if (!switch_strlen_zero(msg->string_arg)){
code = atoi(msg->string_arg);
if ((reason = strchr(msg->string_arg, ' '))) {
reason++;
- }
+ }
}
+ }
- if (!reason && code != 407) {
- reason = "Call Refused";
- }
+ if (!reason && code != 407) {
+ reason = "Call Refused";
+ }
- if (!(code > 400 && code < 700)) {
- code = 488;
- }
+ if (!(code > 400 && code < 700)) {
+ code = 488;
+ }
- if (code == 407) {
- const char *to_uri = switch_channel_get_variable(channel, "sip_to_uri");
- const char *to_host = reason;
+ if (code == 407) {
+ const char *to_uri = switch_channel_get_variable(channel, "sip_to_uri");
+ const char *to_host = reason;
- if (switch_strlen_zero(to_host)) {
- to_host = switch_channel_get_variable(channel, "sip_to_host");
- }
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Challenging call %s\n", to_uri);
- sofia_reg_auth_challange(NULL, tech_pvt->profile, tech_pvt->nh, REG_INVITE, to_host, 0);
- switch_channel_hangup(channel, SWITCH_CAUSE_USER_CHALLENGE);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Rejecting with %d %s\n", code, reason);
- nua_respond(tech_pvt->nh, code, reason, TAG_END());
+ if (switch_strlen_zero(to_host)) {
+ to_host = switch_channel_get_variable(channel, "sip_to_host");
}
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Challenging call %s\n", to_uri);
+ sofia_reg_auth_challange(NULL, tech_pvt->profile, tech_pvt->nh, REG_INVITE, to_host, 0);
+ switch_channel_hangup(channel, SWITCH_CAUSE_USER_CHALLENGE);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Rejecting with %d %s\n", code, reason);
+ nua_respond(tech_pvt->nh, code, reason, TAG_END());
}
+
}
break;
case SWITCH_MESSAGE_INDICATE_RINGING:
switch_channel_mark_pre_answered(channel);
nua_respond(tech_pvt->nh,
SIP_183_SESSION_PROGRESS,
+ NUTAG_AUTOANSWER(0),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), TAG_END());
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created agent for %s\n", profile->name);
nua_set_params(profile->nua,
- NUTAG_APPL_METHOD("OPTIONS"),
- NUTAG_APPL_METHOD("NOTIFY"),
- NUTAG_APPL_METHOD("INFO"),
- NUTAG_AUTOANSWER(0),
- NUTAG_AUTOALERT(0),
- NUTAG_ALLOW("REGISTER"),
- NUTAG_ALLOW("REFER"),
- NUTAG_ALLOW("INFO"),
- NUTAG_ALLOW("NOTIFY"),
- NUTAG_ALLOW_EVENTS("talk"),
- NUTAG_SESSION_TIMER(profile->session_timeout),
- NTATAG_MAX_PROCEEDING(profile->max_proceeding),
- TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("PUBLISH")),
- TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("SUBSCRIBE")),
- TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ENABLEMESSAGE(1)),
- TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence")),
- TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("dialog")),
- TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("call-info")),
- TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence.winfo")),
- TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("message-summary")),
- SIPTAG_SUPPORTED_STR("100rel, precondition, timer"), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END());
+ NUTAG_APPL_METHOD("OPTIONS"),
+ NUTAG_APPL_METHOD("NOTIFY"),
+ NUTAG_APPL_METHOD("INFO"),
+ NUTAG_AUTOANSWER(0),
+ NUTAG_AUTOALERT(0),
+ NUTAG_ALLOW("REGISTER"),
+ NUTAG_ALLOW("REFER"),
+ NUTAG_ALLOW("INFO"),
+ NUTAG_ALLOW("NOTIFY"),
+ NUTAG_ALLOW_EVENTS("talk"),
+ NUTAG_SESSION_TIMER(profile->session_timeout),
+ NTATAG_MAX_PROCEEDING(profile->max_proceeding),
+ TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("PUBLISH")),
+ TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("SUBSCRIBE")),
+ TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ENABLEMESSAGE(1)),
+ TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence")),
+ TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("dialog")),
+ TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("call-info")),
+ TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence.winfo")),
+ TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("message-summary")),
+ SIPTAG_SUPPORTED_STR("100rel, precondition, timer"), 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);
{
- if (sip && session && (status == 180 || status == 183 || status == 200)) {
+ if (sip && session) {
switch_channel_t *channel = switch_core_session_get_channel(session);
- const char *astate = "early";
- url_t *from = NULL, *to = NULL, *contact = NULL;
-
- if (sip->sip_to) {
- to = sip->sip_to->a_url;
- }
- if (sip->sip_from) {
- from = sip->sip_from->a_url;
- }
- if (sip->sip_contact) {
- contact = sip->sip_contact->m_url;
- }
-
- if (status == 200) {
- astate = "confirmed";
+ const char *uuid;
+ switch_core_session_t *other_session;
+
+ if (switch_channel_test_flag(channel, CF_BYPASS_MEDIA)) {
+ if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
+ switch_core_session_message_t msg;
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Passing %d %s to other leg\n", status, phrase);
+
+ msg.message_id = SWITCH_MESSAGE_INDICATE_RESPOND;
+ msg.from = __FILE__;
+ msg.numeric_arg = status;
+ msg.string_arg = phrase;
+ switch_core_session_receive_message(other_session, &msg);
+ switch_core_session_rwunlock(other_session);
+ }
+
+ return;
}
- if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED) &&
- !switch_channel_test_flag(channel, CF_RING_READY)) {
- const char *from_user = "", *from_host = "", *to_user = "", *to_host = "", *contact_user = "", *contact_host = "";
- const char *user_agent = "", *call_id = "";
- char *sql = NULL;
+ if ((status == 180 || status == 183 || status == 200)) {
+ switch_channel_t *channel = switch_core_session_get_channel(session);
+ const char *astate = "early";
+ url_t *from = NULL, *to = NULL, *contact = NULL;
- if (sip->sip_user_agent) {
- user_agent = switch_str_nil(sip->sip_user_agent->g_string);
+ if (sip->sip_to) {
+ to = sip->sip_to->a_url;
}
-
- if (sip->sip_call_id) {
- call_id = switch_str_nil(sip->sip_call_id->i_id);
+ if (sip->sip_from) {
+ from = sip->sip_from->a_url;
}
-
- if (to) {
- from_user = switch_str_nil(to->url_user);
+ if (sip->sip_contact) {
+ contact = sip->sip_contact->m_url;
}
- if (from) {
- from_host = switch_str_nil(from->url_host);
- to_user = switch_str_nil(from->url_user);
- to_host = switch_str_nil(from->url_host);
+ if (status == 200) {
+ astate = "confirmed";
}
- if (contact) {
- contact_user = switch_str_nil(contact->url_user);
- contact_host = switch_str_nil(contact->url_host);
- }
+ if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED) &&
+ !switch_channel_test_flag(channel, CF_RING_READY)) {
+ const char *from_user = "", *from_host = "", *to_user = "", *to_host = "", *contact_user = "", *contact_host = "";
+ const char *user_agent = "", *call_id = "";
+ char *sql = NULL;
+
+ if (sip->sip_user_agent) {
+ user_agent = switch_str_nil(sip->sip_user_agent->g_string);
+ }
+
+ if (sip->sip_call_id) {
+ call_id = switch_str_nil(sip->sip_call_id->i_id);
+ }
+
+ if (to) {
+ from_user = switch_str_nil(to->url_user);
+ }
+
+ if (from) {
+ from_host = switch_str_nil(from->url_host);
+ to_user = switch_str_nil(from->url_user);
+ to_host = switch_str_nil(from->url_host);
+ }
- sql = switch_mprintf(
- "insert into sip_dialogs values('%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
- );
-
- switch_assert(sql);
-
- sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
- free(sql);
- } else if (status == 200) {
- char *sql = NULL;
- sql = switch_mprintf("update sip_dialogs set state='%s' where uuid='%s';\n", astate, switch_core_session_get_uuid(session));
- switch_assert(sql);
- sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
- free(sql);
+ if (contact) {
+ contact_user = switch_str_nil(contact->url_user);
+ contact_host = switch_str_nil(contact->url_host);
+ }
+
+ sql = switch_mprintf(
+ "insert into sip_dialogs values('%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
+ );
+
+ switch_assert(sql);
+
+ sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
+ free(sql);
+ } else if (status == 200) {
+ char *sql = NULL;
+ sql = switch_mprintf("update sip_dialogs set state='%s' where uuid='%s';\n", astate, switch_core_session_get_uuid(session));
+ switch_assert(sql);
+ sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
+ free(sql);
+ }
}
}
}
}
}
+ state_process:
+
switch ((enum nua_callstate) ss_state) {
case nua_callstate_init:
break;
goto done;
}
}
+
+ } else {
+ ss_state = nua_callstate_completed;
+ goto state_process;
}
break;
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
}
+
+
+ nua_respond(tech_pvt->nh, SIP_200_OK,
+ SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
+ SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
+ SOATAG_AUDIO_AUX("cn telephone-event"),
+ NUTAG_INCLUDE_EXTRA_SDP(1),
+ TAG_END());
}
}
break;