You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
3.2 KiB

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