MEDIUM: acl/pattern: use the same direction scheme

Patterns were using a bitmask to indicate if request or response was desired
in fetch functions and keywords. ACLs were using a bitmask in fetch keywords
and a single bit in fetch functions. ACLs were also using an ACL_PARTIAL bit
in fetch functions indicating that a non-final fetch was performed, which was
an abuse of the existing direction flag.

The change now consists in using :
  - a capabilities field for fetch keywords => SMP_CAP_REQ/RES to indicate
    if a keyword supports requests, responses, both, etc...
  - an option field for fetch functions to indicate what the caller expects
    (request/response, final/non-final)

The ACL_PARTIAL bit was reversed to get SMP_OPT_FINAL as it's more explicit
to know we're working on a final buffer than on a non-final one.

ACL_DIR_* were removed, as well as PATTERN_FETCH_*. L4 fetches were improved
to support being called on responses too since they're still available.

The <dir> field of all fetch functions was changed to <opt> which is now
unsigned.

The patch is large but mostly made of cosmetic changes to accomodate this, as
almost no logic change happened.
diff --git a/include/proto/acl.h b/include/proto/acl.h
index 493b56e..3a7606b 100644
--- a/include/proto/acl.h
+++ b/include/proto/acl.h
@@ -94,7 +94,7 @@
  * condition, it does not apply the polarity required by IF/UNLESS, it's up to
  * the caller to do this.
  */
-int acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct session *l4, void *l7, int dir);
+int acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct session *l4, void *l7, unsigned int opt);
 
 /* Reports a pointer to the first ACL used in condition <cond> which requires
  * at least one of the USE_FLAGS in <require>. Returns NULL if none matches.
@@ -171,7 +171,7 @@
 int acl_parse_ip(const char **text, struct acl_pattern *pattern, int *opaque);
 
 /* always fake a data retrieval */
-int acl_fetch_nothing(struct proxy *px, struct session *l4, void *l7, int dir,
+int acl_fetch_nothing(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
                       const struct arg *args, struct sample *smp);
 
 /* always return false */
diff --git a/include/proto/pattern.h b/include/proto/pattern.h
index 5a9f944..f3250ec 100644
--- a/include/proto/pattern.h
+++ b/include/proto/pattern.h
@@ -27,7 +27,7 @@
 
 struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err_size);
 struct sample *pattern_process(struct proxy *px, struct session *l4,
-                               void *l7, int dir, struct pattern_expr *expr,
+                               void *l7, unsigned int dir, struct pattern_expr *expr,
                                struct sample *p);
 void pattern_register_fetches(struct pattern_fetch_kw_list *psl);
 void pattern_register_convs(struct pattern_conv_kw_list *psl);
diff --git a/include/proto/proto_tcp.h b/include/proto/proto_tcp.h
index 91573e9..947699b 100644
--- a/include/proto/proto_tcp.h
+++ b/include/proto/proto_tcp.h
@@ -34,7 +34,7 @@
 int tcp_inspect_request(struct session *s, struct buffer *req, int an_bit);
 int tcp_inspect_response(struct session *s, struct buffer *rep, int an_bit);
 int tcp_exec_req_rules(struct session *s);
-int smp_fetch_rdp_cookie(struct proxy *px, struct session *l4, void *l7, int dir, const struct arg *args, struct sample *smp);
+int smp_fetch_rdp_cookie(struct proxy *px, struct session *l4, void *l7, unsigned int opt, const struct arg *args, struct sample *smp);
 
 /* Converts the TCP source address to a stick_table key usable for table
  * lookups. Returns either NULL if the source cannot be converted (eg: not
diff --git a/include/proto/stick_table.h b/include/proto/stick_table.h
index 5da327c..7756623 100644
--- a/include/proto/stick_table.h
+++ b/include/proto/stick_table.h
@@ -47,7 +47,7 @@
 struct stksess *stktable_lookup_key(struct stktable *t, struct stktable_key *key);
 struct stksess *stktable_update_key(struct stktable *table, struct stktable_key *key);
 struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px,
-				        struct session *l4, void *l7, int dir,
+				        struct session *l4, void *l7, unsigned int opt,
 				        struct pattern_expr *expr);
 int stktable_compatible_pattern(struct pattern_expr *expr, unsigned long table_type);
 int stktable_get_data_type(char *name);
diff --git a/include/types/acl.h b/include/types/acl.h
index 564c4bb..cff3ae2 100644
--- a/include/types/acl.h
+++ b/include/types/acl.h
@@ -71,14 +71,6 @@
 	ACL_COND_UNLESS,	/* negative condition (after 'unless') */
 };
 
