]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix possible bad pointer in global vars (please test)
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 2 Feb 2011 21:43:26 +0000 (15:43 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 2 Feb 2011 21:43:26 +0000 (15:43 -0600)
26 files changed:
src/include/private/switch_core_pvt.h
src/include/switch_core.h
src/include/switch_nat.h
src/mod/applications/mod_commands/mod_commands.c
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/applications/mod_redis/mod_redis.c
src/mod/applications/mod_voicemail/mod_voicemail.c
src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_khomp/src/khomp_pvt.cpp
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/sofia.c
src/mod/event_handlers/mod_event_socket/mod_event_socket.c
src/mod/formats/mod_file_string/mod_file_string.c
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c
src/switch_channel.c
src/switch_console.c
src/switch_core.c
src/switch_core_file.c
src/switch_core_sqldb.c
src/switch_event.c
src/switch_nat.c
src/switch_rtp.c
src/switch_utils.c
src/switch_xml.c

index 30690b1848208cb4b667731a9222c873ac8432a5..05cd24d230eadb8a08de60a9566ca96961d7b3e3 100644 (file)
@@ -246,6 +246,7 @@ struct switch_runtime {
        int sql_buffer_len;
        int max_sql_buffer_len;
        switch_dbtype_t odbc_dbtype;
+       char hostname[256];
 };
 
 extern struct switch_runtime runtime;
index 109a16901bb2f41ea38a36ea55e4b3d30f721e22..69b06420a31c2f25419b32aca472bdeb115be43b 100644 (file)
@@ -759,6 +759,9 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_force_locate(_In_z_
   \return the value of the desired variable
 */
 SWITCH_DECLARE(char *) switch_core_get_variable(_In_z_ const char *varname);
+SWITCH_DECLARE(char *) switch_core_get_variable_dup(_In_z_ const char *varname);
+SWITCH_DECLARE(char *) switch_core_get_variable_pdup(_In_z_ const char *varname, switch_memory_pool_t *pool);
+SWITCH_DECLARE(const char *) switch_core_get_hostname(void);
 
 /*! 
   \brief Add a global variable to the core
index bdbd51b592c8bcc3775a7c3ae0e89e308ad3f2c5..9e405463450d094447e79a8bd6e670e9796fee84 100644 (file)
@@ -49,7 +49,7 @@ typedef enum {
        SWITCH_NAT_TCP
 } switch_nat_ip_proto_t;
 
-
+SWITCH_DECLARE(const char *) switch_nat_get_type(void);
 
 /*! 
   \brief Initilize the NAT Traversal System
index 7771b0996c79d1d0e8917fdd5dab3f8d34d0a95d..807770ac159d49883cc322637a15cf5b8f4d7695 100644 (file)
@@ -349,7 +349,7 @@ SWITCH_STANDARD_API(timer_test_function)
 
 SWITCH_STANDARD_API(group_call_function)
 {
-       char *domain;
+       char *domain, *dup_domain = NULL;
        char *group_name = NULL;
        char *flags;
        int ok = 0;
@@ -392,7 +392,9 @@ SWITCH_STANDARD_API(group_call_function)
        if (domain) {
                *domain++ = '\0';
        } else {
-               domain = switch_core_get_variable("domain");
+               if ((dup_domain = switch_core_get_variable_dup("domain"))) {
+                       domain = dup_domain;
+               }
        }
 
        if (!zstr(domain)) {
@@ -544,13 +546,14 @@ SWITCH_STANDARD_API(group_call_function)
        }
 
   end:
-
+       
        switch_safe_free(group_name);
+       switch_safe_free(dup_domain);
 
        if (!ok) {
                stream->write_function(stream, "error/NO_ROUTE_DESTINATION");
        }
-
+       
        return SWITCH_STATUS_SUCCESS;
 }
 
@@ -559,7 +562,7 @@ SWITCH_STANDARD_API(in_group_function)
 {
        switch_xml_t x_domain, xml = NULL, x_user = NULL, x_group;
        int argc;
-       char *mydata = NULL, *argv[2], *user, *domain;
+       char *mydata = NULL, *argv[2], *user, *domain, *dup_domain = NULL;
        char delim = ',';
        switch_event_t *params = NULL;
        const char *rval = "false";
@@ -579,7 +582,9 @@ SWITCH_STANDARD_API(in_group_function)
        if ((domain = strchr(user, '@'))) {
                *domain++ = '\0';
        } else {
-               domain = switch_core_get_variable("domain");
+               if ((dup_domain = switch_core_get_variable_dup("domain"))) {
+                       domain = dup_domain;
+               }
        }
 
        switch_event_create(&params, SWITCH_EVENT_REQUEST_PARAMS);
@@ -601,6 +606,7 @@ SWITCH_STANDARD_API(in_group_function)
 
        switch_xml_free(xml);
        switch_safe_free(mydata);
+       switch_safe_free(dup_domain);
        switch_event_destroy(&params);
 
        return SWITCH_STATUS_SUCCESS;
@@ -610,7 +616,7 @@ SWITCH_STANDARD_API(user_data_function)
 {
        switch_xml_t x_domain, xml = NULL, x_user = NULL, x_group = NULL, x_param, x_params;
        int argc;
-       char *mydata = NULL, *argv[3], *key = NULL, *type = NULL, *user, *domain;
+       char *mydata = NULL, *argv[3], *key = NULL, *type = NULL, *user, *domain, *dup_domain = NULL;
        char delim = ' ';
        const char *container = "params", *elem = "param";
        const char *result = NULL;
@@ -631,7 +637,9 @@ SWITCH_STANDARD_API(user_data_function)
        if ((domain = strchr(user, '@'))) {
                *domain++ = '\0';
        } else {
-               if (!(domain = switch_core_get_variable("domain"))) {
+               if ((dup_domain = switch_core_get_variable("domain"))) {
+                       domain = dup_domain;
+               } else {
                        domain = "cluecon.com";
                }
        }
@@ -694,6 +702,7 @@ SWITCH_STANDARD_API(user_data_function)
        }
        switch_xml_free(xml);
        switch_safe_free(mydata);
+       switch_safe_free(dup_domain);
        switch_event_destroy(&params);
 
        return SWITCH_STATUS_SUCCESS;
@@ -4375,7 +4384,9 @@ SWITCH_STANDARD_API(global_getvar_function)
        if (zstr(cmd)) {
                switch_core_dump_variables(stream);
        } else {
-               stream->write_function(stream, "%s", switch_str_nil(switch_core_get_variable(cmd)));
+               char *var = switch_core_get_variable_dup(cmd);
+               stream->write_function(stream, "%s", switch_str_nil(var));
+               switch_safe_free(var);
        }
        return SWITCH_STATUS_SUCCESS;
 }
index 928a9b854983aefd45bbc214f8a26a2ff48ccff6..4be2a64f61474fc59f8161e65ec42cf0c3fa07d7 100755 (executable)
@@ -2787,7 +2787,7 @@ static switch_call_cause_t group_outgoing_channel(switch_core_session_t *session
        if ((domain = strchr(group, '@'))) {
                *domain++ = '\0';
        } else {
-               domain = switch_core_get_variable("domain");
+               domain = switch_core_get_variable_pdup("domain", switch_core_session_get_pool(session));
        }
 
        if (!domain) {
@@ -2908,7 +2908,7 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
        if ((domain = strchr(user, '@'))) {
                *domain++ = '\0';
        } else {
-               domain = switch_core_get_variable("domain");
+               domain = switch_core_get_variable_pdup("domain", switch_core_session_get_pool(session));
        }
 
        if (!domain) {
@@ -3193,10 +3193,11 @@ static switch_status_t event_chat_send(const char *proto, const char *from, cons
                if (body)
                        switch_event_add_body(event, "%s", body);
                if (to) {
-                       const char *v;
+                       char *v;
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "To", to);
-                       if ((v = switch_core_get_variable(to))) {
+                       if ((v = switch_core_get_variable_dup(to))) {
                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Command", v);
+                               free(v);
                        }
                }
 
@@ -3214,15 +3215,15 @@ static switch_status_t api_chat_send(const char *proto, const char *from, const
                                                                         const char *body, const char *type, const char *hint)
 {
        if (to) {
-               const char *v;
+               char *v = NULL;
                switch_stream_handle_t stream = { 0 };
                char *cmd = NULL, *arg;
 
-               if (!(v = switch_core_get_variable(to))) {
-                       v = to;
+               if (!(v = switch_core_get_variable_dup(to))) {
+                       v = strdup(to);
                }
 
-               cmd = strdup(v);
+               cmd = v;
                switch_assert(cmd);
 
                switch_url_decode(cmd);
index 1e999675b1e0055f605af0c2bc7b7c8c65e1a224..ebf2a9e324520a6f9da71d5bf6d58c2a95c7dc9f 100755 (executable)
@@ -89,7 +89,7 @@ SWITCH_LIMIT_INCR(limit_incr_redis)
        }
        
        /* Get the keys for redis server */
-       uuid_rediskey = switch_core_session_sprintf(session,"%s_%s_%s", switch_core_get_variable("hostname"), realm, resource);
+       uuid_rediskey = switch_core_session_sprintf(session,"%s_%s_%s", switch_core_get_hostname(), realm, resource);
        rediskey = switch_core_session_sprintf(session, "%s_%s", realm, resource);
 
        if ((pvt = switch_channel_get_private(channel, "limit_redis"))) {
@@ -179,7 +179,7 @@ SWITCH_LIMIT_RELEASE(limit_release_redis)
                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Couldn't decrement value corresponding to %s\n", (char *)p_key);
                                switch_goto_status(SWITCH_STATUS_FALSE, end);
                        }
-                       p_uuid_key = switch_core_session_sprintf(session, "%s_%s", switch_core_get_variable("hostname"), (char *)p_key);
+                       p_uuid_key = switch_core_session_sprintf(session, "%s_%s", switch_core_get_hostname(), (char *)p_key);
                        if (credis_decr(redis,p_uuid_key,&uuid_val) != 0) {
                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Couldn't decrement value corresponding to %s\n", p_uuid_key);
                                switch_goto_status(SWITCH_STATUS_FALSE, end);
@@ -193,7 +193,7 @@ SWITCH_LIMIT_RELEASE(limit_release_redis)
        
        } else {        
                rediskey = switch_core_session_sprintf(session, "%s_%s", realm, resource);
-               uuid_rediskey = switch_core_session_sprintf(session, "%s_%s_%s", switch_core_get_variable("hostname"), realm, resource);
+               uuid_rediskey = switch_core_session_sprintf(session, "%s_%s_%s", switch_core_get_hostname(), realm, resource);
                switch_core_hash_delete(pvt->hash, (const char *) rediskey);
 
                if (credis_decr(redis, rediskey, &val) != 0) {
@@ -249,13 +249,13 @@ SWITCH_LIMIT_RESET(limit_reset_redis)
 {
        REDIS redis;
        if (redis_factory(&redis) == SWITCH_STATUS_SUCCESS) {
-               char *rediskey = switch_mprintf("%s_*", switch_core_get_variable("hostname"));
+               char *rediskey = switch_mprintf("%s_*", switch_core_get_hostname());
                int dec = 0, val = 0, keyc;
                char *uuids[2000];
        
                if ((keyc = credis_keys(redis, rediskey, uuids, switch_arraylen(uuids))) > 0) {
                        int i = 0;
-                       int hostnamelen = strlen(switch_core_get_variable("hostname"))+1;
+                       int hostnamelen = strlen(switch_core_get_hostname())+1;
                        
                        for (i = 0; i < keyc && uuids[i]; i++){
                                const char *key = uuids[i] + hostnamelen;
index 76870f75b9e94ee691ffaa6990c13fea2efb7dae..80b011e1890acd1ab84acb6f6704274ac7f6df05 100644 (file)
@@ -2734,6 +2734,7 @@ static switch_status_t voicemail_inject(const char *data, switch_core_session_t
        switch_memory_pool_t *pool = NULL;
        char *forwarded_by = NULL;
        char *read_flags = NORMAL_FLAG_STRING;
+       char *dup_domain = NULL;
        
        if (zstr(data)) {
                status = SWITCH_STATUS_FALSE;
@@ -2781,7 +2782,9 @@ static switch_status_t voicemail_inject(const char *data, switch_core_session_t
        }
 
        if (zstr(domain)) {
-               domain = switch_core_get_variable("domain");
+               if ((dup_domain = switch_core_get_variable_dup("domain"))) {
+                       domain = dup_domain;
+               }
                profile_name = domain;
        }
 
@@ -2915,6 +2918,7 @@ static switch_status_t voicemail_inject(const char *data, switch_core_session_t
   end:
 
        switch_safe_free(dup);
+       switch_safe_free(dup_domain);
 
        return status;
 }
index 5869d14c3ad9767e5208aaf5fc9acc49f497fa8a..43534dadbadc711b9c80c202b988001f5965c89d 100644 (file)
@@ -313,7 +313,7 @@ static switch_call_cause_t sip_outgoing_channel(switch_core_session_t *session,
        if (session) {
                profile = switch_channel_get_variable(switch_core_session_get_channel(session), "sip_profile");
        } else {
-               profile = switch_core_get_variable("sip_profile");
+               profile = switch_core_get_variable_pdup("sip_profile", switch_core_session_get_pool(session));
        }
        if (zstr(profile)) {
                profile = "default";
index 66f62b229503804cbe677f908c2d69880ccb957b..9fb1f39e115ab9d9ad4a2d852d16bdf224b7cf82 100644 (file)
@@ -2049,7 +2049,7 @@ static void set_profile_val(mdl_profile_t *profile, char *var, char *val)
        } else if (!strcasecmp(var, "ext-rtp-ip")) {
                char *ip = globals.guess_ip;
                if (val && !strcasecmp(val, "auto-nat")) {
-                       ip = globals.auto_nat ? switch_core_get_variable("nat_public_addr") : globals.guess_ip;
+                       ip = globals.auto_nat ? switch_core_get_variable_pdup("nat_public_addr", module_pool) : globals.guess_ip;
                } else if (val && !strcasecmp(val, "auto")) {
                        globals.auto_nat = 0;
                        ip = globals.guess_ip;
@@ -2523,7 +2523,7 @@ static switch_status_t load_config(void)
 
        memset(&globals, 0, sizeof(globals));
        globals.running = 1;
-       globals.auto_nat = (switch_core_get_variable("nat_type") ? 1 : 0);
+       globals.auto_nat = (switch_nat_get_type() ? 1 : 0);
 
        switch_find_local_ip(globals.guess_ip, sizeof(globals.guess_ip), NULL, AF_INET);
 
index 1b126eb277257659c45f48c39a3c9b446bf9132e..15009f22865f593cf35e4ac6ea6b7cb20dfe6ccc 100644 (file)
@@ -1625,9 +1625,10 @@ bool Board::KhompPvt::setCollectCall()
     DBG(FUNC, PVT_FMT(_target, "option drop collect call is '%s'") % (Opt::_options._drop_collect_call() ? "yes" : "no"));
 
     // get global filter configuration value
-    tmp_var = switch_core_get_variable("KDropCollectCall");
+    tmp_var = switch_core_get_variable_dup("KDropCollectCall");
     confvalues.push_back(getTriStateValue(tmp_var));
     DBG(FUNC, PVT_FMT(_target, "global KDropCollectCall was '%s'") % (tmp_var ? tmp_var : "(empty)"));
+       switch_safe_free(tmp_var);
 
     try 
     {
index 8bceb3bba570db7863227e8c9a28873667ae070f..c78aac79335f6e2cd61ceac7a5f5c99fa4f0d399 100644 (file)
@@ -3501,7 +3501,7 @@ SWITCH_STANDARD_API(sofia_contact_function)
        }
 
        if (zstr(domain)) {
-               domain = switch_core_get_variable("domain");
+               domain = switch_core_get_variable_pdup("domain", switch_core_session_get_pool(session));
        }
 
        if (!user) goto end;
@@ -4776,7 +4776,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
        mod_sofia_globals.running = 1;
        switch_mutex_unlock(mod_sofia_globals.mutex);
 
-       mod_sofia_globals.auto_nat = (switch_core_get_variable("nat_type") ? 1 : 0);
+       mod_sofia_globals.auto_nat = (switch_nat_get_type() ? 1 : 0);
 
        switch_queue_create(&mod_sofia_globals.presence_queue, SOFIA_QUEUE_SIZE, mod_sofia_globals.pool);
        switch_queue_create(&mod_sofia_globals.mwi_queue, SOFIA_QUEUE_SIZE, mod_sofia_globals.pool);
index 47f94b151a5cc7ddd2f82d876c2017b9f8010671..825d1bf46e1d6a888373ac5bf7b592a7df05ae82 100644 (file)
@@ -1459,7 +1459,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
 
        supported = switch_core_sprintf(profile->pool, "%s%sprecondition, path, replaces", use_100rel ? "100rel, " : "", use_timer ? "timer, " : "");
 
-       if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && switch_core_get_variable("nat_type")) {
+       if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && switch_nat_get_type()) {
                if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_UDP, NULL, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created UDP nat mapping for %s port %d\n", profile->name, profile->sip_port);
                }
@@ -1676,7 +1676,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
                switch_event_fire(&s_event);
        }
 
-       if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && switch_core_get_variable("nat_type")) {
+       if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && switch_nat_get_type()) {
                if (switch_nat_del_mapping(profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted UDP nat mapping for %s port %d\n", profile->name, profile->sip_port);
                }
@@ -3741,9 +3741,9 @@ switch_status_t config_sofia(int reload, char *profile_name)
                                if (!profile->rtpip[0]) {
                                        profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, mod_sofia_globals.guess_ip);
                                }
-
-                               if (switch_core_get_variable("nat_type")) {
-                                       const char *ip = switch_core_get_variable("nat_public_addr");
+                               
+                               if (switch_nat_get_type()) {
+                                       char *ip = switch_core_get_variable_dup("nat_public_addr");
                                        if (ip && !strchr(profile->sipip, ':')) {
                                                if (!profile->extrtpip) {
                                                        profile->extrtpip = switch_core_strdup(profile->pool, ip);
@@ -3754,6 +3754,7 @@ switch_status_t config_sofia(int reload, char *profile_name)
                                                sofia_set_pflag(profile, PFLAG_AUTO_NAT);
                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "NAT detected setting external ip to %s\n", ip);
                                        }
+                                       switch_safe_free(ip);
                                }
 
                                if (profile->nonce_ttl < 60) {
index f3a2c92eb3382e71e6bd52542b3d99fc5cab0268..1462e4ec544bc2520462d720abb3065c4b3669fb 100644 (file)
@@ -2642,7 +2642,7 @@ static int config(void)
                                } else if (!strcmp(var, "debug")) {
                                        globals.debug = atoi(val);
                                } else if (!strcmp(var, "nat-map")) {
-                                       if (switch_true(val) && switch_core_get_variable("nat_type")) {
+                                       if (switch_true(val) && switch_nat_get_type()) {
                                                prefs.nat_map = 1;
                                        }
                                } else if (!strcmp(var, "listen-port")) {
@@ -2795,7 +2795,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
 
        close_socket(&listen_list.sock);
 
-       if (prefs.nat_map && switch_core_get_variable("nat_type")) {
+       if (prefs.nat_map && switch_nat_get_type()) {
                switch_nat_del_mapping(prefs.port, SWITCH_NAT_TCP);
        }
 
index ca86cbdfcf7af59e1530e6ebcb531db6d7d5a6bd..7e36c720aace492b93405c01c4309c64985c487e 100644 (file)
@@ -77,7 +77,7 @@ static int next_file(switch_file_handle_t *handle)
 
 
        if (!prefix) {
-               if (!(prefix = switch_core_get_variable("sound_prefix"))) {
+               if (!(prefix = switch_core_get_variable_pdup("sound_prefix", handle->memory_pool))) {
                        prefix = SWITCH_GLOBAL_dirs.sounds_dir;
                }
        }
index 9eb2636f4a728518d2cdad7c80ae1b367b794b67..1d6ee8d6797e4bce4253b70d314b2fbe9ebc0fb2 100644 (file)
@@ -3378,8 +3378,9 @@ static JSBool js_global_get(JSContext * cx, JSObject * obj, uintN argc, jsval *
 
        if (argc > 0) {
                var_name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
-               val = switch_core_get_variable(var_name);
+               val = switch_core_get_variable_dup(var_name);
                *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, val));
+               free(val);
                return JS_TRUE;
        }
 
index 468190d887a64089156a2e4340b64f55f37c004d..9e61312417689fd86e008f0ee30c0bc845b960ca 100644 (file)
@@ -322,6 +322,7 @@ static abyss_bool http_directory_auth(TSession * r, char *domain_name)
        int at = 0;
        char *dp;
        abyss_bool rval = FALSE;
+       char *dup_domain = NULL;
 
        p = RequestHeaderValue(r, "authorization");
 
@@ -354,7 +355,9 @@ static abyss_bool http_directory_auth(TSession * r, char *domain_name)
                                                if (globals.default_domain) {
                                                        domain_name = globals.default_domain;
                                                } else {
-                                                       domain_name = switch_core_get_variable("domain");
+                                                       if ((dup_domain = switch_core_get_variable_dup("domain"))) {
+                                                               domain_name = dup_domain;
+                                                       }
                                                }
                                        }
                                }
@@ -465,6 +468,7 @@ static abyss_bool http_directory_auth(TSession * r, char *domain_name)
        switch_safe_free(mypass1);
        switch_safe_free(mypass2);
        switch_safe_free(box);
+       switch_safe_free(dup_domain);
 
        return rval;
 }
index 70b18792744c3d4ae55656f39af798d25f473e37..f750496323207078b8c9044bc41a0b53ed752a72 100644 (file)
@@ -672,7 +672,7 @@ SWITCH_DECLARE(const char *) switch_channel_get_hold_music_partner(switch_channe
 
 SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup)
 {
-       const char *v = NULL, *r = NULL;
+       const char *v = NULL, *r = NULL, *vdup = NULL;
        switch_assert(channel != NULL);
 
        switch_mutex_lock(channel->profile_mutex);
@@ -690,13 +690,16 @@ SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *c
                }
 
                if (!cp || !(v = switch_caller_get_field_by_name(cp, varname))) {
-                       v = switch_core_get_variable(varname);
+                       if ((vdup = switch_core_get_variable_pdup(varname, switch_core_session_get_pool(channel->session)))) {
+                               v = vdup;
+                       }
                }
        }
 
-       if (dup) {
-               if (v)
+       if (dup && v != vdup) {
+               if (v) {
                        r = switch_core_session_strdup(channel->session, v);
+               }
        } else {
                r = v;
        }
index 41bbb91ad0ab7ad5b37d885566b873e0a01a5ff7..c5d601b9a2f5c7b2d6b2092eaadd97513ce9d704 100644 (file)
@@ -643,9 +643,9 @@ SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_list_uuid(const char *line
 
        if (!zstr(cursor)) {
                sql = switch_mprintf("select distinct uuid from channels where uuid like '%q%%' and hostname='%q' order by uuid",
-                                                        cursor, switch_core_get_variable("hostname"));
+                                                        cursor, switch_core_get_hostname());
        } else {
-               sql = switch_mprintf("select distinct uuid from channels where hostname='%q' order by uuid", switch_core_get_variable("hostname"));
+               sql = switch_mprintf("select distinct uuid from channels where hostname='%q' order by uuid", switch_core_get_hostname());
        }
 
        switch_cache_db_execute_sql_callback(db, sql, uuid_callback, &h, &errmsg);
@@ -764,7 +764,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
 
        if (h.words == 0) {
                sql = switch_mprintf("select distinct name from interfaces where type='api' and name like '%q%%' and hostname='%q' order by name",
-                                                        buf, switch_core_get_variable("hostname"));
+                                                        buf, switch_core_get_hostname());
        }
 
        if (sql) {
@@ -792,7 +792,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
 
                if (h.words == 0) {
                        stream.write_function(&stream, "select distinct a1 from complete where " "a1 not in (select name from interfaces where hostname='%s') %s ",
-                                                                 switch_core_get_variable("hostname"), argc ? "and" : "");
+                                                                 switch_core_get_hostname(), argc ? "and" : "");
                } else {
                        if (db->type == SCDB_TYPE_CORE_DB) {
                                stream.write_function(&stream, "select distinct a%d,'%q','%q' from complete where ", h.words + 1, switch_str_nil(dup), switch_str_nil(lp));
@@ -821,7 +821,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
                        }
                }
 
-               stream.write_function(&stream, " and hostname='%s' order by a%d", switch_core_get_variable("hostname"), h.words + 1);
+               stream.write_function(&stream, " and hostname='%s' order by a%d", switch_core_get_hostname(), h.words + 1);
                
                switch_cache_db_execute_sql_callback(db, stream.data, comp_callback, &h, &errmsg);
 
@@ -1794,7 +1794,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
                                                }
                                        }
                                }
-                               mystream.write_function(&mystream, " '%s')", switch_core_get_variable("hostname"));
+                               mystream.write_function(&mystream, " '%s')", switch_core_get_hostname());
                                switch_cache_db_persistant_execute(db, mystream.data, 5);
                                status = SWITCH_STATUS_SUCCESS;
                        } else if (!strcasecmp(argv[0], "add")) {
@@ -1810,7 +1810,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
                                                }
                                        }
                                }
-                               mystream.write_function(&mystream, " '%s')", switch_core_get_variable("hostname"));
+                               mystream.write_function(&mystream, " '%s')", switch_core_get_hostname());
 
                                switch_cache_db_persistant_execute(db, mystream.data, 5);
                                status = SWITCH_STATUS_SUCCESS;
@@ -1827,7 +1827,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
                                                        mystream.write_function(&mystream, "a%d = '%w'%w", x + 1, switch_str_nil(argv[x + 1]), x == argc - 2 ? "" : " and ");
                                                }
                                        }
-                                       mystream.write_function(&mystream, " and hostname='%s'", switch_core_get_variable("hostname"));
+                                       mystream.write_function(&mystream, " and hostname='%s'", switch_core_get_hostname());
                                        switch_cache_db_persistant_execute(db, mystream.data, 1);
                                }
                                status = SWITCH_STATUS_SUCCESS;
@@ -1863,38 +1863,38 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string)
                        }
                        
                        if (!strcasecmp(argv[0], "stickyadd") && argc == 3) {
-                               sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_variable("hostname"));
+                               sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_hostname());
                                switch_cache_db_persistant_execute(db, sql, 5);
                                switch_safe_free(sql);
                                if (db->type == SCDB_TYPE_CORE_DB) {
                                        sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%q','%q','%q')",
-                                                                                argv[1], argv[2], switch_core_get_variable("hostname"));
+                                                                                argv[1], argv[2], switch_core_get_hostname());
                                } else {
                                        sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%w','%w','%w')",
-                                                                                argv[1], argv[2], switch_core_get_variable("hostname"));
+                                                                                argv[1], argv[2], switch_core_get_hostname());
                                }
                                switch_cache_db_persistant_execute(db, sql, 5);
                                status = SWITCH_STATUS_SUCCESS;
                        } else if (!strcasecmp(argv[0], "add") && argc == 3) {
-                               sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_variable("hostname"));
+                               sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_hostname());
                                switch_cache_db_persistant_execute(db, sql, 5);
                                switch_safe_free(sql);
                                if (db->type == SCDB_TYPE_CORE_DB) {
                                        sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%q','%q','%q')",
-                                                                                argv[1], argv[2], switch_core_get_variable("hostname"));
+                                                                                argv[1], argv[2], switch_core_get_hostname());
                                } else {
                                        sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%w','%w','%w')",
-                                                                                argv[1], argv[2], switch_core_get_variable("hostname"));
+                                                                                argv[1], argv[2], switch_core_get_hostname());
                                }
                                switch_cache_db_persistant_execute(db, sql, 5);
                                status = SWITCH_STATUS_SUCCESS;
                        } else if (!strcasecmp(argv[0], "del") && argc == 2) {
                                char *what = argv[1];
                                if (!strcasecmp(what, "*")) {
-                                       sql = switch_mprintf("delete from aliases where hostname='%q'", switch_core_get_variable("hostname"));
+                                       sql = switch_mprintf("delete from aliases where hostname='%q'", switch_core_get_hostname());
                                        switch_cache_db_persistant_execute(db, sql, 1);
                                } else {
-                                       sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_variable("hostname"));
+                                       sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_hostname());
                                        switch_cache_db_persistant_execute(db, sql, 5);
                                }
                                status = SWITCH_STATUS_SUCCESS;
