1 commit 72fdff1fdb5b82685dc3d2db23ece042195a0cbd
2 Author: Christopher Faulet <cfaulet@haproxy.com>
3 Date: Fri Apr 26 14:30:15 2019 +0200
5 MINOR: spoe: Use the sample context to pass frag_ctx info during encoding
7 This simplifies the API and hide the details in the sample. This way, only
8 string and binary are aware of these info, because other types cannot be
11 This patch may be backported to 1.9 and 1.8.
13 (cherry picked from commit 85db3212b87b33f1a39a688546f4f53a5c4ba4da)
14 Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
15 (cherry picked from commit b93366e3ee44f5de93f01569fcdcd602f6d0703f)
16 Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
18 diff --git a/include/proto/spoe.h b/include/proto/spoe.h
19 index 2cdca10b..cce13e50 100644
20 --- a/include/proto/spoe.h
21 +++ b/include/proto/spoe.h
22 @@ -117,11 +117,9 @@ spoe_decode_buffer(char **buf, char *end, char **str, uint64_t *len)
24 * If the value is too big to be encoded, depending on its type, then encoding
25 * failed or the value is partially encoded. Only strings and binaries can be
26 - * partially encoded. In this case, the offset <*off> is updated to known how
27 - * many bytes has been encoded. If <*off> is zero at the end, it means that all
28 - * data has been encoded. */
29 + * partially encoded. */
31 -spoe_encode_data(unsigned int *len, struct sample *smp, unsigned int *off, char **buf, char *end)
32 +spoe_encode_data(struct sample *smp, char **buf, char *end)
36 @@ -164,12 +162,16 @@ spoe_encode_data(unsigned int *len, struct sample *smp, unsigned int *off, char
40 + /* If defined, get length and offset of the sample by reading the sample
41 + * context. ctx.a[0] is the pointer to the length and ctx.a[1] is the
42 + * pointer to the offset. If the offset is greater than 0, it means the
43 + * sample is partially encoded. In this case, we only need to encode the
44 + * reamining. When all the sample is encoded, the offset is reset to 0.
45 + * So the caller know it can try to encode the next sample. */
46 struct chunk *chk = &smp->data.u.str;
47 + unsigned int *len = (smp->ctx.a[0] ? smp->ctx.a[0] : 0);
48 + unsigned int *off = (smp->ctx.a[1] ? smp->ctx.a[1] : 0);
50 - /* Here, we need to know if the sample has already been
51 - * partially encoded. If yes, we only need to encode the
52 - * remaining, <*off> reprensenting the number of bytes
53 - * already encoded. */
55 /* First evaluation of the sample : encode the
56 * type (string or binary), the buffer length
57 diff --git a/src/flt_spoe.c b/src/flt_spoe.c
58 index 0c0b3794..66d8b045 100644
61 @@ -2187,7 +2187,9 @@ spoe_encode_message(struct stream *s, struct spoe_context *ctx,
63 /* Fetch the arguement value */
64 smp = sample_process(s->be, s->sess, s, dir|SMP_OPT_FINAL, arg->expr, NULL);
65 - ret = spoe_encode_data(&ctx->frag_ctx.curlen, smp, &ctx->frag_ctx.curoff, buf, end);
66 + smp->ctx.a[0] = &ctx->frag_ctx.curlen;
67 + smp->ctx.a[1] = &ctx->frag_ctx.curoff;
68 + ret = spoe_encode_data(smp, buf, end);
69 if (ret == -1 || ctx->frag_ctx.curoff)