]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8971 Resolve globals struct handling. Thanks to Ben Hood for reporting the issue.
authorWilliam King <william.king@quentustech.com>
Wed, 23 Mar 2016 03:24:27 +0000 (20:24 -0700)
committerWilliam King <william.king@quentustech.com>
Thu, 24 Mar 2016 14:50:23 +0000 (07:50 -0700)
src/mod/event_handlers/mod_amqp/mod_amqp.c
src/mod/event_handlers/mod_amqp/mod_amqp.h
src/mod/event_handlers/mod_amqp/mod_amqp_command.c
src/mod/event_handlers/mod_amqp/mod_amqp_logging.c
src/mod/event_handlers/mod_amqp/mod_amqp_producer.c
src/mod/event_handlers/mod_amqp/mod_amqp_utils.c

index ce82d739e8d983c9bbb0fcd60a59abc478a46c48..e5deaf745aeef0f584d7414827cb848c440bc356 100644 (file)
@@ -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);
        }
index 238236a3b42fbbae5fd2f056b08bd4f7262ad76d..5eba349998953615af50ed437af21e6092be5e86 100644 (file)
@@ -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);
index 430257c53223f2339891b085b5571a035a0fc918..fd71f2b7a8fead6b18c3a1567d8e74ee7fc4c356 100644 (file)
@@ -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);
index 08427b80833a66818a3293ac17f2ee3a14a42bd6..8d4e4805be3d9a17479fb681baeb3322dc8094cb 100644 (file)
@@ -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;
        }
index 39e6d5e5e195fcec272763a10bccb63bbb5b862f..12ba35a5df86b31839bb4acdb66ce4d654da2d59 100644 (file)
@@ -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;
        }
index eda879d3108ad2cbd269831b8a077923383d59a0..bd0289ca8f20fb7a6ff2753408175fb6ce982151 100644 (file)
@@ -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);