index 43fb36d70572d3e38e1687fdf0b7be8bead27fc9..87543050b2d40a751a0fc0bcf3ca9b6bd68fdc61 100644 (file)
@@ -261,6 +261,11 @@ SWITCH_DECLARE(void) switch_core_dump_variables(switch_stream_handle_t *stream)
        switch_mutex_unlock(runtime.global_mutex);
 }
 
+SWITCH_DECLARE(const char *) switch_core_get_hostname(void)
+{
+       return runtime.hostname;
+}
+
 SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname)
 {
        char *val;
@@ -270,6 +275,32 @@ SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname)
        return val;
 }
 
+SWITCH_DECLARE(char *) switch_core_get_variable_dup(const char *varname)
+{
+       char *val = NULL, *v;
+
+       switch_mutex_lock(runtime.global_var_mutex);
+       if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
+               val = strdup(v);
+       }
+       switch_mutex_unlock(runtime.global_var_mutex);
+
+       return val;
+}
+
+SWITCH_DECLARE(char *) switch_core_get_variable_pdup(const char *varname, switch_memory_pool_t *pool)
+{
+       char *val = NULL, *v;
+
+       switch_mutex_lock(runtime.global_var_mutex);
+       if ((v = (char *) switch_event_get_header(runtime.global_vars, varname))) {
+               val = switch_core_strdup(pool, v);
+       }
+       switch_mutex_unlock(runtime.global_var_mutex);
+
+       return val;
+}
+
 static void switch_core_unset_variables(void)
 {
        switch_mutex_lock(runtime.global_var_mutex);
@@ -1202,12 +1233,18 @@ static void switch_core_set_serial(void)
 
 
        if ((fd = open(path, O_RDONLY, 0)) < 0) {
-               char *ip = switch_core_get_variable("local_ip_v4");
+               char *ip = switch_core_get_variable_dup("local_ip_v4");
                uint32_t ipi = 0;
                switch_byte_t *byte;
                int i = 0;
 
-               switch_inet_pton(AF_INET, ip, &ipi);
+               if (ip) {
+                       switch_inet_pton(AF_INET, ip, &ipi);
+                       free(ip);
+                       ip = NULL;
+               }
+
+
                byte = (switch_byte_t *) & ipi;
 
                for (i = 0; i < 8; i += 2) {
@@ -1237,7 +1274,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
        char guess_ip[256];
        int mask = 0;
        struct in_addr in;
-       char hostname[256] = "";
+
 
        if (runtime.runlevel > 0) {
                /* one per customer */
@@ -1310,8 +1347,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
                runtime.console = stdout;
        }
 
-       gethostname(hostname, sizeof(hostname));
-       switch_core_set_variable("hostname", hostname);
+       gethostname(runtime.hostname, sizeof(runtime.hostname));
+       switch_core_set_variable("hostname", runtime.hostname);
 
        switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET);
        switch_core_set_variable("local_ip_v4", guess_ip);
index 19f23546f0fef7ee18b203e39f67a0d0e904c721..fc7d223b5baf3d08c1bf34d606555c3493c4eab8 100644 (file)
@@ -102,7 +102,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
                        }
 
                        if (!spool_path) {
-                               spool_path = switch_core_get_variable(SWITCH_AUDIO_SPOOL_PATH_VARIABLE);
+                               spool_path = switch_core_get_variable_pdup(SWITCH_AUDIO_SPOOL_PATH_VARIABLE, fh->memory_pool);
                        }
 
                        file_path = fh->file_path;
index 2db2a0dd466a5eb39bab082cbc519b3512d470ce..73890a1e4fa4dab02b270d3bf4fea48c1d13b825 100644 (file)
@@ -1134,7 +1134,7 @@ static void core_event_handler(switch_event_t *event)
                                new_sql() = switch_mprintf("insert into tasks values(%q,'%q','%q',%q, '%q')",
                                                                                   id,
                                                                                   switch_event_get_header_nil(event, "task-desc"),
-                                                                                  switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", switch_core_get_variable("hostname")
+                                                                                  switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", switch_core_get_hostname()
                                                                                   );
                        }
                }
