diff --git a/Makefile.am b/Makefile.am index c875c841a0..fc54f24fb4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -88,14 +88,6 @@ CORE_INCLUDES += -I$(PWD)/libs/libteletone/src CORE_CFLAGS = $(shell $(APR_CONFIG) --cflags --cppflags --includes) CORE_CFLAGS += $(shell $(APU_CONFIG) --includes) -CORE_CFLAGS += -DSWITCH_MOD_DIR=\"$(PREFIX)/mod\" -CORE_CFLAGS += -DSWITCH_PREFIX_DIR=\"$(PREFIX)\" -CORE_CFLAGS += -DSWITCH_CONF_DIR=\"$(PREFIX)/conf\" -CORE_CFLAGS += -DSWITCH_DB_DIR=\"$(PREFIX)/db\" -CORE_CFLAGS += -DSWITCH_LOG_DIR=\"$(PREFIX)/log\" -CORE_CFLAGS += -DSWITCH_SCRIPT_DIR=\"$(PREFIX)/scripts\" -CORE_CFLAGS += -DSWITCH_HTDOCS_DIR=\"$(PREFIX)/htdocs\" -CORE_CFLAGS += -DSWITCH_GRAMMAR_DIR=\"$(PREFIX)/grammar\" CORE_LDFLAGS = $(shell $(APR_CONFIG) --link-ld --libs ) CORE_LDFLAGS += $(shell $(APU_CONFIG) --link-ld --libs ) diff --git a/src/include/switch_am_config.h.in b/src/include/switch_am_config.h.in index aa2c7ff399..9659c5c597 100644 --- a/src/include/switch_am_config.h.in +++ b/src/include/switch_am_config.h.in @@ -9,6 +9,7 @@ #define SWITCH_SSIZE_T @ssize_t_value@ #define SWITCH_SIZEOF_VOIDP @voidp_size@ +#define SWITCH_PREFIX_DIR @prefix@ @ssize_t_fmt@ @size_t_fmt@ diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 4d5e2c4047..12b71ee494 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -98,7 +98,6 @@ SWITCH_BEGIN_EXTERN_C #define SWITCH_SEQ_CLEARLINEEND SWITCH_SEQ_ESC SWITCH_SEQ_CLEARLINEEND_CHAR #define SWITCH_SEQ_CLEARSCR SWITCH_SEQ_ESC SWITCH_SEQ_CLEARSCR_CHAR SWITCH_SEQ_HOME - #ifdef WIN32 #define SWITCH_PATH_SEPARATOR "\\" #else @@ -107,38 +106,6 @@ SWITCH_BEGIN_EXTERN_C #define SWITCH_URL_SEPARATOR "://" -#ifndef SWITCH_PREFIX_DIR -#define SWITCH_PREFIX_DIR "." -#endif - -#ifndef SWITCH_MOD_DIR -#define SWITCH_MOD_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "mod" -#endif - -#ifndef SWITCH_CONF_DIR -#define SWITCH_CONF_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "conf" -#endif - -#ifndef SWITCH_LOG_DIR -#define SWITCH_LOG_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "log" -#endif - -#ifndef SWITCH_DB_DIR -#define SWITCH_DB_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "db" -#endif - -#ifndef SWITCH_SCRIPT_DIR -#define SWITCH_SCRIPT_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "scripts" -#endif - -#ifndef SWITCH_HTDOCS_DIR -#define SWITCH_HTDOCS_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "htdocs" -#endif - -#ifndef SWITCH_GRAMMAR_DIR -#define SWITCH_GRAMMAR_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "grammar" -#endif - #define SWITCH_ENDPOINT_DISPOSITION_VARIABLE "endpoint_disposition" #define SWITCH_EXPORT_VARS_VARIABLE "export_vars" #define SWITCH_R_SDP_VARIABLE "switch_r_sdp" diff --git a/src/switch_core.c b/src/switch_core.c index 7f55ee5e21..a96ef469b3 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -145,7 +145,7 @@ struct switch_core_session { switch_media_bug_t *bugs; }; -SWITCH_DECLARE_DATA switch_directories SWITCH_GLOBAL_dirs; +SWITCH_DECLARE_DATA switch_directories SWITCH_GLOBAL_dirs = {0}; struct switch_core_runtime { switch_time_t initiated; @@ -4230,63 +4230,98 @@ static void core_event_handler(switch_event_t *event) } #endif +#ifndef SWITCH_PREFIX_DIR +#define SWITCH_PREFIX_DIR "." +#endif + SWITCH_DECLARE(void) switch_core_set_globals(void) { -#ifdef WIN32 #define BUFSIZE 1024 +#ifdef WIN32 char lpPathBuffer[BUFSIZE]; DWORD dwBufSize=BUFSIZE; - char exePath[1024]; + char base_dir[1024]; char *lastbacklash; - GetModuleFileName( NULL, exePath, BUFSIZE ); - lastbacklash = strrchr( exePath, '\\'); - exePath[(lastbacklash - exePath + 1)] = '\0'; - if (!SWITCH_GLOBAL_dirs.base_dir && (SWITCH_GLOBAL_dirs.base_dir = (char *) malloc(BUFSIZE))) { - snprintf(SWITCH_GLOBAL_dirs.base_dir, BUFSIZE, "%s", exePath); - } - if (!SWITCH_GLOBAL_dirs.mod_dir && (SWITCH_GLOBAL_dirs.mod_dir = (char *) malloc(BUFSIZE))) { - snprintf(SWITCH_GLOBAL_dirs.mod_dir, BUFSIZE, "%smod", exePath); - } - if (!SWITCH_GLOBAL_dirs.conf_dir && (SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(BUFSIZE))) { - snprintf(SWITCH_GLOBAL_dirs.conf_dir, BUFSIZE, "%sconf", exePath); - } - if (!SWITCH_GLOBAL_dirs.log_dir && (SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(BUFSIZE))) { - snprintf(SWITCH_GLOBAL_dirs.log_dir, BUFSIZE, "%slog", exePath); - } - if (!SWITCH_GLOBAL_dirs.db_dir && (SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(BUFSIZE))) { - snprintf(SWITCH_GLOBAL_dirs.db_dir, BUFSIZE, "%sdb", exePath); - } - if (!SWITCH_GLOBAL_dirs.script_dir && (SWITCH_GLOBAL_dirs.script_dir = (char *) malloc(BUFSIZE))) { - snprintf(SWITCH_GLOBAL_dirs.script_dir, BUFSIZE, "%sscripts", exePath); - } - if (!SWITCH_GLOBAL_dirs.htdocs_dir && (SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(BUFSIZE))) { - snprintf(SWITCH_GLOBAL_dirs.htdocs_dir, BUFSIZE, "%shtdocs", exePath); - } - if (!SWITCH_GLOBAL_dirs.htdocs_dir && (SWITCH_GLOBAL_dirs.grammar_dir = (char *) malloc(BUFSIZE))) { - snprintf(SWITCH_GLOBAL_dirs.grammar_dir, BUFSIZE, "%sgrammar", exePath); - } + GetModuleFileName( NULL, base_dir, BUFSIZE ); + lastbacklash = strrchr( base_dir, '\\'); + base_dir[(lastbacklash - base_dir)] = '\0'; #else - SWITCH_GLOBAL_dirs.base_dir = SWITCH_PREFIX_DIR; - SWITCH_GLOBAL_dirs.mod_dir = SWITCH_MOD_DIR; - if(!SWITCH_GLOBAL_dirs.conf_dir) SWITCH_GLOBAL_dirs.conf_dir = SWITCH_CONF_DIR; - if(!SWITCH_GLOBAL_dirs.log_dir) SWITCH_GLOBAL_dirs.log_dir = SWITCH_LOG_DIR; - if(!SWITCH_GLOBAL_dirs.db_dir) SWITCH_GLOBAL_dirs.db_dir = SWITCH_DB_DIR; - SWITCH_GLOBAL_dirs.script_dir = SWITCH_SCRIPT_DIR; - SWITCH_GLOBAL_dirs.htdocs_dir = SWITCH_HTDOCS_DIR; - SWITCH_GLOBAL_dirs.grammar_dir = SWITCH_GRAMMAR_DIR; + char base_dir[1024] = SWITCH_PREFIX_DIR; #endif + + if (!SWITCH_GLOBAL_dirs.base_dir && (SWITCH_GLOBAL_dirs.base_dir = (char *) malloc(BUFSIZE))) { + switch_snprintf(SWITCH_GLOBAL_dirs.base_dir, BUFSIZE, "%s", base_dir); + } + + if (!SWITCH_GLOBAL_dirs.mod_dir && (SWITCH_GLOBAL_dirs.mod_dir = (char *) malloc(BUFSIZE))) { +#ifdef SWITCH_MOD_DIR + switch_snprintf(SWITCH_GLOBAL_dirs.mod_dir, BUFSIZE, "%s", SWITCH_MOD_DIR); +#else + switch_snprintf(SWITCH_GLOBAL_dirs.mod_dir, BUFSIZE, "%s%smod", base_dir, SWITCH_PATH_SEPARATOR); +#endif + } + + if (!SWITCH_GLOBAL_dirs.conf_dir && (SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(BUFSIZE))) { +#ifdef SWITCH_CONF_DIR + switch_snprintf(SWITCH_GLOBAL_dirs.conf_dir, BUFSIZE, "%s", SWITCH_CONF_DIR); +#else + switch_snprintf(SWITCH_GLOBAL_dirs.conf_dir, BUFSIZE, "%s%sconf", base_dir, SWITCH_PATH_SEPARATOR); +#endif + } + + if (!SWITCH_GLOBAL_dirs.log_dir && (SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(BUFSIZE))) { +#ifdef SWITCH_LOG_DIR + switch_snprintf(SWITCH_GLOBAL_dirs.log_dir, BUFSIZE, "%s", SWITCH_LOG_DIR); +#else + switch_snprintf(SWITCH_GLOBAL_dirs.log_dir, BUFSIZE, "%s%slog", base_dir, SWITCH_PATH_SEPARATOR); +#endif + } + + if (!SWITCH_GLOBAL_dirs.db_dir && (SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(BUFSIZE))) { +#ifdef SWITCH_DB_DIR + switch_snprintf(SWITCH_GLOBAL_dirs.db_dir, BUFSIZE, "%s", SWITCH_DB_DIR); +#else + switch_snprintf(SWITCH_GLOBAL_dirs.db_dir, BUFSIZE, "%s%sdb", base_dir, SWITCH_PATH_SEPARATOR); +#endif + } + + if (!SWITCH_GLOBAL_dirs.script_dir && (SWITCH_GLOBAL_dirs.script_dir = (char *) malloc(BUFSIZE))) { +#ifdef SWITCH_SCRIPT_DIR + switch_snprintf(SWITCH_GLOBAL_dirs.script_dir, BUFSIZE, "%s", SWITCH_SCRIPT_DIR); +#else + switch_snprintf(SWITCH_GLOBAL_dirs.script_dir, BUFSIZE, "%s%sscripts", base_dir, SWITCH_PATH_SEPARATOR); +#endif + } + + if (!SWITCH_GLOBAL_dirs.htdocs_dir && (SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(BUFSIZE))) { +#ifdef SWITCH_HTDOCS_DIR + switch_snprintf(SWITCH_GLOBAL_dirs.htdocs_dir, BUFSIZE, "%s", SWITCH_HTDOCS_DIR); +#else + switch_snprintf(SWITCH_GLOBAL_dirs.htdocs_dir, BUFSIZE, "%s%shtdocs", base_dir, SWITCH_PATH_SEPARATOR); +#endif + } + + if (!SWITCH_GLOBAL_dirs.grammar_dir && (SWITCH_GLOBAL_dirs.grammar_dir = (char *) malloc(BUFSIZE))) { +#ifdef SWITCH_GRAMMAR_DIR + switch_snprintf(SWITCH_GLOBAL_dirs.grammar_dir, BUFSIZE, "%s", SWITCH_GRAMMAR_DIR); +#else + switch_snprintf(SWITCH_GLOBAL_dirs.grammar_dir, BUFSIZE, "%s%sgrammar", base_dir, SWITCH_PATH_SEPARATOR); +#endif + } + + if (!SWITCH_GLOBAL_dirs.temp_dir && (SWITCH_GLOBAL_dirs.temp_dir = (char *) malloc(BUFSIZE))) { #ifdef SWITCH_TEMP_DIR - SWITCH_GLOBAL_dirs.temp_dir = SWITCH_TEMP_DIR; + switch_snprintf(SWITCH_GLOBAL_dirs.temp_dir, BUFSIZE, "%s", SWITCH_TEMP_DIR); #else #ifdef WIN32 - GetTempPath(dwBufSize, lpPathBuffer); - if (!SWITCH_GLOBAL_dirs.temp_dir && (SWITCH_GLOBAL_dirs.temp_dir = (char *) malloc(BUFSIZE))) { - snprintf(SWITCH_GLOBAL_dirs.temp_dir, BUFSIZE, "%s", lpPathBuffer); - } + GetTempPath(dwBufSize, lpPathBuffer); + switch_snprintf(SWITCH_GLOBAL_dirs.temp_dir, BUFSIZE, "%s", lpPathBuffer); #else - SWITCH_GLOBAL_dirs.temp_dir = "/tmp/"; + switch_snprintf(SWITCH_GLOBAL_dirs.temp_dir, BUFSIZE, "%s", "/tmp/"); #endif #endif + } + } @@ -4678,17 +4713,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void) switch_yield(1000000); -#ifdef WIN32 - free(SWITCH_GLOBAL_dirs.base_dir); - free(SWITCH_GLOBAL_dirs.mod_dir); - free(SWITCH_GLOBAL_dirs.conf_dir); - free(SWITCH_GLOBAL_dirs.log_dir); - free(SWITCH_GLOBAL_dirs.db_dir); - free(SWITCH_GLOBAL_dirs.script_dir); - free(SWITCH_GLOBAL_dirs.htdocs_dir); - free(SWITCH_GLOBAL_dirs.grammar_dir); - free(SWITCH_GLOBAL_dirs.temp_dir); -#endif + switch_safe_free(SWITCH_GLOBAL_dirs.base_dir); + switch_safe_free(SWITCH_GLOBAL_dirs.mod_dir); + switch_safe_free(SWITCH_GLOBAL_dirs.conf_dir); + switch_safe_free(SWITCH_GLOBAL_dirs.log_dir); + switch_safe_free(SWITCH_GLOBAL_dirs.db_dir); + switch_safe_free(SWITCH_GLOBAL_dirs.script_dir); + switch_safe_free(SWITCH_GLOBAL_dirs.htdocs_dir); + switch_safe_free(SWITCH_GLOBAL_dirs.grammar_dir); + switch_safe_free(SWITCH_GLOBAL_dirs.temp_dir); if (runtime.memory_pool) { apr_pool_destroy(runtime.memory_pool); diff --git a/w32/Library/FreeSwitchCore.vcproj b/w32/Library/FreeSwitchCore.vcproj index 7ed692f7e2..e25e5243d7 100644 --- a/w32/Library/FreeSwitchCore.vcproj +++ b/w32/Library/FreeSwitchCore.vcproj @@ -403,6 +403,26 @@ + + + + + + + +