FS-8971 Resolve globals struct handling. Thanks to Ben Hood for reporting the issue.
This commit is contained in:
parent
a42ab11022
commit
eec93d87fa
|
@ -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());
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue