diff --git a/src/include/switch_loadable_module.h b/src/include/switch_loadable_module.h index 7d9b2e34bb..fbf5a64ec7 100644 --- a/src/include/switch_loadable_module.h +++ b/src/include/switch_loadable_module.h @@ -187,6 +187,15 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(switch_codec_interf */ SWITCH_DECLARE(switch_status) switch_api_execute(char *cmd, char *arg, char *retbuf, switch_size_t len); + +/*! + \brief Load a module + \param dir the directory where the module resides + \param fname the file name of the module + \return the status +*/ +SWITCH_DECLARE(switch_status) switch_loadable_module_load_module(char *dir, char *fname); + /* Prototypes of module interface functions */ /*! @@ -202,6 +211,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_resume(void); SWITCH_MOD_DECLARE(switch_status) switch_module_status(void); SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void); + /*! \brief Shutdown a module \return SWITCH_STATUS_SUCCESS on a successful shutdown diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 35517097af..e35de19a51 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -34,6 +34,13 @@ static const char modname[] = "mod_commands"; +static switch_status load_function(char *mod, char *out, size_t outlen) +{ + switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod); + snprintf(out, outlen, "OK\n"); + return SWITCH_STATUS_SUCCESS; +} + static switch_status kill_function(char *dest, char *out, size_t outlen) { switch_core_session *session = NULL; @@ -51,11 +58,19 @@ static switch_status kill_function(char *dest, char *out, size_t outlen) } +static struct switch_api_interface load_api_interface = { + /*.interface_name */ "load", + /*.desc */ "Load Modile", + /*.function */ load_function, + /*.next */ NULL +}; + + static struct switch_api_interface commands_api_interface = { /*.interface_name */ "killchan", /*.desc */ "Kill Channel", /*.function */ kill_function, - /*.next */ NULL + /*.next */ &load_api_interface }; diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 95a12c5566..f09be47ec7 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -99,8 +99,7 @@ static void *switch_loadable_module_exec(switch_thread *thread, void *obj) typedef switch_status (*switch_load_fp_t)(switch_loadable_module_interface **, char *); -static switch_status switch_loadable_module_load_file(char *filename, switch_memory_pool *pool, - switch_loadable_module **new_module) +static switch_status switch_loadable_module_load_file(char *filename, switch_loadable_module **new_module) { switch_loadable_module *module = NULL; apr_dso_handle_t *dso = NULL; @@ -116,7 +115,7 @@ static switch_status switch_loadable_module_load_file(char *filename, switch_mem assert(filename != NULL); *new_module = NULL; - status = apr_dso_load(&dso, filename, pool); + status = apr_dso_load(&dso, filename, loadable_modules.pool); while (loading) { if (status != APR_SUCCESS) { @@ -193,7 +192,7 @@ static switch_status switch_loadable_module_load_file(char *filename, switch_mem } -static void process_module_file(char *dir, char *fname) +SWITCH_DECLARE(switch_status) switch_loadable_module_load_module(char *dir, char *fname) { switch_size_t len = 0; char *path; @@ -210,7 +209,7 @@ static void process_module_file(char *dir, char *fname) if ((file = switch_core_strdup(loadable_modules.pool, fname)) == 0) { - return; + return SWITCH_STATUS_FALSE; } if (*file == '/') { @@ -231,7 +230,7 @@ static void process_module_file(char *dir, char *fname) } } - if (switch_loadable_module_load_file(path, loadable_modules.pool, &new_module) == SWITCH_STATUS_SUCCESS) { + if (switch_loadable_module_load_file(path, &new_module) == SWITCH_STATUS_SUCCESS) { switch_core_hash_insert(loadable_modules.module_hash, (char *) file, new_module); if (new_module->interface->endpoint_interface) { @@ -326,6 +325,8 @@ static void process_module_file(char *dir, char *fname) } } } + + return SWITCH_STATUS_SUCCESS; } #ifdef WIN32 @@ -408,7 +409,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init() switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val); continue; } - process_module_file((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) val); + switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) val); } } } @@ -450,7 +451,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init() continue; } - process_module_file((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) fname); + switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) fname); } apr_dir_close(module_dir_handle); }