]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: add a new helper to initialize the owner of a sample
authorWilly Tarreau <w@1wt.eu>
Thu, 10 Mar 2016 15:15:46 +0000 (16:15 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 10 Mar 2016 15:42:58 +0000 (16:42 +0100)
Since commit 6879ad3 ("MEDIUM: sample: fill the struct sample with the
session, proxy and stream pointers") merged in 1.6-dev2, the sample
contains the pointer to the stream and sample fetch functions as well
as converters use it heavily. This requires from a lot of call places
to initialize 4 fields, and it was even forgotten at a few places.

This patch provides a convenient helper to initialize all these fields
at once, making it easy to prepare a new sample from a previous one for
example.

A few call places were cleaned up to make use of it. It will be needed
by further fixes.

At one place in the Lua code, it was moved earlier because we used to
call sample casts with a non completely initialized sample, which is
not clean eventhough at the moment there are no consequences.

include/proto/sample.h
src/hlua.c
src/sample.c

index bcdd23baac242fb2af6ceedbc11929db26fc7ade..268e7a0d2b12fe355f594187a3b5670b97b065db 100644 (file)
@@ -63,4 +63,15 @@ int sample_convert(struct sample *sample, int req_type)
        return sample_casts[sample->data.type][req_type](sample);
 }
 
+static inline
+struct sample *smp_set_owner(struct sample *smp, struct proxy *px,
+                             struct session *sess, struct stream *strm, int opt)
+{
+       smp->px   = px;
+       smp->sess = sess;
+       smp->strm = strm;
+       smp->opt  = opt;
+       return smp;
+}
+
 #endif /* _PROTO_SAMPLE_H */
index 9291517b129c2edfa7a6be202492ef7ff65de115..2ed6f525d7f301c516b0335b1c0d39e71a351322 100644 (file)
@@ -3011,10 +3011,7 @@ __LJMP static int hlua_run_sample_fetch(lua_State *L)
        memset(&smp, 0, sizeof(smp));
 
        /* Run the sample fetch process. */
-       smp.px = hsmp->p;
-       smp.sess = hsmp->s->sess;
-       smp.strm = hsmp->s;
-       smp.opt = hsmp->dir & SMP_OPT_DIR;
+       smp_set_owner(&smp, hsmp->p, hsmp->s->sess, hsmp->s, hsmp->dir & SMP_OPT_DIR);
        if (!f->process(args, &smp, f->kw, f->private)) {
                if (hsmp->flags & HLUA_F_AS_STRING)
                        lua_pushstring(L, "");
@@ -3121,6 +3118,8 @@ __LJMP static int hlua_run_sample_conv(lua_State *L)
                WILL_LJMP(lua_error(L));
        }
 
+       smp_set_owner(&smp, hsmp->p, hsmp->s->sess, hsmp->s, hsmp->dir & SMP_OPT_DIR);
+
        /* Apply expected cast. */
        if (!sample_casts[smp.data.type][conv->in_type]) {
                hlua_pusherror(L, "invalid input argument: cannot cast '%s' to '%s'",
@@ -3134,10 +3133,6 @@ __LJMP static int hlua_run_sample_conv(lua_State *L)
        }
 
        /* Run the sample conversion process. */
-       smp.px = hsmp->p;
-       smp.sess = hsmp->s->sess;
-       smp.strm = hsmp->s;
-       smp.opt = hsmp->dir & SMP_OPT_DIR;
        if (!conv->process(args, &smp, conv->private)) {
                if (hsmp->flags & HLUA_F_AS_STRING)
                        lua_pushstring(L, "");
index 5a79955bcb8a235c447d0068a60ccd4afcc0df48..7c2d9058f00035f87785b151586140bd0bafbe2f 100644 (file)
@@ -1040,10 +1040,7 @@ struct sample *sample_process(struct proxy *px, struct session *sess,
                memset(p, 0, sizeof(*p));
        }
 
-       p->px   = px;
-       p->sess = sess;
-       p->strm = strm;
-       p->opt  = opt;
+       smp_set_owner(p, px, sess, strm, opt);
        if (!expr->fetch->process(expr->arg_p, p, expr->fetch->kw, expr->fetch->private))
                return NULL;