]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: sample: fill the struct sample with the session, proxy and stream pointers
authorThierry FOURNIER <tfournier@haproxy.com>
Mon, 11 May 2015 09:54:58 +0000 (11:54 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 11 May 2015 18:00:03 +0000 (20:00 +0200)
Some sample analyzer (sample-fetch or converters) needs to known the proxy,
session and stream attached to the sampel. The sample-fetches and the converters
function pointers cannot be called without these 3 pointers filled.

This patch permits to reduce the sample-fetch and the converters called
prototypes, and provides a new mean to add information for this type of
functions.

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

index daab2a141321c8f4cafafb0153bfabb11c89b57c..4d932c63d995498302c767cc1776ae9266fffdb3 100644 (file)
@@ -243,6 +243,15 @@ struct sample {
                struct meth     meth;  /* used for http method */
        } data;                        /* sample data */
        union smp_ctx ctx;
+
+       /* Some sample analyzer (sample-fetch or converters) needs to
+        * known the attached proxy, session and stream. The sample-fetches
+        * and the converters function pointers cannot be called without
+        * these 3 pointers filled.
+        */
+       struct proxy *px;
+       struct session *sess;
+       struct stream *strm;
 };
 
 /* Used to store sample constant */
index 37fce89edfeac8b8e5a7f9de0b6c0e86b43209a5..d0eb7f50b943323e67786403d25b3ad3c002ab8a 100644 (file)
@@ -2770,6 +2770,9 @@ __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;
        if (!f->process(hsmp->p, hsmp->s->sess, hsmp->s, 0, args, &smp, f->kw, f->private)) {
                if (hsmp->stringsafe)
                        lua_pushstring(L, "");
@@ -2888,6 +2891,9 @@ __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;
        if (!conv->process(hsmp->s, args, &smp, conv->private)) {
                if (hsmp->stringsafe)
                        lua_pushstring(L, "");
index 77192be1de607a399d6d3b883c752140cdf5cf41..53c9d0d3c189558badc284b69b4dba76d21971d5 100644 (file)
@@ -1033,6 +1033,9 @@ struct sample *sample_process(struct proxy *px, struct session *sess,
                memset(p, 0, sizeof(*p));
        }
 
+       p->px   = px;
+       p->sess = sess;
+       p->strm = strm;
        if (!expr->fetch->process(px, sess, strm, opt, expr->arg_p, p, expr->fetch->kw, expr->fetch->private))
                return NULL;