]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-3277 --resolve There are actually really only 2 places where it needs the real...
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 29 Apr 2011 15:24:50 +0000 (10:24 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 29 Apr 2011 15:24:50 +0000 (10:24 -0500)
18 files changed:
conf/autoload_configs/switch.conf.xml
src/include/private/switch_core_pvt.h
src/include/switch_core.h
src/mod/applications/mod_cidlookup/mod_cidlookup.c
src/mod/applications/mod_commands/mod_commands.c
src/mod/applications/mod_curl/mod_curl.c
src/mod/applications/mod_db/mod_db.c
src/mod/applications/mod_directory/mod_directory.c
src/mod/applications/mod_fifo/mod_fifo.c
src/mod/applications/mod_redis/mod_redis.c
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
src/mod/event_handlers/mod_snmp/subagent.c
src/mod/xml_int/mod_xml_curl/mod_xml_curl.c
src/switch_console.c
src/switch_core.c
src/switch_core_sqldb.c
src/switch_event.c

index d2500a6463146a682f98d9e4f3d3942dddc3a103..3cba428e451aa0e1823ed677d9d3a5087271cfde 100644 (file)
     <!--Colorize the Console -->
     <param name="colorize-console" value="true"/>
 
+    <!--
+    Set the Switch Name for HA environments.
+    When setting the switch name, it will override the system hostname for all DB and CURL requests
+    allowing cluster environments such as RHCS to have identical FreeSWITCH configurations but run
+    as different hostnames.
+    -->
+    <!-- <param name="switchname" value="freeswitch"/>-->
+
     <!-- maximum number of simo db handles open -->
     <param name="max-db-handles" value="50"/>
     <!-- maximum number of seconds to wait for a new db handle before failing -->
index 0ef64d10798a20b983f960d0feacca520ed297ec..23c5272a1f35456f5166edab97d22f4d945cc135 100644 (file)
@@ -248,6 +248,7 @@ struct switch_runtime {
        int max_sql_buffer_len;
        switch_dbtype_t odbc_dbtype;
        char hostname[256];
+       char *switchname;
        int multiple_registrations;
        uint32_t max_db_handles;
        uint32_t db_handle_timeout;
index 5a2b8992b26e8b6fb80243b95d70759768de96a3..88e8152f2aaa0ff801a6772d98a7bda0c2d95922 100644 (file)
@@ -762,6 +762,7 @@ 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);
+SWITCH_DECLARE(const char *) switch_core_get_switchname(void);
 
 /*! 
   \brief Add a global variable to the core
index 06bf615ce5878270a2195e95c768ec963cbb89f3..64e5fc75203b52fff857f320e1ce264aec5431df 100755 (executable)
@@ -366,7 +366,6 @@ static long do_lookup_url(switch_memory_pool_t *pool, switch_event_t *event, cha
        switch_time_t time_diff = 0;
        CURL *curl_handle = NULL;
        long httpRes = 0;
-       char hostname[256] = "";
 
        struct http_data http_data;
 
@@ -375,8 +374,6 @@ static long do_lookup_url(switch_memory_pool_t *pool, switch_event_t *event, cha
        http_data.max_bytes = 10240;
        SWITCH_STANDARD_STREAM(http_data.stream);
 
-       gethostname(hostname, sizeof(hostname));
-
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "url: %s\n", query);
        curl_handle = curl_easy_init();
 
index 96ef58299eaba1fe90456d3e183aeffc69f9d0ca..d7d67223e41f3cd6a610195ce11375b0c31a0db2 100644 (file)
@@ -249,9 +249,13 @@ SWITCH_STANDARD_API(banner_function)
 
 SWITCH_STANDARD_API(hostname_api_function)
 {
-       char hostname[256] = "";
-       gethostname(hostname, sizeof(hostname));
-       stream->write_function(stream, "%s", hostname);
+       stream->write_function(stream, "%s", switch_core_get_hostname());
+       return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_STANDARD_API(switchname_api_function)
+{
+       stream->write_function(stream, "%s", switch_core_get_switchname());
        return SWITCH_STATUS_SUCCESS;
 }
 
@@ -3862,9 +3866,7 @@ SWITCH_STANDARD_API(show_function)
        char *command = NULL, *as = NULL;
        switch_core_flag_t cflags = switch_core_flags();
        switch_status_t status = SWITCH_STATUS_SUCCESS;
-       char hostname[256] = "";
-       gethostname(hostname, sizeof(hostname));
-
+    const char *hostname = switch_core_get_switchname();
 
        if (!(cflags & SCF_USE_SQL)) {
                stream->write_function(stream, "-ERR SQL DISABLED NO DATA AVAILABLE!\n");
@@ -5150,6 +5152,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
        SWITCH_ADD_API(commands_api_interface, "help", "Show help for all the api commands", help_function, "");
        SWITCH_ADD_API(commands_api_interface, "host_lookup", "host_lookup", host_lookup_function, "<hostname>");
        SWITCH_ADD_API(commands_api_interface, "hostname", "Returns the system hostname", hostname_api_function, "");
+       SWITCH_ADD_API(commands_api_interface, "switchname", "Returns the switch name", switchname_api_function, "");
        SWITCH_ADD_API(commands_api_interface, "hupall", "hupall", hupall_api_function, "<cause> [<var> <value>]");
        SWITCH_ADD_API(commands_api_interface, "in_group", "determine if a user is in a group", in_group_function, "<user>[@<domain>] <group_name>");
        SWITCH_ADD_API(commands_api_interface, "is_lan_addr", "see if an ip is a lan addr", lan_addr_function, "<ip>");
index 633e4c80e2d91ca4d0b8e8418888ba7b3b261f2d..adcfe453deacb26e1457653b7a66d910dd2240ac 100644 (file)
@@ -104,7 +104,6 @@ static http_data_t *do_lookup_url(switch_memory_pool_t *pool, const char *url, c
 
        CURL *curl_handle = NULL;
        long httpRes = 0;
-       char hostname[256] = "";
 
        http_data_t *http_data = NULL;
 
@@ -115,8 +114,6 @@ static http_data_t *do_lookup_url(switch_memory_pool_t *pool, const char *url, c
        http_data->max_bytes = 64000;
        SWITCH_STANDARD_STREAM(http_data->stream);
 
-       gethostname(hostname, sizeof(hostname));
-
        if (!method) {
                method = "get";
        }
index e611d036ea6810b7f462be06621404915dd1ebd7..165e02e949b30b34b902fae410d704fa383b197f 100644 (file)
@@ -598,7 +598,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_db_load)
        switch_limit_interface_t *limit_interface;
 
        memset(&globals, 0, sizeof(&globals));
-       gethostname(globals.hostname, sizeof(globals.hostname));
+       strncpy(globals.hostname, switch_core_get_switchname(), sizeof(globals.hostname));
        globals.pool = pool;
 
 
index 01273630648dcf920016ca1ca965e405682fff14..b4c7d94e78c2f29215d7532cec93450484db7443 100644 (file)
@@ -67,7 +67,7 @@ static switch_xml_config_int_options_t config_int_ht_0 = { SWITCH_TRUE, 0 };
 
 static struct {
        switch_hash_t *profile_hash;
-       char hostname[256];
+       const char *hostname;
        int integer;
        int debug;
        char *dbname;
@@ -949,7 +949,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_directory_load)
        /* connect my internal structure to the blank pointer passed to me */
        *module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
-       gethostname(globals.hostname, sizeof(globals.hostname));
+       globals.hostname = switch_core_get_switchname();
 
        globals.dbname = switch_core_sprintf(pool, "directory");
 
index a0a1f9df5688b75b34c34f02bb0cc90f6481b3b7..1984406effe59321f16ccc22b481ba8082fe4bb8 100644 (file)
@@ -3885,7 +3885,7 @@ static switch_status_t load_config(int reload, int del_all)
        switch_cache_db_handle_t *dbh = NULL;
        fifo_node_t *node;
 
-       gethostname(globals.hostname, sizeof(globals.hostname));
+       strncpy(globals.hostname, switch_core_get_switchname(), sizeof(globals.hostname));
 
        if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
index ebf2a9e324520a6f9da71d5bf6d58c2a95c7dc9f..36376dd0694bda31de32da5ec4fa1a511e9488ad 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_hostname(), realm, resource);
+       uuid_rediskey = switch_core_session_sprintf(session,"%s_%s_%s", switch_core_get_switchname(), 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_hostname(), (char *)p_key);
+                       p_uuid_key = switch_core_session_sprintf(session, "%s_%s", switch_core_get_switchname(), (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_hostname(), realm, resource);
+               uuid_rediskey = switch_core_session_sprintf(session, "%s_%s_%s", switch_core_get_switchname(), 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_hostname());
+               char *rediskey = switch_mprintf("%s_*", switch_core_get_switchname());
                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_hostname())+1;