@@ -1142,7 +1142,7 @@ static void core_event_handler(switch_event_t *event)
        case SWITCH_EVENT_DEL_SCHEDULE:
        case SWITCH_EVENT_EXE_SCHEDULE:
                new_sql() = switch_mprintf("delete from tasks where task_id=%q and hostname='%q'",
-                                                                  switch_event_get_header_nil(event, "task-id"), switch_core_get_variable("hostname"));
+                                                                  switch_event_get_header_nil(event, "task-id"), switch_core_get_hostname());
                break;
        case SWITCH_EVENT_RE_SCHEDULE:
                {
@@ -1153,7 +1153,7 @@ static void core_event_handler(switch_event_t *event)
                                new_sql() = switch_mprintf("update tasks set task_desc='%q',task_group='%q', task_sql_manager=%q where task_id=%q and hostname='%q'",
                                                                                   switch_event_get_header_nil(event, "task-desc"),
                                                                                   switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", id,
-                                                                                  switch_core_get_variable("hostname"));
+                                                                                  switch_core_get_hostname());
                        }
                }
                break;
@@ -1163,10 +1163,10 @@ static void core_event_handler(switch_event_t *event)
                        
                        if (uuid) {
                                new_sql() = switch_mprintf("delete from channels where uuid='%q' and hostname='%q'",
-                                                                                  uuid, switch_core_get_variable("hostname"));
+                                                                                  uuid, switch_core_get_hostname());
 
                                new_sql() = switch_mprintf("delete from calls where (caller_uuid='%q' or callee_uuid='%q') and hostname='%q'",
-                                                                                  uuid, uuid, switch_core_get_variable("hostname"));
+                                                                                  uuid, uuid, switch_core_get_hostname());
 
                        }
                }
