CLEANUP: http-htx: Rename http_error structure into http_error_msg

The structure owns an error message, most of time loaded from a file, and
converted to HTX. It is created when an errorfile or errorloc directive is
parsed. It is renamed to avoid ambiguities with http_reply structure.
This commit is contained in:
Christopher Faulet 2020-05-13 21:45:22 +02:00
parent 7bd3de06e7
commit b6ea17c6fc
2 changed files with 35 additions and 35 deletions

View File

@ -71,7 +71,7 @@ struct http_reply {
/* A custom HTTP error message load from a row file and converted in HTX. The /* A custom HTTP error message load from a row file and converted in HTX. The
* node key is the file path. * node key is the file path.
*/ */
struct http_error { struct http_error_msg {
struct buffer msg; struct buffer msg;
struct ebpt_node node; struct ebpt_node node;
}; };

View File

@ -984,16 +984,16 @@ static void http_htx_deinit(void)
{ {
struct http_errors *http_errs, *http_errsb; struct http_errors *http_errs, *http_errsb;
struct ebpt_node *node, *next; struct ebpt_node *node, *next;
struct http_error *http_err; struct http_error_msg *http_errmsg;
node = ebpt_first(&http_error_messages); node = ebpt_first(&http_error_messages);
while (node) { while (node) {
next = ebpt_next(node); next = ebpt_next(node);
ebpt_delete(node); ebpt_delete(node);
http_err = container_of(node, typeof(*http_err), node); http_errmsg = container_of(node, typeof(*http_errmsg), node);
chunk_destroy(&http_err->msg); chunk_destroy(&http_errmsg->msg);
free(node->key); free(node->key);
free(http_err); free(http_errmsg);
node = next; node = next;
} }
@ -1017,7 +1017,7 @@ struct buffer *http_load_errorfile(const char *file, char **errmsg)
struct buffer *buf = NULL; struct buffer *buf = NULL;
struct buffer chk; struct buffer chk;
struct ebpt_node *node; struct ebpt_node *node;
struct http_error *http_err; struct http_error_msg *http_errmsg;
struct stat stat; struct stat stat;
char *err = NULL; char *err = NULL;
int errnum, errlen; int errnum, errlen;
@ -1026,8 +1026,8 @@ struct buffer *http_load_errorfile(const char *file, char **errmsg)
/* already loaded */ /* already loaded */
node = ebis_lookup_len(&http_error_messages, file, strlen(file)); node = ebis_lookup_len(&http_error_messages, file, strlen(file));
if (node) { if (node) {
http_err = container_of(node, typeof(*http_err), node); http_errmsg = container_of(node, typeof(*http_errmsg), node);
buf = &http_err->msg; buf = &http_errmsg->msg;
goto out; goto out;
} }
@ -1059,30 +1059,30 @@ struct buffer *http_load_errorfile(const char *file, char **errmsg)
} }
/* Create the node corresponding to the error file */ /* Create the node corresponding to the error file */
http_err = calloc(1, sizeof(*http_err)); http_errmsg = calloc(1, sizeof(*http_errmsg));
if (!http_err) { if (!http_errmsg) {
memprintf(errmsg, "out of memory."); memprintf(errmsg, "out of memory.");
goto out; goto out;
} }
http_err->node.key = strdup(file); http_errmsg->node.key = strdup(file);
if (!http_err->node.key) { if (!http_errmsg->node.key) {
memprintf(errmsg, "out of memory."); memprintf(errmsg, "out of memory.");
free(http_err); free(http_errmsg);
goto out; goto out;
} }
/* Convert the error file into an HTX message */ /* Convert the error file into an HTX message */
if (!http_str_to_htx(&chk, ist2(err, errlen))) { if (!http_str_to_htx(&chk, ist2(err, errlen))) {
memprintf(errmsg, "unable to convert custom error message file '%s' in HTX.", file); memprintf(errmsg, "unable to convert custom error message file '%s' in HTX.", file);
free(http_err->node.key); free(http_errmsg->node.key);
free(http_err); free(http_errmsg);
goto out; goto out;
} }
/* Insert the node in the tree and return the HTX message */ /* Insert the node in the tree and return the HTX message */
http_err->msg = chk; http_errmsg->msg = chk;
ebis_insert(&http_error_messages, &http_err->node); ebis_insert(&http_error_messages, &http_errmsg->node);
buf = &http_err->msg; buf = &http_errmsg->msg;
out: out:
if (fd >= 0) if (fd >= 0)
@ -1100,40 +1100,40 @@ struct buffer *http_load_errormsg(const char *key, const struct ist msg, char **
struct buffer *buf = NULL; struct buffer *buf = NULL;
struct buffer chk; struct buffer chk;
struct ebpt_node *node; struct ebpt_node *node;
struct http_error *http_err; struct http_error_msg *http_errmsg;
/* already loaded */ /* already loaded */
node = ebis_lookup_len(&http_error_messages, key, strlen(key)); node = ebis_lookup_len(&http_error_messages, key, strlen(key));
if (node) { if (node) {
http_err = container_of(node, typeof(*http_err), node); http_errmsg = container_of(node, typeof(*http_errmsg), node);
buf = &http_err->msg; buf = &http_errmsg->msg;
goto out; goto out;
} }
/* Create the node corresponding to the error file */ /* Create the node corresponding to the error file */
http_err = calloc(1, sizeof(*http_err)); http_errmsg = calloc(1, sizeof(*http_errmsg));
if (!http_err) { if (!http_errmsg) {
memprintf(errmsg, "out of memory."); memprintf(errmsg, "out of memory.");
goto out; goto out;
} }
http_err->node.key = strdup(key); http_errmsg->node.key = strdup(key);
if (!http_err->node.key) { if (!http_errmsg->node.key) {
memprintf(errmsg, "out of memory."); memprintf(errmsg, "out of memory.");
free(http_err); free(http_errmsg);
goto out; goto out;
} }
/* Convert the error file into an HTX message */ /* Convert the error file into an HTX message */
if (!http_str_to_htx(&chk, msg)) { if (!http_str_to_htx(&chk, msg)) {
memprintf(errmsg, "unable to convert message in HTX."); memprintf(errmsg, "unable to convert message in HTX.");
free(http_err->node.key); free(http_errmsg->node.key);
free(http_err); free(http_errmsg);
goto out; goto out;
} }
/* Insert the node in the tree and return the HTX message */ /* Insert the node in the tree and return the HTX message */
http_err->msg = chk; http_errmsg->msg = chk;
ebis_insert(&http_error_messages, &http_err->node); ebis_insert(&http_error_messages, &http_errmsg->node);
buf = &http_err->msg; buf = &http_errmsg->msg;
out: out:
return buf; return buf;
} }
@ -1416,16 +1416,16 @@ static int proxy_check_errors(struct proxy *px)
static int post_check_errors() static int post_check_errors()
{ {
struct ebpt_node *node; struct ebpt_node *node;
struct http_error *http_err; struct http_error_msg *http_errmsg;
struct htx *htx; struct htx *htx;
int err_code = 0; int err_code = 0;
node = ebpt_first(&http_error_messages); node = ebpt_first(&http_error_messages);
while (node) { while (node) {
http_err = container_of(node, typeof(*http_err), node); http_errmsg = container_of(node, typeof(*http_errmsg), node);
if (b_is_null(&http_err->msg)) if (b_is_null(&http_errmsg->msg))
goto next; goto next;
htx = htxbuf(&http_err->msg); htx = htxbuf(&http_errmsg->msg);
if (htx_free_data_space(htx) < global.tune.maxrewrite) { if (htx_free_data_space(htx) < global.tune.maxrewrite) {
ha_warning("config: errorfile '%s' runs over the buffer space" ha_warning("config: errorfile '%s' runs over the buffer space"
" reserved to headers rewritting. It may lead to internal errors if " " reserved to headers rewritting. It may lead to internal errors if "