]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: spoe: Add a type to qualify the message list during encoding
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 21 Sep 2017 14:50:56 +0000 (16:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 10:36:12 +0000 (11:36 +0100)
Because we can have messages chained by event or by group, we need to have a way
to know which kind of list we manipulate during the encoding. So 2 types of list
has been added, SPOE_MSGS_BY_EVENT and SPOE_MSGS_BY_GROUP. And the right type is
passed when spoe_encode_messages is called.

include/types/spoe.h
src/flt_spoe.c

index ff649fafc9f8b121f18f9dc39440c829e3113f10..2bfd15947583c3849b838b632d9e3ba747bc6287 100644 (file)
 #include <types/stream.h>
 #include <types/task.h>
 
+/* Type of list of messages */
+#define SPOE_MSGS_BY_EVENT 0x01
+#define SPOE_MSGS_BY_GROUP 0x02
+
 /* Flags set on the SPOE agent */
 #define SPOE_FL_CONT_ON_ERR       0x00000001 /* Do not stop events processing when an error occurred */
 #define SPOE_FL_PIPELINING        0x00000002 /* Set when SPOE agent supports pipelining (set by default) */
index b8bb6ce36e8e34e2e6c5c2b5d7e4baa09dc224f5..d5539c98c2faaeed938586a70c172ae98214f86c 100644 (file)
@@ -2174,13 +2174,13 @@ spoe_encode_message(struct stream *s, struct spoe_context *ctx,
        return -1;
 }
 
-/* Encode SPOE messages for a specific event. Info in <ctx->frag_ctx>, if any,
- * are used to handle fragmented content. On success it returns 1. If an error
- * occurred, -1 is returned. If nothing has been encoded, it returns 0 (this is
- * only possible for unfragmented payload). */
+/* Encode list of SPOE messages. Info in <ctx->frag_ctx>, if any, are used to
+ * handle fragmented content. On success it returns 1. If an error occurred, -1
+ * is returned. If nothing has been encoded, it returns 0 (this is only possible
+ * for unfragmented payload). */
 static int
 spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
-                    struct list *messages, int dir)
+                    struct list *messages, int dir, int type)
 {
        struct spoe_config  *conf = FLT_CONF(ctx->filter);
        struct spoe_agent   *agent = conf->agent;
@@ -2190,22 +2190,43 @@ spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
        p   = ctx->buffer->p;
        end =  p + agent->frame_size - FRAME_HDR_SIZE;
 
-       /* Resume encoding of a SPOE message */
-       if (ctx->frag_ctx.curmsg != NULL) {
-               msg = ctx->frag_ctx.curmsg;
-               goto encode_message;
+       if (type == SPOE_MSGS_BY_EVENT) { /* Loop on messages by event */
+               /* Resume encoding of a SPOE message */
+               if (ctx->frag_ctx.curmsg != NULL) {
+                       msg = ctx->frag_ctx.curmsg;
+                       goto encode_evt_message;
+               }
+
+               list_for_each_entry(msg, messages, by_evt) {
+                       ctx->frag_ctx.curmsg = msg;
+                       ctx->frag_ctx.curarg = NULL;
+                       ctx->frag_ctx.curoff = UINT_MAX;
+
+               encode_evt_message:
+                       if (spoe_encode_message(s, ctx, msg, dir, &p, end) == -1)
+                               goto too_big;
+               }
        }
+       else if (type == SPOE_MSGS_BY_GROUP) { /* Loop on messages by group */
+               /* Resume encoding of a SPOE message */
+               if (ctx->frag_ctx.curmsg != NULL) {
+                       msg = ctx->frag_ctx.curmsg;
+                       goto encode_grp_message;
+               }
 
-       /* Loop on messages */
-       list_for_each_entry(msg, messages, by_evt) {
-               ctx->frag_ctx.curmsg = msg;
-               ctx->frag_ctx.curarg = NULL;
-               ctx->frag_ctx.curoff = UINT_MAX;
+               list_for_each_entry(msg, messages, by_grp) {
+                       ctx->frag_ctx.curmsg = msg;
+                       ctx->frag_ctx.curarg = NULL;
+                       ctx->frag_ctx.curoff = UINT_MAX;
 
-         encode_message:
-               if (spoe_encode_message(s, ctx, msg, dir, &p, end) == -1)
-                       goto too_big;
+               encode_grp_message:
+                       if (spoe_encode_message(s, ctx, msg, dir, &p, end) == -1)
+                               goto too_big;
+               }
        }
+       else
+               goto skip;
+
 
        /* nothing has been encoded for an unfragmented payload */
        if (!(ctx->flags & SPOE_CTX_FL_FRAGMENTED) && p == ctx->buffer->p)
@@ -2544,7 +2565,7 @@ spoe_process_event(struct stream *s, struct spoe_context *ctx,
        if (ctx->state == SPOE_CTX_ST_ENCODING_MSGS) {
                if (!spoe_acquire_buffer(&ctx->buffer, &ctx->buffer_wait))
                        goto out;
-               ret = spoe_encode_messages(s, ctx, &(ctx->events[ev]), dir);
+               ret = spoe_encode_messages(s, ctx, &(ctx->events[ev]), dir, SPOE_MSGS_BY_EVENT);
                if (ret < 0)
                        goto error;
                if (!ret)