]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: opentracing: added FLT_OT_PARSE_INVALID_enum enum
authorMiroslav Zagorac <mzagorac@haproxy.com>
Mon, 7 Mar 2022 12:14:16 +0000 (13:14 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Apr 2022 14:31:33 +0000 (16:31 +0200)
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.

addons/ot/include/parser.h
addons/ot/src/parser.c

index 96939916da0fe74917fdaf771e646a554ae60b53..53e414b355db6e57736b23ea95654ee2cd48fc0d 100644 (file)
  * flt_ot_parse_data definition
  */
 #define FLT_OT_PARSE_TRACER_DEFINES                                                                                                                          \
-       FLT_OT_PARSE_TRACER_DEF(         ID, 0, 1, 2, 2, "ot-tracer",   " <name>")                                                                           \
-       FLT_OT_PARSE_TRACER_DEF(        ACL, 0, 1, 3, 0, "acl",         " <name> <criterion> [flags] [operator] <value> ...")                                \
-       FLT_OT_PARSE_TRACER_DEF(        LOG, 0, 1, 2, 0, "log",         " { global | <addr> [len <len>] [format <fmt>] <facility> [<level> [<minlevel>]] }") \
-       FLT_OT_PARSE_TRACER_DEF(     CONFIG, 0, 0, 2, 2, "config",      " <file>")                                                                           \
-       FLT_OT_PARSE_TRACER_DEF(     PLUGIN, 0, 0, 2, 2, "plugin",      " <file>")                                                                           \
-       FLT_OT_PARSE_TRACER_DEF(     GROUPS, 0, 0, 2, 0, "groups",      " <name> ...")                                                                       \
-       FLT_OT_PARSE_TRACER_DEF(     SCOPES, 0, 0, 2, 0, "scopes",      " <name> ...")                                                                       \
-       FLT_OT_PARSE_TRACER_DEF( RATE_LIMIT, 0, 0, 2, 2, "rate-limit",  " <value>")                                                                          \
-       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", " <value>")
+       FLT_OT_PARSE_TRACER_DEF(         ID, 0, CHAR, 2, 2, "ot-tracer",   " <name>")                                                                           \
+       FLT_OT_PARSE_TRACER_DEF(        ACL, 0, CHAR, 3, 0, "acl",         " <name> <criterion> [flags] [operator] <value> ...")                                \
+       FLT_OT_PARSE_TRACER_DEF(        LOG, 0, CHAR, 2, 0, "log",         " { global | <addr> [len <len>] [format <fmt>] <facility> [<level> [<minlevel>]] }") \
+       FLT_OT_PARSE_TRACER_DEF(     CONFIG, 0, NONE, 2, 2, "config",      " <file>")                                                                           \
+       FLT_OT_PARSE_TRACER_DEF(     PLUGIN, 0, NONE, 2, 2, "plugin",      " <file>")                                                                           \
+       FLT_OT_PARSE_TRACER_DEF(     GROUPS, 0, NONE, 2, 0, "groups",      " <name> ...")                                                                       \
+       FLT_OT_PARSE_TRACER_DEF(     SCOPES, 0, NONE, 2, 0, "scopes",      " <name> ...")                                                                       \
+       FLT_OT_PARSE_TRACER_DEF( RATE_LIMIT, 0, NONE, 2, 2, "rate-limit",  " <value>")                                                                          \
+       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", " <value>")
 
 #define FLT_OT_PARSE_GROUP_DEFINES                                        \
-       FLT_OT_PARSE_GROUP_DEF(    ID, 0, 1, 2, 2, "ot-group", " <name>") \
-       FLT_OT_PARSE_GROUP_DEF(SCOPES, 0, 0, 2, 0, "scopes",   " <name> ...")
+       FLT_OT_PARSE_GROUP_DEF(    ID, 0, CHAR, 2, 2, "ot-group", " <name>") \
+       FLT_OT_PARSE_GROUP_DEF(SCOPES, 0, NONE, 2, 0, "scopes",   " <name> ...")
 
 #ifdef USE_OT_VARS
 #  define FLT_OT_PARSE_SCOPE_INJECT_HELP    " <name-prefix> [use-vars] [use-headers]"
  * 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", " <name>")                                            \
-       FLT_OT_PARSE_SCOPE_DEF(   SPAN, 0, 0, 2, 5, "span",     " <name> [<reference>] [root]")                       \
-       FLT_OT_PARSE_SCOPE_DEF(    TAG, 1, 0, 3, 0, "tag",      " <name> <sample> ...")                               \
-       FLT_OT_PARSE_SCOPE_DEF(    LOG, 1, 0, 3, 0, "log",      " <name> <sample> ...")                               \
-       FLT_OT_PARSE_SCOPE_DEF(BAGGAGE, 1, 4, 3, 0, "baggage",  " <name> <sample> ...")                               \
-       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",   " <name> ...")                                        \
-       FLT_OT_PARSE_SCOPE_DEF(    ACL, 0, 1, 3, 0, "acl",      " <name> <criterion> [flags] [operator] <value> ...") \
-       FLT_OT_PARSE_SCOPE_DEF(  EVENT, 0, 0, 2, 0, "event",    " <name> [{ if | unless } <condition>]")
+       FLT_OT_PARSE_SCOPE_DEF(     ID, 0, CHAR, 2, 2, "ot-scope", " <name>")                                            \
+       FLT_OT_PARSE_SCOPE_DEF(   SPAN, 0, NONE, 2, 5, "span",     " <name> [<reference>] [root]")                       \
+       FLT_OT_PARSE_SCOPE_DEF(    TAG, 1, NONE, 3, 0, "tag",      " <name> <sample> ...")                               \
+       FLT_OT_PARSE_SCOPE_DEF(    LOG, 1, NONE, 3, 0, "log",      " <name> <sample> ...")                               \
+       FLT_OT_PARSE_SCOPE_DEF(BAGGAGE, 1,  VAR, 3, 0, "baggage",  " <name> <sample> ...")                               \
+       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",   " <name> ...")                                        \
+       FLT_OT_PARSE_SCOPE_DEF(    ACL, 0, CHAR, 3, 0, "acl",      " <name> <criterion> [flags] [operator] <value> ...") \
+       FLT_OT_PARSE_SCOPE_DEF(  EVENT, 0, NONE, 2, 0, "event",    " <name> [{ if | unless } <condition>]")
+
+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,
index aed328614f8c437b944cb4fd81e4777f0a7a3ae0..1fd7007ff85e9c1e6b9bf02fe2b141f4d2303446 100644 (file)
@@ -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;