]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Use enums and structs to keep things better organized
authorJim Jagielski <jim@apache.org>
Sun, 10 Jan 2016 19:20:31 +0000 (19:20 +0000)
committerJim Jagielski <jim@apache.org>
Sun, 10 Jan 2016 19:20:31 +0000 (19:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1723953 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/mod_proxy.h
modules/proxy/mod_proxy_hcheck.c

index 0c8d215649adcf80f440f5f608947391711f532e..78b2e885a7bad230109f4fa9a16bc3d6d2248c6f 100644 (file)
@@ -75,6 +75,26 @@ enum enctype {
     enc_path, enc_search, enc_user, enc_fpath, enc_parm
 };
 
+typedef enum {
+    NONE, TCP, OPTIONS, HEAD, GET, CPING, PROVIDER, EOT
+} hcmethod_t;
+
+typedef struct {
+    hcmethod_t method;
+    char *name;
+} hcmethods_t;
+
+static hcmethods_t hcmethods[] = {
+        {NONE, "NONE"},
+        {TCP, "TCP"},
+        {OPTIONS, "OPTIONS"},
+        {HEAD, "HEAD"},
+        {GET, "GET"},
+        {CPING, "CPING"},
+        {PROVIDER, "PROVIDER"},
+        {EOT, NULL}
+};
+
 #define BALANCER_PREFIX "balancer://"
 
 #if APR_CHARSET_EBCDIC
@@ -365,7 +385,7 @@ typedef struct {
     char      redirect[PROXY_WORKER_MAX_ROUTE_SIZE];  /* temporary balancing redirection route */
     char      flusher[PROXY_WORKER_MAX_SCHEME_SIZE];  /* flush provider used by mod_proxy_fdpass */
     char      uds_path[PROXY_WORKER_MAX_NAME_SIZE];   /* path to worker's unix domain socket if applicable */
-    char      hurl[PROXY_WORKER_MAX_ROUTE_SIZE];      /* health check url */
+    char      hcuri[PROXY_WORKER_MAX_ROUTE_SIZE];     /* health check uri */
     int             lbset;      /* load balancer cluster set */
     int             retries;    /* number of retries on this worker */
     int             lbstatus;   /* Current lbstatus */
@@ -375,7 +395,6 @@ typedef struct {
     int             hmax;       /* Hard maximum on the total number of connections */
     int             flush_wait; /* poll wait time in microseconds if flush_auto */
     int             index;      /* shm array index */
-    int             method;     /* method to use for health check */
     int             passes;     /* number of successes for check to pass */
     int             pcount;     /* current count of passes */
     int             fails;      /* number of failures for check to fail */
@@ -386,7 +405,8 @@ typedef struct {
         flush_off,
         flush_on,
         flush_auto
-    } flush_packets;           /* control AJP flushing */
+    } flush_packets;            /* control AJP flushing */
+    hcmethod_t      method;     /* method to use for health check */
     apr_time_t      updated;    /* timestamp of last update */
     apr_time_t      error_time; /* time of the last error */
     apr_interval_time_t ttl;    /* maximum amount of time in seconds a connection
index c742d912166404ddaea9ef132643d976569db1cc..96096bfbca4ca29a8f13ef5a7231966198701cd9 100644 (file)
@@ -19,7 +19,6 @@
 #include "ap_slotmem.h"
 #include "ap_expr.h"
 
-
 module AP_MODULE_DECLARE_DATA proxy_hcheck_module;
 
 #define HCHECK_WATHCHDOG_NAME ("_proxy_hcheck_")
@@ -28,13 +27,9 @@ module AP_MODULE_DECLARE_DATA proxy_hcheck_module;
 /* The watchdog runs every 5 seconds, which is also the minimal check */
 #define HCHECK_WATHCHDOG_INTERVAL (5)
 
-static char *methods[] = {
-      "NULL", "OPTIONS", "HEAD", "CPING", NULL
-};
-
 typedef struct {
     char *name;
-    int method;
+    hcmethod_t method;
     int passes;
     int fails;
     apr_interval_time_t interval;
@@ -95,7 +90,7 @@ static const char *set_worker_hc_param(apr_pool_t *p,
                     worker->s->interval = template->interval;
                     worker->s->passes = template->passes;
                     worker->s->fails = template->fails;
-                    PROXY_STRNCPY(worker->s->hurl, template->hurl);
+                    PROXY_STRNCPY(worker->s->hcuri, template->hurl);
                 } else {
                     temp->method = template->method;
                     temp->interval = template->interval;
@@ -109,12 +104,13 @@ static const char *set_worker_hc_param(apr_pool_t *p,
         return apr_psprintf(p, "Unknown ProxyHCTemplate name: %s", val);
     }
     else if (!strcasecmp(key, "hcmethod")) {
-        for (ival = 1; methods[ival]; ival++) {
-            if (!ap_casecmpstr(val, methods[ival])) {
+        hcmethods_t *method = hcmethods;
+        for (; method->name; method++) {
+            if (!ap_casecmpstr(val, method->name)) {
                 if (worker) {
-                    worker->s->method = ival;
+                    worker->s->method = method->method;
                 } else {
-                    temp->method = ival;
+                    temp->method = method->method;
                 }
                 return NULL;
             }
@@ -152,11 +148,11 @@ static const char *set_worker_hc_param(apr_pool_t *p,
         }
     }
     else if (!strcasecmp(key, "hcuri")) {
-        if (strlen(val) >= sizeof(worker->s->hurl))
+        if (strlen(val) >= sizeof(worker->s->hcuri))
             return apr_psprintf(p, "Health check uri length must be < %d characters",
-                    (int)sizeof(worker->s->hurl));
+                    (int)sizeof(worker->s->hcuri));
         if (worker) {
-            PROXY_STRNCPY(worker->s->hurl, val);
+            PROXY_STRNCPY(worker->s->hcuri, val);
         } else {
             temp->hurl = apr_pstrdup(p, val);
         }