@@ -1178,12 +1178,12 @@ static void core_event_handler(switch_event_t *event)
                                                                           "update calls set callee_uuid='%q' where callee_uuid='%q' and hostname='%q'",
                                                                           switch_event_get_header_nil(event, "unique-id"),
                                                                           switch_event_get_header_nil(event, "old-unique-id"),
-                                                                          switch_core_get_variable("hostname"),
+                                                                          switch_core_get_hostname(),
                                                                           switch_event_get_header_nil(event, "unique-id"),
                                                                           switch_event_get_header_nil(event, "old-unique-id"),
-                                                                          switch_core_get_variable("hostname"),
+                                                                          switch_core_get_hostname(),
                                                                           switch_event_get_header_nil(event, "unique-id"),
-                                                                          switch_event_get_header_nil(event, "old-unique-id"), switch_core_get_variable("hostname")
+                                                                          switch_event_get_header_nil(event, "old-unique-id"), switch_core_get_hostname()
                                                                           );
                        break;
                }
@@ -1198,7 +1198,7 @@ static void core_event_handler(switch_event_t *event)
                                                                   switch_event_get_header_nil(event, "channel-state"),
                                                                   switch_event_get_header_nil(event, "channel-call-state"),
                                                                   switch_event_get_header_nil(event, "caller-dialplan"),