+                       int hostnamelen = strlen(switch_core_get_switchname())+1;
                        
                        for (i = 0; i < keyc && uuids[i]; i++){
                                const char *key = uuids[i] + hostnamelen;
index e18c0ea3c0f51d1456a72eb36eb0a2fcdea32f09..c1431c28e9c3022a04966ecca4aa4833c630fe3e 100644 (file)
@@ -4956,7 +4956,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
        switch_find_local_ip(mod_sofia_globals.guess_ip, sizeof(mod_sofia_globals.guess_ip), &mod_sofia_globals.guess_mask, AF_INET);
        in.s_addr = mod_sofia_globals.guess_mask;
        switch_set_string(mod_sofia_globals.guess_mask_str, inet_ntoa(in));
-       gethostname(mod_sofia_globals.hostname, sizeof(mod_sofia_globals.hostname));
+
+       strcpy(mod_sofia_globals.hostname, switch_core_get_switchname());
 
 
        switch_core_hash_init(&mod_sofia_globals.profile_hash, mod_sofia_globals.pool);
index 5c4d11e807957ba64cce3e2b9ed9a8aac7262d09..2c0b927c0f6428fdf29e89fb786a1a187380ce7e 100644 (file)
@@ -51,7 +51,6 @@ static struct {
        char *address;
        char *bindings;
        uint32_t key_count;
-       char hostname[80];
        switch_port_t port;
        switch_sockaddr_t *addr;
        switch_socket_t *udp_socket;
@@ -282,7 +281,7 @@ static void event_handler(switch_event_t *event)
                case SWITCH_EVENT_LOG:
                        return;
                default:
-                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Multicast-Sender", globals.hostname);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Multicast-Sender", switch_core_get_switchname());
                        if (switch_event_serialize(event, &packet, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
                                size_t len;
                                char *buf;
@@ -377,7 +376,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load)
        switch_core_hash_init(&globals.event_hash, module_pool);
        switch_core_hash_init(&globals.peer_hash, module_pool);
 
-       gethostname(globals.hostname, sizeof(globals.hostname));
        globals.key_count = 0;
 
        if (load_config() != SWITCH_STATUS_SUCCESS) {
index 8d58667687045c3c98ccd16654dfd78ed3975bd3..69f135d6bd190d1ea9a073bfa31845c032996266 100644 (file)
@@ -140,7 +140,7 @@ int channelList_load(netsnmp_cache *cache, void *vmagic)
 
        idx = 1;
 
-       sprintf(sql, "SELECT * FROM channels WHERE hostname='%s' ORDER BY created_epoch", switch_core_get_hostname());
+       sprintf(sql, "SELECT * FROM channels WHERE hostname='%s' ORDER BY created_epoch", switch_core_get_switchname());
        switch_cache_db_execute_sql_callback(dbh, sql, channelList_callback, NULL, NULL);
 
        switch_cache_db_release_db_handle(&dbh);
@@ -237,14 +237,13 @@ int handle_systemStats(netsnmp_mib_handler *handler, netsnmp_handler_registratio
                case SS_CURRENT_CALLS:
                        {
                        switch_cache_db_handle_t *dbh;
-                       char sql[1024] = "", hostname[256] = "";
+                       char sql[1024] = "";
 
                        if (switch_core_db_handle(&dbh) != SWITCH_STATUS_SUCCESS) {
                                return SNMP_ERR_GENERR;
                        }
 
-                       gethostname(hostname, sizeof(hostname));
-                       sprintf(sql, "SELECT COUNT(*) FROM calls WHERE hostname='%s'", hostname);
+                       sprintf(sql, "SELECT COUNT(*) FROM calls WHERE hostname='%s'", switch_core_get_switchname());
                        switch_cache_db_execute_sql_callback(dbh, sql, sql_count_callback, &int_val, NULL);
                        snmp_set_var_typed_integer(requests->requestvb, ASN_GAUGE, int_val);
                        switch_cache_db_release_db_handle(&dbh);
index bc143d7e485625aa1b63a66b2ccc4443412d5dd6..6aa899babb0407d837d10222aa8cff1f2d3e6e58 100644 (file)
@@ -155,7 +155,7 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
        char *uri = NULL;
        char *dynamic_url = NULL;
 
-       gethostname(hostname, sizeof(hostname));
+    strncpy(hostname, switch_core_get_switchname(), sizeof(hostname));
 
        if (!binding) {
                return NULL;
index a73bb58e89836b0b016c6e29f2ad33ed101f94be..d902af69e71675da63abc82d0ea583f7032f1f88 100644 (file)
@@ -443,11 +443,8 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const
        fflush(handle);
 }
 
-static char hostname[256] = "";
 static int32_t running = 1;
 
-
-
 struct helper {
        int len;
        int hits;
@@ -643,9 +640,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_hostname());
+                                                        cursor, switch_core_get_switchname());
        } else {
-               sql = switch_mprintf("select distinct uuid from channels where hostname='%q' order by uuid", switch_core_get_hostname());
+               sql = switch_mprintf("select distinct uuid from channels where hostname='%q' order by uuid", switch_core_get_switchname());
        }
 
        switch_cache_db_execute_sql_callback(db, sql, uuid_callback, &h, &errmsg);
@@ -764,7 +761,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_hostname());
+                                                        buf, switch_core_get_switchname());
        }
 
        if (sql) {
@@ -792,7 +789,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_hostname(), argc ? "and" : "");
+                                                                 switch_core_get_switchname(), argc ? "and" : "");
                } else {
                        if (switch_cache_db_get_type(db) == 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 +818,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_hostname(), h.words + 1);
+               stream.write_function(&stream, " and hostname='%s' order by a%d", switch_core_get_switchname(), h.words + 1);
                
                switch_cache_db_execute_sql_callback(db, stream.data, comp_callback, &h, &errmsg);
 
@@ -1001,7 +998,7 @@ static unsigned char console_f12key(EditLine * el, int ch)
 char *prompt(EditLine * e)
 {
        if (*prompt_str == '\0') {
-               switch_snprintf(prompt_str, sizeof(prompt_str), "freeswitch@%s> ", hostname);
+               switch_snprintf(prompt_str, sizeof(prompt_str), "freeswitch@%s> ", switch_core_get_switchname());
        }
 
        return prompt_str;
@@ -1067,8 +1064,6 @@ SWITCH_DECLARE(void) switch_console_loop(void)
        switch_threadattr_t *thd_attr = NULL;
        switch_memory_pool_t *pool;
 
-       gethostname(hostname, sizeof(hostname));
-
        if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
                return;
@@ -1508,9 +1503,9 @@ SWITCH_DECLARE(void) switch_console_loop(void)
 
        /* Load/Init the config first */
        console_xml_config();
-       gethostname(hostname, sizeof(hostname));
+
 #ifdef _MSC_VER
-       sprintf(cmd, "\nfreeswitch@%s> ", hostname);
+       sprintf(cmd, "\nfreeswitch@%s> ", switch_core_get_switchname());
        console_bufferInput(0, 0, cmd, PROMPT_OP);
        memset(cmd, 0, sizeof(cmd));
 #endif
@@ -1531,7 +1526,7 @@ SWITCH_DECLARE(void) switch_console_loop(void)
                }
 
                if (activity) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "\nfreeswitch@%s> ", hostname);
