diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 4fd03d387c..77da217f04 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1355,7 +1355,7 @@ struct switch_network_list; typedef struct switch_network_list switch_network_list_t; -#define SWITCH_API_VERSION 1 +#define SWITCH_API_VERSION 2 #define SWITCH_MODULE_LOAD_ARGS (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) #define SWITCH_MODULE_RUNTIME_ARGS (void) #define SWITCH_MODULE_SHUTDOWN_ARGS (void) @@ -1366,22 +1366,32 @@ typedef switch_status_t (*switch_module_shutdown_t) SWITCH_MODULE_SHUTDOWN_ARGS; #define SWITCH_MODULE_RUNTIME_FUNCTION(name) switch_status_t name SWITCH_MODULE_RUNTIME_ARGS #define SWITCH_MODULE_SHUTDOWN_FUNCTION(name) switch_status_t name SWITCH_MODULE_SHUTDOWN_ARGS +typedef enum { + SMODF_NONE = 0, + SMODF_GLOBAL_SYMBOLS = (1 << 0) +} switch_module_flag_enum_t; +typedef uint32_t switch_module_flag_t; + typedef struct switch_loadable_module_function_table { int switch_api_version; switch_module_load_t load; switch_module_shutdown_t shutdown; switch_module_runtime_t runtime; + switch_module_flag_t flags; } switch_loadable_module_function_table_t; -#define SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime) \ +#define SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, flags) \ static const char modname[] = #name ; \ SWITCH_MOD_DECLARE_DATA switch_loadable_module_function_table_t name##_module_interface = { \ SWITCH_API_VERSION, \ load, \ shutdown, \ - runtime \ + runtime, \ + flags \ } +#define SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime) \ + SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, SMODF_NONE) /* things we don't deserve to know about */ /*! \brief A channel */ diff --git a/src/mod/asr_tts/mod_cepstral/mod_cepstral.c b/src/mod/asr_tts/mod_cepstral/mod_cepstral.c index 5d914a04f1..c91c2746fd 100644 --- a/src/mod/asr_tts/mod_cepstral/mod_cepstral.c +++ b/src/mod/asr_tts/mod_cepstral/mod_cepstral.c @@ -52,7 +52,7 @@ #define SWIFT_FAILED(r) ((void *)(r) < (void *)0) SWITCH_MODULE_LOAD_FUNCTION(mod_cepstral_load); -SWITCH_MODULE_DEFINITION(mod_cepstral, mod_cepstral_load, NULL, NULL); +SWITCH_MODULE_DEFINITION_EX(mod_cepstral, mod_cepstral_load, NULL, NULL, SMODF_GLOBAL_SYMBOLS); static swift_engine *engine; diff --git a/src/mod/languages/mod_lua/mod_lua.cpp b/src/mod/languages/mod_lua/mod_lua.cpp index 04b17f75df..37af26e23a 100644 --- a/src/mod/languages/mod_lua/mod_lua.cpp +++ b/src/mod/languages/mod_lua/mod_lua.cpp @@ -40,8 +40,7 @@ SWITCH_BEGIN_EXTERN_C SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_lua_shutdown); -SWITCH_MODULE_DEFINITION(mod_lua, mod_lua_load, mod_lua_shutdown, NULL); - +SWITCH_MODULE_DEFINITION_EX(mod_lua, mod_lua_load, mod_lua_shutdown, NULL, SMODF_GLOBAL_SYMBOLS); static struct { switch_memory_pool_t *pool; char *xml_handler; diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 42d7bd1cc8..e65e3e6db2 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -691,6 +691,7 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena char *derr = NULL; const char *err = NULL; switch_memory_pool_t *pool; + switch_bool_t load_global = global; switch_assert(path != NULL); @@ -700,11 +701,11 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena struct_name = switch_core_sprintf(pool, "%s_module_interface", filename); #ifdef WIN32 - dso = switch_dso_open("FreeSwitch.dll", global, &derr); + dso = switch_dso_open("FreeSwitch.dll", load_global, &derr); #elif defined (MACOSX) || defined(DARWIN) - dso = switch_dso_open(SWITCH_PREFIX_DIR "/lib/libfreeswitch.dylib", global, &derr); + dso = switch_dso_open(SWITCH_PREFIX_DIR "/lib/libfreeswitch.dylib", load_global, &derr); #else - dso = switch_dso_open(NULL, global, &derr); + dso = switch_dso_open(NULL, load_global, &derr); #endif if (!derr && dso) { interface_struct_handle = switch_dso_data_sym(dso, struct_name, &derr); @@ -713,7 +714,7 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena switch_safe_free(derr) if (!interface_struct_handle) { - dso = switch_dso_open(path, global, &derr); + dso = switch_dso_open(path, load_global, &derr); } while (loading) { @@ -731,6 +732,20 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena break; } + if (interface_struct_handle && interface_struct_handle->switch_api_version != SWITCH_API_VERSION) { + err = "Trying to load an out of date module, please rebuild the module."; + break; + } + + if (!load_global && interface_struct_handle && switch_test_flag(interface_struct_handle, SMODF_GLOBAL_SYMBOLS)) { + load_global = SWITCH_TRUE; + switch_dso_destroy(&dso); + interface_struct_handle = NULL; + dso = switch_dso_open(path, load_global, &derr); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading module with global namespace at request of module\n"); + continue; + } + if (interface_struct_handle) { mod_interface_functions = interface_struct_handle; load_func_ptr = mod_interface_functions->load;