-                                                                  switch_event_get_header_nil(event, "caller-context"), switch_core_get_variable("hostname")
+                                                                  switch_event_get_header_nil(event, "caller-context"), switch_core_get_hostname()
                                                                   );
                break;
        case SWITCH_EVENT_CODEC:
@@ -1211,7 +1211,7 @@ static void core_event_handler(switch_event_t *event)
                         switch_event_get_header_nil(event, "channel-write-codec-name"),
                         switch_event_get_header_nil(event, "channel-write-codec-rate"),
                         switch_event_get_header_nil(event, "channel-write-codec-bit-rate"),
-                        switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+                        switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
                break;
        case SWITCH_EVENT_CHANNEL_HOLD:
        case SWITCH_EVENT_CHANNEL_UNHOLD:
@@ -1223,7 +1223,7 @@ static void core_event_handler(switch_event_t *event)
                                                                   switch_event_get_header_nil(event, "application-data"),
                                                                   switch_event_get_header_nil(event, "channel-presence-id"),
                                                                   switch_event_get_header_nil(event, "channel-presence-data"),
-                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname")
+                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname()
                                                                   );
 
        }
@@ -1238,7 +1238,7 @@ static void core_event_handler(switch_event_t *event)
                                                                                   switch_event_get_header_nil(event, "channel-presence-data"),
                                                                                   switch_event_get_header_nil(event, "channel-call-uuid"),
                                                                                   extra_cols,
