int sql_buffer_len;
int max_sql_buffer_len;
switch_dbtype_t odbc_dbtype;
+ char hostname[256];
};
extern struct switch_runtime runtime;
\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
SWITCH_NAT_TCP
} switch_nat_ip_proto_t;
-
+SWITCH_DECLARE(const char *) switch_nat_get_type(void);
/*!
\brief Initilize the NAT Traversal System
SWITCH_STANDARD_API(group_call_function)
{
- char *domain;
+ char *domain, *dup_domain = NULL;
char *group_name = NULL;
char *flags;
int ok = 0;
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)) {
}
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;
}
{
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";
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(¶ms, SWITCH_EVENT_REQUEST_PARAMS);
switch_xml_free(xml);
switch_safe_free(mydata);
+ switch_safe_free(dup_domain);
switch_event_destroy(¶ms);
return SWITCH_STATUS_SUCCESS;
{
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;
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";
}
}
}
switch_xml_free(xml);
switch_safe_free(mydata);
+ switch_safe_free(dup_domain);
switch_event_destroy(¶ms);
return SWITCH_STATUS_SUCCESS;
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;
}
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) {
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) {
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);
}
}
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);
}
/* 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"))) {
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);
} 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) {
{
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;
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;
}
if (zstr(domain)) {
- domain = switch_core_get_variable("domain");
+ if ((dup_domain = switch_core_get_variable_dup("domain"))) {
+ domain = dup_domain;
+ }
profile_name = domain;
}
end:
switch_safe_free(dup);
+ switch_safe_free(dup_domain);
return status;
}
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";
} 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;
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);
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
{
}
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;
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);
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);
}
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);
}
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);
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) {
} 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")) {
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);
}
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;
}
}
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;
}
int at = 0;
char *dp;
abyss_bool rval = FALSE;
+ char *dup_domain = NULL;
p = RequestHeaderValue(r, "authorization");
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;
+ }
}
}
}
switch_safe_free(mypass1);
switch_safe_free(mypass2);
switch_safe_free(box);
+ switch_safe_free(dup_domain);
return rval;
}
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);
}
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;
}
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);
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) {
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));
}
}
- 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);
}
}
}
- 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")) {
}
}
}
- 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;
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;
}
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;
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;
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);
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) {
char guess_ip[256];
int mask = 0;
struct in_addr in;
- char hostname[256] = "";
+
if (runtime.runlevel > 0) {
/* one per customer */
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);
}
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;
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()
);
}
}
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:
{
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;
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());
}
}
"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;
}
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:
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:
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()
);
}
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 "
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());
}
}
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");
{
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;
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',"
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;
}
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";
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;
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:
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;
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;
}
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;
}
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)) {
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);
int offset = 0;
int ooffset = 0;
char *ptr;
+ char *gvar = NULL;
if ((expanded = switch_event_expand_headers(event, (char *) vname)) == vname) {
expanded = NULL;
}
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) {
}
}
+ switch_safe_free(gvar);
switch_safe_free(expanded);
} else {
switch_stream_handle_t stream = { 0 };
typedef struct {
switch_nat_type_t nat_type;
+ char nat_type_str[5];
struct UPNPUrls urls;
struct IGDdatas data;
char *descURL;
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);
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)
{
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;
{
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;
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;
}
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) {