]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: configuration: File and line propagation
authorThierry FOURNIER <tfournier@exceliance.fr>
Tue, 11 Feb 2014 13:00:19 +0000 (14:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 17 Mar 2014 17:06:08 +0000 (18:06 +0100)
This patch permits to communicate file and line of the
configuration file at the configuration parser.

12 files changed:
include/proto/log.h
include/proto/pattern.h
include/proto/sample.h
include/types/sample.h
src/acl.c
src/cfgparse.c
src/log.c
src/map.c
src/pattern.c
src/proto_http.c
src/proto_tcp.c
src/sample.c

index 86b41856252e8fb24761ba6f5b6075ae92f6ab0b..e3c1a75ebc71aa46683025914af745a21658a9fa 100644 (file)
@@ -70,7 +70,7 @@ void add_to_logformat_list(char *start, char *end, int type, struct list *list_f
  * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
  * You can set arguments using { } : %{many arguments}varname
  */
-void parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap);
+void parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap, const char *file, int line);
 /*
  * Displays the message on stderr with the date and pid. Overrides the quiet
  * mode during startup.
index e9269e4ebbef1e3be1bb80b7cef1a3009dc6fbef..4b5afe1207dcb2f1a1079b800044cd7eb04beae2 100644 (file)
@@ -186,7 +186,7 @@ int pat_ref_load(struct pat_ref *ref, struct pattern_expr *expr, int patflags, i
  */
 void pattern_init_head(struct pattern_head *head);
 void pattern_prune(struct pattern_head *head);
-int pattern_read_from_file(struct pattern_head *head, unsigned int refflags, const char *filename, int patflags, int load_smp, char **err, const char *display);
+int pattern_read_from_file(struct pattern_head *head, unsigned int refflags, const char *filename, int patflags, int load_smp, char **err, const char *display, const char *file, int line);
 
 /*
  * pattern_expr manipulation.
index d78e82dd763012d2c53be0223825d976365c89cd..6b76662589c781bc8feaf602b3107ec22037d13c 100644 (file)
@@ -28,7 +28,7 @@
 
 extern const char *smp_to_type[SMP_TYPES];
 
-struct sample_expr *sample_parse_expr(char **str, int *idx, char **err, struct arg_list *al);
+struct sample_expr *sample_parse_expr(char **str, int *idx, const char *file, int line, char **err, struct arg_list *al);
 struct sample_conv *find_sample_conv(const char *kw, int len);
 struct sample *sample_process(struct proxy *px, struct session *l4,
                                void *l7, unsigned int dir, struct sample_expr *expr,
index ce1bba92a48f4b98391bb2f38de90157b48e2bfc..a5140d6a714ad39eb8da9d451074dbb2b30718a7 100644 (file)
@@ -265,6 +265,7 @@ struct sample_conv {
        unsigned int arg_mask;                    /* arguments (ARG*()) */
        int (*val_args)(struct arg *arg_p,
                        struct sample_conv *smp_conv,
+                       const char *file, int line,
                        char **err_msg);          /* argument validation function */
        unsigned int in_type;                     /* expected input sample type */
        unsigned int out_type;                    /* output sample type */
index 0e3f2bfc1d86daae50f3008555edaae55f353719..2a7435dab801a21e60ee505775d089e4bcebe932 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -323,7 +323,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
                                if (!conv_expr->arg_p)
                                        conv_expr->arg_p = empty_arg_list;
 