-                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
                                free(extra_cols);
                        } else {
                                new_sql() = switch_mprintf("update channels set "
@@ -1246,7 +1246,7 @@ static void core_event_handler(switch_event_t *event)
                                                                                   switch_event_get_header_nil(event, "channel-presence-id"),
                                                                                   switch_event_get_header_nil(event, "channel-presence-data"),
                                                                                   switch_event_get_header_nil(event, "channel-call-uuid"),
-                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
                        }
 
                }
@@ -1281,7 +1281,7 @@ static void core_event_handler(switch_event_t *event)
                                                                                   switch_str_nil(name),
                                                                                   switch_str_nil(number),
                                                                                   switch_event_get_header_nil(event, "direction"),
-                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 
                                name = switch_event_get_header(event, "callee-name");
                                number = switch_event_get_header(event, "callee-number");
@@ -1298,7 +1298,7 @@ static void core_event_handler(switch_event_t *event)
                {
                        new_sql() = switch_mprintf("update channels set callstate='%q' where uuid='%q' and hostname='%q'",
                                                                           switch_event_get_header_nil(event, "channel-call-state"),
-                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 
                }
                break;
@@ -1330,7 +1330,7 @@ static void core_event_handler(switch_event_t *event)
                                                                                           switch_event_get_header_nil(event, "channel-presence-id"),
                                                                                           switch_event_get_header_nil(event, "channel-presence-data"),
                                                                                           extra_cols,
-                                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+                                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
                                        free(extra_cols);
                                } else {
                                        new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',"
@@ -1345,13 +1345,13 @@ static void core_event_handler(switch_event_t *event)
                                                                                           switch_event_get_header_nil(event, "caller-context"),
                                                                                           switch_event_get_header_nil(event, "channel-presence-id"),
                                                                                           switch_event_get_header_nil(event, "channel-presence-data"),
-                                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+                                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
                                }
                                break;
                        default:
                                new_sql() = switch_mprintf("update channels set state='%s' where uuid='%s' and hostname='%q'",
                                                                                   switch_event_get_header_nil(event, "channel-state"),
-                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
                                break;
                        }
 
