BUG/MEDIUM: lua: sample fetches based on response doesn't work

The direction (request or response) is not propagated in the
sample fecthes called throught Lua. This patch adds the direction
status in some structs (hlua_txn and hlua_smp) to make sure that
the sample fetches will be called with all the information.

The converters can not access to a TXN object, so there are not
impacted the direction. However, the samples used as input of the
Lua converter wrapper are initiliazed with the direction. Thereby,
the struct smp stay consistent.
[wt: needs to be backported to 1.6]
diff --git a/include/types/hlua.h b/include/types/hlua.h
index 48f7487..a9b6498 100644
--- a/include/types/hlua.h
+++ b/include/types/hlua.h
@@ -100,6 +100,7 @@
 struct hlua_txn {
 	struct stream *s;
 	struct proxy *p;
+	int dir;                /* SMP_OPT_DIR_{REQ,RES} */
 };
 
 /* This struct contains the applet context. */
@@ -114,6 +115,7 @@
 	struct stream *s;
 	struct proxy *p;
 	int stringsafe;
+	int dir;                /* SMP_OPT_DIR_{REQ,RES} */
 };
 
 /* This struct contains data used with sleep functions. */
diff --git a/src/hlua.c b/src/hlua.c
index 016aead..8fc85a6 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2979,6 +2979,7 @@
 
 	hsmp->s = txn->s;
 	hsmp->p = txn->p;
+	hsmp->dir = txn->dir;
 	hsmp->stringsafe = stringsafe;
 
 	/* Pop a class sesison metatable and affect it to the userdata. */
@@ -3032,7 +3033,7 @@
 	smp.px = hsmp->p;
 	smp.sess = hsmp->s->sess;
 	smp.strm = hsmp->s;
-	smp.opt = 0;
+	smp.opt = hsmp->dir & SMP_OPT_DIR;
 	if (!f->process(args, &smp, f->kw, f->private)) {
 		if (hsmp->stringsafe)
 			lua_pushstring(L, "");
@@ -3086,6 +3087,7 @@
 
 	hsmp->s = txn->s;
 	hsmp->p = txn->p;
+	hsmp->dir = txn->dir;
 	hsmp->stringsafe = stringsafe;
 
 	/* Pop a class stream metatable and affect it to the table. */
@@ -3154,7 +3156,7 @@
 	smp.px = hsmp->p;
 	smp.sess = hsmp->s->sess;
 	smp.strm = hsmp->s;
-	smp.opt = 0;
+	smp.opt = hsmp->dir & SMP_OPT_DIR;
 	if (!conv->process(args, &smp, conv->private)) {
 		if (hsmp->stringsafe)
 			lua_pushstring(L, "");
@@ -4591,7 +4593,7 @@
  * return 0 if the stack does not contains free slots,
  * otherwise it returns 1.
  */
-static int hlua_txn_new(lua_State *L, struct stream *s, struct proxy *p)
+static int hlua_txn_new(lua_State *L, struct stream *s, struct proxy *p, int dir)
 {
 	struct hlua_txn *htxn;
 
@@ -4610,6 +4612,7 @@
 
 	htxn->s = s;
 	htxn->p = p;
+	htxn->dir = dir;
 
 	/* Create the "f" field that contains a list of fetches. */
 	lua_pushstring(L, "f");
@@ -5241,7 +5244,7 @@
 		lua_rawgeti(stream->hlua.T, LUA_REGISTRYINDEX, fcn->function_ref);
 
 		/* push arguments in the stack. */
-		if (!hlua_txn_new(stream->hlua.T, stream, smp->px)) {
+		if (!hlua_txn_new(stream->hlua.T, stream, smp->px, smp->opt & SMP_OPT_DIR)) {
 			SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
 			RESET_SAFE_LJMP(stream->hlua.T);
 			return 0;
@@ -5482,7 +5485,7 @@
 		lua_rawgeti(s->hlua.T, LUA_REGISTRYINDEX, rule->arg.hlua_rule->fcn.function_ref);
 
 		/* Create and and push object stream in the stack. */
-		if (!hlua_txn_new(s->hlua.T, s, px)) {
+		if (!hlua_txn_new(s->hlua.T, s, px, dir)) {
 			SEND_ERR(px, "Lua function '%s': full stack.\n",
 			         rule->arg.hlua_rule->fcn.name);
 			RESET_SAFE_LJMP(s->hlua.T);