提交 eec93d87 authored 作者: William King's avatar William King

FS-8971 Resolve globals struct handling. Thanks to Ben Hood for reporting the issue.

上级 a42ab110
...@@ -42,6 +42,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_amqp_shutdown); ...@@ -42,6 +42,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_amqp_shutdown);
SWITCH_MODULE_LOAD_FUNCTION(mod_amqp_load); SWITCH_MODULE_LOAD_FUNCTION(mod_amqp_load);
SWITCH_MODULE_DEFINITION(mod_amqp, mod_amqp_load, mod_amqp_shutdown, NULL); SWITCH_MODULE_DEFINITION(mod_amqp, mod_amqp_load, mod_amqp_shutdown, NULL);
mod_amqp_globals_t mod_amqp_globals;
SWITCH_STANDARD_API(amqp_reload) SWITCH_STANDARD_API(amqp_reload)
{ {
return mod_amqp_do_config(SWITCH_TRUE); return mod_amqp_do_config(SWITCH_TRUE);
...@@ -56,13 +58,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amqp_load) ...@@ -56,13 +58,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amqp_load)
{ {
switch_api_interface_t *api_interface; switch_api_interface_t *api_interface;
memset(&globals, 0, sizeof(globals)); memset(&mod_amqp_globals, 0, sizeof(mod_amqp_globals_t));
*module_interface = switch_loadable_module_create_module_interface(pool, modname); *module_interface = switch_loadable_module_create_module_interface(pool, modname);
globals.pool = pool; mod_amqp_globals.pool = pool;
switch_core_hash_init(&(globals.producer_hash)); switch_core_hash_init(&(mod_amqp_globals.producer_hash));
switch_core_hash_init(&(globals.command_hash)); switch_core_hash_init(&(mod_amqp_globals.command_hash));
switch_core_hash_init(&(globals.logging_hash)); switch_core_hash_init(&(mod_amqp_globals.logging_hash));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "mod_apqp loading: Version %s\n", switch_version_full()); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "mod_apqp loading: Version %s\n", switch_version_full());
...@@ -74,7 +76,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amqp_load) ...@@ -74,7 +76,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amqp_load)
SWITCH_ADD_API(api_interface, "amqp", "amqp API", amqp_reload, "syntax"); SWITCH_ADD_API(api_interface, "amqp", "amqp API", amqp_reload, "syntax");
switch_log_bind_logger(mod_amqp_logging_recv, SWITCH_LOG_DEBUG, SWITCH_FALSE); switch_log_bind_logger(mod_amqp_logging_recv, SWITCH_LOG_DEBUG, SWITCH_FALSE);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -92,19 +94,18 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_amqp_shutdown) ...@@ -92,19 +94,18 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_amqp_shutdown)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Mod starting shutting down\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Mod starting shutting down\n");
switch_event_unbind_callback(mod_amqp_producer_event_handler); switch_event_unbind_callback(mod_amqp_producer_event_handler);
while ((hi = switch_core_hash_first(globals.producer_hash))) { while ((hi = switch_core_hash_first(mod_amqp_globals.producer_hash))) {
switch_core_hash_this(hi, NULL, NULL, (void **)&producer); switch_core_hash_this(hi, NULL, NULL, (void **)&producer);
mod_amqp_producer_destroy(&producer); mod_amqp_producer_destroy(&producer);
} }
while ((hi = switch_core_hash_first(globals.command_hash))) { while ((hi = switch_core_hash_first(mod_amqp_globals.command_hash))) {
switch_core_hash_this(hi, NULL, NULL, (void **)&command); switch_core_hash_this(hi, NULL, NULL, (void **)&command);
mod_amqp_command_destroy(&command); mod_amqp_command_destroy(&command);
} }
switch_log_unbind_logger(mod_amqp_logging_recv); switch_log_unbind_logger(mod_amqp_logging_recv);
while ((hi = switch_core_hash_first(mod_amqp_globals.logging_hash))) {
while ((hi = switch_core_hash_first(globals.logging_hash))) {
switch_core_hash_this(hi, NULL, NULL, (void **)&logging); switch_core_hash_this(hi, NULL, NULL, (void **)&logging);
mod_amqp_logging_destroy(&logging); mod_amqp_logging_destroy(&logging);
} }
......
...@@ -173,13 +173,15 @@ typedef struct { ...@@ -173,13 +173,15 @@ typedef struct {
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
} mod_amqp_logging_profile_t; } mod_amqp_logging_profile_t;
struct { typedef struct mod_amqp_globals_s {
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
switch_hash_t *producer_hash; switch_hash_t *producer_hash;
switch_hash_t *command_hash; switch_hash_t *command_hash;
switch_hash_t *logging_hash; switch_hash_t *logging_hash;
} globals; } mod_amqp_globals_t;
extern mod_amqp_globals_t mod_amqp_globals;
/* utils */ /* utils */
switch_status_t mod_amqp_do_config(switch_bool_t reload); switch_status_t mod_amqp_do_config(switch_bool_t reload);
......
...@@ -53,7 +53,7 @@ switch_status_t mod_amqp_command_destroy(mod_amqp_command_profile_t **prof) ...@@ -53,7 +53,7 @@ switch_status_t mod_amqp_command_destroy(mod_amqp_command_profile_t **prof)
pool = profile->pool; pool = profile->pool;
if (profile->name) { if (profile->name) {
switch_core_hash_delete(globals.command_hash, profile->name); switch_core_hash_delete(mod_amqp_globals.command_hash, profile->name);
} }
profile->running = 0; profile->running = 0;
...@@ -165,7 +165,7 @@ switch_status_t mod_amqp_command_create(char *name, switch_xml_t cfg) ...@@ -165,7 +165,7 @@ switch_status_t mod_amqp_command_create(char *name, switch_xml_t cfg)
goto err; goto err;
} }
if ( switch_core_hash_insert(globals.command_hash, name, (void *) profile) != SWITCH_STATUS_SUCCESS) { if ( switch_core_hash_insert(mod_amqp_globals.command_hash, name, (void *) profile) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to insert new profile [%s] into mod_amqp profile hash\n", name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to insert new profile [%s] into mod_amqp profile hash\n", name);
goto err; goto err;
} }
...@@ -219,7 +219,7 @@ static void mod_amqp_command_response(mod_amqp_command_profile_t *profile, char ...@@ -219,7 +219,7 @@ static void mod_amqp_command_response(mod_amqp_command_profile_t *profile, char
switch_safe_free(json_output); switch_safe_free(json_output);
if (status < 0) { if (status != AMQP_STATUS_OK) {
const char *errstr = amqp_error_string2(-status); const char *errstr = amqp_error_string2(-status);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile[%s] failed to send event on connection[%s]: %s\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile[%s] failed to send event on connection[%s]: %s\n",
profile->name, profile->conn_active->name, errstr); profile->name, profile->conn_active->name, errstr);
......
...@@ -55,7 +55,7 @@ switch_status_t mod_amqp_logging_recv(const switch_log_node_t *node, switch_log_ ...@@ -55,7 +55,7 @@ switch_status_t mod_amqp_logging_recv(const switch_log_node_t *node, switch_log_
3. Queue copy of event into logging profile send queue 3. Queue copy of event into logging profile send queue
4. Destroy local event copy 4. Destroy local event copy
*/ */
for (hi = switch_core_hash_first(globals.logging_hash); hi; hi = switch_core_hash_next(&hi)) { for (hi = switch_core_hash_first(mod_amqp_globals.logging_hash); hi; hi = switch_core_hash_next(&hi)) {
switch_core_hash_this(hi, NULL, NULL, (void **)&logging); switch_core_hash_this(hi, NULL, NULL, (void **)&logging);
if ( logging && switch_log_check_mask(logging->log_level_mask, level) ) { if ( logging && switch_log_check_mask(logging->log_level_mask, level) ) {
...@@ -121,7 +121,7 @@ switch_status_t mod_amqp_logging_destroy(mod_amqp_logging_profile_t **prof) ...@@ -121,7 +121,7 @@ switch_status_t mod_amqp_logging_destroy(mod_amqp_logging_profile_t **prof)
if (profile->name) { if (profile->name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Profile[%s] shutting down...\n", profile->name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Profile[%s] shutting down...\n", profile->name);
switch_core_hash_delete(globals.logging_hash, profile->name); switch_core_hash_delete(mod_amqp_globals.logging_hash, profile->name);
} }
profile->running = 0; profile->running = 0;
...@@ -269,7 +269,7 @@ switch_status_t mod_amqp_logging_create(char *name, switch_xml_t cfg) ...@@ -269,7 +269,7 @@ switch_status_t mod_amqp_logging_create(char *name, switch_xml_t cfg)
goto err; goto err;
} }
if ( switch_core_hash_insert(globals.logging_hash, name, (void *) profile) != SWITCH_STATUS_SUCCESS) { if ( switch_core_hash_insert(mod_amqp_globals.logging_hash, name, (void *) profile) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to insert new profile [%s] into mod_amqp profile hash\n", name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to insert new profile [%s] into mod_amqp profile hash\n", name);
goto err; goto err;
} }
......
...@@ -128,7 +128,7 @@ switch_status_t mod_amqp_producer_destroy(mod_amqp_producer_profile_t **prof) { ...@@ -128,7 +128,7 @@ switch_status_t mod_amqp_producer_destroy(mod_amqp_producer_profile_t **prof) {
if (profile->name) { if (profile->name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Profile[%s] shutting down...\n", profile->name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Profile[%s] shutting down...\n", profile->name);
switch_core_hash_delete(globals.producer_hash, profile->name); switch_core_hash_delete(mod_amqp_globals.producer_hash, profile->name);
} }
profile->running = 0; profile->running = 0;
...@@ -366,7 +366,7 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg) ...@@ -366,7 +366,7 @@ switch_status_t mod_amqp_producer_create(char *name, switch_xml_t cfg)
} }
} }
if ( switch_core_hash_insert(globals.producer_hash, name, (void *) profile) != SWITCH_STATUS_SUCCESS) { if ( switch_core_hash_insert(mod_amqp_globals.producer_hash, name, (void *) profile) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to insert new profile [%s] into mod_amqp profile hash\n", name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to insert new profile [%s] into mod_amqp profile hash\n", name);
goto err; goto err;
} }
......
...@@ -129,7 +129,7 @@ switch_status_t mod_amqp_do_config(switch_bool_t reload) ...@@ -129,7 +129,7 @@ switch_status_t mod_amqp_do_config(switch_bool_t reload)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load mod_amqp profile. Check configs missing name attr\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load mod_amqp profile. Check configs missing name attr\n");
continue; continue;
} }
name = switch_core_strdup(globals.pool, name); name = switch_core_strdup(mod_amqp_globals.pool, name);
if ( mod_amqp_command_create(name, profile) != SWITCH_STATUS_SUCCESS) { if ( mod_amqp_command_create(name, profile) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load mod_amqp profile [%s]. Check configs\n", name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load mod_amqp profile [%s]. Check configs\n", name);
...@@ -153,7 +153,7 @@ switch_status_t mod_amqp_do_config(switch_bool_t reload) ...@@ -153,7 +153,7 @@ switch_status_t mod_amqp_do_config(switch_bool_t reload)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load mod_amqp profile. Check configs missing name attr\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load mod_amqp profile. Check configs missing name attr\n");
continue; continue;
} }
name = switch_core_strdup(globals.pool, name); name = switch_core_strdup(mod_amqp_globals.pool, name);
if ( mod_amqp_logging_create(name, profile) != SWITCH_STATUS_SUCCESS) { if ( mod_amqp_logging_create(name, profile) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load mod_amqp profile [%s]. Check configs\n", name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load mod_amqp profile [%s]. Check configs\n", name);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论