@@ -1377,7 +1377,7 @@ static void core_event_handler(switch_event_t *event)
 
                        new_sql() = switch_mprintf("update channels set call_uuid='%q' where uuid='%s' and hostname='%q'",
                                                                           switch_event_get_header_nil(event, "channel-call-uuid"),
-                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
+                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_hostname());
 
                        if (runtime.odbc_dbtype == DBTYPE_DEFAULT) {
                                func_name = "function";
@@ -1404,7 +1404,7 @@ static void core_event_handler(switch_event_t *event)
                                                                           callee_cid_num,
                                                                           switch_event_get_header_nil(event, "Other-Leg-destination-number"),
                                                                           switch_event_get_header_nil(event, "Other-Leg-channel-name"),
-                                                                          switch_event_get_header_nil(event, "Other-Leg-unique-id"), switch_core_get_variable("hostname")
+                                                                          switch_event_get_header_nil(event, "Other-Leg-unique-id"), switch_core_get_hostname()
                                                                           );
                }
                break;
@@ -1413,14 +1413,14 @@ static void core_event_handler(switch_event_t *event)
                        char *uuid = switch_event_get_header_nil(event, "caller-unique-id");
 
                        new_sql() = switch_mprintf("delete from calls where (caller_uuid='%q' or callee_uuid='%q') and hostname='%q'",
-                                                                          uuid, uuid, switch_core_get_variable("hostname"));
+                                                                          uuid, uuid, switch_core_get_hostname());
                        break;
                }
        case SWITCH_EVENT_SHUTDOWN:
                new_sql() = switch_mprintf("delete from channels where hostname='%q';"
                                                                   "delete from interfaces where hostname='%q';"
                                                                   "delete from calls where hostname='%q'",
-                                                                  switch_core_get_variable("hostname"), switch_core_get_variable("hostname"), switch_core_get_variable("hostname")
+                                                                  switch_core_get_hostname(), switch_core_get_hostname(), switch_core_get_hostname()
                                                                   );
                break;
        case SWITCH_EVENT_LOG:
@@ -1438,7 +1438,7 @@ static void core_event_handler(switch_event_t *event)
                                        switch_mprintf
                                        ("insert into interfaces (type,name,description,syntax,ikey,filename,hostname) values('%q','%q','%q','%q','%q','%q','%q')", type, name,
                                         switch_str_nil(description), switch_str_nil(syntax), switch_str_nil(key), switch_str_nil(filename),
-                                        switch_core_get_variable("hostname")
+                                        switch_core_get_hostname()
                                         );
                        }
                        break;
@@ -1449,7 +1449,7 @@ static void core_event_handler(switch_event_t *event)
                        const char *name = switch_event_get_header_nil(event, "name");
                        if (!zstr(type) && !zstr(name)) {
                                new_sql() = switch_mprintf("delete from interfaces where type='%q' and name='%q' and hostname='%q'", type, name,
-                                                                                  switch_core_get_variable("hostname"));
+                                                                                  switch_core_get_hostname());
                        }
                        break;
                }
@@ -1461,7 +1461,7 @@ static void core_event_handler(switch_event_t *event)
                                break;
                        }
                        new_sql() = switch_mprintf("update channels set secure='%s' where uuid='%s' and hostname='%q'",
-                                                                          type, switch_event_get_header_nil(event, "caller-unique-id"), switch_core_get_variable("hostname")
+                                                                          type, switch_event_get_header_nil(event, "caller-unique-id"), switch_core_get_hostname()
                                                                           );
                        break;
                }
