From: Miroslav Zagorac Date: Mon, 7 Mar 2022 12:14:16 +0000 (+0100) Subject: CLEANUP: opentracing: added FLT_OT_PARSE_INVALID_enum enum X-Git-Tag: v2.6-dev5~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=854384f400b7e2faf2b4805e05815ff77c8069c8;p=thirdparty%2Fhaproxy.git CLEANUP: opentracing: added FLT_OT_PARSE_INVALID_enum enum It's always good to replace "hard-coded" values with something that looks less "hard-coded" (even though that doesn't change anything in the code). This is done here using FLT_OT_PARSE_INVALID_enum enum. This patch must be backported as far as 2.4. --- diff --git a/addons/ot/include/parser.h b/addons/ot/include/parser.h index 96939916da..53e414b355 100644 --- a/addons/ot/include/parser.h +++ b/addons/ot/include/parser.h @@ -50,20 +50,20 @@ * flt_ot_parse_data definition */ #define FLT_OT_PARSE_TRACER_DEFINES \ - FLT_OT_PARSE_TRACER_DEF( ID, 0, 1, 2, 2, "ot-tracer", " ") \ - FLT_OT_PARSE_TRACER_DEF( ACL, 0, 1, 3, 0, "acl", " [flags] [operator] ...") \ - FLT_OT_PARSE_TRACER_DEF( LOG, 0, 1, 2, 0, "log", " { global | [len ] [format ] [ []] }") \ - FLT_OT_PARSE_TRACER_DEF( CONFIG, 0, 0, 2, 2, "config", " ") \ - FLT_OT_PARSE_TRACER_DEF( PLUGIN, 0, 0, 2, 2, "plugin", " ") \ - FLT_OT_PARSE_TRACER_DEF( GROUPS, 0, 0, 2, 0, "groups", " ...") \ - FLT_OT_PARSE_TRACER_DEF( SCOPES, 0, 0, 2, 0, "scopes", " ...") \ - FLT_OT_PARSE_TRACER_DEF( RATE_LIMIT, 0, 0, 2, 2, "rate-limit", " ") \ - FLT_OT_PARSE_TRACER_DEF( OPTION, 0, 0, 2, 2, "option", " { disabled | dontlog-normal | hard-errors }") \ - FLT_OT_PARSE_TRACER_DEF(DEBUG_LEVEL, 0, 0, 2, 2, "debug-level", " ") + FLT_OT_PARSE_TRACER_DEF( ID, 0, CHAR, 2, 2, "ot-tracer", " ") \ + FLT_OT_PARSE_TRACER_DEF( ACL, 0, CHAR, 3, 0, "acl", " [flags] [operator] ...") \ + FLT_OT_PARSE_TRACER_DEF( LOG, 0, CHAR, 2, 0, "log", " { global | [len ] [format ] [ []] }") \ + FLT_OT_PARSE_TRACER_DEF( CONFIG, 0, NONE, 2, 2, "config", " ") \ + FLT_OT_PARSE_TRACER_DEF( PLUGIN, 0, NONE, 2, 2, "plugin", " ") \ + FLT_OT_PARSE_TRACER_DEF( GROUPS, 0, NONE, 2, 0, "groups", " ...") \ + FLT_OT_PARSE_TRACER_DEF( SCOPES, 0, NONE, 2, 0, "scopes", " ...") \ + FLT_OT_PARSE_TRACER_DEF( RATE_LIMIT, 0, NONE, 2, 2, "rate-limit", " ") \ + FLT_OT_PARSE_TRACER_DEF( OPTION, 0, NONE, 2, 2, "option", " { disabled | dontlog-normal | hard-errors }") \ + FLT_OT_PARSE_TRACER_DEF(DEBUG_LEVEL, 0, NONE, 2, 2, "debug-level", " ") #define FLT_OT_PARSE_GROUP_DEFINES \ - FLT_OT_PARSE_GROUP_DEF( ID, 0, 1, 2, 2, "ot-group", " ") \ - FLT_OT_PARSE_GROUP_DEF(SCOPES, 0, 0, 2, 0, "scopes", " ...") + FLT_OT_PARSE_GROUP_DEF( ID, 0, CHAR, 2, 2, "ot-group", " ") \ + FLT_OT_PARSE_GROUP_DEF(SCOPES, 0, NONE, 2, 0, "scopes", " ...") #ifdef USE_OT_VARS # define FLT_OT_PARSE_SCOPE_INJECT_HELP " [use-vars] [use-headers]" @@ -81,16 +81,24 @@ * so I will not complicate it here with additional definitions. */ #define FLT_OT_PARSE_SCOPE_DEFINES \ - FLT_OT_PARSE_SCOPE_DEF( ID, 0, 1, 2, 2, "ot-scope", " ") \ - FLT_OT_PARSE_SCOPE_DEF( SPAN, 0, 0, 2, 5, "span", " [] [root]") \ - FLT_OT_PARSE_SCOPE_DEF( TAG, 1, 0, 3, 0, "tag", " ...") \ - FLT_OT_PARSE_SCOPE_DEF( LOG, 1, 0, 3, 0, "log", " ...") \ - FLT_OT_PARSE_SCOPE_DEF(BAGGAGE, 1, 4, 3, 0, "baggage", " ...") \ - FLT_OT_PARSE_SCOPE_DEF( INJECT, 1, 3, 2, 4, "inject", FLT_OT_PARSE_SCOPE_INJECT_HELP) \ - FLT_OT_PARSE_SCOPE_DEF(EXTRACT, 0, 3, 2, 3, "extract", FLT_OT_PARSE_SCOPE_EXTRACT_HELP) \ - FLT_OT_PARSE_SCOPE_DEF( FINISH, 0, 0, 2, 0, "finish", " ...") \ - FLT_OT_PARSE_SCOPE_DEF( ACL, 0, 1, 3, 0, "acl", " [flags] [operator] ...") \ - FLT_OT_PARSE_SCOPE_DEF( EVENT, 0, 0, 2, 0, "event", " [{ if | unless } ]") + FLT_OT_PARSE_SCOPE_DEF( ID, 0, CHAR, 2, 2, "ot-scope", " ") \ + FLT_OT_PARSE_SCOPE_DEF( SPAN, 0, NONE, 2, 5, "span", " [] [root]") \ + FLT_OT_PARSE_SCOPE_DEF( TAG, 1, NONE, 3, 0, "tag", " ...") \ + FLT_OT_PARSE_SCOPE_DEF( LOG, 1, NONE, 3, 0, "log", " ...") \ + FLT_OT_PARSE_SCOPE_DEF(BAGGAGE, 1, VAR, 3, 0, "baggage", " ...") \ + FLT_OT_PARSE_SCOPE_DEF( INJECT, 1, CTX, 2, 4, "inject", FLT_OT_PARSE_SCOPE_INJECT_HELP) \ + FLT_OT_PARSE_SCOPE_DEF(EXTRACT, 0, CTX, 2, 3, "extract", FLT_OT_PARSE_SCOPE_EXTRACT_HELP) \ + FLT_OT_PARSE_SCOPE_DEF( FINISH, 0, NONE, 2, 0, "finish", " ...") \ + FLT_OT_PARSE_SCOPE_DEF( ACL, 0, CHAR, 3, 0, "acl", " [flags] [operator] ...") \ + FLT_OT_PARSE_SCOPE_DEF( EVENT, 0, NONE, 2, 0, "event", " [{ if | unless } ]") + +enum FLT_OT_PARSE_INVCHAR_enum { + FLT_OT_PARSE_INVALID_NONE, + FLT_OT_PARSE_INVALID_CHAR, + FLT_OT_PARSE_INVALID_DOM, + FLT_OT_PARSE_INVALID_CTX, + FLT_OT_PARSE_INVALID_VAR, +}; enum FLT_OT_PARSE_TRACER_enum { #define FLT_OT_PARSE_TRACER_DEF(a,b,c,d,e,f,g) FLT_OT_PARSE_TRACER_##a, diff --git a/addons/ot/src/parser.c b/addons/ot/src/parser.c index aed328614f..1fd7007ff8 100644 --- a/addons/ot/src/parser.c +++ b/addons/ot/src/parser.c @@ -139,16 +139,16 @@ static const char *flt_ot_parse_invalid_char(const char *name, int type) if (!FLT_OT_STR_ISVALID(name)) FLT_OT_RETURN_EX(retptr, const char *, "%p"); - if (type == 1) { + if (type == FLT_OT_PARSE_INVALID_CHAR) { retptr = invalid_char(name); } - else if (type == 2) { + else if (type == FLT_OT_PARSE_INVALID_DOM) { retptr = invalid_domainchar(name); } - else if (type == 3) { + else if (type == FLT_OT_PARSE_INVALID_CTX) { retptr = invalid_prefix_char(name); } - else if (type == 4) { + else if (type == FLT_OT_PARSE_INVALID_VAR) { retptr = name; /* @@ -229,7 +229,7 @@ static int flt_ot_parse_cfg_check(const char *file, int linenum, char **args, co FLT_OT_PARSE_ERR(err, "'%s' : too many arguments (use '%s%s')", args[0], (*pdata)->name, (*pdata)->usage); /* Checking that the first argument has only allowed characters. */ - if (!(retval & ERR_CODE) && ((*pdata)->check_name > 0)) { + if (!(retval & ERR_CODE) && ((*pdata)->check_name != FLT_OT_PARSE_INVALID_NONE)) { const char *ic; ic = flt_ot_parse_invalid_char(args[1], (*pdata)->check_name); @@ -460,7 +460,7 @@ static bool flt_ot_parse_check_scope(void) */ static int flt_ot_parse_cfg_tracer(const char *file, int linenum, char **args, int kw_mod) { -#define FLT_OT_PARSE_TRACER_DEF(a,b,c,d,e,f,g) { FLT_OT_PARSE_TRACER_##a, b, c, d, e, f, g }, +#define FLT_OT_PARSE_TRACER_DEF(a,b,c,d,e,f,g) { FLT_OT_PARSE_TRACER_##a, b, FLT_OT_PARSE_INVALID_##c, d, e, f, g }, static const struct flt_ot_parse_data parse_data[] = { FLT_OT_PARSE_TRACER_DEFINES }; #undef FLT_OT_PARSE_TRACER_DEF const struct flt_ot_parse_data *pdata = NULL; @@ -623,7 +623,7 @@ static int flt_ot_post_parse_cfg_tracer(void) */ static int flt_ot_parse_cfg_group(const char *file, int linenum, char **args, int kw_mod) { -#define FLT_OT_PARSE_GROUP_DEF(a,b,c,d,e,f,g) { FLT_OT_PARSE_GROUP_##a, b, c, d, e, f, g }, +#define FLT_OT_PARSE_GROUP_DEF(a,b,c,d,e,f,g) { FLT_OT_PARSE_GROUP_##a, b, FLT_OT_PARSE_INVALID_##c, d, e, f, g }, static const struct flt_ot_parse_data parse_data[] = { FLT_OT_PARSE_GROUP_DEFINES }; #undef FLT_OT_PARSE_GROUP_DEF const struct flt_ot_parse_data *pdata = NULL; @@ -799,7 +799,7 @@ static struct acl_cond *flt_ot_parse_acl(const char *file, int linenum, struct p */ static int flt_ot_parse_cfg_scope(const char *file, int linenum, char **args, int kw_mod) { -#define FLT_OT_PARSE_SCOPE_DEF(a,b,c,d,e,f,g) { FLT_OT_PARSE_SCOPE_##a, b, c, d, e, f, g }, +#define FLT_OT_PARSE_SCOPE_DEF(a,b,c,d,e,f,g) { FLT_OT_PARSE_SCOPE_##a, b, FLT_OT_PARSE_INVALID_##c, d, e, f, g }, static const struct flt_ot_parse_data parse_data[] = { FLT_OT_PARSE_SCOPE_DEFINES }; #undef FLT_OT_PARSE_SCOPE_DEF const struct flt_ot_parse_data *pdata = NULL;