]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: prepare to support more http-request actions
authorWilly Tarreau <w@1wt.eu>
Mon, 24 Dec 2012 11:00:25 +0000 (12:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 24 Dec 2012 11:26:26 +0000 (12:26 +0100)
We'll need to support per-action arguments, so we need to have an
"arg" union in http_req_rule.

include/types/proto_http.h
src/proto_http.c

index ef9e125623764b615e41cf0b1b5ec286624e3bcf..c6efc55733fc30731806e1d193b97aa150b1b7b9 100644 (file)
@@ -341,11 +341,13 @@ struct http_auth_data {
 
 struct http_req_rule {
        struct list list;
-       struct acl_cond *cond;                  /* acl condition to meet */
-       unsigned int action;
-       struct {
-               char *realm;
-       } http_auth;
+       struct acl_cond *cond;                 /* acl condition to meet */
+       unsigned int action;                   /* HTTP_REQ_* */
+       union {
+               struct {
+                       char *realm;
+               } auth;                        /* arg used by "auth" */
+       } arg;                                 /* arguments used by some actions */
 };
 
 /* This is an HTTP transaction. It contains both a request message and a
index d49ef05535b67ef3dfd23c5d8dbd87f775c14af4..b1039d60d185b64f9ef0a69cc03df2b46c835fc4 100644 (file)
@@ -3268,7 +3268,7 @@ int http_process_req_common(struct session *s, struct channel *req, int an_bit,
         * either to pass or to access stats.
         */
        if (http_req_last_rule && http_req_last_rule->action == HTTP_REQ_ACT_HTTP_AUTH) {
-               char *realm = http_req_last_rule->http_auth.realm;
+               char *realm = http_req_last_rule->arg.auth.realm;
 
                if (!realm)
                        realm = do_stats?STATS_DEFAULT_REALM:px->id;
@@ -7971,7 +7971,7 @@ void free_http_req_rules(struct list *r) {
        list_for_each_entry_safe(pr, tr, r, list) {
                LIST_DEL(&pr->list);
                if (pr->action == HTTP_REQ_ACT_HTTP_AUTH)
-                       free(pr->http_auth.realm);
+                       free(pr->arg.auth.realm);
 
                free(pr);
        }
@@ -7988,9 +7988,7 @@ struct http_req_rule *parse_http_req_cond(const char **args, const char *file, i
                return NULL;
        }
 
-       if (!*args[0]) {
-               goto req_error_parsing;
-       } else if (!strcmp(args[0], "allow")) {
+       if (!strcmp(args[0], "allow")) {
                rule->action = HTTP_REQ_ACT_ALLOW;
                cur_arg = 1;
        } else if (!strcmp(args[0], "deny")) {
@@ -8002,16 +8000,15 @@ struct http_req_rule *parse_http_req_cond(const char **args, const char *file, i
 
                while(*args[cur_arg]) {
                        if (!strcmp(args[cur_arg], "realm")) {
-                               rule->http_auth.realm = strdup(args[cur_arg + 1]);
+                               rule->arg.auth.realm = strdup(args[cur_arg + 1]);
                                cur_arg+=2;
                                continue;
                        } else
                                break;
                }
        } else {
-req_error_parsing:
-               Alert("parsing [%s:%d]: %s '%s', expects 'allow', 'deny', 'auth'.\n",
-                       file, linenum, *args[1]?"unknown parameter":"missing keyword in", args[*args[1]?1:0]);
+               Alert("parsing [%s:%d]: 'http-request' expects 'allow', 'deny', 'auth', but got '%s'%s.\n",
+                     file, linenum, args[0], *args[0] ? "" : " (missing argument)");
                return NULL;
        }