REORG/MEDIUM: channel: only use chn_prod / chn_cons to find stream-interfaces

The purpose of these two macros will be to pass via the session to
find the relevant stream interfaces so that we don't need to store
the ->cons nor ->prod pointers anymore. Currently they're only defined
so that all references could be removed.

Note that many places need a second pass of clean up so that we don't
have any chn_prod(&s->req) anymore and only &s->si[0] instead, and
conversely for the 3 other cases.
diff --git a/src/session.c b/src/session.c
index ca8efca..a924e8c 100644
--- a/src/session.c
+++ b/src/session.c
@@ -1087,7 +1087,7 @@
 		s->req, s->rep,
 		s->req.rex, s->res.wex,
 		s->req.flags, s->res.flags,
-		s->req.buf->i, s->req.buf->o, s->res.buf->i, s->res.buf->o, s->res.cons->state, s->req.cons->state);
+		s->req.buf->i, s->req.buf->o, s->res.buf->i, s->res.buf->o, chn_cons(&s->res)->state, s->req.cons->state);
 
 	if (si->state == SI_ST_ASS) {
 		/* Server assigned to connection request, we have to try to connect now */
@@ -1279,7 +1279,7 @@
 		s->req, s->rep,
 		s->req.rex, s->res.wex,
 		s->req.flags, s->res.flags,
-		s->req.buf->i, s->req.buf->o, s->res.buf->i, s->res.buf->o, s->res.cons->state, s->req.cons->state);
+		s->req.buf->i, s->req.buf->o, s->res.buf->i, s->res.buf->o, chn_cons(&s->res)->state, s->req.cons->state);
 
 	if (si->state != SI_ST_REQ)
 		return;
@@ -1750,8 +1750,8 @@
 	rpf_last = s->res.flags & ~CF_MASK_ANALYSER;
 
 	/* we don't want the stream interface functions to recursively wake us up */
-	s->req.prod->flags |= SI_FL_DONT_WAKE;
-	s->req.cons->flags |= SI_FL_DONT_WAKE;
+	s->si[0].flags |= SI_FL_DONT_WAKE;
+	s->si[1].flags |= SI_FL_DONT_WAKE;
 
 	/* 1a: Check for low level timeouts if needed. We just set a flag on
 	 * stream interfaces when their timeouts have expired.
@@ -1769,27 +1769,27 @@
 		channel_check_timeouts(&s->req);
 
 		if (unlikely((s->req.flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) {
-			s->req.cons->flags |= SI_FL_NOLINGER;
-			si_shutw(s->req.cons);
+			chn_cons(&s->req)->flags |= SI_FL_NOLINGER;
+			si_shutw(chn_cons(&s->req));
 		}
 
 		if (unlikely((s->req.flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) {
-			if (s->req.prod->flags & SI_FL_NOHALF)
-				s->req.prod->flags |= SI_FL_NOLINGER;
-			si_shutr(s->req.prod);
+			if (chn_prod(&s->req)->flags & SI_FL_NOHALF)
+				chn_prod(&s->req)->flags |= SI_FL_NOLINGER;
+			si_shutr(chn_prod(&s->req));
 		}
 
 		channel_check_timeouts(&s->res);
 
 		if (unlikely((s->res.flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) {
-			s->res.cons->flags |= SI_FL_NOLINGER;
-			si_shutw(s->res.cons);
+			chn_cons(&s->res)->flags |= SI_FL_NOLINGER;
+			si_shutw(chn_cons(&s->res));
 		}
 
 		if (unlikely((s->res.flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) {
-			if (s->res.prod->flags & SI_FL_NOHALF)
-				s->res.prod->flags |= SI_FL_NOLINGER;
-			si_shutr(s->res.prod);
+			if (chn_prod(&s->res)->flags & SI_FL_NOHALF)
+				chn_prod(&s->res)->flags |= SI_FL_NOLINGER;
+			si_shutr(chn_prod(&s->res));
 		}
 
 		/* Once in a while we're woken up because the task expires. But
@@ -1894,19 +1894,19 @@
 		s->req, s->rep,
 		s->req.rex, s->res.wex,
 		s->req.flags, s->res.flags,
-		s->req.buf->i, s->req.buf->o, s->res.buf->i, s->res.buf->o, s->res.cons->state, s->req.cons->state,
-		s->res.cons->err_type, s->req.cons->err_type,
-		s->req.cons->conn_retries);
+		s->req.buf->i, s->req.buf->o, s->res.buf->i, s->res.buf->o, chn_cons(&s->res)->state, chn_cons(&s->req)->state,
+		chn_cons(&s->res)->err_type, chn_cons(&s->req)->err_type,
+		chn_cons(&s->req)->conn_retries);
 
 	/* nothing special to be done on client side */
