Skip to content

Commit

Permalink
Merge pull request FRRouting#14525 from LabNConsulting/chopps/mgmtd-s…
Browse files Browse the repository at this point in the history
…implify-xpaths

chopps/mgmtd simplify xpaths
  • Loading branch information
idryzhov committed Nov 8, 2023
2 parents 85a80ba + bec1091 commit 448f75e
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 372 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ ForEachMacros:
- 'FOREACH_AFI_SAFI'
- 'FOREACH_AFI_SAFI_NSF'
- 'FOREACH_BE_APPLY_BATCH_IN_LIST'
- 'FOREACH_BE_CLIENT_BITS'
- 'FOREACH_BE_TXN_BATCH_IN_LIST'
- 'FOREACH_BE_TXN_IN_LIST'
- 'FOREACH_CMT_REC'
Expand Down
24 changes: 24 additions & 0 deletions lib/frrstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
8 changes: 8 additions & 0 deletions lib/frrstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions lib/mgmt_be_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
44 changes: 0 additions & 44 deletions lib/mgmt_be_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,6 @@ extern "C" {
#include "mgmt_pb.h"
#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
***************************************************************/
Expand Down Expand Up @@ -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;

/***************************************************************
Expand Down
9 changes: 1 addition & 8 deletions lib/yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,8 @@ struct lysc_node *yang_find_snode(struct ly_ctx *ly_ctx, const char *xpath,
uint32_t options)
{
struct lysc_node *snode;
struct ly_set *set;
LY_ERR err;

err = lys_find_xpath(ly_native_ctx, NULL, xpath, options, &set);
if (err || !set->count)
return NULL;

snode = set->snodes[0];
ly_set_free(set, NULL);
snode = (struct lysc_node *)lys_find_path(ly_ctx, NULL, xpath, 0);

return snode;
}
Expand Down
Loading

0 comments on commit 448f75e

Please sign in to comment.