]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7911: reduce pool memory allocation where not necessary
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 23 Sep 2015 16:58:57 +0000 (11:58 -0500)
committerMichael Jerris <mike@jerris.com>
Fri, 25 Sep 2015 13:46:18 +0000 (08:46 -0500)
Conflicts:
src/mod/endpoints/mod_sofia/mod_sofia.c

src/include/switch_core_media.h
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/sofia.c
src/switch_channel.c

index 808e22fc10b4515a4300f7c27eccf0953e6476ef..f137d6fba6d6f881a6475f42a1a6ac15e6ec8783 100644 (file)
@@ -1,3 +1,4 @@
+
 /* 
  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
@@ -107,6 +108,8 @@ typedef struct switch_core_media_params_s {
        char *local_sdp_str;
        char *last_sdp_str;
        char *last_sdp_response;
+       char *prev_sdp_str;
+       char *prev_sdp_response;
 
        char *stun_ip;
        switch_port_t stun_port;
index 9fa263b1e2ded6a4fc0fef377edac247e6a4efb8..53d7baa31c21e21cbff5f64530af95119454d701 100644 (file)
@@ -1495,7 +1495,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                break;
        case SWITCH_MESSAGE_INDICATE_MESSAGE:
                {
-                       char *ct = "text/plain";
+                       char ct[256] = "text/plain";
                        int ok = 0;
 
                        if (!zstr(msg->string_array_arg[3]) && !strcmp(msg->string_array_arg[3], tech_pvt->caller_profile->uuid)) {
@@ -1503,6 +1503,11 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                                break;
                        }
 
+                       if (!zstr(msg->string_array_arg[0]) && !zstr(msg->string_array_arg[1])) {
+                               switch_snprintf(ct, sizeof(ct), "%s/%s", msg->string_array_arg[0], msg->string_array_arg[1]);
+                               ok = 1;
+                       }
+
                        if (switch_stristr("send_message", tech_pvt->x_freeswitch_support_remote)) {
                                ok = 1;
                        }
@@ -1535,26 +1540,14 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                break;
        case SWITCH_MESSAGE_INDICATE_INFO:
                {
-                       char *ct = "freeswitch/data";
+                       char ct[256] = "freeswitch/data";
                        int ok = 0;
 
-                       if (!zstr(msg->string_array_arg[0]) && !zstr(msg->string_array_arg[1])) {
-                               ct = switch_core_session_sprintf(session, "%s/%s", msg->string_array_arg[0], msg->string_array_arg[1]);
-                               ok = 1;
-                       }
-
                        if (switch_stristr("send_info", tech_pvt->x_freeswitch_support_remote)) {
                                ok = 1;
                        }
 
-                       /* TODO: 1.4 remove this stanza */
-                       if (switch_true(switch_channel_get_variable(channel, "fs_send_unspported_info"))) {
-                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
-                                                                 "fs_send_unspported_info is deprecated in favor of correctly spelled fs_send_unsupported_info\n");
-                               ok = 1;
-                       }
-
-                       if (switch_true(switch_channel_get_variable(channel, "fs_send_unsupported_info"))) {
+                       if (switch_true(switch_channel_get_variable_dup(channel, "fs_send_unsupported_info", SWITCH_FALSE, -1))) {
                                ok = 1;
                        }
 
@@ -1562,6 +1555,10 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
                                char *headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_INFO_HEADER_PREFIX);
                                const char *pl = NULL;
 
+                               if (!zstr(msg->string_array_arg[0]) && !zstr(msg->string_array_arg[1])) {
+                                       switch_snprintf(ct, sizeof(ct), "%s/%s", msg->string_array_arg[0], msg->string_array_arg[1]);
+                               }
+
                                if (!zstr(msg->string_array_arg[2])) {
                                        pl = msg->string_array_arg[2];
                                }
index e535b1a366da832485828475ac6e39ed0d6a8093..94f0628abab1fe1a81d8be90ec09dc8727e46c2e 100644 (file)
@@ -5872,14 +5872,24 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
                switch_channel_set_variable_printf(channel, "sip_network_ip", "%s", network_ip);
                switch_channel_set_variable_printf(channel, "sip_network_port", "%d", network_port);
 
