MAJOR: sample: pass a pointer to the session to each sample fetch function

Many such function need a session, and till now they used to dereference
the stream. Once we remove the stream from the embryonic session, this
will not be possible anymore.

So as of now, sample fetch functions will be called with this :

   - sess = NULL,  strm = NULL                     : never
   - sess = valid, strm = NULL                     : tcp-req connection
   - sess = valid, strm = valid, strm->txn = NULL  : tcp-req content
   - sess = valid, strm = valid, strm->txn = valid : http-req / http-res
diff --git a/src/stream.c b/src/stream.c
index 5833b07..91c2a0d 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -1369,7 +1369,8 @@
 static int process_switching_rules(struct stream *s, struct channel *req, int an_bit)
 {
 	struct persist_rule *prst_rule;
-	struct proxy *fe = strm_sess(s)->fe;
+	struct session *sess = s->sess;
+	struct proxy *fe = sess->fe;
 
 	req->analysers &= ~an_bit;
 	req->analyse_exp = TICK_ETERNITY;
@@ -1391,7 +1392,7 @@
 			int ret = 1;
 
 			if (rule->cond) {
-				ret = acl_exec_cond(rule->cond, fe, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
+				ret = acl_exec_cond(rule->cond, fe, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
 				ret = acl_pass(ret);
 				if (rule->cond->pol == ACL_COND_UNLESS)
 					ret = !ret;
@@ -1444,7 +1445,7 @@
 		int ret = 1;
 
 		if (prst_rule->cond) {
-	                ret = acl_exec_cond(prst_rule->cond, s->be, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
+	                ret = acl_exec_cond(prst_rule->cond, s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
 			ret = acl_pass(ret);
 			if (prst_rule->cond->pol == ACL_COND_UNLESS)
 				ret = !ret;
@@ -1487,6 +1488,7 @@
 static int process_server_rules(struct stream *s, struct channel *req, int an_bit)
 {
 	struct proxy *px = s->be;
+	struct session *sess = s->sess;
 	struct server_rule *rule;
 
 	DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n",
@@ -1502,7 +1504,7 @@
 		list_for_each_entry(rule, &px->server_rules, list) {
 			int ret;
 
-			ret = acl_exec_cond(rule->cond, s->be, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
+			ret = acl_exec_cond(rule->cond, s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
 			ret = acl_pass(ret);
 			if (rule->cond->pol == ACL_COND_UNLESS)
 				ret = !ret;
@@ -1536,6 +1538,7 @@
 static int process_sticking_rules(struct stream *s, struct channel *req, int an_bit)
 {
 	struct proxy    *px   = s->be;
+	struct session *sess  = s->sess;
 	struct sticking_rule  *rule;
 
 	DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
@@ -1567,7 +1570,7 @@
 			continue;
 
 		if (rule->cond) {
-	                ret = acl_exec_cond(rule->cond, px, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
+	                ret = acl_exec_cond(rule->cond, px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
 			ret = acl_pass(ret);
 			if (rule->cond->pol == ACL_COND_UNLESS)
 				ret = !ret;
@@ -1576,7 +1579,7 @@
 		if (ret) {
 			struct stktable_key *key;
 
-			key = stktable_fetch_key(rule->table.t, px, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->expr, NULL);
+			key = stktable_fetch_key(rule->table.t, px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->expr, NULL);
 			if (!key)
 				continue;
 
@@ -1632,6 +1635,7 @@
 static int process_store_rules(struct stream *s, struct channel *rep, int an_bit)
 {
 	struct proxy    *px   = s->be;
+	struct session *sess  = s->sess;
 	struct sticking_rule  *rule;
 	int i;
 	int nbreq = s->store_count;
@@ -1670,7 +1674,7 @@
 			continue;
 
 		if (rule->cond) {
-	                ret = acl_exec_cond(rule->cond, px, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL);
+	                ret = acl_exec_cond(rule->cond, px, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL);
 	                ret = acl_pass(ret);
 			if (rule->cond->pol == ACL_COND_UNLESS)
 				ret = !ret;
@@ -1679,7 +1683,7 @@
 		if (ret) {
 			struct stktable_key *key;
 
-			key = stktable_fetch_key(rule->table.t, px, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->expr, NULL);
+			key = stktable_fetch_key(rule->table.t, px, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->expr, NULL);
 			if (!key)
 				continue;
 
@@ -2899,9 +2903,8 @@
  * multiple tables).
  */
 struct stkctr *
-smp_fetch_sc_stkctr(struct stream *l4, const struct arg *args, const char *kw)
+smp_fetch_sc_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw)
 {
-	struct session *sess = strm_sess(l4);
 	static struct stkctr stkctr;
 	struct stksess *stksess;
 	unsigned int num = kw[2] - '0';
@@ -2933,7 +2936,7 @@
 	 * the sc[0-9]_ form, or even higher using sc_(num) if needed.
 	 * args[arg] is the first optional argument.
 	 */
-	stksess = stkctr_entry(&l4->stkctr[num]);
+	stksess = stkctr_entry(&strm->stkctr[num]);
 	if (!stksess)
 		return NULL;
 
@@ -2943,7 +2946,7 @@
 		stkctr_set_entry(&stkctr, stktable_lookup(stkctr.table, stksess));
 		return &stkctr;
 	}
-	return &l4->stkctr[num];
+	return &strm->stkctr[num];
 }
 
 /* set return a boolean indicating if the requested stream counter is
@@ -2951,12 +2954,12 @@
  * Supports being called as "sc[0-9]_tracked" only.
  */
 static int
-smp_fetch_sc_tracked(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_tracked(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                      const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
 	smp->flags = SMP_F_VOL_TEST;
 	smp->type = SMP_T_BOOL;
-	smp->data.uint = !!smp_fetch_sc_stkctr(strm, args, kw);
+	smp->data.uint = !!smp_fetch_sc_stkctr(sess, strm, args, kw);
 	return 1;
 }
 
@@ -2966,10 +2969,10 @@
  * zero is returned if the key is new.
  */
 static int
-smp_fetch_sc_get_gpc0(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_get_gpc0(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                       const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -2993,10 +2996,10 @@
  * Value zero is returned if the key is new.
  */
 static int
-smp_fetch_sc_gpc0_rate(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_gpc0_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                        const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3019,10 +3022,10 @@
  * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only.
  */
 static int
-smp_fetch_sc_inc_gpc0(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_inc_gpc0(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                       const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3056,10 +3059,10 @@
  * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only.
  */
 static int
-smp_fetch_sc_clr_gpc0(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_clr_gpc0(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                       const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3082,10 +3085,10 @@
  * "src_conn_cnt" only.
  */
 static int
-smp_fetch_sc_conn_cnt(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_conn_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                       const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3107,10 +3110,10 @@
  * only.
  */
 static int
-smp_fetch_sc_conn_rate(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_conn_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                        const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3133,10 +3136,9 @@
  * Accepts exactly 1 argument of type table.
  */
 static int
-smp_fetch_src_updt_conn_cnt(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_src_updt_conn_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                             const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct session *sess = strm_sess(strm);
 	struct connection *conn = objt_conn(sess->origin);
 	struct stksess *ts;
 	struct stktable_key *key;
@@ -3170,10 +3172,10 @@
  * "src_conn_cur" only.
  */
 static int
-smp_fetch_sc_conn_cur(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_conn_cur(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                       const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3195,10 +3197,10 @@
  * "src_sess_cnt" only.
  */
 static int
-smp_fetch_sc_sess_cnt(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_sess_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                       const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3219,10 +3221,10 @@
  * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only.
  */
 static int
-smp_fetch_sc_sess_rate(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_sess_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                        const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3245,10 +3247,10 @@
  * "src_http_req_cnt" only.
  */
 static int
-smp_fetch_sc_http_req_cnt(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_http_req_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                           const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3270,10 +3272,10 @@
  * "src_http_req_rate" only.
  */
 static int
-smp_fetch_sc_http_req_rate(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_http_req_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                            const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3296,10 +3298,10 @@
  * "src_http_err_cnt" only.
  */
 static int
-smp_fetch_sc_http_err_cnt(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_http_err_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                           const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3321,10 +3323,10 @@
  * "src_http_err_rate" only.
  */
 static int
-smp_fetch_sc_http_err_rate(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_http_err_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                            const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3347,10 +3349,10 @@
  * "sc[0-9]_kbytes_in" or "src_kbytes_in" only.
  */
 static int
-smp_fetch_sc_kbytes_in(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_kbytes_in(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                        const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3372,10 +3374,10 @@
  * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only.
  */
 static int
-smp_fetch_sc_bytes_in_rate(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_bytes_in_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                            const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3398,10 +3400,10 @@
  * "sc[0-9]_kbytes_out" or "src_kbytes_out" only.
  */
 static int
-smp_fetch_sc_kbytes_out(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_kbytes_out(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                         const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3423,10 +3425,10 @@
  * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only.
  */
 static int
-smp_fetch_sc_bytes_out_rate(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_bytes_out_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                             const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3448,10 +3450,10 @@
  * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only.
  */
 static int
-smp_fetch_sc_trackers(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_sc_trackers(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                        const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct stkctr *stkctr = smp_fetch_sc_stkctr(strm, args, kw);
+	struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw);
 
 	if (!stkctr)
 		return 0;
@@ -3466,7 +3468,7 @@
  * Accepts exactly 1 argument of type table.
  */
 static int
-smp_fetch_table_cnt(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_table_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                     const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
 	smp->flags = SMP_F_VOL_TEST;
@@ -3479,7 +3481,7 @@
  * Accepts exactly 1 argument of type table.
  */
 static int
-smp_fetch_table_avl(struct proxy *px, struct stream *strm, unsigned int opt,
+smp_fetch_table_avl(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt,
                     const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
 	px = args->data.prx;