diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp.c b/src/mod/event_handlers/mod_amqp/mod_amqp.c index ce82d739e8..e5deaf745a 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp.c +++ b/src/mod/event_handlers/mod_amqp/mod_amqp.c @@ -42,6 +42,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_amqp_shutdown); SWITCH_MODULE_LOAD_FUNCTION(mod_amqp_load); SWITCH_MODULE_DEFINITION(mod_amqp, mod_amqp_load, mod_amqp_shutdown, NULL); +mod_amqp_globals_t mod_amqp_globals; + SWITCH_STANDARD_API(amqp_reload) { return mod_amqp_do_config(SWITCH_TRUE); @@ -56,13 +58,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amqp_load) { 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); - globals.pool = pool; - switch_core_hash_init(&(globals.producer_hash)); - switch_core_hash_init(&(globals.command_hash)); - switch_core_hash_init(&(globals.logging_hash)); + mod_amqp_globals.pool = pool; + switch_core_hash_init(&(mod_amqp_globals.producer_hash)); + switch_core_hash_init(&(mod_amqp_globals.command_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()); @@ -74,7 +76,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amqp_load) SWITCH_ADD_API(api_interface, "amqp", "amqp API", amqp_reload, "syntax"); switch_log_bind_logger(mod_amqp_logging_recv, SWITCH_LOG_DEBUG, SWITCH_FALSE); - + return SWITCH_STATUS_SUCCESS; } @@ -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_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); 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); mod_amqp_command_destroy(&command); } switch_log_unbind_logger(mod_amqp_logging_recv); - - while ((hi = switch_core_hash_first(globals.logging_hash))) { + while ((hi = switch_core_hash_first(mod_amqp_globals.logging_hash))) { switch_core_hash_this(hi, NULL, NULL, (void **)&logging); mod_amqp_logging_destroy(&logging); } diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp.h b/src/mod/event_handlers/mod_amqp/mod_amqp.h index 238236a3b4..5eba349998 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp.h +++ b/src/mod/event_handlers/mod_amqp/mod_amqp.h @@ -173,13 +173,15 @@ typedef struct { switch_memory_pool_t *pool; } mod_amqp_logging_profile_t; -struct { +typedef struct mod_amqp_globals_s { switch_memory_pool_t *pool; - + switch_hash_t *producer_hash; switch_hash_t *command_hash; switch_hash_t *logging_hash; -} globals; +} mod_amqp_globals_t; + +extern mod_amqp_globals_t mod_amqp_globals; /* utils */ switch_status_t mod_amqp_do_config(switch_bool_t reload); diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp_command.c b/src/mod/event_handlers/mod_amqp/mod_amqp_command.c index 430257c532..fd71f2b7a8 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp_command.c +++ b/src/mod/event_handlers/mod_amqp/mod_amqp_command.c @@ -53,7 +53,7 @@ switch_status_t mod_amqp_command_destroy(mod_amqp_command_profile_t **prof) pool = profile->pool; 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; @@ -165,7 +165,7 @@ switch_status_t mod_amqp_command_create(char *name, switch_xml_t cfg) 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); goto err; } @@ -219,7 +219,7 @@ static void mod_amqp_command_response(mod_amqp_command_profile_t *profile, char switch_safe_free(json_output); - if (status < 0) { + if (status != AMQP_STATUS_OK) { 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", profile->name, profile->conn_active->name, errstr); diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp_logging.c b/src/mod/event_handlers/mod_amqp/mod_amqp_logging.c index 08427b8083..8d4e4805be 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp_logging.c +++ b/src/mod/event_handlers/mod_amqp/mod_amqp_logging.c @@ -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 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); 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) if (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; @@ -269,7 +269,7 @@ switch_status_t mod_amqp_logging_create(char *name, switch_xml_t cfg) 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); goto err; } diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp_producer.c b/src/mod/event_handlers/mod_amqp/mod_amqp_producer.c index 39e6d5e5e1..12ba35a5df 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp_producer.c +++ b/src/mod/event_handlers/mod_amqp/mod_amqp_producer.c @@ -128,7 +128,7 @@ switch_status_t mod_amqp_producer_destroy(mod_amqp_producer_profile_t **prof) { if (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; @@ -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); goto err; } diff --git a/src/mod/event_handlers/mod_amqp/mod_amqp_utils.c b/src/mod/event_handlers/mod_amqp/mod_amqp_utils.c index eda879d310..bd0289ca8f 100644 --- a/src/mod/event_handlers/mod_amqp/mod_amqp_utils.c +++ b/src/mod/event_handlers/mod_amqp/mod_amqp_utils.c @@ -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"); 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) { 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) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load mod_amqp profile. Check configs missing name attr\n"); 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) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load mod_amqp profile [%s]. Check configs\n", name);