[commit] r7067 - in freeswitch/trunk/src: include mod/applications/mod_dptools mod/endpoints/mod_iax mod/endpoints/mod_sofia
Author: anthm Date: Wed Jan 2 19:50:53 2008 New Revision: 7067 Modified: freeswitch/trunk/src/include/switch_types.h freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Log: update Modified: freeswitch/trunk/src/include/switch_types.h ============================================================================== --- freeswitch/trunk/src/include/switch_types.h (original) +++ freeswitch/trunk/src/include/switch_types.h Wed Jan 2 19:50:53 2008 @@ -428,7 +428,7 @@ SWITCH_MESSAGE_INDICATE_HOLD - indicate hold SWITCH_MESSAGE_INDICATE_UNHOLD - indicate unhold SWITCH_MESSAGE_INDICATE_REDIRECT - indicate redirect - SWITCH_MESSAGE_INDICATE_REJECT - indicate reject + SWITCH_MESSAGE_INDICATE_RESPOND - indicate reject SWITCH_MESSAGE_INDICATE_BROADCAST - indicate media broadcast SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT - indicate media broadcast </pre> @@ -447,7 +447,7 @@ SWITCH_MESSAGE_INDICATE_HOLD, SWITCH_MESSAGE_INDICATE_UNHOLD, SWITCH_MESSAGE_INDICATE_REDIRECT, - SWITCH_MESSAGE_INDICATE_REJECT, + SWITCH_MESSAGE_INDICATE_RESPOND, SWITCH_MESSAGE_INDICATE_BROADCAST, SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT } switch_core_session_message_types_t; Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c ============================================================================== --- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c (original) +++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c Wed Jan 2 19:50:53 2008 @@ -416,14 +416,14 @@ } -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); } @@ -1631,7 +1631,8 @@ 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); Modified: freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c Wed Jan 2 19:50:53 2008 @@ -761,7 +761,7 @@ switch_assert(tech_pvt != NULL); switch (msg->message_id) { - case SWITCH_MESSAGE_INDICATE_REJECT: + case SWITCH_MESSAGE_INDICATE_RESPOND: { if (tech_pvt->iax_session) { iax_reject(tech_pvt->iax_session, msg->string_arg ? msg->string_arg : "Call Rejected"); Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Wed Jan 2 19:50:53 2008 @@ -415,6 +415,7 @@ } 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), @@ -932,46 +933,45 @@ 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: @@ -1023,6 +1023,7 @@ 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()); } Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jan 2 19:50:53 2008 @@ -436,27 +436,27 @@ 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); @@ -1260,79 +1260,102 @@ { - 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; - 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 - ); + if (sip->sip_user_agent) { + user_agent = switch_str_nil(sip->sip_user_agent->g_string); + } - switch_assert(sql); + 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); + } + + if (contact) { + contact_user = switch_str_nil(contact->url_user); + contact_host = switch_str_nil(contact->url_host); + } - 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); + 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); + } } } } @@ -1390,6 +1413,8 @@ } } + state_process: + switch ((enum nua_callstate) ss_state) { case nua_callstate_init: break; @@ -1537,6 +1562,10 @@ goto done; } } + + } else { + ss_state = nua_callstate_completed; + goto state_process; } break; @@ -1589,6 +1618,14 @@ 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; Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed Jan 2 19:50:53 2008 @@ -836,6 +836,7 @@ } nua_invite(tech_pvt->nh, + NUTAG_AUTOANSWER(0), NUTAG_SESSION_TIMER(session_timeout), TAG_IF(!switch_strlen_zero(tech_pvt->rpid), SIPTAG_HEADER_STR(tech_pvt->rpid)), TAG_IF(!switch_strlen_zero(alert_info), SIPTAG_HEADER_STR(alert_info)), @@ -1069,6 +1070,10 @@ switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec); tech_pvt->fmtp_out = switch_core_session_strdup(tech_pvt->session, tech_pvt->write_codec.fmtp_out); + if (switch_rtp_ready(tech_pvt->rtp_session)) { + switch_rtp_set_default_payload(tech_pvt->rtp_session, tech_pvt->pt); + } + return SWITCH_STATUS_SUCCESS; } @@ -1428,20 +1433,39 @@ greed: x = 0; + + //xxxxxx + if (tech_pvt->rm_encoding) { + for (map = m->m_rtpmaps; map; map = map->rm_next) { + if (map->rm_pt < 96) { + match = (map->rm_pt == tech_pvt->pt) ? 1 : 0; + } else { + match = strcasecmp(switch_str_nil(map->rm_encoding), tech_pvt->iananame) ? 0 : 1; + } + + if (match) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Our existing codec is still good, let's keep it\n"); + goto end; + } + } + } + + + for (map = m->m_rtpmaps; map; map = map->rm_next) { int32_t i; const switch_codec_implementation_t *mimp = NULL, *near_match = NULL; const char *rm_encoding; if (x++ < skip) { - printf("skip %s\n", map->rm_encoding); + //printf("skip %s\n", map->rm_encoding); continue; } if (!(rm_encoding = map->rm_encoding)) { rm_encoding = ""; } - + if (!te && !strcasecmp(rm_encoding, "telephone-event")) { te = tech_pvt->te = (switch_payload_t) map->rm_pt; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set 2833 dtmf payload to %u\n", te); @@ -1632,6 +1656,8 @@ } } + end: + switch_set_flag_locked(tech_pvt, TFLAG_SDP); return match;
participants (1)
-
Freeswitch SVN