From 2056736453e1ce47418cdcb007db1dbdf603761e Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Fri, 15 May 2020 14:52:49 +0200 Subject: [PATCH] MINOR: htx: Add a function to copy a buffer in an HTX message The htx_copy_msg() function can now be used to copy the HTX message stored in a buffer in an existing HTX message. It takes care to not overwrite existing data. If the destination message is empty, a raw copy is performed. All the message is copied or nothing. This function is used instead of channel_htx_copy_msg(). --- include/common/htx.h | 16 ++++++++++++++++ src/http_ana.c | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/common/htx.h b/include/common/htx.h index 7bd12b407..3d54c4a0f 100644 --- a/include/common/htx.h +++ b/include/common/htx.h @@ -780,6 +780,22 @@ static inline int htx_is_not_empty(const struct htx *htx) return (htx->head != -1); } +/* Copy an HTX message stored in the buffer to . We take care to + * not overwrite existing data. All the message is copied or nothing. It returns + * 1 on success and 0 on error. + */ +static inline int htx_copy_msg(struct htx *htx, const struct buffer *msg) +{ + /* The destination HTX message is empty, we can do a raw copy */ + if (htx_is_empty(htx)) { + memcpy(htx, msg->area, msg->size); + return 1; + } + + /* Otherwise, we need to append the HTX message */ + return htx_append_msg(htx, htxbuf(msg)); +} + /* Returns the number of used blocks in the HTX message . Note that it is * illegal to call this function with htx == NULL. Note also blocks of type * HTX_BLK_UNUSED are part of used blocks. diff --git a/src/http_ana.c b/src/http_ana.c index 138c0291c..c93edfea7 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -4700,7 +4700,7 @@ int http_reply_message(struct stream *s, struct http_reply *reply) /* implicit or explicit error message*/ errmsg = reply->body.errmsg; if (errmsg && !b_is_null(errmsg)) { - if (!channel_htx_copy_msg(res, htx, errmsg)) + if (!htx_copy_msg(htx, errmsg)) goto fail; } }