-/* ACLs can be evaluated on requests and on responses, and on partial or complete data */
-enum {
-	ACL_DIR_REQ = 0,        /* ACL evaluated on request */
-	ACL_DIR_RTR = (1 << 0), /* ACL evaluated on response */
-	ACL_DIR_MASK = (ACL_DIR_REQ | ACL_DIR_RTR),
-	ACL_PARTIAL = (1 << 1), /* partial data, return MISS if data are missing */
-};
-
 /* possible flags for expressions or patterns */
 enum {
 	ACL_PAT_F_IGNORE_CASE = 1 << 0,       /* ignore case */
@@ -238,7 +230,7 @@
 struct acl_keyword {
 	const char *kw;
 	int (*parse)(const char **text, struct acl_pattern *pattern, int *opaque);
-	int (*fetch)(struct proxy *px, struct session *l4, void *l7, int dir,
+	int (*fetch)(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
 	             const struct arg *args, struct sample *smp);
 	int (*match)(struct sample *smp, struct acl_pattern *pattern);
 	unsigned int requires;   /* bit mask of all ACL_USE_* required to evaluate this keyword */
diff --git a/include/types/pattern.h b/include/types/pattern.h
index d4d3838..3ee18cb 100644
--- a/include/types/pattern.h
+++ b/include/types/pattern.h
@@ -41,6 +41,26 @@
 	SMP_TYPES        /* number of types, must always be last */
 };
 
+/* Sample fetch capabilities are used to declare keywords. Right now only
+ * the supportd fetch directions are specified.
+ */
+enum {
+	SMP_CAP_REQ = 1 << 0, /* fetch supported on request */
+	SMP_CAP_RES = 1 << 1, /* fetch supported on response */
+};
+
+/* Sample fetch options are passed to sample fetch functions to add precision
+ * about what is desired :
+ *   - fetch direction (req/resp)
+ *   - intermediary / final fetch
+ */
+enum {
+	SMP_OPT_DIR_REQ = 0,    /* direction = request */
+	SMP_OPT_DIR_RES = 1,    /* direction = response */
+	SMP_OPT_DIR     = (SMP_OPT_DIR_REQ|SMP_OPT_DIR_RES), /* mask to get direction */
+	SMP_OPT_FINAL   = 2,    /* final fetch, contents won't change anymore */
+};
+
 /* Flags used to describe fetched samples. MAY_CHANGE indicates that the result
  * of the fetch might still evolve, for instance because of more data expected,
  * even if the fetch has failed. VOL_* indicates how long a result may be cached.
@@ -56,11 +76,6 @@
 	SMP_F_VOLATILE   = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6), /* any volatility condition */
 };
 
-/* pattern fetch direction */
-#define PATTERN_FETCH_REQ	1
-#define PATTERN_FETCH_RTR	2
-
-
 /* a sample context might be used by any sample fetch function in order to
  * store information needed across multiple calls (eg: restart point for a
  * next occurrence). By definition it may store up to 8 pointers, or any
@@ -115,13 +130,14 @@
 	int (*process)(struct proxy *px,
 	               struct session *l4,
 	               void *l7,
-	               int dir, const struct arg *arg_p,
+		       unsigned int opt,          /* fetch options (SMP_OPT_*) */
+		       const struct arg *arg_p,
 	               struct sample *smp);       /* fetch processing function */
 	unsigned int arg_mask;                    /* arguments (ARG*()) */
 	int (*val_args)(struct arg *arg_p,
 			char **err_msg);          /* argument validation function */
 	unsigned long out_type;                   /* output pattern type */
-	int dir;                                  /* usable directions */
+	unsigned int cap;                         /* fetch capabilities (SMP_CAP_*) */
 };
 
 /* pattern expression */