MINOR: hlua: Add a flag on the lua txn to know in which context it can be used

When a lua action or a lua sample fetch is called, a lua transaction is
created. It is an entry in the stack containing the class TXN. Thanks to it, we
can know the direction (request or response) of the call. But, for some
functions, it is also necessary to know if the buffer is "HTTP ready" for the
given direction. "HTTP ready" means there is a valid HTTP message in the
channel's buffer. So, when a lua action or a lua sample fetch is called, the
flag HLUA_TXN_HTTP_RDY is set if it is appropriate.
This commit is contained in:
Christopher Faulet 2019-07-26 15:09:53 +02:00
parent 51fa358432
commit bfab2dddad
2 changed files with 19 additions and 11 deletions

View File

@ -43,7 +43,8 @@ struct stream;
#define HLUA_F_AS_STRING 0x01
#define HLUA_F_MAY_USE_HTTP 0x02
#define HLUA_TXN_NOTERM 0x00000001
#define HLUA_TXN_NOTERM 0x00000001
#define HLUA_TXN_HTTP_RDY 0x00000002 /* Set if the txn is HTTP ready for the defined direction */
#define HLUA_CONCAT_BLOCSZ 2048

View File

@ -5853,6 +5853,7 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
struct stream *stream = smp->strm;
const char *error;
const struct buffer msg = { };
unsigned int hflags = HLUA_TXN_NOTERM;
if (!stream)
return 0;
@ -5876,6 +5877,13 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
consistency_set(stream, smp->opt, &stream->hlua->cons);
if (stream->be->mode == PR_MODE_HTTP) {
if ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ)
hflags |= ((stream->txn->req.msg_state < HTTP_MSG_BODY) ? 0 : HLUA_TXN_HTTP_RDY);
else
hflags |= ((stream->txn->rsp.msg_state < HTTP_MSG_BODY) ? 0 : HLUA_TXN_HTTP_RDY);
}
/* If it is the first run, initialize the data for the call. */
if (!HLUA_IS_RUNNING(stream->hlua)) {
@ -5900,8 +5908,7 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
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, smp->opt & SMP_OPT_DIR,
HLUA_TXN_NOTERM)) {
if (!hlua_txn_new(stream->hlua->T, stream, smp->px, smp->opt & SMP_OPT_DIR, hflags)) {
SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
RESET_SAFE_LJMP(stream->hlua->T);
return 0;
@ -6118,16 +6125,16 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
struct session *sess, struct stream *s, int flags)
{
char **arg;
unsigned int analyzer;
unsigned int hflags = 0;
int dir;
const char *error;
const struct buffer msg = { };
switch (rule->from) {
case ACT_F_TCP_REQ_CNT: analyzer = AN_REQ_INSPECT_FE ; dir = SMP_OPT_DIR_REQ; break;
case ACT_F_TCP_RES_CNT: analyzer = AN_RES_INSPECT ; dir = SMP_OPT_DIR_RES; break;
case ACT_F_HTTP_REQ: analyzer = AN_REQ_HTTP_PROCESS_FE; dir = SMP_OPT_DIR_REQ; break;
case ACT_F_HTTP_RES: analyzer = AN_RES_HTTP_PROCESS_BE; dir = SMP_OPT_DIR_RES; break;
case ACT_F_TCP_REQ_CNT: ; dir = SMP_OPT_DIR_REQ; break;
case ACT_F_TCP_RES_CNT: ; dir = SMP_OPT_DIR_RES; break;
case ACT_F_HTTP_REQ: hflags = HLUA_TXN_HTTP_RDY ; dir = SMP_OPT_DIR_REQ; break;
case ACT_F_HTTP_RES: hflags = HLUA_TXN_HTTP_RDY ; dir = SMP_OPT_DIR_RES; break;
default:
SEND_ERR(px, "Lua: internal error while execute action.\n");
return ACT_RET_CONT;
@ -6180,7 +6187,7 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
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, dir, 0)) {
if (!hlua_txn_new(s->hlua->T, s, px, dir, hflags)) {
SEND_ERR(px, "Lua function '%s': full stack.\n",
rule->arg.hlua_rule->fcn.name);
RESET_SAFE_LJMP(s->hlua->T);
@ -6223,9 +6230,9 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
case HLUA_E_AGAIN:
/* Set timeout in the required channel. */
if (s->hlua->wake_time != TICK_ETERNITY) {
if (analyzer & (AN_REQ_INSPECT_FE|AN_REQ_HTTP_PROCESS_FE))
if (dir & SMP_OPT_DIR_REQ)
s->req.analyse_exp = s->hlua->wake_time;
else if (analyzer & (AN_RES_INSPECT|AN_RES_HTTP_PROCESS_BE))
else
s->res.analyse_exp = s->hlua->wake_time;
}
/* Some actions can be wake up when a "write" event