fix possible bad pointer in global vars (please test)

This commit is contained in:
Anthony Minessale 2011-02-02 15:43:26 -06:00
parent 89c5f3bf82
commit 4ae8282e6c
26 changed files with 185 additions and 100 deletions

View File

@ -246,6 +246,7 @@ struct switch_runtime {
int sql_buffer_len; int sql_buffer_len;
int max_sql_buffer_len; int max_sql_buffer_len;
switch_dbtype_t odbc_dbtype; switch_dbtype_t odbc_dbtype;
char hostname[256];
}; };
extern struct switch_runtime runtime; extern struct switch_runtime runtime;

View 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 \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(_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 \brief Add a global variable to the core

View File

@ -49,7 +49,7 @@ typedef enum {
SWITCH_NAT_TCP SWITCH_NAT_TCP
} switch_nat_ip_proto_t; } switch_nat_ip_proto_t;
SWITCH_DECLARE(const char *) switch_nat_get_type(void);
/*! /*!
\brief Initilize the NAT Traversal System \brief Initilize the NAT Traversal System

View File

@ -349,7 +349,7 @@ SWITCH_STANDARD_API(timer_test_function)
SWITCH_STANDARD_API(group_call_function) SWITCH_STANDARD_API(group_call_function)
{ {
char *domain; char *domain, *dup_domain = NULL;
char *group_name = NULL; char *group_name = NULL;
char *flags; char *flags;
int ok = 0; int ok = 0;
@ -392,7 +392,9 @@ SWITCH_STANDARD_API(group_call_function)
if (domain) { if (domain) {
*domain++ = '\0'; *domain++ = '\0';
} else { } else {
domain = switch_core_get_variable("domain"); if ((dup_domain = switch_core_get_variable_dup("domain"))) {
domain = dup_domain;
}
} }
if (!zstr(domain)) { if (!zstr(domain)) {
@ -544,13 +546,14 @@ SWITCH_STANDARD_API(group_call_function)
} }
end: end:
switch_safe_free(group_name); switch_safe_free(group_name);
switch_safe_free(dup_domain);
if (!ok) { if (!ok) {
stream->write_function(stream, "error/NO_ROUTE_DESTINATION"); stream->write_function(stream, "error/NO_ROUTE_DESTINATION");
} }
return SWITCH_STATUS_SUCCESS; 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; switch_xml_t x_domain, xml = NULL, x_user = NULL, x_group;
int argc; int argc;
char *mydata = NULL, *argv[2], *user, *domain; char *mydata = NULL, *argv[2], *user, *domain, *dup_domain = NULL;
char delim = ','; char delim = ',';
switch_event_t *params = NULL; switch_event_t *params = NULL;
const char *rval = "false"; const char *rval = "false";
@ -579,7 +582,9 @@ SWITCH_STANDARD_API(in_group_function)
if ((domain = strchr(user, '@'))) { if ((domain = strchr(user, '@'))) {
*domain++ = '\0'; *domain++ = '\0';
} else { } 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); switch_event_create(&params, SWITCH_EVENT_REQUEST_PARAMS);
@ -601,6 +606,7 @@ SWITCH_STANDARD_API(in_group_function)
switch_xml_free(xml); switch_xml_free(xml);
switch_safe_free(mydata); switch_safe_free(mydata);
switch_safe_free(dup_domain);
switch_event_destroy(&params); switch_event_destroy(&params);
return SWITCH_STATUS_SUCCESS; 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; switch_xml_t x_domain, xml = NULL, x_user = NULL, x_group = NULL, x_param, x_params;
int argc; 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 = ' '; char delim = ' ';
const char *container = "params", *elem = "param"; const char *container = "params", *elem = "param";
const char *result = NULL; const char *result = NULL;
@ -631,7 +637,9 @@ SWITCH_STANDARD_API(user_data_function)
if ((domain = strchr(user, '@'))) { if ((domain = strchr(user, '@'))) {
*domain++ = '\0'; *domain++ = '\0';
} else { } else {
if (!(domain = switch_core_get_variable("domain"))) { if ((dup_domain = switch_core_get_variable("domain"))) {
domain = dup_domain;
} else {
domain = "cluecon.com"; domain = "cluecon.com";
} }
} }
@ -694,6 +702,7 @@ SWITCH_STANDARD_API(user_data_function)
} }
switch_xml_free(xml); switch_xml_free(xml);
switch_safe_free(mydata); switch_safe_free(mydata);
switch_safe_free(dup_domain);
switch_event_destroy(&params); switch_event_destroy(&params);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
@ -4375,7 +4384,9 @@ SWITCH_STANDARD_API(global_getvar_function)
if (zstr(cmd)) { if (zstr(cmd)) {
switch_core_dump_variables(stream); switch_core_dump_variables(stream);
} else { } 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; return SWITCH_STATUS_SUCCESS;
} }

View File

@ -2787,7 +2787,7 @@ static switch_call_cause_t group_outgoing_channel(switch_core_session_t *session
if ((domain = strchr(group, '@'))) { if ((domain = strchr(group, '@'))) {
*domain++ = '\0'; *domain++ = '\0';
} else { } else {
domain = switch_core_get_variable("domain"); domain = switch_core_get_variable_pdup("domain", switch_core_session_get_pool(session));
} }
if (!domain) { if (!domain) {
@ -2908,7 +2908,7 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
if ((domain = strchr(user, '@'))) { if ((domain = strchr(user, '@'))) {
*domain++ = '\0'; *domain++ = '\0';
} else { } else {
domain = switch_core_get_variable("domain"); domain = switch_core_get_variable_pdup("domain", switch_core_session_get_pool(session));
} }
if (!domain) { if (!domain) {
@ -3193,10 +3193,11 @@ static switch_status_t event_chat_send(const char *proto, const char *from, cons
if (body) if (body)
switch_event_add_body(event, "%s", body); switch_event_add_body(event, "%s", body);
if (to) { if (to) {
const char *v; char *v;
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "To", to); 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); 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) const char *body, const char *type, const char *hint)
{ {
if (to) { if (to) {
const char *v; char *v = NULL;
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
char *cmd = NULL, *arg; char *cmd = NULL, *arg;
if (!(v = switch_core_get_variable(to))) { if (!(v = switch_core_get_variable_dup(to))) {
v = to; v = strdup(to);
} }
cmd = strdup(v); cmd = v;
switch_assert(cmd); switch_assert(cmd);
switch_url_decode(cmd); switch_url_decode(cmd);

View File

@ -89,7 +89,7 @@ SWITCH_LIMIT_INCR(limit_incr_redis)
} }
/* Get the keys for redis server */ /* 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); rediskey = switch_core_session_sprintf(session, "%s_%s", realm, resource);
if ((pvt = switch_channel_get_private(channel, "limit_redis"))) { 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_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); 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) { 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_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); switch_goto_status(SWITCH_STATUS_FALSE, end);
@ -193,7 +193,7 @@ SWITCH_LIMIT_RELEASE(limit_release_redis)
} else { } else {
rediskey = switch_core_session_sprintf(session, "%s_%s", realm, resource); 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); switch_core_hash_delete(pvt->hash, (const char *) rediskey);
if (credis_decr(redis, rediskey, &val) != 0) { if (credis_decr(redis, rediskey, &val) != 0) {
@ -249,13 +249,13 @@ SWITCH_LIMIT_RESET(limit_reset_redis)
{ {
REDIS redis; REDIS redis;
if (redis_factory(&redis) == SWITCH_STATUS_SUCCESS) { 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; int dec = 0, val = 0, keyc;
char *uuids[2000]; char *uuids[2000];
if ((keyc = credis_keys(redis, rediskey, uuids, switch_arraylen(uuids))) > 0) { if ((keyc = credis_keys(redis, rediskey, uuids, switch_arraylen(uuids))) > 0) {
int i = 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++){ for (i = 0; i < keyc && uuids[i]; i++){
const char *key = uuids[i] + hostnamelen; const char *key = uuids[i] + hostnamelen;

View File

@ -2734,6 +2734,7 @@ static switch_status_t voicemail_inject(const char *data, switch_core_session_t
switch_memory_pool_t *pool = NULL; switch_memory_pool_t *pool = NULL;
char *forwarded_by = NULL; char *forwarded_by = NULL;
char *read_flags = NORMAL_FLAG_STRING; char *read_flags = NORMAL_FLAG_STRING;
char *dup_domain = NULL;
if (zstr(data)) { if (zstr(data)) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
@ -2781,7 +2782,9 @@ static switch_status_t voicemail_inject(const char *data, switch_core_session_t
} }
if (zstr(domain)) { if (zstr(domain)) {
domain = switch_core_get_variable("domain"); if ((dup_domain = switch_core_get_variable_dup("domain"))) {
domain = dup_domain;
}
profile_name = domain; profile_name = domain;
} }
@ -2915,6 +2918,7 @@ static switch_status_t voicemail_inject(const char *data, switch_core_session_t
end: end:
switch_safe_free(dup); switch_safe_free(dup);
switch_safe_free(dup_domain);
return status; return status;
} }

View File

@ -313,7 +313,7 @@ static switch_call_cause_t sip_outgoing_channel(switch_core_session_t *session,
if (session) { if (session) {
profile = switch_channel_get_variable(switch_core_session_get_channel(session), "sip_profile"); profile = switch_channel_get_variable(switch_core_session_get_channel(session), "sip_profile");
} else { } 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)) { if (zstr(profile)) {
profile = "default"; profile = "default";

View 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")) { } else if (!strcasecmp(var, "ext-rtp-ip")) {
char *ip = globals.guess_ip; char *ip = globals.guess_ip;
if (val && !strcasecmp(val, "auto-nat")) { 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")) { } else if (val && !strcasecmp(val, "auto")) {
globals.auto_nat = 0; globals.auto_nat = 0;
ip = globals.guess_ip; ip = globals.guess_ip;
@ -2523,7 +2523,7 @@ static switch_status_t load_config(void)
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
globals.running = 1; 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); switch_find_local_ip(globals.guess_ip, sizeof(globals.guess_ip), NULL, AF_INET);

View 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")); DBG(FUNC, PVT_FMT(_target, "option drop collect call is '%s'") % (Opt::_options._drop_collect_call() ? "yes" : "no"));
// get global filter configuration value // 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)); confvalues.push_back(getTriStateValue(tmp_var));
DBG(FUNC, PVT_FMT(_target, "global KDropCollectCall was '%s'") % (tmp_var ? tmp_var : "(empty)")); DBG(FUNC, PVT_FMT(_target, "global KDropCollectCall was '%s'") % (tmp_var ? tmp_var : "(empty)"));
switch_safe_free(tmp_var);
try try
{ {

View File

@ -3501,7 +3501,7 @@ SWITCH_STANDARD_API(sofia_contact_function)
} }
if (zstr(domain)) { 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; if (!user) goto end;
@ -4776,7 +4776,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
mod_sofia_globals.running = 1; mod_sofia_globals.running = 1;
switch_mutex_unlock(mod_sofia_globals.mutex); 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.presence_queue, SOFIA_QUEUE_SIZE, mod_sofia_globals.pool);
switch_queue_create(&mod_sofia_globals.mwi_queue, SOFIA_QUEUE_SIZE, mod_sofia_globals.pool); switch_queue_create(&mod_sofia_globals.mwi_queue, SOFIA_QUEUE_SIZE, mod_sofia_globals.pool);

View 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, " : ""); 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) { 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); 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); 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) { 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); 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]) { if (!profile->rtpip[0]) {
profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, mod_sofia_globals.guess_ip); profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, mod_sofia_globals.guess_ip);
} }
if (switch_core_get_variable("nat_type")) { if (switch_nat_get_type()) {
const char *ip = switch_core_get_variable("nat_public_addr"); char *ip = switch_core_get_variable_dup("nat_public_addr");
if (ip && !strchr(profile->sipip, ':')) { if (ip && !strchr(profile->sipip, ':')) {
if (!profile->extrtpip) { if (!profile->extrtpip) {
profile->extrtpip = switch_core_strdup(profile->pool, ip); 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); 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_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) { if (profile->nonce_ttl < 60) {

View File

@ -2642,7 +2642,7 @@ static int config(void)
} else if (!strcmp(var, "debug")) { } else if (!strcmp(var, "debug")) {
globals.debug = atoi(val); globals.debug = atoi(val);
} else if (!strcmp(var, "nat-map")) { } 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; prefs.nat_map = 1;
} }
} else if (!strcmp(var, "listen-port")) { } else if (!strcmp(var, "listen-port")) {
@ -2795,7 +2795,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
close_socket(&listen_list.sock); 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); switch_nat_del_mapping(prefs.port, SWITCH_NAT_TCP);
} }

View File

@ -77,7 +77,7 @@ static int next_file(switch_file_handle_t *handle)
if (!prefix) { 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; prefix = SWITCH_GLOBAL_dirs.sounds_dir;
} }
} }

View File

@ -3378,8 +3378,9 @@ static JSBool js_global_get(JSContext * cx, JSObject * obj, uintN argc, jsval *
if (argc > 0) { if (argc > 0) {
var_name = JS_GetStringBytes(JS_ValueToString(cx, argv[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)); *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, val));
free(val);
return JS_TRUE; return JS_TRUE;
} }

View File

@ -322,6 +322,7 @@ static abyss_bool http_directory_auth(TSession * r, char *domain_name)
int at = 0; int at = 0;
char *dp; char *dp;
abyss_bool rval = FALSE; abyss_bool rval = FALSE;
char *dup_domain = NULL;
p = RequestHeaderValue(r, "authorization"); p = RequestHeaderValue(r, "authorization");
@ -354,7 +355,9 @@ static abyss_bool http_directory_auth(TSession * r, char *domain_name)
if (globals.default_domain) { if (globals.default_domain) {
domain_name = globals.default_domain; domain_name = globals.default_domain;
} else { } 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(mypass1);
switch_safe_free(mypass2); switch_safe_free(mypass2);
switch_safe_free(box); switch_safe_free(box);
switch_safe_free(dup_domain);
return rval; return rval;
} }

View 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) 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_assert(channel != NULL);
switch_mutex_lock(channel->profile_mutex); 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))) { 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 (dup && v != vdup) {
if (v) if (v) {
r = switch_core_session_strdup(channel->session, v); r = switch_core_session_strdup(channel->session, v);
}
} else { } else {
r = v; r = v;
} }

View File

@ -643,9 +643,9 @@ SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_list_uuid(const char *line
if (!zstr(cursor)) { if (!zstr(cursor)) {
sql = switch_mprintf("select distinct uuid from channels where uuid like '%q%%' and hostname='%q' order by uuid", 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 { } 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); 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) { 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", 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) { if (sql) {
@ -792,7 +792,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
if (h.words == 0) { 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 ", 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 { } else {
if (db->type == SCDB_TYPE_CORE_DB) { 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)); 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); 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); switch_cache_db_persistant_execute(db, mystream.data, 5);
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} else if (!strcasecmp(argv[0], "add")) { } 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); switch_cache_db_persistant_execute(db, mystream.data, 5);
status = SWITCH_STATUS_SUCCESS; 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, "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); switch_cache_db_persistant_execute(db, mystream.data, 1);
} }
status = SWITCH_STATUS_SUCCESS; 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) { 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_cache_db_persistant_execute(db, sql, 5);
switch_safe_free(sql); switch_safe_free(sql);
if (db->type == SCDB_TYPE_CORE_DB) { if (db->type == SCDB_TYPE_CORE_DB) {
sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%q','%q','%q')", 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 { } else {
sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%w','%w','%w')", 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); switch_cache_db_persistant_execute(db, sql, 5);
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} else if (!strcasecmp(argv[0], "add") && argc == 3) { } 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_cache_db_persistant_execute(db, sql, 5);
switch_safe_free(sql); switch_safe_free(sql);
if (db->type == SCDB_TYPE_CORE_DB) { if (db->type == SCDB_TYPE_CORE_DB) {
sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%q','%q','%q')", 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 { } else {
sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%w','%w','%w')", 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); switch_cache_db_persistant_execute(db, sql, 5);
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} else if (!strcasecmp(argv[0], "del") && argc == 2) { } else if (!strcasecmp(argv[0], "del") && argc == 2) {
char *what = argv[1]; char *what = argv[1];
if (!strcasecmp(what, "*")) { 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); switch_cache_db_persistant_execute(db, sql, 1);
} else { } 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); switch_cache_db_persistant_execute(db, sql, 5);
} }
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;

View File

@ -261,6 +261,11 @@ SWITCH_DECLARE(void) switch_core_dump_variables(switch_stream_handle_t *stream)
switch_mutex_unlock(runtime.global_mutex); 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) SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname)
{ {
char *val; char *val;
@ -270,6 +275,32 @@ SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname)
return val; 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) static void switch_core_unset_variables(void)
{ {
switch_mutex_lock(runtime.global_var_mutex); 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) { 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; uint32_t ipi = 0;
switch_byte_t *byte; switch_byte_t *byte;
int i = 0; 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; byte = (switch_byte_t *) & ipi;
for (i = 0; i < 8; i += 2) { 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]; char guess_ip[256];
int mask = 0; int mask = 0;
struct in_addr in; struct in_addr in;
char hostname[256] = "";
if (runtime.runlevel > 0) { if (runtime.runlevel > 0) {
/* one per customer */ /* one per customer */
@ -1310,8 +1347,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
runtime.console = stdout; runtime.console = stdout;
} }
gethostname(hostname, sizeof(hostname)); gethostname(runtime.hostname, sizeof(runtime.hostname));
switch_core_set_variable("hostname", hostname); switch_core_set_variable("hostname", runtime.hostname);
switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET); switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET);
switch_core_set_variable("local_ip_v4", guess_ip); switch_core_set_variable("local_ip_v4", guess_ip);

