diff --git a/libs/esl/src/esl_event.c b/libs/esl/src/esl_event.c index 3705b4f549..65bcb341dd 100644 --- a/libs/esl/src/esl_event.c +++ b/libs/esl/src/esl_event.c @@ -121,6 +121,8 @@ static const char *EVENT_NAMES[] = { "SESSION_HEARTBEAT", "CLIENT_DISCONNECTED", "SERVER_DISCONNECTED", + "SEND_INFO", + "RECV_INFO", "ALL" }; diff --git a/libs/esl/src/include/esl_event.h b/libs/esl/src/include/esl_event.h index d9e7a3e4ba..cfc93104b9 100644 --- a/libs/esl/src/include/esl_event.h +++ b/libs/esl/src/include/esl_event.h @@ -109,6 +109,8 @@ typedef enum { ESL_EVENT_SESSION_HEARTBEAT, ESL_EVENT_CLIENT_DISCONNECTED, ESL_EVENT_SERVER_DISCONNECTED, + ESL_EVENT_SEND_INFO, + ESL_EVENT_RECV_INFO, ESL_EVENT_ALL } esl_event_types_t; diff --git a/src/include/switch_types.h b/src/include/switch_types.h index fea61d5ec6..78bf3a096d 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1257,6 +1257,8 @@ typedef enum { SWITCH_EVENT_SESSION_HEARTBEAT, SWITCH_EVENT_CLIENT_DISCONNECTED, SWITCH_EVENT_SERVER_DISCONNECTED, + SWITCH_EVENT_SEND_INFO, + SWITCH_EVENT_RECV_INFO, SWITCH_EVENT_ALL } switch_event_types_t; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index c9138b03d5..df65ce3da1 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -2867,6 +2867,56 @@ static void general_event_handler(switch_event_t *event) sofia_glue_release_profile(profile); } + } + break; + case SWITCH_EVENT_SEND_INFO: + { + const char *profile_name = switch_event_get_header(event, "profile"); + const char *ct = switch_event_get_header(event, "content-type"); + const char *to_uri = switch_event_get_header(event, "to-uri"); + const char *from_uri = switch_event_get_header(event, "from-uri"); + const char *body = switch_event_get_body(event); + sofia_profile_t *profile; + nua_handle_t *nh; + + if (!profile_name) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Profile Name\n"); + return; + } + + if (!to_uri) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing To-URI header\n"); + return; + } + + if (!from_uri) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing From-URI header\n"); + return; + } + + + if (!(profile = sofia_glue_find_profile(profile_name))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find profile %s\n", profile_name); + return; + } + + + nh = nua_handle(profile->nua, + NULL, + NUTAG_URL(to_uri), + SIPTAG_FROM_STR(from_uri), + SIPTAG_TO_STR(to_uri), + SIPTAG_CONTACT_STR(profile->url), + TAG_END()); + + nua_info(nh, + TAG_IF(ct, SIPTAG_CONTENT_TYPE_STR(ct)), + TAG_IF(!switch_strlen_zero(body), SIPTAG_PAYLOAD_STR(body)), + TAG_END()); + + + sofia_glue_release_profile(profile); + } break; case SWITCH_EVENT_TRAP: @@ -3018,6 +3068,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load) return SWITCH_STATUS_GENERR; } + if (switch_event_bind(modname, SWITCH_EVENT_SEND_INFO, SWITCH_EVENT_SUBCLASS_ANY, general_event_handler, NULL) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n"); + return SWITCH_STATUS_GENERR; + } + /* connect my internal structure to the blank pointer passed to me */ *module_interface = switch_loadable_module_create_module_interface(pool, modname); sofia_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 82b9c2474b..e4697b1d3f 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -190,7 +190,8 @@ typedef enum { typedef enum { PFLAG_NDLB_TO_IN_200_CONTACT = (1 << 0), - PFLAG_NDLB_BROKEN_AUTH_HASH = (1 << 1) + PFLAG_NDLB_BROKEN_AUTH_HASH = (1 << 1), + PFLAG_NDLB_SENDRECV_IN_SESSION = (1 << 2) } sofia_NDLB_t; typedef enum { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 2a780ddd6c..306d5c058f 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1668,6 +1668,12 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile) } else { profile->ndlb &= ~PFLAG_NDLB_BROKEN_AUTH_HASH; } + } else if (!strcasecmp(var, "NDLB-sendrecv-in-session")) { + if (switch_true(val)) { + profile->ndlb |= PFLAG_NDLB_SENDRECV_IN_SESSION; + } else { + profile->ndlb &= ~PFLAG_NDLB_SENDRECV_IN_SESSION; + } } else if (!strcasecmp(var, "pass-rfc2833")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_PASS_RFC2833); @@ -2215,6 +2221,12 @@ switch_status_t config_sofia(int reload, char *profile_name) if (switch_true(val)) { profile->ndlb |= PFLAG_NDLB_BROKEN_AUTH_HASH; } + } else if (!strcasecmp(var, "NDLB-sendrecv-in-session")) { + if (switch_true(val)) { + profile->ndlb |= PFLAG_NDLB_SENDRECV_IN_SESSION; + } else { + profile->ndlb &= ~PFLAG_NDLB_SENDRECV_IN_SESSION; + } } else if (!strcasecmp(var, "pass-rfc2833")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_PASS_RFC2833); @@ -3863,6 +3875,7 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t const char *rec_header; const char *clientcode_header; switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) }; + switch_event_t *event; if (session) { /* Get the channel */ @@ -3932,7 +3945,7 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t /* Send 200 OK response */ nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END()); - return; + goto end; } else { goto fail; } @@ -3946,7 +3959,7 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t } else { goto fail; } - return; + goto end; } if ((rec_header = sofia_glue_get_unknown_header(sip, "record"))) { @@ -3978,13 +3991,66 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t } } } - return; + goto end; } } - return; + goto end; fail: - nua_respond(nh, 488, "Unsupported Request", NUTAG_WITH_THIS(nua), TAG_END()); + + /* *shrug* just ok it */ + nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END()); + + end: + + + if (switch_event_create(&event, SWITCH_EVENT_RECV_INFO) == SWITCH_STATUS_SUCCESS) { + + if (sip->sip_content_type) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-Content-Type", "%s", sip->sip_content_type->c_type); + } + + if (sip->sip_from && sip->sip_from->a_url) { + if (sip->sip_from->a_url->url_user) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-From-User", sip->sip_from->a_url->url_user); + } + + if (sip->sip_from->a_url->url_host) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-From-Host", sip->sip_from->a_url->url_host); + } + } + + if (sip->sip_to && sip->sip_to->a_url) { + if (sip->sip_to->a_url->url_user) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-To-User", sip->sip_to->a_url->url_user); + } + + if (sip->sip_to->a_url->url_host) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-To-Host", sip->sip_to->a_url->url_host); + } + } + + + if (sip->sip_contact && sip->sip_contact->m_url) { + if (sip->sip_contact->m_url->url_user) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-Contact-User", sip->sip_contact->m_url->url_user); + } + + if (sip->sip_contact->m_url->url_host) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-Contact-Host", sip->sip_contact->m_url->url_host); + } + } + + if (sip->sip_payload->pl_data) { + switch_event_add_body(event, "%s", sip->sip_payload->pl_data); + } + + switch_event_fire(&event); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dispatched freeswitch event for INFO\n"); + } + + return; + } #define url_set_chanvars(session, url, varprefix) _url_set_chanvars(session, url, #varprefix "_user", #varprefix "_host", #varprefix "_port", #varprefix "_uri", #varprefix "_params") diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index fe9ae02d27..bfd4cc2bc4 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -117,6 +117,8 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, uint32 const char *family; const char *pass_fmtp = switch_channel_get_variable(tech_pvt->channel, "sip_video_fmtp"); const char *ov_fmtp = switch_channel_get_variable(tech_pvt->channel, "sip_force_video_fmtp"); + char srbuf[128] = ""; + const char *var_val; if (sofia_test_pflag(tech_pvt->profile, PFLAG_SUPPRESS_CNG) || ((val = switch_channel_get_variable(tech_pvt->channel, "supress_cng")) && switch_true(val)) || @@ -155,14 +157,22 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, uint32 tech_pvt->session_id++; + if ((tech_pvt->profile->ndlb & PFLAG_NDLB_SENDRECV_IN_SESSION) || + ((var_val=switch_channel_get_variable(tech_pvt->channel, "ndlb_sendrecv_in_session")) && switch_true(var_val))) { + switch_snprintf(srbuf, sizeof(srbuf), "a=%s\n", sr); + sr = NULL; + } + family = strchr(ip, ':') ? "IP6" : "IP4"; switch_snprintf(buf, sizeof(buf), "v=0\n" "o=FreeSWITCH %010u %010u IN %s %s\n" "s=FreeSWITCH\n" "c=IN %s %s\n" "t=0 0\n" - "m=audio %d RTP/%sAVP", - tech_pvt->owner_id, tech_pvt->session_id, family, ip, family, ip, port, + "%sm=audio %d RTP/%sAVP", + tech_pvt->owner_id, tech_pvt->session_id, family, ip, family, ip, + srbuf, + port, (!switch_strlen_zero(tech_pvt->local_crypto_key) && sofia_test_flag(tech_pvt,TFLAG_SECURE)) ? "S" : ""); diff --git a/src/switch_event.c b/src/switch_event.c index 924c95b6c8..1c46ebdb6d 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -175,6 +175,8 @@ static char *EVENT_NAMES[] = { "SESSION_HEARTBEAT", "CLIENT_DISCONNECTED", "SERVER_DISCONNECTED", + "SEND_INFO", + "RECV_INFO", "ALL" };