*/
static lua_State *hlua_states[MAX_THREADS + 1];
+#define HLUA_FLT_CTX_FL_PAYLOAD 0x00000001
+
struct hlua_reg_filter {
char *name;
int flt_ref[MAX_THREADS + 1];
DECLARE_STATIC_POOL(pool_head_hlua_flt_ctx, "hlua_flt_ctx", sizeof(struct hlua_flt_ctx));
+static int hlua_filter_from_payload(struct filter *filter);
+
/* This is the chained list of struct hlua_flt referenced
* for haproxy filters. It is used for a post-initialisation control.
*/
return 1;
}
+/* Helper function returning a filter attached to a channel at the position <ud>
+ * in the stack, filling the current offset and length of the filter. If no
+ * filter is attached, NULL is returned and <offet> and <len> are not
+ * initialized.
+ */
+static __maybe_unused struct filter *hlua_channel_filter(lua_State *L, int ud, struct channel *chn, size_t *offset, size_t *len)
+{
+ struct filter *filter = NULL;
+
+ if (lua_getfield(L, ud, "__filter") == LUA_TLIGHTUSERDATA) {
+ struct hlua_flt_ctx *flt_ctx;
+
+ filter = lua_touserdata (L, -1);
+ flt_ctx = filter->ctx;
+ if (hlua_filter_from_payload(filter)) {
+ *offset = flt_ctx->cur_off[CHN_IDX(chn)];
+ *len = flt_ctx->cur_len[CHN_IDX(chn)];
+ }
+ }
+
+ lua_pop(L, 1);
+ return filter;
+}
+
/* Copies <len> bytes of data present in the channel's buffer, starting at the
* offset <offset>, and put it in a LUA string variable. It is the caller
* responsibility to ensure <len> and <offset> are valid. It always return the
filter->ctx = NULL;
}
+static int hlua_filter_from_payload(struct filter *filter)
+{
+ struct hlua_flt_ctx *flt_ctx = filter->ctx;
+
+ return (flt_ctx && !!(flt_ctx->flags & HLUA_FLT_CTX_FL_PAYLOAD));
+}
+
static int hlua_filter_parse_fct(char **args, int *cur_arg, struct proxy *px,
struct flt_conf *fconf, char **err, void *private)
{