View File

@ -102,7 +102,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
} }
if (!spool_path) { 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; file_path = fh->file_path;

View 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')", new_sql() = switch_mprintf("insert into tasks values(%q,'%q','%q',%q, '%q')",
id, id,
switch_event_get_header_nil(event, "task-desc"), 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_DEL_SCHEDULE:
case SWITCH_EVENT_EXE_SCHEDULE: case SWITCH_EVENT_EXE_SCHEDULE:
new_sql() = switch_mprintf("delete from tasks where task_id=%q and hostname='%q'", 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; break;
case SWITCH_EVENT_RE_SCHEDULE: 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'", 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-desc"),
switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", id, switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", id,
switch_core_get_variable("hostname")); switch_core_get_hostname());
} }
} }
break; break;
@ -1163,10 +1163,10 @@ static void core_event_handler(switch_event_t *event)
if (uuid) { if (uuid) {
new_sql() = switch_mprintf("delete from channels where uuid='%q' and hostname='%q'", 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'", 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'", "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, "unique-id"),
switch_event_get_header_nil(event, "old-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, "unique-id"),
switch_event_get_header_nil(event, "old-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, "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; 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-state"),
switch_event_get_header_nil(event, "channel-call-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-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; break;
case SWITCH_EVENT_CODEC: 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-name"),
switch_event_get_header_nil(event, "channel-write-codec-rate"), 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, "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; break;
case SWITCH_EVENT_CHANNEL_HOLD: case SWITCH_EVENT_CHANNEL_HOLD:
case SWITCH_EVENT_CHANNEL_UNHOLD: 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, "application-data"),
switch_event_get_header_nil(event, "channel-presence-id"), 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-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-presence-data"),
switch_event_get_header_nil(event, "channel-call-uuid"), switch_event_get_header_nil(event, "channel-call-uuid"),
extra_cols, 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); free(extra_cols);
} else { } else {
new_sql() = switch_mprintf("update channels set " 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-id"),
switch_event_get_header_nil(event, "channel-presence-data"), switch_event_get_header_nil(event, "channel-presence-data"),
switch_event_get_header_nil(event, "channel-call-uuid"), 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(name),
switch_str_nil(number), switch_str_nil(number),
switch_event_get_header_nil(event, "direction"), 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"); name = switch_event_get_header(event, "callee-name");
number = switch_event_get_header(event, "callee-number"); 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'", 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, "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; 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-id"),
switch_event_get_header_nil(event, "channel-presence-data"), switch_event_get_header_nil(event, "channel-presence-data"),
extra_cols, 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); free(extra_cols);
} else { } else {
new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q'," 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, "caller-context"),
switch_event_get_header_nil(event, "channel-presence-id"), 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-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; break;
default: default:
new_sql() = switch_mprintf("update channels set state='%s' where uuid='%s' and hostname='%q'", 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, "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; 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'", 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, "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) { if (runtime.odbc_dbtype == DBTYPE_DEFAULT) {
func_name = "function"; func_name = "function";
@ -1404,7 +1404,7 @@ static void core_event_handler(switch_event_t *event)
callee_cid_num, callee_cid_num,
switch_event_get_header_nil(event, "Other-Leg-destination-number"), 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-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; 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"); 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'", 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; break;
} }
case SWITCH_EVENT_SHUTDOWN: case SWITCH_EVENT_SHUTDOWN:
new_sql() = switch_mprintf("delete from channels where hostname='%q';" new_sql() = switch_mprintf("delete from channels where hostname='%q';"
"delete from interfaces where hostname='%q';" "delete from interfaces where hostname='%q';"
"delete from calls 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; break;
case SWITCH_EVENT_LOG: case SWITCH_EVENT_LOG:
@ -1438,7 +1438,7 @@ static void core_event_handler(switch_event_t *event)
switch_mprintf switch_mprintf
("insert into interfaces (type,name,description,syntax,ikey,filename,hostname) values('%q','%q','%q','%q','%q','%q','%q')", type, name, ("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_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; break;
@ -1449,7 +1449,7 @@ static void core_event_handler(switch_event_t *event)
const char *name = switch_event_get_header_nil(event, "name"); const char *name = switch_event_get_header_nil(event, "name");
if (!zstr(type) && !zstr(name)) { if (!zstr(type) && !zstr(name)) {
new_sql() = switch_mprintf("delete from interfaces where type='%q' and name='%q' and hostname='%q'", type, 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; break;
} }
@ -1461,7 +1461,7 @@ static void core_event_handler(switch_event_t *event)
break; break;
} }
new_sql() = switch_mprintf("update channels set secure='%s' where uuid='%s' and hostname='%q'", 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; break;
} }
@ -1472,12 +1472,12 @@ static void core_event_handler(switch_event_t *event)
if (!strcmp("add", op)) { if (!strcmp("add", op)) {
new_sql() = switch_mprintf("insert into nat (port, proto, sticky, hostname) values (%s, %s, %d,'%q')", 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, "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)) { } else if (!strcmp("del", op)) {
new_sql() = switch_mprintf("delete from nat where port=%s and proto=%s and hostname='%q'", 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, "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)) { } else if (!strcmp("status", op)) {
/* call show nat api */ /* call show nat api */
} else if (!strcmp("status_response", op)) { } 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 sql[512] = "";
char *tables[] = { "channels", "calls", "interfaces", "tasks", NULL }; char *tables[] = { "channels", "calls", "interfaces", "tasks", NULL };
int i; int i;
const char *hostname = switch_core_get_variable("hostname"); const char *hostname = switch_core_get_hostname();
for (i = 0; tables[i]; i++) { for (i = 0; tables[i]; i++) {
switch_snprintf(sql, sizeof(sql), "delete from %s where hostname='%s'", tables[i], hostname); switch_snprintf(sql, sizeof(sql), "delete from %s where hostname='%s'", tables[i], hostname);

View File

@ -1673,6 +1673,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
int offset = 0; int offset = 0;
int ooffset = 0; int ooffset = 0;
char *ptr; char *ptr;
char *gvar = NULL;
if ((expanded = switch_event_expand_headers(event, (char *) vname)) == vname) { if ((expanded = switch_event_expand_headers(event, (char *) vname)) == vname) {
expanded = NULL; 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))) { 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) { 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); switch_safe_free(expanded);
} else { } else {
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };

View File

@ -45,6 +45,7 @@
typedef struct { typedef struct {
switch_nat_type_t nat_type; switch_nat_type_t nat_type;
char nat_type_str[5];
struct UPNPUrls urls; struct UPNPUrls urls;
struct IGDdatas data; struct IGDdatas data;
char *descURL; 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_public_addr", nat_globals.pub_addr);
switch_core_set_variable("nat_private_addr", nat_globals.pvt_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"); 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", 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); 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; 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_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) switch_bool_t sticky, switch_bool_t publish)
{ {

View 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) SWITCH_DECLARE(void) switch_rtp_init(switch_memory_pool_t *pool)
{ {
#ifdef ENABLE_ZRTP #ifdef ENABLE_ZRTP
const char *zid_string = switch_core_get_variable("switch_serial"); const char *zid_string = switch_core_get_variable_pdup("switch_serial", pool);
const char *zrtp_enabled = switch_core_get_variable("zrtp_enabled"); const char *zrtp_enabled = switch_core_get_variable_pdup("zrtp_enabled", pool);
zrtp_config_t zrtp_config; zrtp_config_t zrtp_config;
char zrtp_cache_path[256] = ""; char zrtp_cache_path[256] = "";
zrtp_on = zrtp_enabled ? switch_true(zrtp_enabled) : 0; zrtp_on = zrtp_enabled ? switch_true(zrtp_enabled) : 0;

View 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; switch_status_t status = SWITCH_STATUS_FALSE;
char *base; char *base;
const char *force_local_ip_v4 = switch_core_get_variable("force_local_ip_v4"); char *force_local_ip_v4 = switch_core_get_variable_dup("force_local_ip_v4");
const char *force_local_ip_v6 = switch_core_get_variable("force_local_ip_v6"); char *force_local_ip_v6 = switch_core_get_variable_dup("force_local_ip_v6");
#ifdef WIN32 #ifdef WIN32
SOCKET tmp_socket; 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: case AF_INET:
if (force_local_ip_v4) { if (force_local_ip_v4) {
switch_copy_string(buf, force_local_ip_v4, len); 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; return SWITCH_STATUS_SUCCESS;
} }
case AF_INET6: case AF_INET6:
if (force_local_ip_v6) { if (force_local_ip_v6) {
switch_copy_string(buf, force_local_ip_v6, len); 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; return SWITCH_STATUS_SUCCESS;
} }
default: default:
switch_safe_free(force_local_ip_v4);
switch_safe_free(force_local_ip_v6);
break; break;
} }

View File

@ -1208,11 +1208,12 @@ static char *expand_vars(char *buf, char *ebuf, switch_size_t elen, switch_size_
var = rp; var = rp;
*e++ = '\0'; *e++ = '\0';
rp = e; rp = e;
if ((val = switch_core_get_variable(var))) { if ((val = switch_core_get_variable_dup(var))) {
char *p; char *p;
for (p = val; p && *p && wp <= ep; p++) { for (p = val; p && *p && wp <= ep; p++) {
*wp++ = *p; *wp++ = *p;
} }
free(val);
} }
continue; continue;
} else if (err) { } else if (err) {