MINOR: http: prepare to support more http-request actions
We'll need to support per-action arguments, so we need to have an
"arg" union in http_req_rule.
diff --git a/include/types/proto_http.h b/include/types/proto_http.h
index ef9e125..c6efc55 100644
--- a/include/types/proto_http.h
+++ b/include/types/proto_http.h
@@ -341,11 +341,13 @@
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
diff --git a/src/proto_http.c b/src/proto_http.c
index d49ef05..b1039d6 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -3268,7 +3268,7 @@
* 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 @@
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 @@
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 @@
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;
}