-               if ((caller_profile = switch_channel_get_caller_profile(channel))) {
+               if ((caller_profile = switch_channel_get_caller_profile(channel)) && !zstr(network_ip) &&
+                       (zstr(caller_profile->network_addr) || strcmp(caller_profile->network_addr, network_ip))) {
                        caller_profile->network_addr = switch_core_strdup(caller_profile->pool, network_ip);
                }
 
+               if (tech_pvt->mparams.last_sdp_response) {
+                       tech_pvt->mparams.prev_sdp_response = tech_pvt->mparams.last_sdp_response;
+               }
                tech_pvt->mparams.last_sdp_response = NULL;
+
                if (sip->sip_payload && sip->sip_payload->pl_data) {
                        switch_core_media_set_sdp_codec_string(session, sip->sip_payload->pl_data, SDP_TYPE_RESPONSE);
-                       tech_pvt->mparams.last_sdp_response = switch_core_session_strdup(session, sip->sip_payload->pl_data);
+
+                       if (!zstr(tech_pvt->mparams.prev_sdp_response) && !strcmp(tech_pvt->mparams.prev_sdp_response, sip->sip_payload->pl_data)) {
+                               tech_pvt->mparams.last_sdp_response = tech_pvt->mparams.prev_sdp_response;
+                       } else {
+                               tech_pvt->mparams.last_sdp_response = switch_core_session_strdup(session, sip->sip_payload->pl_data);
+                       }
                }
 
                if (status > 299 && switch_channel_test_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_REQ)) {
@@ -6575,6 +6585,15 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
                                }
                        }
                }
+
+               if (tech_pvt->mparams.last_sdp_str) {
+                       tech_pvt->mparams.prev_sdp_str = tech_pvt->mparams.last_sdp_str;
+               }
+
+               if (tech_pvt->mparams.last_sdp_response) {
+                       tech_pvt->mparams.prev_sdp_response = tech_pvt->mparams.last_sdp_response;
+               }
+
                tech_pvt->mparams.last_sdp_str = NULL;
                tech_pvt->mparams.last_sdp_response = NULL;
                
@@ -8823,10 +8842,18 @@ void sofia_handle_sip_i_reinvite(switch_core_session_t *session,
        }
 
        if (channel) {
+               if (tech_pvt->mparams.last_sdp_str) {
+                       tech_pvt->mparams.prev_sdp_str = tech_pvt->mparams.last_sdp_str;
+               }
                tech_pvt->mparams.last_sdp_str = NULL;
+
                if (sip->sip_payload && sip->sip_payload->pl_data) {
-                       switch_channel_set_variable(channel, "sip_reinvite_sdp", sip->sip_payload->pl_data);
-                       tech_pvt->mparams.last_sdp_str = switch_core_session_strdup(session, sip->sip_payload->pl_data);
+                       if (!zstr(tech_pvt->mparams.prev_sdp_str) && strcmp(tech_pvt->mparams.prev_sdp_str, sip->sip_payload->pl_data)) {
+                               switch_channel_set_variable(channel, "sip_reinvite_sdp", sip->sip_payload->pl_data);
+                               tech_pvt->mparams.last_sdp_str = switch_core_session_strdup(session, sip->sip_payload->pl_data);
+                       } else {
+                               tech_pvt->mparams.last_sdp_str = tech_pvt->mparams.prev_sdp_str;
+                       }
                }
                switch_channel_execute_on(channel, "execute_on_sip_reinvite");
        }
index e15aa4cd0087eeb5fdb46f608b9aafeb914115fd..a56a2eeb87a8bfdde165846b81f70e241be1a3c4 100644 (file)
@@ -2490,21 +2490,21 @@ SWITCH_DECLARE(void) switch_channel_event_set_basic_data(switch_channel_t *chann
                                                                   switch_channel_test_flag(channel, CF_DIALPLAN) ? "true" : "false");
 
 
-       if ((v = switch_channel_get_variable(channel, "presence_id"))) {
+       if ((v = switch_channel_get_variable_dup(channel, "presence_id", SWITCH_FALSE, -1))) {
                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-ID", v);
        }
 
-       if ((v = switch_channel_get_variable(channel, "presence_data"))) {
+       if ((v = switch_channel_get_variable_dup(channel, "presence_data", SWITCH_FALSE, -1))) {
                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-Data", v);
        }
 
 
-       if ((v = switch_channel_get_variable(channel, "presence_data_cols"))) {
+       if ((v = switch_channel_get_variable_dup(channel, "presence_data_cols", SWITCH_FALSE, -1))) {
                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Data-Cols", v);
                switch_event_add_presence_data_cols(channel, event, "PD-");
        }
 
-       if ((v = switch_channel_get_variable(channel, "call_uuid"))) {
+       if ((v = switch_channel_get_variable_dup(channel, "call_uuid", SWITCH_FALSE, -1))) {
                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-UUID", v);
        } else {
                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-UUID", switch_core_session_get_uuid(channel->session));