+                       switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "\nfreeswitch@%s> ", switch_core_get_switchname());
                }
 #ifdef _MSC_VER
                activity = 0;
@@ -1799,7 +1794,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
                                                }
                                        }
                                }
-                               mystream.write_function(&mystream, " '%s')", switch_core_get_hostname());
+                               mystream.write_function(&mystream, " '%s')", switch_core_get_switchname());
                                switch_cache_db_persistant_execute(db, mystream.data, 5);
                                status = SWITCH_STATUS_SUCCESS;
                        } else if (!strcasecmp(argv[0], "add")) {
@@ -1815,7 +1810,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
                                                }
                                        }
                                }
-                               mystream.write_function(&mystream, " '%s')", switch_core_get_hostname());
+                               mystream.write_function(&mystream, " '%s')", switch_core_get_switchname());
 
                                switch_cache_db_persistant_execute(db, mystream.data, 5);
                                status = SWITCH_STATUS_SUCCESS;
@@ -1832,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_hostname());
+                                       mystream.write_function(&mystream, " and hostname='%s'", switch_core_get_switchname());
                                        switch_cache_db_persistant_execute(db, mystream.data, 1);
                                }
                                status = SWITCH_STATUS_SUCCESS;
@@ -1868,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_hostname());
+                               sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_switchname());
                                switch_cache_db_persistant_execute(db, sql, 5);
                                switch_safe_free(sql);
                                if (switch_cache_db_get_type(db) == 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_hostname());