@@ -1472,12 +1472,12 @@ static void core_event_handler(switch_event_t *event)
                        if (!strcmp("add", op)) {
                                new_sql() = switch_mprintf("insert into nat (port, proto, sticky, hostname) values (%s, %s, %d,'%q')",
                                                                                   switch_event_get_header_nil(event, "port"),
-                                                                                  switch_event_get_header_nil(event, "proto"), sticky, switch_core_get_variable("hostname")
+                                                                                  switch_event_get_header_nil(event, "proto"), sticky, switch_core_get_hostname()
                                                                                   );
                        } else if (!strcmp("del", op)) {
                                new_sql() = switch_mprintf("delete from nat where port=%s and proto=%s and hostname='%q'",
                                                                                   switch_event_get_header_nil(event, "port"),
-                                                                                  switch_event_get_header_nil(event, "proto"), switch_core_get_variable("hostname"));
+                                                                                  switch_event_get_header_nil(event, "proto"), switch_core_get_hostname());
                        } else if (!strcmp("status", op)) {
                                /* call show nat api */
                        } else if (!strcmp("status_response", op)) {
@@ -1664,7 +1664,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
                        char sql[512] = "";
                        char *tables[] = { "channels", "calls", "interfaces", "tasks", NULL };
                        int i;
-                       const char *hostname = switch_core_get_variable("hostname");
+                       const char *hostname = switch_core_get_hostname();
 
                        for (i = 0; tables[i]; i++) {
                                switch_snprintf(sql, sizeof(sql), "delete from %s where hostname='%s'", tables[i], hostname);
index 003fc8229629891c84e53bc5309694782e2cf89e..3e12ea115f31089ffd040027d5b8ec4292121736 100644 (file)
@@ -1673,6 +1673,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
                                        int offset = 0;
                                        int ooffset = 0;
                                        char *ptr;
+                                       char *gvar = NULL;
 
                                        if ((expanded = switch_event_expand_headers(event, (char *) vname)) == vname) {
                                                expanded = NULL;
@@ -1689,7 +1690,9 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
                                        }
 
                                        if (!(sub_val = switch_event_get_header(event, vname))) {
-                                               sub_val = switch_core_get_variable(vname);
+                                               if ((gvar = switch_core_get_variable_dup(vname))) {
+                                                       sub_val = gvar;
+                                               }
                                        }
 
                                        if (offset || ooffset) {
@@ -1710,6 +1713,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
                                                }
                                        }
 
+                                       switch_safe_free(gvar);
                                        switch_safe_free(expanded);
                                } else {
                                        switch_stream_handle_t stream = { 0 };
index 536baeedffb6e4119867d8f1431d0e832083d8a6..85b0247d6d0c39791c4988a876dfbeb8b1eda8b9 100644 (file)
@@ -45,6 +45,7 @@
 
 typedef struct {
        switch_nat_type_t nat_type;
+       char nat_type_str[5];
        struct UPNPUrls urls;
        struct IGDdatas data;
        char *descURL;
@@ -420,6 +421,7 @@ SWITCH_DECLARE(void) switch_nat_init(switch_memory_pool_t *pool)
                switch_core_set_variable("nat_public_addr", nat_globals.pub_addr);
                switch_core_set_variable("nat_private_addr", nat_globals.pvt_addr);
                switch_core_set_variable("nat_type", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp");
+               strncpy(nat_globals.nat_type_str, nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp", sizeof(nat_globals.nat_type_str) - 1);
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "NAT detected type: %s, ExtIP: '%s'\n",
                                                  nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp", nat_globals.pub_addr);
 
@@ -564,6 +566,11 @@ static switch_status_t switch_nat_del_mapping_upnp(switch_port_t port, switch_na
        return status;
 }
 
+SWITCH_DECLARE(const char *) switch_nat_get_type(void)
+{
+       return nat_globals.nat_type_str;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping_internal(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t * external_port,
                                                                                                                                switch_bool_t sticky, switch_bool_t publish)
 {
index 4acadfe2ff1d50e279f5660982d4f1071b07ea66..e8d7558bced8a6feb7e82cd45102b8af261d7f01 100644 (file)
@@ -791,8 +791,8 @@ static void zrtp_logger(int level, const char *data, int len, int offset)
 SWITCH_DECLARE(void) switch_rtp_init(switch_memory_pool_t *pool)
 {
 #ifdef ENABLE_ZRTP
-       const char *zid_string = switch_core_get_variable("switch_serial");
-       const char *zrtp_enabled = switch_core_get_variable("zrtp_enabled");
+       const char *zid_string = switch_core_get_variable_pdup("switch_serial", pool);
+       const char *zrtp_enabled = switch_core_get_variable_pdup("zrtp_enabled", pool);
        zrtp_config_t zrtp_config;
        char zrtp_cache_path[256] = "";
        zrtp_on = zrtp_enabled ? switch_true(zrtp_enabled) : 0;
index 850b07f51ddaf2b3978305ce5ef26d84aefd5f79..eb5ed7f8302434b56191487013390b883b3fb576 100644 (file)
@@ -1154,8 +1154,8 @@ SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int *ma
 {
        switch_status_t status = SWITCH_STATUS_FALSE;
        char *base;
-       const char *force_local_ip_v4 = switch_core_get_variable("force_local_ip_v4");
-       const char *force_local_ip_v6 = switch_core_get_variable("force_local_ip_v6");
+       char *force_local_ip_v4 = switch_core_get_variable_dup("force_local_ip_v4");
+       char *force_local_ip_v6 = switch_core_get_variable_dup("force_local_ip_v6");
 
 #ifdef WIN32
        SOCKET tmp_socket;
@@ -1176,14 +1176,20 @@ SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int *ma
        case AF_INET:
                if (force_local_ip_v4) {
                        switch_copy_string(buf, force_local_ip_v4, len);
+                       switch_safe_free(force_local_ip_v4);
+                       switch_safe_free(force_local_ip_v6);
                        return SWITCH_STATUS_SUCCESS;
                }
        case AF_INET6:
                if (force_local_ip_v6) {
                        switch_copy_string(buf, force_local_ip_v6, len);
+                       switch_safe_free(force_local_ip_v4);
+                       switch_safe_free(force_local_ip_v6);
                        return SWITCH_STATUS_SUCCESS;
                }
        default:
+               switch_safe_free(force_local_ip_v4);
+               switch_safe_free(force_local_ip_v6);
                break;
        }
 
index 964a7694b20e32b4b3fd768a805c1631b64b8b86..4c30d986a6e084fe2eb65f158c3fc43fba57ecfb 100644 (file)
@@ -1208,11 +1208,12 @@ static char *expand_vars(char *buf, char *ebuf, switch_size_t elen, switch_size_
                                var = rp;
                                *e++ = '\0';
                                rp = e;
-                               if ((val = switch_core_get_variable(var))) {
+                               if ((val = switch_core_get_variable_dup(var))) {
                                        char *p;
                                        for (p = val; p && *p && wp <= ep; p++) {
                                                *wp++ = *p;
                                        }
+                                       free(val);
                                }
                                continue;
                        } else if (err) {