-                               if (conv->val_args && !conv->val_args(conv_expr->arg_p, conv, err)) {
+                               if (conv->val_args && !conv->val_args(conv_expr->arg_p, conv, file, line, err)) {
                                        memprintf(err, "ACL keyword '%s' : invalid args in conv method '%s' : %s.",
                                                  aclkw->kw, ckw, *err);
                                        goto out_free_smp;
@@ -342,7 +342,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
                 * so, we retrieve a completely parsed expression with args and
                 * convs already done.
                 */
-               smp = sample_parse_expr((char **)args, &idx, err, al);
+               smp = sample_parse_expr((char **)args, &idx, file, line, err, al);
                if (!smp) {
                        memprintf(err, "%s in ACL expression '%s'", *err, *args);
                        goto out_return;
@@ -453,7 +453,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
                        snprintf(trash.str, trash.size, "acl(s) loaded from file '%s'", args[1]);
                        trash.str[trash.size - 1] = '\0';
 
-                       if (!pattern_read_from_file(&expr->pat, PAT_REF_ACL, args[1], patflags | PAT_F_FROM_FILE, load_as_map, err, trash.str))
+                       if (!pattern_read_from_file(&expr->pat, PAT_REF_ACL, args[1], patflags | PAT_F_FROM_FILE, load_as_map, err, trash.str, file, line))
                                goto out_free_expr;
                        is_loaded = 1;
                        args++;
index 2aa2ff9ed8f83e5d14ae7eafc4b2f8c8e8f89fee..6611d6cfc169289a9248a9fc9222dee2dfa0c581 100644 (file)
@@ -3212,7 +3212,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                }
 
                curproxy->conf.args.ctx = ARGC_STK;
-               expr = sample_parse_expr(args, &myidx, &errmsg, &curproxy->conf.args);
+               expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args);
                if (!expr) {
                        Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -7088,7 +7088,7 @@ out_uri_auth_compat:
                        curproxy->conf.args.file = curproxy->conf.lfs_file;
                        curproxy->conf.args.line = curproxy->conf.lfs_line;
                        parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY,
-                                              SMP_VAL_FE_LOG_END);
+                                              SMP_VAL_FE_LOG_END, curproxy->conf.lfs_file, curproxy->conf.lfs_line);
                        curproxy->conf.args.file = NULL;
                        curproxy->conf.args.line = 0;
                }
@@ -7098,7 +7098,8 @@ out_uri_auth_compat:
                        curproxy->conf.args.file = curproxy->conf.uif_file;
                        curproxy->conf.args.line = curproxy->conf.uif_line;
                        parse_logformat_string(curproxy->conf.uniqueid_format_string, curproxy, &curproxy->format_unique_id, LOG_OPT_HTTP,
-                                              (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR);
+                                              (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
+                                              curproxy->conf.uif_file, curproxy->conf.uif_line);
                        curproxy->conf.args.file = NULL;
                        curproxy->conf.args.line = 0;
                }