+                                                                                argv[1], argv[2], switch_core_get_switchname());
                                } else {
                                        sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%w','%w','%w')",
-                                                                                argv[1], argv[2], switch_core_get_hostname());
+                                                                                argv[1], argv[2], switch_core_get_switchname());
                                }
                                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_hostname());
+                               sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_switchname());
                                switch_cache_db_persistant_execute(db, sql, 5);
                                switch_safe_free(sql);
                                if (switch_cache_db_get_type(db) == 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_hostname());
+                                                                                argv[1], argv[2], switch_core_get_switchname());
                                } else {
                                        sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%w','%w','%w')",
-                                                                                argv[1], argv[2], switch_core_get_hostname());
+                                                                                argv[1], argv[2], switch_core_get_switchname());
                                }
                                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_hostname());
+                                       sql = switch_mprintf("delete from aliases where hostname='%q'", switch_core_get_switchname());
                                        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_hostname());
+                                       sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_switchname());
                                        switch_cache_db_persistant_execute(db, sql, 5);
                                }
                                status = SWITCH_STATUS_SUCCESS;
index 740b0629b58a3a65c2237cde5ebf2b7cfb5050da..b80ca810eb073d621eee7e758d3086b5d78af9dc 100644 (file)
@@ -265,6 +265,13 @@ SWITCH_DECLARE(const char *) switch_core_get_hostname(void)
        return runtime.hostname;
 }
 
