MEDIUM: vars: adds support of variables

This patch adds support of variables during the processing of each stream. The
variables scope can be set as 'session', 'transaction', 'request' or 'response'.
The variable type is the type returned by the assignment expression. The type
can change while the processing.

The allocated memory can be controlled for each scope and each request, and for
the global process.
diff --git a/src/stream.c b/src/stream.c
index 0f9fbe2..0b70e28 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -50,6 +50,7 @@
 #include <proto/stick_table.h>
 #include <proto/stream_interface.h>
 #include <proto/task.h>
+#include <proto/vars.h>
 
 struct pool_head *pool2_stream;
 struct list streams;
@@ -136,6 +137,13 @@
 	s->req_cap = NULL;
 	s->res_cap = NULL;
 
+	/* Initialise alle the variable context even if will not use.
+	 * This permits to prune these context without errors.
+	 */
+	vars_init(&s->vars_sess,   SCOPE_SESS);
+	vars_init(&s->vars_txn,    SCOPE_TXN);
+	vars_init(&s->vars_reqres, SCOPE_REQ);
+
 	/* this part should be common with other protocols */
 	si_reset(&s->si[0]);
 	si_set_state(&s->si[0], SI_ST_EST);
@@ -293,6 +301,11 @@
 		pool_free2(fe->req_cap_pool, s->req_cap);
 	}
 
+	/* Cleanup all variable contexts. */
+	vars_prune(&s->vars_sess, s);
+	vars_prune(&s->vars_txn, s);
+	vars_prune(&s->vars_reqres, s);
+
 	stream_store_counters(s);
 
 	list_for_each_entry_safe(bref, back, &s->back_refs, users) {
@@ -2060,6 +2073,13 @@
 	 * for completion.
 	 */
 	if (si_b->state >= SI_ST_REQ && si_b->state < SI_ST_CON) {
+
+		/* prune the request variables and swap to the response variables. */
+		if (s->vars_reqres.scope != SCOPE_RES) {
+			vars_prune(&s->vars_reqres, s);
+			vars_init(&s->vars_reqres, SCOPE_RES);
+		}
+
 		do {
 			/* nb: step 1 might switch from QUE to ASS, but we first want
 			 * to give a chance to step 2 to perform a redirect if needed.