index f39168a08039323334b6ed3254cbcc0470a7b752..176a7253a6c05671c57dcf0858ff27e70b339a04 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -338,7 +338,7 @@ void add_to_logformat_list(char *start, char *end, int type, struct list *list_f
  * success. At the moment, sample converters are not yet supported but fetch arguments
  * should work. The curpx->conf.args.ctx must be set by the caller.
  */
-void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct proxy *curpx, struct list *list_format, int options, int cap)
+void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct proxy *curpx, struct list *list_format, int options, int cap, const char *file, int line)
 {
        char *cmd[2];
        struct sample_expr *expr;
@@ -350,7 +350,7 @@ void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct pro
        cmd[1] = "";
        cmd_arg = 0;
 
-       expr = sample_parse_expr(cmd, &cmd_arg, &errmsg, &curpx->conf.args);
+       expr = sample_parse_expr(cmd, &cmd_arg, file, line, &errmsg, &curpx->conf.args);
        if (!expr) {
                Warning("parsing [%s:%d] : '%s' : sample fetch <%s> failed with : %s\n",
                        curpx->conf.args.file, curpx->conf.args.line, fmt_directive(curpx),
@@ -403,7 +403,7 @@ void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct pro
  *  options: LOG_OPT_* to force on every node
  *  cap: all SMP_VAL_* flags supported by the consumer
  */
-void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list *list_format, int options, int cap)
+void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list *list_format, int options, int cap, const char *file, int line)
 {
        char *sp, *str, *backfmt; /* start pointer for text parts */
        char *arg = NULL; /* start pointer for args */
@@ -522,7 +522,7 @@ void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list
                                parse_logformat_var(arg, arg_len, var, var_len, curproxy, list_format, &options);
                                break;
                        case LF_STEXPR:
-                               add_sample_to_logformat_list(var, arg, arg_len, curproxy, list_format, options, cap);
+                               add_sample_to_logformat_list(var, arg, arg_len, curproxy, list_format, options, cap, file, line);
                                break;
                        case LF_TEXT:
                        case LF_SEPARATOR:
index ea671512baa81a19200fe90375414f1697261f9c..16f86bb21c30a3202d98972bf0b3d2fd44e3577d 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -114,7 +114,8 @@ static struct map_descriptor *map_create_descriptor(struct sample_conv *conv)
  * This function choose the indexation type (ebtree or list) according with
  * the type of match needed.
  */
-static int sample_load_map(struct arg *arg, struct sample_conv *conv, char **err)
+static int sample_load_map(struct arg *arg, struct sample_conv *conv,
+                           const char *file, int line, char **err)
 {
        struct map_descriptor *desc;
 
@@ -157,7 +158,7 @@ static int sample_load_map(struct arg *arg, struct sample_conv *conv, char **err
 
        /* Load map. */
        if (!pattern_read_from_file(&desc->pat, PAT_REF_MAP, arg[0].data.str.str, 0,
-                                   1, err, trash.str))
+                                   1, err, trash.str, file, line))
                return 0;
 
        /* The second argument is the default value */
index 10931a7c22638580b17e00d048a8b9f103c89d6f..da79c9fd00d43c81da67ef7682dac75468d07f09 100644 (file)
@@ -1972,7 +1972,8 @@ int pat_ref_read_from_file(struct pat_ref *ref, const char *filename, char **err
 
 int pattern_read_from_file(struct pattern_head *head, unsigned int refflags,
                            const char *filename, int patflags, int load_smp,
-                           char **err, const char *display)
+                           char **err, const char *display, const char *file,
+                           int line)
 {
        struct pat_ref *ref;
        struct pattern_expr *expr;
index 661e469b061593b387b686e3858b79d0af8d4478..105b9a8d8eba08f3f23dad9caf4aaa23bce98e1c 100644 (file)
@@ -8503,7 +8503,8 @@ struct http_req_rule *parse_http_req_cond(const char **args, const char *file, i
 
                proxy->conf.args.ctx = ARGC_HRQ;
                parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.hdr_add.fmt, LOG_OPT_HTTP,
-                                      (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR);
+                                      (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
+                                      file, linenum);
                free(proxy->conf.lfs_file);
                proxy->conf.lfs_file = strdup(proxy->conf.args.file);
                proxy->conf.lfs_line = proxy->conf.args.line;
@@ -8674,7 +8675,8 @@ struct http_res_rule *parse_http_res_cond(const char **args, const char *file, i
 
                proxy->conf.args.ctx = ARGC_HRS;
                parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.hdr_add.fmt, LOG_OPT_HTTP,
-                                      (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR);
+                                      (proxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR,
+                                      file, linenum);
                free(proxy->conf.lfs_file);
                proxy->conf.lfs_file = strdup(proxy->conf.args.file);
                proxy->conf.lfs_line = proxy->conf.args.line;
@@ -8830,7 +8832,8 @@ struct redirect_rule *http_parse_redirect_rule(const char *file, int linenum, st
                proxy->conf.args.ctx = ARGC_RDR;
                if (!(type == REDIRECT_TYPE_PREFIX && destination[0] == '/' && destination[1] == '\0')) {
                        parse_logformat_string(destination, curproxy, &rule->rdr_fmt, LOG_OPT_HTTP,
-                                              (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR);
+                                              (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
+                                              file, linenum);
                        free(curproxy->conf.lfs_file);
                        curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
                        curproxy->conf.lfs_line = curproxy->conf.args.line;
index 5ede8233e73defffcaf1a3842457b1bde4eaf0fe..f77203a4e1ddd05e96195455a34d2b6982e8c703 100644 (file)
@@ -1296,7 +1296,7 @@ static int tcp_parse_request_rule(char **args, int arg, int section_type,
                arg++;
 
                curpx->conf.args.ctx = ARGC_TRK;
-               expr = sample_parse_expr(args, &arg, err, &curpx->conf.args);
+               expr = sample_parse_expr(args, &arg, file, line, err, &curpx->conf.args);
                if (!expr) {
                        memprintf(err,
                                  "'%s %s %s' : %s",
index 356caf6bb05584b210cb2aa842360750d5fff46d..7001f36ab1d5fa69bda84dc8894cc8311307b841 100644 (file)
@@ -678,7 +678,7 @@ sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES] = {
  * Returns a pointer on allocated sample expression structure.
  * The caller must have set al->ctx.
  */
-struct sample_expr *sample_parse_expr(char **str, int *idx, char **err_msg, struct arg_list *al)
+struct sample_expr *sample_parse_expr(char **str, int *idx, const char *file, int line, char **err_msg, struct arg_list *al)
 {
        const char *begw; /* beginning of word */
        const char *endw; /* end of word */
@@ -862,7 +862,7 @@ struct sample_expr *sample_parse_expr(char **str, int *idx, char **err_msg, stru
                        if (!conv_expr->arg_p)
                                conv_expr->arg_p = empty_arg_list;
 
-                       if (conv->val_args && !conv->val_args(conv_expr->arg_p, conv, err_msg)) {
+                       if (conv->val_args && !conv->val_args(conv_expr->arg_p, conv, file, line, err_msg)) {
                                memprintf(err_msg, "invalid args in conv method '%s' : %s", ckw, *err_msg);
                                goto out_error;
                        }