+SWITCH_DECLARE(const char *) switch_core_get_switchname(void)
+{
+    if (!zstr(runtime.switchname)) return runtime.switchname;
+       return runtime.hostname;
+}
+
+
 SWITCH_DECLARE(char *) switch_core_get_variable(const char *varname)
 {
        char *val;
@@ -1716,6 +1723,9 @@ static void switch_load_core_config(const char *file)
                                } else if (!strcasecmp(var, "rtp-enable-zrtp")) {
                                        switch_core_set_variable("zrtp_enabled", val);
 #endif
+                } else if (!strcasecmp(var, "switchname") && !zstr(val)) {
+                                       runtime.switchname = switch_core_strdup(runtime.memory_pool, val);
+                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Set switchname to %s\n", runtime.switchname);
                                }
                        }
                }
index 106c7b0599d99d05eaddc3cd220b1dac93ef34be..686c5d24de7625558a2a5c22ceb4eb10daaa0ab5 100644 (file)
@@ -1141,7 +1141,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_hostname()
+                                                                                  switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", switch_core_get_switchname()
                                                                                   );
                        }
                }
@@ -1149,7 +1149,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_hostname());
+                                                                  switch_event_get_header_nil(event, "task-id"), switch_core_get_switchname());
                break;
        case SWITCH_EVENT_RE_SCHEDULE:
                {
@@ -1160,7 +1160,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_hostname());
+                                                                                  switch_core_get_switchname());
                        }
                }
                break;
@@ -1170,10 +1170,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_hostname());
+                                                                                  uuid, switch_core_get_switchname());
 
                                new_sql() = switch_mprintf("delete from calls where (caller_uuid='%q' or callee_uuid='%q') and hostname='%q'",
-                                                                                  uuid, uuid, switch_core_get_hostname());
+                                                                                  uuid, uuid, switch_core_get_switchname());
 
                        }
                }
