From: Jim Jagielski Date: Sun, 10 Jan 2016 19:20:31 +0000 (+0000) Subject: Use enums and structs to keep things better organized X-Git-Tag: 2.5.0-alpha~2446 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b66e366bdc5cd821194978c7d8a231493a8a9bad;p=thirdparty%2Fapache%2Fhttpd.git Use enums and structs to keep things better organized git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1723953 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 0c8d215649a..78b2e885a7b 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -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 diff --git a/modules/proxy/mod_proxy_hcheck.c b/modules/proxy/mod_proxy_hcheck.c index c742d912166..96096bfbca4 100644 --- a/modules/proxy/mod_proxy_hcheck.c +++ b/modules/proxy/mod_proxy_hcheck.c @@ -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); }