MINOR: proxy: Make `header_unique_id` a `struct ist`
authorTim Duesterhus <tim@bastelstu.be>
Thu, 5 Mar 2020 16:56:35 +0000 (17:56 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 5 Mar 2020 18:58:22 +0000 (19:58 +0100)
The `header_unique_id` member of `struct proxy` now is a `struct ist`.

include/types/proxy.h
src/cfgparse-listen.c
src/http_ana.c

index f3b0e6b..b64d448 100644 (file)
@@ -405,7 +405,7 @@ struct proxy {
        struct list logformat;                  /* log_format linked list */
        struct list logformat_sd;               /* log_format linked list for the RFC5424 structured-data part */
        struct buffer log_tag;                   /* override default syslog tag */
-       char *header_unique_id;                 /* unique-id header */
+       struct ist header_unique_id;            /* unique-id header */
        struct list format_unique_id;           /* unique-id format */
        int to_log;                             /* things to be logged (LW_*) */
        int stop_time;                          /* date to stop listening, when stopping != 0 (int ticks) */
index bd22752..5079800 100644 (file)
@@ -429,8 +429,15 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                }
 
                /* copy default header unique id */
-               if (defproxy.header_unique_id)
-                       curproxy->header_unique_id = strdup(defproxy.header_unique_id);
+               if (isttest(defproxy.header_unique_id)) {
+                       const struct ist copy = istdup(defproxy.header_unique_id);
+                       if (!isttest(copy)) {
+                               ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
+                       curproxy->header_unique_id = copy;
+               }
 
                /* default compression options */
                if (defproxy.comp != NULL) {
@@ -3484,13 +3491,21 @@ stats_error_parsing:
        }
 
        else if (strcmp(args[0], "unique-id-header") == 0) {
+               char *copy;
                if (!*(args[1])) {
                        ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }
-               free(curproxy->header_unique_id);
-               curproxy->header_unique_id = strdup(args[1]);
+               copy = strdup(args[1]);
+               if (copy == NULL) {
+                       ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
+
+               istfree(&curproxy->header_unique_id);
+               curproxy->header_unique_id = ist(copy);
        }
 
        else if (strcmp(args[0], "log-format") == 0) {
index a970660..010b170 100644 (file)
@@ -802,14 +802,9 @@ int http_process_request(struct stream *s, struct channel *req, int an_bit)
                }
 
                /* send unique ID if a "unique-id-header" is defined */
-               if (sess->fe->header_unique_id) {
-                       struct ist n, v;
-                       n = ist2(sess->fe->header_unique_id, strlen(sess->fe->header_unique_id));
-                       v = ist2(s->unique_id, length);
-
-                       if (unlikely(!http_add_header(htx, n, v)))
+               if (isttest(sess->fe->header_unique_id) &&
+                   !http_add_header(htx, sess->fe->header_unique_id, ist2(s->unique_id, length)))
                                goto return_int_err;
-               }
        }
 
        /*