]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9054 [mod_hiredis] add ignore-connect-fail profile param so that calls do not...
authorChris Rienzo <chris.rienzo@citrix.com>
Tue, 12 Apr 2016 13:44:17 +0000 (09:44 -0400)
committerChris Rienzo <chris.rienzo@citrix.com>
Tue, 12 Apr 2016 13:44:17 +0000 (09:44 -0400)
conf/vanilla/autoload_configs/hiredis.conf.xml
src/mod/applications/mod_hiredis/hiredis_profile.c
src/mod/applications/mod_hiredis/hiredis_utils.c
src/mod/applications/mod_hiredis/mod_hiredis.c
src/mod/applications/mod_hiredis/mod_hiredis.h

index 4288cb4c4fa67c98e2292560337d081e4decf594..e82453928b2ebe8f8348fa5333a7e813e44ac453 100644 (file)
@@ -16,7 +16,7 @@
        </connection>
       </connections>
       <params>
-       <param name="debug" value="1"/>
+       <param name="ignore-connect-fail" value="true"/>
       </params>
     </profile>
   </profiles>
index ce63d881d68b2f627dd27c3ad53be66aa92e4c3c..ca7164838aa2b9f0a697003a9c6defbeac265fec 100644 (file)
@@ -93,7 +93,7 @@ static hiredis_context_t *hiredis_connection_get_context(hiredis_connection_t *c
        return NULL;
 }
 
-switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *name, uint8_t port)
+switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *name, uint8_t ignore_connect_fail)
 {
        hiredis_profile_t *profile = NULL;
        switch_memory_pool_t *pool = NULL;
@@ -105,6 +105,7 @@ switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *na
        profile->pool = pool;
        profile->name = name ? switch_core_strdup(profile->pool, name) : "default";
        profile->conn_head = NULL;
+       profile->ignore_connect_fail = ignore_connect_fail;
 
        switch_core_hash_insert(mod_hiredis_globals.profiles, name, (void *) profile);
 
@@ -260,7 +261,7 @@ switch_status_t hiredis_profile_execute_sync(hiredis_profile_t *profile, const c
                        return SWITCH_STATUS_GENERR;
                }
        }
-       return SWITCH_STATUS_GENERR;
+       return SWITCH_STATUS_SOCKERR;
 }
 
 
