mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-29 23:01:03 +01:00
MINOR: spoe: Add a type to qualify the message list during encoding
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.
This commit is contained in:
parent
10e376727a
commit
c718b82dfe
@ -32,6 +32,10 @@
|
|||||||
#include <types/stream.h>
|
#include <types/stream.h>
|
||||||
#include <types/task.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 */
|
/* 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_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) */
|
#define SPOE_FL_PIPELINING 0x00000002 /* Set when SPOE agent supports pipelining (set by default) */
|
||||||
|
|||||||
@ -2174,13 +2174,13 @@ spoe_encode_message(struct stream *s, struct spoe_context *ctx,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Encode SPOE messages for a specific event. Info in <ctx->frag_ctx>, if any,
|
/* Encode list of SPOE messages. Info in <ctx->frag_ctx>, if any, are used to
|
||||||
* are used to handle fragmented content. On success it returns 1. If an error
|
* handle fragmented content. On success it returns 1. If an error occurred, -1
|
||||||
* occurred, -1 is returned. If nothing has been encoded, it returns 0 (this is
|
* is returned. If nothing has been encoded, it returns 0 (this is only possible
|
||||||
* only possible for unfragmented payload). */
|
* for unfragmented payload). */
|
||||||
static int
|
static int
|
||||||
spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
|
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_config *conf = FLT_CONF(ctx->filter);
|
||||||
struct spoe_agent *agent = conf->agent;
|
struct spoe_agent *agent = conf->agent;
|
||||||
@ -2190,22 +2190,43 @@ spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
|
|||||||
p = ctx->buffer->p;
|
p = ctx->buffer->p;
|
||||||
end = p + agent->frame_size - FRAME_HDR_SIZE;
|
end = p + agent->frame_size - FRAME_HDR_SIZE;
|
||||||
|
|
||||||
/* Resume encoding of a SPOE message */
|
if (type == SPOE_MSGS_BY_EVENT) { /* Loop on messages by event */
|
||||||
if (ctx->frag_ctx.curmsg != NULL) {
|
/* Resume encoding of a SPOE message */
|
||||||
msg = ctx->frag_ctx.curmsg;
|
if (ctx->frag_ctx.curmsg != NULL) {
|
||||||
goto encode_message;
|
msg = ctx->frag_ctx.curmsg;
|
||||||
}
|
goto encode_evt_message;
|
||||||
|
}
|
||||||
|
|
||||||
/* Loop on messages */
|
list_for_each_entry(msg, messages, by_evt) {
|
||||||
list_for_each_entry(msg, messages, by_evt) {
|
ctx->frag_ctx.curmsg = msg;
|
||||||
ctx->frag_ctx.curmsg = msg;
|
ctx->frag_ctx.curarg = NULL;
|
||||||
ctx->frag_ctx.curarg = NULL;
|
ctx->frag_ctx.curoff = UINT_MAX;
|
||||||
ctx->frag_ctx.curoff = UINT_MAX;
|
|
||||||
|
|
||||||
encode_message:
|
encode_evt_message:
|
||||||
if (spoe_encode_message(s, ctx, msg, dir, &p, end) == -1)
|
if (spoe_encode_message(s, ctx, msg, dir, &p, end) == -1)
|
||||||
goto too_big;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_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 */
|
/* nothing has been encoded for an unfragmented payload */
|
||||||
if (!(ctx->flags & SPOE_CTX_FL_FRAGMENTED) && p == ctx->buffer->p)
|
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 (ctx->state == SPOE_CTX_ST_ENCODING_MSGS) {
|
||||||
if (!spoe_acquire_buffer(&ctx->buffer, &ctx->buffer_wait))
|
if (!spoe_acquire_buffer(&ctx->buffer, &ctx->buffer_wait))
|
||||||
goto out;
|
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)
|
if (ret < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (!ret)
|
if (!ret)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user