From 573bb3f6dd97e675a48de09f0b07089b70be9fc8 Mon Sep 17 00:00:00 2001
From: Krzysztof Piotr Oledzki <ole#ans.pl>
Date: Fri, 6 Nov 2009 15:19:33 +0100
Subject: [MINOR] join findproxy() and findproxy_mode() into more generic findproxy()
This patch joins two functions into a one. The new one expects a
bit mask of allowed modes or 0 if any mode is acceptable, so now
it is possible to remove hardcoded condition allowing switching
from tcp to http.
---
include/proto/proxy.h | 3 +-- src/cfgparse.c | 10 ++++++---- src/proxy.c | 48 +++++++++++++++++++++++-------------------------3 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/include/proto/proxy.h b/include/proto/proxy.h
index 5297d08..a3280b5 100644
--- a/include/proto/proxy.h
+++ b/include/proto/proxy.h
@@ -39,8 +39,7 @@ int session_set_backend(struct session *s, struct proxy *be);
const char *proxy_cap_str(int cap);
const char *proxy_mode_str(int mode);
-struct proxy *findproxy_mode(const char *name, int mode, int cap);
-struct proxy *findproxy(const char *name, int cap);
+struct proxy *findproxy(const char *name, int mode_mask, int cap);
struct server *findserver(const struct proxy *px, const char *name);
int proxy_cfg_ensure_no_http(struct proxy *curproxy);
int get_backend_server(const char *bk_name, const char *sv_name,
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 34d4476..078c0e9 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -4166,7 +4166,7 @@ int check_config_validity()
if (curproxy->defbe.name) { struct proxy *target;diff --git a/src/proxy.c b/src/proxy.c
- target = findproxy_mode(curproxy->defbe.name, curproxy->mode, PR_CAP_BE);
+ target = findproxy(curproxy->defbe.name, 1 << curproxy->mode, PR_CAP_BE); if (!target) { Alert("Proxy '%s': unable to find required default_backend: '%s'.\n", curproxy->id, curproxy->defbe.name); @@ -4196,7 +4196,7 @@ int check_config_validity() if (exp->action != ACT_SETBE) continue;
- target = findproxy_mode(exp->replace, PR_MODE_HTTP, PR_CAP_BE);
+ target = findproxy(exp->replace, 1 << PR_MODE_HTTP, PR_CAP_BE); if (!target) { Alert("Proxy '%s': unable to find required setbe: '%s'.\n", curproxy->id, exp->replace); @@ -4221,7 +4221,9 @@ int check_config_validity() list_for_each_entry(rule, &curproxy->switching_rules, list) { struct proxy *target;
- target = findproxy_mode(rule->be.name, curproxy->mode, PR_CAP_BE);
+ target = findproxy(rule->be.name, + (curproxy->mode == PR_MODE_TCP)?(1 << PR_MODE_TCP)|(1 << PR_MODE_HTTP):1 << curproxy->mode, + PR_CAP_BE); if (!target) { Alert("Proxy '%s': unable to find required use_backend: '%s'.\n", @@ -4433,7 +4435,7 @@ int check_config_validity() } if (pname) {
- px = findproxy(pname, PR_CAP_BE);
+ px = findproxy(pname, 0, PR_CAP_BE); if (!px) { Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n", proxy_type_str(curproxy), curproxy->id,
return "unknown";
}
+const char *proxy_mode_mask_str(char *buff, int mode_mask) { + + int mode, n = 0; + char *p = buff; + + p[0] = '\0'; + + for(mode = 0; mode_mask; mode++, mode_mask >>= 1) + if (mode_mask & 1) { + if (n++) + p += sprintf(p, "|"); + + p += sprintf(p, "%s", proxy_mode_str(mode)); + } + + return buff; +} + /*
-struct proxy *findproxy_mode(const char *name, int mode, int cap) {
+struct proxy *findproxy(const char *name, int mode_mask, int cap) {
struct proxy *curproxy, *target = NULL;
for (curproxy = proxy; curproxy; curproxy = curproxy->next) {
- if ((curproxy->cap & cap)!=cap || strcmp(curproxy->id, name))
+ if ((curproxy->cap & cap) != cap || strcmp(curproxy->id, name)) continue;
- if (curproxy->mode != mode &&
- !(curproxy->mode == PR_MODE_HTTP && mode == PR_MODE_TCP)) {
+ if (mode_mask && !((1 << curproxy->mode) & mode_mask)) { Alert("Unable to use proxy '%s' with wrong mode, required: %s, has: %s.\n",
- name, proxy_mode_str(mode), proxy_mode_str(curproxy->mode));
- Alert("You may want to use 'mode %s'.\n", proxy_mode_str(mode));
+ name, proxy_mode_mask_str(trash, mode_mask), proxy_mode_str(curproxy->mode)); + Alert("You may want to use 'mode %s'.\n", proxy_mode_mask_str(trash, mode_mask)); return NULL; } @@ -311,25 +328,6 @@ struct proxy *findproxy_mode(const char *name, int mode, int cap) { return target;
-struct proxy *findproxy(const char *name, int cap) {
-
This archive was generated by hypermail 2.2.0 : 2009/11/06 15:30 CET