@@ -1185,12 +1185,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_hostname(),
+                                                                          switch_core_get_switchname(),
                                                                           switch_event_get_header_nil(event, "unique-id"),
                                                                           switch_event_get_header_nil(event, "old-unique-id"),
-                                                                          switch_core_get_hostname(),
+                                                                          switch_core_get_switchname(),
                                                                           switch_event_get_header_nil(event, "unique-id"),
-                                                                          switch_event_get_header_nil(event, "old-unique-id"), switch_core_get_hostname()
+                                                                          switch_event_get_header_nil(event, "old-unique-id"), switch_core_get_switchname()
                                                                           );
                        break;
                }
@@ -1205,7 +1205,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_hostname()
+                                                                  switch_event_get_header_nil(event, "caller-context"), switch_core_get_switchname()
                                                                   );
                break;
        case SWITCH_EVENT_CODEC:
@@ -1218,7 +1218,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_hostname());
+                        switch_event_get_header_nil(event, "unique-id"), switch_core_get_switchname());
                break;
        case SWITCH_EVENT_CHANNEL_HOLD:
        case SWITCH_EVENT_CHANNEL_UNHOLD:
@@ -1230,7 +1230,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_hostname()
+                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_switchname()
                                                                   );
 
        }
@@ -1245,7 +1245,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_hostname());
+                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_switchname());
                                free(extra_cols);
                        } else {
                                new_sql() = switch_mprintf("update channels set "
@@ -1253,7 +1253,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_hostname());
+                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_switchname());
                        }
 
                }
@@ -1288,7 +1288,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_hostname());
+                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_switchname());
 
                                name = switch_event_get_header(event, "callee-name");
                                number = switch_event_get_header(event, "callee-number");
@@ -1305,7 +1305,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_hostname());
+                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_switchname());
 
                }
                break;
@@ -1337,7 +1337,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_hostname());
+                                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_switchname());
                                        free(extra_cols);
                                } else {
                                        new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',"
@@ -1352,13 +1352,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_hostname());
+                                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_switchname());
                                }
                                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_hostname());
+                                                                                  switch_event_get_header_nil(event, "unique-id"), switch_core_get_switchname());
                                break;
                        }
 
@@ -1384,7 +1384,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_hostname());
+                                                                          switch_event_get_header_nil(event, "unique-id"), switch_core_get_switchname());
 
                        if (runtime.odbc_dbtype == DBTYPE_DEFAULT) {
                                func_name = "function";
@@ -1411,7 +1411,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_hostname()
+                                                                          switch_event_get_header_nil(event, "Other-Leg-unique-id"), switch_core_get_switchname()
                                                                           );
                }
                break;
@@ -1420,14 +1420,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_hostname());
+                                                                          uuid, uuid, switch_core_get_switchname());
                        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_hostname(), switch_core_get_hostname(), switch_core_get_hostname()
+                                                                  switch_core_get_switchname(), switch_core_get_switchname(), switch_core_get_switchname()
                                                                   );
                break;
        case SWITCH_EVENT_LOG:
@@ -1445,7 +1445,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_hostname()
+                                        switch_core_get_switchname()
                                         );
                        }
                        break;
@@ -1456,7 +1456,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_hostname());
+                                                                                  switch_core_get_switchname());
                        }
                        break;
                }
@@ -1468,7 +1468,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_hostname()
+                                                                          type, switch_event_get_header_nil(event, "caller-unique-id"), switch_core_get_switchname()
                                                                           );
                        break;
                }
@@ -1479,12 +1479,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_hostname()
+                                                                                  switch_event_get_header_nil(event, "proto"), sticky, switch_core_get_switchname()
                                                                                   );
                        } 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_hostname());
+                                                                                  switch_event_get_header_nil(event, "proto"), switch_core_get_switchname());
                        } else if (!strcmp("status", op)) {
                                /* call show nat api */
                        } else if (!strcmp("status_response", op)) {
@@ -1650,10 +1650,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, c
 
        if (runtime.multiple_registrations) {
                sql = switch_mprintf("delete from registrations where hostname='%q' and (url='%q' or token='%q')", 
-                                                        switch_core_get_hostname(), url, switch_str_nil(token));
+                                                        switch_core_get_switchname(), url, switch_str_nil(token));
        } else {
                sql = switch_mprintf("delete from registrations where reg_user='%q' and realm='%q' and hostname='%q'", 
-                                                        user, realm, switch_core_get_hostname());
+                                                        user, realm, switch_core_get_switchname());
        }
 
        switch_queue_push(sql_manager.sql_queue[0], sql);
