diff options
| author | Christian Hopps <chopps@labn.net> | 2023-07-08 23:11:15 -0400 |
|---|---|---|
| committer | Christian Hopps <chopps@labn.net> | 2023-11-06 17:44:58 -0500 |
| commit | a65cda16b28bc84b052636118823082de9600cfc (patch) | |
| tree | 975a1abb64919cc9a9c201b8c50ef7602bd72483 /lib | |
| parent | e1b2381f40132650f1c0a2285432c0d00aef7383 (diff) | |
mgmtd: simplify xpath registries
- move from client id indexed array of uints for register info
per client to a u64 bitmask.
- add bit walking FOREACH macro
Walk the client IDs whose bits are set in a mask.
Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/frrstr.c | 24 | ||||
| -rw-r--r-- | lib/frrstr.h | 8 | ||||
| -rw-r--r-- | lib/mgmt_be_client.c | 7 | ||||
| -rw-r--r-- | lib/mgmt_be_client.h | 44 |
4 files changed, 32 insertions, 51 deletions
diff --git a/lib/frrstr.c b/lib/frrstr.c index e5440c5093..bb112afef7 100644 --- a/lib/frrstr.c +++ b/lib/frrstr.c @@ -3,6 +3,7 @@ * FRR string processing utilities. * Copyright (C) 2018 Cumulus Networks, Inc. * Quentin Young + * Copyright (c) 2023, LabN Consulting, L.L.C. */ #include "zebra.h" @@ -225,3 +226,26 @@ char *frrstr_hex(char *buff, size_t bufsiz, const uint8_t *str, size_t num) return buff; } + +const char *frrstr_skip_over_char(const char *s, int skipc) +{ + int c, quote = 0; + + while ((c = *s++)) { + if (c == '\\') { + if (!*s++) + return NULL; + continue; + } + if (quote) { + if (c == quote) + quote = 0; + continue; + } + if (c == skipc) + return s; + if (c == '"' || c == '\'') + quote = c; + } + return NULL; +} diff --git a/lib/frrstr.h b/lib/frrstr.h index 19ba09e213..9a4fe257a2 100644 --- a/lib/frrstr.h +++ b/lib/frrstr.h @@ -3,6 +3,7 @@ * FRR string processing utilities. * Copyright (C) 2018 Cumulus Networks, Inc. * Quentin Young + * Copyright (c) 2023, LabN Consulting, L.L.C. */ #ifndef _FRRSTR_H_ @@ -166,6 +167,13 @@ int all_digit(const char *str); */ char *frrstr_hex(char *buff, size_t bufsiz, const uint8_t *str, size_t num); + +/* + * Advance past a given char `skipc` in a string, while honoring quoting and + * backslash escapes (i.e., ignore `skipc` which occur in quoted sections). + */ +const char *frrstr_skip_over_char(const char *s, int skipc); + #ifdef __cplusplus } #endif diff --git a/lib/mgmt_be_client.c b/lib/mgmt_be_client.c index be10dcf6a1..762ace1361 100644 --- a/lib/mgmt_be_client.c +++ b/lib/mgmt_be_client.c @@ -118,13 +118,6 @@ struct mgmt_be_client { struct debug mgmt_dbg_be_client = {0, "Management backend client operations"}; -const char *mgmt_be_client_names[MGMTD_BE_CLIENT_ID_MAX + 1] = { -#ifdef HAVE_STATICD - [MGMTD_BE_CLIENT_ID_STATICD] = "staticd", -#endif - [MGMTD_BE_CLIENT_ID_MAX] = "Unknown/Invalid", -}; - static int mgmt_be_client_send_msg(struct mgmt_be_client *client_ctx, Mgmtd__BeMessage *be_msg) { diff --git a/lib/mgmt_be_client.h b/lib/mgmt_be_client.h index 4ad5ca5957..051c908a37 100644 --- a/lib/mgmt_be_client.h +++ b/lib/mgmt_be_client.h @@ -17,27 +17,6 @@ extern "C" { #include "mgmtd/mgmt_defines.h" /*************************************************************** - * Client IDs - ***************************************************************/ - -/* - * Add enum value for each supported component, wrap with - * #ifdef HAVE_COMPONENT - */ -enum mgmt_be_client_id { - MGMTD_BE_CLIENT_ID_MIN = 0, - MGMTD_BE_CLIENT_ID_INIT = -1, -#ifdef HAVE_STATICD - MGMTD_BE_CLIENT_ID_STATICD, -#endif - MGMTD_BE_CLIENT_ID_MAX -}; - -#define FOREACH_MGMTD_BE_CLIENT_ID(id) \ - for ((id) = MGMTD_BE_CLIENT_ID_MIN; \ - (id) < MGMTD_BE_CLIENT_ID_MAX; (id)++) - -/*************************************************************** * Constants ***************************************************************/ @@ -108,29 +87,6 @@ struct mgmt_be_client_cbs { * Global data exported ***************************************************************/ -extern const char *mgmt_be_client_names[MGMTD_BE_CLIENT_ID_MAX + 1]; - -static inline const char *mgmt_be_client_id2name(enum mgmt_be_client_id id) -{ - if (id > MGMTD_BE_CLIENT_ID_MAX) - id = MGMTD_BE_CLIENT_ID_MAX; - return mgmt_be_client_names[id]; -} - -static inline enum mgmt_be_client_id -mgmt_be_client_name2id(const char *name) -{ - enum mgmt_be_client_id id; - - FOREACH_MGMTD_BE_CLIENT_ID (id) { - if (!strncmp(mgmt_be_client_names[id], name, - MGMTD_CLIENT_NAME_MAX_LEN)) - return id; - } - - return MGMTD_BE_CLIENT_ID_MAX; -} - extern struct debug mgmt_dbg_be_client; /*************************************************************** |
