]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
ndlb_sendrecv_in_session var NDLB-sendrecv-in-session profile option to reverse the...
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 20 Apr 2009 17:07:54 +0000 (17:07 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 20 Apr 2009 17:07:54 +0000 (17:07 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13084 d0543943-73ff-0310-b7d9-9358b9ac24b2

libs/esl/src/esl_event.c
libs/esl/src/include/esl_event.h
src/include/switch_types.h
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c
src/switch_event.c

index 3705b4f549c722e6dbbdb53084cc834994798a86..65bcb341dddb99720e3ec4f179d3c813daeab5e2 100644 (file)
@@ -121,6 +121,8 @@ static const char *EVENT_NAMES[] = {
        "SESSION_HEARTBEAT",
        "CLIENT_DISCONNECTED",
        "SERVER_DISCONNECTED",
+       "SEND_INFO",
+       "RECV_INFO",
        "ALL"
 };
 
index d9e7a3e4ba7a31d52168e25f76a58bb7586ebc93..cfc93104b99722251f06e46db89023997f316ae8 100644 (file)
@@ -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;
 
index fea61d5ec6f25d70db204a7a51e12381086f3846..78bf3a096df53dff5817bd845973f35b080cfc94 100644 (file)
@@ -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;
 
index c9138b03d501743c5dfc65e752b7f91814bd332f..df65ce3da1008ba12c9a98a3c5a2310ddd5dc156 100644 (file)
@@ -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);
index 82b9c2474bb22b496fe483789df559341e397e5f..e4697b1d3f88a6c58a6bafccfb5795c2b8569d0a 100644 (file)
@@ -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 {
index 2a780ddd6c0475261e07ef6e6594511b6043cc49..306d5c058ff10a917724d6b7c65cd288d6f69b8f 100644 (file)
@@ -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")
index fe9ae02d27436e94ade8e1f2d45042bcada8ccfb..bfd4cc2bc4f49a3df7368cc051622ceeb79fc088 100644 (file)
@@ -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" : "");
 
index 924c95b6c8d0897451e5285afb75ef3a8789c511..1c46ebdb6de7ffea4ab24e4c8a132076f4c41b97 100644 (file)
@@ -175,6 +175,8 @@ static char *EVENT_NAMES[] = {
        "SESSION_HEARTBEAT",
        "CLIENT_DISCONNECTED",
        "SERVER_DISCONNECTED",
+       "SEND_INFO",
+       "RECV_INFO",
        "ALL"
 };