@@ -1668,7 +1668,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, c
                                                 switch_str_nil(network_ip),
                                                 switch_str_nil(network_port),
                                                 switch_str_nil(network_proto),
-                                                switch_core_get_hostname()
+                                                switch_core_get_switchname()
                                                 );
 
        
@@ -1687,9 +1687,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_del_registration(const char *user, c
        }
 
        if (!zstr(token) && runtime.multiple_registrations) {
-               sql = switch_mprintf("delete from registrations where reg_user='%q' and realm='%q' and hostname='%q' and token='%q'", user, realm, switch_core_get_hostname(), token);
+               sql = switch_mprintf("delete from registrations where reg_user='%q' and realm='%q' and hostname='%q' and token='%q'", user, realm, switch_core_get_switchname(), token);
        } else {
-               sql = switch_mprintf("delete from registrations where reg_user='%q' and realm='%q' and hostname='%q'", user, realm, switch_core_get_hostname());
+               sql = switch_mprintf("delete from registrations where reg_user='%q' and realm='%q' and hostname='%q'", user, realm, switch_core_get_switchname());
        }
 
        switch_queue_push(sql_manager.sql_queue[0], sql);
@@ -1710,9 +1710,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_expire_registration(int force)
        now = switch_epoch_time_now(NULL);
 
        if (force) {
-               sql = switch_mprintf("delete from registrations where hostname='%q'", switch_core_get_hostname());
+               sql = switch_mprintf("delete from registrations where hostname='%q'", switch_core_get_switchname());
        } else {
-               sql = switch_mprintf("delete from registrations where expires > 0 and expires <= %ld and hostname='%q'", now, switch_core_get_hostname());
+               sql = switch_mprintf("delete from registrations where expires > 0 and expires <= %ld and hostname='%q'", now, switch_core_get_switchname());
        }
 
        switch_queue_push(sql_manager.sql_queue[0], sql);
@@ -1767,7 +1767,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_hostname();
+                       const char *hostname = switch_core_get_switchname();
 
                        for (i = 0; tables[i]; i++) {
                                switch_snprintf(sql, sizeof(sql), "delete from %s where hostname='%s'", tables[i], hostname);
index 9816834d37ba026f395948546674437022c51098..8c48b61f7c566f22513628d08f6ab8d5889cc994 100644 (file)
@@ -66,7 +66,6 @@ struct switch_event_subclass {
 #define MAX_DISPATCH_VAL 20
 static unsigned int MAX_DISPATCH = MAX_DISPATCH_VAL;
 static unsigned int SOFT_MAX_DISPATCH = 0;
-static char hostname[128] = "";
 static char guess_ip_v4[80] = "";
 static char guess_ip_v6[80] = "";
 static switch_event_node_t *EVENT_NODES[SWITCH_EVENT_ALL + 1] = { NULL };
@@ -647,7 +646,6 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
        switch_mutex_unlock(EVENT_QUEUE_MUTEX);
 
        switch_threadattr_create(&thd_attr, pool);
-       gethostname(hostname, sizeof(hostname));
        switch_find_local_ip(guess_ip_v4, sizeof(guess_ip_v4), NULL, AF_INET);
        switch_find_local_ip(guess_ip_v6, sizeof(guess_ip_v6), NULL, AF_INET6);
 
@@ -1359,7 +1357,8 @@ SWITCH_DECLARE(void) switch_event_prep_for_delivery_detailed(const char *file, c
 
        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Event-Name", switch_event_name(event->event_id));
        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Core-UUID", switch_core_get_uuid());
-       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FreeSWITCH-Hostname", hostname);
+       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FreeSWITCH-Hostname", switch_core_get_hostname());
+       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FreeSWITCH-Switchname", switch_core_get_switchname());
        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FreeSWITCH-IPv4", guess_ip_v4);
        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FreeSWITCH-IPv6", guess_ip_v6);