Make optional modules.conf that allows you to pick the module load order
and to exclude some modules. (see example in trunk/conf) Make ';' a valid comment in config files Interpret a line in config files beginning with "__END__" as eof git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@608 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
0e79051b10
commit
cb463b4e52
|
@ -0,0 +1,43 @@
|
|||
[modules]
|
||||
|
||||
; If this option is the first one the rest of them will be ignored
|
||||
;load => all
|
||||
|
||||
; Event Handlers
|
||||
load => mod_zeroconf.so
|
||||
load => mod_xmpp_event.so
|
||||
|
||||
; Directory Interfaces
|
||||
load => mod_ldap.so
|
||||
|
||||
; Endpoints
|
||||
load => mod_exosip.so
|
||||
load => mod_iax.so
|
||||
load => mod_woomera.so
|
||||
|
||||
; Applications
|
||||
load => mod_bridgecall.so
|
||||
load => mod_ivrtest.so
|
||||
load => mod_playback.so
|
||||
|
||||
; Dialplan Interfaces
|
||||
load => mod_dialplan_demo.so
|
||||
load => mod_dialplan_directory.so
|
||||
load => mod_pcre.so
|
||||
|
||||
; Codec Interfaces
|
||||
load => mod_g711.so
|
||||
load => mod_gsm.so
|
||||
load => mod_l16.so
|
||||
load => mod_speex.so
|
||||
|
||||
; File Format Interfaces
|
||||
load => mod_sndfile.so
|
||||
|
||||
; Timers
|
||||
load => mod_softtimer.so
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -101,10 +101,14 @@ SWITCH_DECLARE(int) switch_config_next_pair(switch_config *cfg, char **var, char
|
|||
continue;
|
||||
}
|
||||
|
||||
if (**var == '#' || **var == '\n' || **var == '\r') {
|
||||
if (**var == '#' || **var == ';' || **var == '\n' || **var == '\r') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strncmp(*var, "__END__", 7)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((end = strchr(*var, '#'))) {
|
||||
*end = '\0';
|
||||
end--;
|
||||
|
|
|
@ -187,69 +187,27 @@ static switch_status switch_loadable_module_load_file(char *filename, switch_mem
|
|||
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status) switch_loadable_module_init()
|
||||
static void process_module_file(char *dir, char *fname)
|
||||
{
|
||||
|
||||
char *file = NULL;
|
||||
size_t len = 0;
|
||||
char *ptr = NULL;
|
||||
apr_finfo_t finfo = {0};
|
||||
apr_dir_t *module_dir_handle = NULL;
|
||||
apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
|
||||
char *path;
|
||||
char *file;
|
||||
switch_loadable_module *new_module = NULL;
|
||||
#ifdef WIN32
|
||||
const char *ext = ".dll";
|
||||
const char *EXT = ".DLL";
|
||||
#else
|
||||
const char *ext = ".so";
|
||||
const char *EXT = ".SO";
|
||||
#endif
|
||||
|
||||
memset(&loadable_modules, 0, sizeof(loadable_modules));
|
||||
switch_core_new_memory_pool(&loadable_modules.pool);
|
||||
|
||||
if (apr_dir_open(&module_dir_handle, SWITCH_MOD_DIR, loadable_modules.pool) != APR_SUCCESS) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open directory: %s\n", SWITCH_MOD_DIR);
|
||||
return SWITCH_STATUS_GENERR;
|
||||
if (!(file = switch_core_strdup(loadable_modules.pool, fname))) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch_core_hash_init(&loadable_modules.module_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.endpoint_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.codec_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.timer_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.application_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.api_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.file_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.speech_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.directory_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.dialplan_hash, loadable_modules.pool);
|
||||
|
||||
while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == APR_SUCCESS) {
|
||||
const char *fname = finfo.fname;
|
||||
|
||||
if (finfo.filetype != APR_REG) {
|
||||
continue;
|
||||
if (*file == '/') {
|
||||
path = switch_core_strdup(loadable_modules.pool, file);
|
||||
} else {
|
||||
len = strlen(dir) + strlen(file) + 3;
|
||||
path = (char *) switch_core_alloc(loadable_modules.pool, len);
|
||||
snprintf(path, len, "%s/%s", dir, file);
|
||||
}
|
||||
|
||||
if (!fname) {
|
||||
fname = finfo.name;
|
||||
}
|
||||
|
||||
if (!(ptr = (char *) fname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strstr(fname, ext) && !strstr(fname, EXT)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
len = strlen(SWITCH_MOD_DIR) + strlen(fname) + 3;
|
||||
file = (char *) switch_core_alloc(loadable_modules.pool, len);
|
||||
snprintf(file, len, "%s/%s", SWITCH_MOD_DIR, fname);
|
||||
|
||||
if (switch_loadable_module_load_file(file, loadable_modules.pool, &new_module) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_core_hash_insert(loadable_modules.module_hash, (char *) fname, new_module);
|
||||
if (switch_loadable_module_load_file(path, loadable_modules.pool, &new_module) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_core_hash_insert(loadable_modules.module_hash, (char *) file, new_module);
|
||||
|
||||
if (new_module->interface->endpoint_interface) {
|
||||
const switch_endpoint_interface *ptr;
|
||||
|
@ -342,11 +300,109 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
|
|||
switch_core_hash_insert(loadable_modules.directory_hash, (char *) ptr->interface_name, (void *) ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status) switch_loadable_module_init()
|
||||
{
|
||||
|
||||
char *ptr = NULL;
|
||||
apr_finfo_t finfo = {0};
|
||||
apr_dir_t *module_dir_handle = NULL;
|
||||
apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
|
||||
char *cf = "modules.conf";
|
||||
char *var, *val;
|
||||
switch_config cfg;
|
||||
unsigned char all = 0;
|
||||
unsigned int count = 0;
|
||||
|
||||
#ifdef WIN32
|
||||
const char *ext = ".dll";
|
||||
const char *EXT = ".DLL";
|
||||
#else
|
||||
const char *ext = ".so";
|
||||
const char *EXT = ".SO";
|
||||
#endif
|
||||
|
||||
memset(&loadable_modules, 0, sizeof(loadable_modules));
|
||||
switch_core_new_memory_pool(&loadable_modules.pool);
|
||||
|
||||
|
||||
switch_core_hash_init(&loadable_modules.module_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.endpoint_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.codec_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.timer_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.application_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.api_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.file_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.speech_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.directory_hash, loadable_modules.pool);
|
||||
switch_core_hash_init(&loadable_modules.dialplan_hash, loadable_modules.pool);
|
||||
|
||||
|
||||
if (switch_config_open_file(&cfg, cf)) {
|
||||
while (switch_config_next_pair(&cfg, &var, &val)) {
|
||||
count++;
|
||||
if (!strcasecmp(cfg.category, "modules")) {
|
||||
if (!strcasecmp(var, "load")) {
|
||||
if (!strcasecmp(val, "all")) {
|
||||
if (count == 1) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Loading all modules.");
|
||||
all = 1;
|
||||
break;
|
||||
} else {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "This option must be the first one to work.");
|
||||
}
|
||||
} else {
|
||||
if (!strstr(val, ext) && !strstr(val, EXT)) {
|
||||
continue;
|
||||
}
|
||||
process_module_file((char *) SWITCH_MOD_DIR, (char *) val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
switch_config_close_file(&cfg);
|
||||
} else {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf);
|
||||
all = 1;
|
||||
}
|
||||
|
||||
if (!count && !all) {
|
||||
all = 1;
|
||||
}
|
||||
|
||||
if (all) {
|
||||
if (apr_dir_open(&module_dir_handle, SWITCH_MOD_DIR, loadable_modules.pool) != APR_SUCCESS) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open directory: %s\n", SWITCH_MOD_DIR);
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (all) {
|
||||
while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == APR_SUCCESS) {
|
||||
const char *fname = finfo.fname;
|
||||
|
||||
if (finfo.filetype != APR_REG) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!fname) {
|
||||
fname = finfo.name;
|
||||
}
|
||||
|
||||
if (!(ptr = (char *) fname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strstr(fname, ext) && !strstr(fname, EXT)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
process_module_file((char *) SWITCH_MOD_DIR, (char *) fname);
|
||||
}
|
||||
apr_dir_close(module_dir_handle);
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue