BUG/MAJOR: channel: Fix the definition order of channel analyzers

It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.

With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.

So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.

Some other analyzers have been reordered to respect the evaluation order:

  * AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
  * AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
  * AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP

Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.

[wt: all of this must be backported to 1.7, and part of it must be backported
 to 1.6 and 1.5]
diff --git a/src/filters.c b/src/filters.c
index 14ea0f1..9ec794a 100644
--- a/src/filters.c
+++ b/src/filters.c
@@ -694,8 +694,16 @@
 	 * so we do not need to check the filter list's emptiness. */
 
 	RESUME_FILTER_LOOP(s, chn) {
-		if (an_bit == AN_FLT_START_BE && !(filter->flags & FLT_FL_IS_BACKEND_FILTER))
-			continue;
+		if (!(chn->flags & CF_ISRESP)) {
+			if (an_bit == AN_REQ_FLT_START_BE &&
+			    !(filter->flags & FLT_FL_IS_BACKEND_FILTER))
+				continue;
+		}
+		else {
+			if (an_bit == AN_RES_FLT_START_BE &&
+			    !(filter->flags & FLT_FL_IS_BACKEND_FILTER))
+				continue;
+		}
 
 		FLT_NXT(filter, chn) = 0;
 		FLT_FWD(filter, chn) = 0;
@@ -764,9 +772,9 @@
 }
 
 /*
- * This function is the AN_FLT_HTTP_HDRS analyzer, used to filter HTTP headers
- * or a request or a response. Returns 0 if an error occurs or if it needs to
- * wait, any other value otherwise.
+ * This function is the AN_REQ/RES_FLT_HTTP_HDRS analyzer, used to filter HTTP
+ * headers or a request or a response. Returns 0 if an error occurs or if it
+ * needs to wait, any other value otherwise.
  */
 int
 flt_analyze_http_headers(struct stream *s, struct channel *chn, unsigned int an_bit)
@@ -828,7 +836,7 @@
 
 	/* Check if 'channel_end_analyze' callback has been called for the
 	 * request and the response. */
-	if (!(s->req.analysers & AN_FLT_END) && !(s->res.analysers & AN_FLT_END)) {
+	if (!(s->req.analysers & AN_REQ_FLT_END) && !(s->res.analysers & AN_RES_FLT_END)) {
 		/* When we are waiting for a new request, so we must reset
 		 * stream analyzers. The input must not be closed the request
 		 * channel, else it is useless to wait. */
@@ -967,11 +975,11 @@
 
 /*
  * Called when TCP data must be filtered on a channel. This function is the
- * AN_FLT_XFER_DATA analyzer. When called, it is responsible to forward data
- * when the proxy is not in http mode. Behind the scene, it calls consecutively
- * 'tcp_data' and 'tcp_forward_data' callbacks for all "data" filters attached
- * to a stream. Returns 0 if an error occurs or if it needs to wait, any other
- * value otherwise.
+ * AN_REQ/RES_FLT_XFER_DATA analyzer. When called, it is responsible to forward
+ * data when the proxy is not in http mode. Behind the scene, it calls
+ * consecutively 'tcp_data' and 'tcp_forward_data' callbacks for all "data"
+ * filters attached to a stream. Returns 0 if an error occurs or if it needs to
+ * wait, any other value otherwise.
  */
 int
 flt_xfer_data(struct stream *s, struct channel *chn, unsigned int an_bit)
@@ -1045,12 +1053,12 @@
 	channel_abort(&s->res);
 
 	if (!(chn->flags & CF_ISRESP)) {
-		s->req.analysers &= AN_FLT_END;
+		s->req.analysers &= AN_REQ_FLT_END;
 		finst = SF_FINST_R;
 		/* FIXME: incr counters */
 	}
 	else {
-		s->res.analysers &= AN_FLT_END;
+		s->res.analysers &= AN_RES_FLT_END;
 		finst = SF_FINST_H;
 		/* FIXME: incr counters */
 	}