-	if (unlikely(s->req.prod->state == SI_ST_DIS))
-		s->req.prod->state = SI_ST_CLO;
+	if (unlikely(chn_prod(&s->req)->state == SI_ST_DIS))
+		chn_prod(&s->req)->state = SI_ST_CLO;
 
 	/* When a server-side connection is released, we have to count it and
 	 * check for pending connections on this server.
 	 */
-	if (unlikely(s->req.cons->state == SI_ST_DIS)) {
-		s->req.cons->state = SI_ST_CLO;
+	if (unlikely(chn_cons(&s->req)->state == SI_ST_DIS)) {
+		chn_cons(&s->req)->state = SI_ST_CLO;
 		srv = objt_server(s->target);
 		if (srv) {
 			if (s->flags & SN_CURR_SESS) {
@@ -1933,7 +1933,7 @@
 	    s->task->state & TASK_WOKEN_MSG) {
 		unsigned int flags = s->req.flags;
 
-		if (s->req.prod->state >= SI_ST_EST) {
+		if (chn_prod(&s->req)->state >= SI_ST_EST) {
 			int max_loops = global.tune.maxpollevents;
 			unsigned int ana_list;
 			unsigned int ana_back;
@@ -2104,7 +2104,7 @@
 			s->req.flags |= CF_WAKE_ONCE;
 		}
 
-		if (s->res.prod->state >= SI_ST_EST) {
+		if (chn_prod(&s->res)->state >= SI_ST_EST) {
 			int max_loops = global.tune.maxpollevents;
 			unsigned int ana_list;
 			unsigned int ana_back;
@@ -2274,7 +2274,7 @@
 	 */
 	if (unlikely(!s->req.analysers &&
 	    !(s->req.flags & (CF_SHUTW|CF_SHUTR_NOW)) &&
-	    (s->req.prod->state >= SI_ST_EST) &&
+	    (chn_prod(&s->req)->state >= SI_ST_EST) &&
 	    (s->req.to_forward != CHN_INFINITE_FORWARD))) {
 		/* This buffer is freewheeling, there's no analyser
 		 * attached to it. If any data are left in, we'll permit them to
@@ -2330,8 +2330,8 @@
 	if (unlikely((s->req.flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW &&
 		     channel_is_empty(&s->req))) {
 		if (s->req.flags & CF_READ_ERROR)
-			s->req.cons->flags |= SI_FL_NOLINGER;
-		si_shutw(s->req.cons);
+			chn_cons(&s->req)->flags |= SI_FL_NOLINGER;
+		si_shutw(chn_cons(&s->req));
 		if (tick_isset(s->be->timeout.serverfin)) {
 			s->res.rto = s->be->timeout.serverfin;
 			s->res.rex = tick_add(now_ms, s->res.rto);
@@ -2345,9 +2345,9 @@
 
 	/* shutdown(read) pending */
 	if (unlikely((s->req.flags & (CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTR_NOW)) {
-		if (s->req.prod->flags & SI_FL_NOHALF)
-			s->req.prod->flags |= SI_FL_NOLINGER;
-		si_shutr(s->req.prod);
+		if (chn_prod(&s->req)->flags & SI_FL_NOHALF)
+			chn_prod(&s->req)->flags |= SI_FL_NOLINGER;
+		si_shutr(chn_prod(&s->req));
 		if (tick_isset(s->fe->timeout.clientfin)) {
 			s->res.wto = s->fe->timeout.clientfin;
 			s->res.wex = tick_add(now_ms, s->res.wto);
@@ -2359,19 +2359,19 @@
 	 *  - there are data scheduled for emission in the buffer
 	 *  - the CF_AUTO_CONNECT flag is set (active connection)
 	 */
-	if (s->req.cons->state == SI_ST_INI) {
+	if (chn_cons(&s->req)->state == SI_ST_INI) {
 		if (!(s->req.flags & CF_SHUTW)) {
 			if ((s->req.flags & CF_AUTO_CONNECT) || !channel_is_empty(&s->req)) {
 				/* If we have an appctx, there is no connect method, so we
 				 * immediately switch to the connected state, otherwise we
 				 * perform a connection request.
 				 */
-				s->req.cons->state = SI_ST_REQ; /* new connection requested */
-				s->req.cons->conn_retries = s->be->conn_retries;
+				chn_cons(&s->req)->state = SI_ST_REQ; /* new connection requested */
+				chn_cons(&s->req)->conn_retries = s->be->conn_retries;
 			}
 		}
 		else {
-			s->req.cons->state = SI_ST_CLO; /* shutw+ini = abort */
+			chn_cons(&s->req)->state = SI_ST_CLO; /* shutw+ini = abort */
 			channel_shutw_now(&s->req);        /* fix buffer flags upon abort */
 			channel_shutr_now(&s->res);
 		}
@@ -2414,7 +2414,7 @@
 	}
 
 	/* Benchmarks have shown that it's optimal to do a full resync now */
-	if (s->req.prod->state == SI_ST_DIS || s->req.cons->state == SI_ST_DIS)
+	if (chn_prod(&s->req)->state == SI_ST_DIS || chn_cons(&s->req)->state == SI_ST_DIS)
 		goto resync_stream_interface;
 
 	/* otherwise we want to check if we need to resync the req buffer or not */
@@ -2430,7 +2430,7 @@
 	 */
 	if (unlikely(!s->res.analysers &&
 	    !(s->res.flags & (CF_SHUTW|CF_SHUTR_NOW)) &&
-	    (s->res.prod->state >= SI_ST_EST) &&
+	    (chn_prod(&s->res)->state >= SI_ST_EST) &&
 	    (s->res.to_forward != CHN_INFINITE_FORWARD))) {
 		/* This buffer is freewheeling, there's no analyser
 		 * attached to it. If any data are left in, we'll permit them to
@@ -2507,7 +2507,7 @@
 	/* shutdown(write) pending */
 	if (unlikely((s->res.flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW &&
 		     channel_is_empty(&s->res))) {
-		si_shutw(s->res.cons);
+		si_shutw(chn_cons(&s->res));
 		if (tick_isset(s->fe->timeout.clientfin)) {
 			s->req.rto = s->fe->timeout.clientfin;
 			s->req.rex = tick_add(now_ms, s->req.rto);
@@ -2521,16 +2521,16 @@
 
 	/* shutdown(read) pending */
 	if (unlikely((s->res.flags & (CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTR_NOW)) {
-		if (s->res.prod->flags & SI_FL_NOHALF)
-			s->res.prod->flags |= SI_FL_NOLINGER;
-		si_shutr(s->res.prod);
+		if (chn_prod(&s->res)->flags & SI_FL_NOHALF)
+			chn_prod(&s->res)->flags |= SI_FL_NOLINGER;
+		si_shutr(chn_prod(&s->res));
 		if (tick_isset(s->be->timeout.serverfin)) {
 			s->req.wto = s->be->timeout.serverfin;
 			s->req.wex = tick_add(now_ms, s->req.wto);
 		}
 	}
 
-	if (s->req.prod->state == SI_ST_DIS || s->req.cons->state == SI_ST_DIS)
+	if (chn_prod(&s->req)->state == SI_ST_DIS || chn_cons(&s->req)->state == SI_ST_DIS)
 		goto resync_stream_interface;
 
 	if (s->req.flags != rqf_last)
@@ -2540,8 +2540,8 @@
 		goto resync_response;
 
 	/* we're interested in getting wakeups again */
-	s->req.prod->flags &= ~SI_FL_DONT_WAKE;
-	s->req.cons->flags &= ~SI_FL_DONT_WAKE;
+	chn_prod(&s->req)->flags &= ~SI_FL_DONT_WAKE;
+	chn_cons(&s->req)->flags &= ~SI_FL_DONT_WAKE;
 
 	/* This is needed only when debugging is enabled, to indicate
 	 * client-side or server-side close. Please note that in the unlikely
@@ -2570,17 +2570,17 @@
 		}
 	}
 
-	if (likely((s->res.cons->state != SI_ST_CLO) ||
-		   (s->req.cons->state > SI_ST_INI && s->req.cons->state < SI_ST_CLO))) {
+	if (likely((chn_cons(&s->res)->state != SI_ST_CLO) ||
+		   (chn_cons(&s->req)->state > SI_ST_INI && chn_cons(&s->req)->state < SI_ST_CLO))) {
 
 		if ((s->fe->options & PR_O_CONTSTATS) && (s->flags & SN_BE_ASSIGNED))
 			session_process_counters(s);
 
-		if (s->res.cons->state == SI_ST_EST && obj_type(s->res.cons->end) != OBJ_TYPE_APPCTX)
-			si_update(s->res.cons);
+		if (chn_cons(&s->res)->state == SI_ST_EST && obj_type(chn_cons(&s->res)->end) != OBJ_TYPE_APPCTX)
+			si_update(chn_cons(&s->res));
 
-		if (s->req.cons->state == SI_ST_EST && obj_type(s->req.cons->end) != OBJ_TYPE_APPCTX)
-			si_update(s->req.cons);
+		if (chn_cons(&s->req)->state == SI_ST_EST && obj_type(chn_cons(&s->req)->end) != OBJ_TYPE_APPCTX)
+			si_update(chn_cons(&s->req));
 
 		s->req.flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED);
 		s->res.flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED);
@@ -2612,7 +2612,7 @@
 		 * both functions are always called and that we wake up if at
 		 * least one did something.
 		 */
-		if ((si_applet_call(s->req.cons) | si_applet_call(s->res.cons)) != 0) {
+		if ((si_applet_call(chn_cons(&s->req)) | si_applet_call(chn_cons(&s->res))) != 0) {
 			if (task_in_rq(t)) {
 				t->expire = TICK_ETERNITY;
 				session_release_buffers(s);