index ad6d625e419d424fba3273c8b08d770d7b65cbe7..98995a08f978ae533c3020d2f40c789a09ee1316 100644 (file)
@@ -45,20 +45,20 @@ switch_status_t mod_hiredis_do_config()
        if ( (profiles = switch_xml_child(cfg, "profiles")) != NULL) {
                for (profile = switch_xml_child(profiles, "profile"); profile; profile = profile->next) {               
                        hiredis_profile_t *new_profile = NULL;
-                       int debug = 0;
+                       uint8_t ignore_connect_fail = 0;
                        char *name = (char *) switch_xml_attr_soft(profile, "name");
 
                        // Load params
                        if ( (params = switch_xml_child(profile, "params")) != NULL) {
                                for (param = switch_xml_child(params, "param"); param; param = param->next) {
                                        char *var = (char *) switch_xml_attr_soft(param, "name");
-                                       if ( ! strncmp(var, "debug", 5) ) {
-                                               debug = atoi(switch_xml_attr_soft(param, "value"));
+                                       if ( !strncmp(var, "ignore-connect-fail", 19) ) {
+                                               ignore_connect_fail = switch_true(switch_xml_attr_soft(param, "value"));
                                        }
                                }
                        }
 
-                       if ( hiredis_profile_create(&new_profile, name, debug) == SWITCH_STATUS_SUCCESS) {
+                       if ( hiredis_profile_create(&new_profile, name, ignore_connect_fail) == SWITCH_STATUS_SUCCESS ) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created profile[%s]\n", name);
                        } else {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create profile[%s]\n", name);
@@ -77,7 +77,7 @@ switch_status_t mod_hiredis_do_config()
                                                } else if ( !strncmp(var, "port", 4) ) {
                                                        port = atoi(switch_xml_attr_soft(param, "value"));
                                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "hiredis: adding conn[%u == %s]\n", port, switch_xml_attr_soft(param, "value"));
-                                               } else if ( !strncmp(var, "timeout_ms", 10) ) {
+                                               } else if ( !strncmp(var, "timeout-ms", 10) || !strncmp(var, "timeout_ms", 10) ) {
                                                        timeout_ms = atoi(switch_xml_attr_soft(param, "value"));
                                                } else if ( !strncmp(var, "password", 8) ) {
                                                        password = (char *) switch_xml_attr_soft(param, "value");
index efe0a034435eddc6e6762d32e323c41cc1d97ac0..1085f189c3f8209770102266275760e048ba19fd 100644 (file)
@@ -1,6 +1,6 @@
 /*
 * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
-* Copyright (C) 2005-2012, Anthony Minessale II <anthm@freeswitch.org>
+* Copyright (C) 2005-2016, Anthony Minessale II <anthm@freeswitch.org>
 *
 * Version: MPL 1.1
 *
@@ -23,6 +23,7 @@
 *
 * Contributor(s):
 * William King <william.king@quentustech.com>
+* Chris Rienzo <chris.rienzo@citrix.com>
 *
 * mod_hiredis.c -- Redis DB access module
 *
@@ -149,9 +150,13 @@ SWITCH_LIMIT_INCR(hiredis_limit_incr)
 
        hashkey = switch_mprintf("incr %s", limit_key);
 
-       if ( hiredis_profile_execute_sync(profile, hashkey, &response) != SWITCH_STATUS_SUCCESS) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hiredis: profile[%s] error executing [%s] because [%s]\n", realm, hashkey, response);
-               switch_channel_set_variable(channel, "hiredis_raw_response", response);
+       if ( (status = hiredis_profile_execute_sync(profile, hashkey, &response)) != SWITCH_STATUS_SUCCESS ) {
+               if ( status == SWITCH_STATUS_SOCKERR && profile->ignore_connect_fail ) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hiredis: ignoring profile[%s] connection error executing [%s]\n", realm, hashkey);
+                       switch_goto_status(SWITCH_STATUS_SUCCESS, done);
+               }
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hiredis: profile[%s] error executing [%s] because [%s]\n", realm, hashkey, response ? response : "");
+               switch_channel_set_variable(channel, "hiredis_raw_response", response ? response : "");
                switch_goto_status(SWITCH_STATUS_GENERR, done);
        }
 
@@ -212,7 +217,11 @@ SWITCH_LIMIT_RELEASE(hiredis_limit_release)
 
                hashkey = switch_mprintf("decr %s", limit_pvt->limit_key);
 
-               if ( hiredis_profile_execute_sync(profile, hashkey, &response) != SWITCH_STATUS_SUCCESS) {
+               if ( ( status = hiredis_profile_execute_sync(profile, hashkey, &response) ) != SWITCH_STATUS_SUCCESS ) {
+                       if ( status == SWITCH_STATUS_SOCKERR && profile->ignore_connect_fail ) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hiredis: ignoring profile[%s] connection error executing [%s]\n", realm, hashkey);
+                               switch_goto_status(SWITCH_STATUS_SUCCESS, done);
+                       }
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hiredis: profile[%s] error executing [%s] because [%s]\n", realm, hashkey, response);
                        switch_channel_set_variable(channel, "hiredis_raw_response", response);
                        switch_goto_status(SWITCH_STATUS_GENERR, done);
index 2403564b062b53ef9fe1636919f03e16b56ef042..0b4c7545751eb6da96b95a7e3602b1f52832b151 100644 (file)
@@ -8,7 +8,6 @@
 typedef struct mod_hiredis_global_s {
   switch_memory_pool_t *pool;
   switch_hash_t *profiles;
-  uint8_t debug;
 } mod_hiredis_global_t;
 
 extern mod_hiredis_global_t mod_hiredis_globals;
@@ -33,7 +32,7 @@ typedef struct hiredis_connection_s {
 typedef struct hiredis_profile_s {
   switch_memory_pool_t *pool;
   char *name;
-  int debug;
+  uint8_t ignore_connect_fail;
 
   hiredis_connection_t *conn_head;
 } hiredis_profile_t;
@@ -48,7 +47,7 @@ typedef struct hiredis_limit_pvt_s {
 } hiredis_limit_pvt_t;
 
 switch_status_t mod_hiredis_do_config();
-switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *name, uint8_t port);
+switch_status_t hiredis_profile_create(hiredis_profile_t **new_profile, char *name, uint8_t ignore_connect_fail);
 switch_status_t hiredis_profile_destroy(hiredis_profile_t **old_profile);
 switch_status_t hiredis_profile_connection_add(hiredis_profile_t *profile, char *host, char *password, uint32_t port, uint32_t timeout_ms, uint32_t max_connections);