From 2f3c4d1b6c34f11b66dec682712ff32ac6b84818 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 22 Jul 2024 18:57:00 +0200 Subject: [PATCH] MINOR: spoe: export the list of SPOP error reasons The strings representing the human-readable version for SPOP errors are now exported. It is now an array of IST to ease manipulation. --- include/haproxy/spoe.h | 1 + src/mux_spop.c | 37 ++++++++++++++++++------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/haproxy/spoe.h b/include/haproxy/spoe.h index 37f00ef68..585b8bff9 100644 --- a/include/haproxy/spoe.h +++ b/include/haproxy/spoe.h @@ -29,6 +29,7 @@ struct appctx; +extern const struct ist spop_err_reasons[SPOP_ERR_ENTRIES]; extern const struct spop_version spop_supported_versions[]; struct spoe_agent *spoe_appctx_agent(struct appctx *appctx); diff --git a/src/mux_spop.c b/src/mux_spop.c index e660f4733..8147e711e 100644 --- a/src/mux_spop.c +++ b/src/mux_spop.c @@ -213,22 +213,22 @@ DECLARE_STATIC_POOL(pool_head_spop_conn, "spop_conn", sizeof(struct spop_conn)); DECLARE_STATIC_POOL(pool_head_spop_strm, "spop_strm", sizeof(struct spop_strm)); -const char *spop_err_reasons[SPOP_ERR_ENTRIES] = { - [SPOP_ERR_NONE] = "normal", - [SPOP_ERR_IO] = "I/O error", - [SPOP_ERR_TOUT] = "a timeout occurred", - [SPOP_ERR_TOO_BIG] = "frame is too big", - [SPOP_ERR_INVALID] = "invalid frame received", - [SPOP_ERR_NO_VSN] = "version value not found", - [SPOP_ERR_NO_FRAME_SIZE] = "max-frame-size value not found", - [SPOP_ERR_NO_CAP] = "capabilities value not found", - [SPOP_ERR_BAD_VSN] = "unsupported version", - [SPOP_ERR_BAD_FRAME_SIZE] = "max-frame-size too big or too small", - [SPOP_ERR_FRAG_NOT_SUPPORTED] = "fragmentation not supported", - [SPOP_ERR_INTERLACED_FRAMES] = "invalid interlaced frames", - [SPOP_ERR_FRAMEID_NOTFOUND] = "frame-id not found", - [SPOP_ERR_RES] = "resource allocation error", - [SPOP_ERR_UNKNOWN] = "an unknown error occurred", +const struct ist spop_err_reasons[SPOP_ERR_ENTRIES] = { + [SPOP_ERR_NONE] = IST("normal"), + [SPOP_ERR_IO] = IST("I/O error"), + [SPOP_ERR_TOUT] = IST("a timeout occurred"), + [SPOP_ERR_TOO_BIG] = IST("frame is too big"), + [SPOP_ERR_INVALID] = IST("invalid frame received"), + [SPOP_ERR_NO_VSN] = IST("version value not found"), + [SPOP_ERR_NO_FRAME_SIZE] = IST("max-frame-size value not found"), + [SPOP_ERR_NO_CAP] = IST("capabilities value not found"), + [SPOP_ERR_BAD_VSN] = IST("unsupported version"), + [SPOP_ERR_BAD_FRAME_SIZE] = IST("max-frame-size too big or too small"), + [SPOP_ERR_FRAG_NOT_SUPPORTED] = IST("fragmentation not supported"), + [SPOP_ERR_INTERLACED_FRAMES] = IST("invalid interlaced frames"), + [SPOP_ERR_FRAMEID_NOTFOUND] = IST("frame-id not found"), + [SPOP_ERR_RES] = IST("resource allocation error"), + [SPOP_ERR_UNKNOWN] = IST("an unknown error occurred"), }; @@ -1463,7 +1463,7 @@ static int spop_conn_send_hello(struct spop_conn *spop_conn) */ static int spop_conn_send_disconnect(struct spop_conn *spop_conn) { - const char *reason; + struct ist reason; struct buffer outbuf; struct buffer *mbuf; char *p, *end; @@ -1519,8 +1519,7 @@ static int spop_conn_send_disconnect(struct spop_conn *spop_conn) reason = spop_err_reasons[spop_conn->errcode]; *p++ = SPOP_DATA_T_STR; - sz = strlen(reason); - if (spoe_encode_buffer(reason, sz, &p, end) == -1) + if (spoe_encode_buffer(istptr(reason), istlen(reason), &p, end) == -1) goto full; outbuf.data += p - b_tail(&outbuf);