From db452508bf3d808a33b3fc04c946d8cc2939bbb7 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Fri, 2 Nov 2018 22:07:07 -0200 Subject: [PATCH] lib, tools: use CHECK_FLAG/SET_FLAG more often in the northbound code Cosmetic change to improve code readability a bit. No binary changes. Signed-off-by: Renato Westphal --- lib/northbound.c | 24 +++++++++++++----------- lib/northbound_cli.c | 8 ++++---- lib/northbound_confd.c | 4 ++-- lib/northbound_sysrepo.c | 4 ++-- lib/yang.c | 10 +++++----- tools/gen_northbound_callbacks.c | 6 +++--- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/lib/northbound.c b/lib/northbound.c index 21bbc63f6..2fabae22b 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -380,7 +380,8 @@ static void nb_config_diff(const struct nb_config *config1, nb_config_diff_add_change(changes, operation, dnode); if (type == LYD_DIFF_CREATED - && (dnode->schema->nodetype & (LYS_CONTAINER | LYS_LIST))) + && CHECK_FLAG(dnode->schema->nodetype, + LYS_CONTAINER | LYS_LIST)) nb_config_diff_new_subtree(dnode, changes); } @@ -898,7 +899,7 @@ bool nb_operation_is_valid(enum nb_operation operation, switch (operation) { case NB_OP_CREATE: - if (!(snode->flags & LYS_CONFIG_W)) + if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W)) return false; switch (snode->nodetype) { @@ -920,7 +921,7 @@ bool nb_operation_is_valid(enum nb_operation operation, } return true; case NB_OP_MODIFY: - if (!(snode->flags & LYS_CONFIG_W)) + if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W)) return false; switch (snode->nodetype) { @@ -938,7 +939,7 @@ bool nb_operation_is_valid(enum nb_operation operation, } return true; case NB_OP_DELETE: - if (!(snode->flags & LYS_CONFIG_W)) + if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W)) return false; switch (snode->nodetype) { @@ -957,7 +958,8 @@ bool nb_operation_is_valid(enum nb_operation operation, return true; if (sleaf->when) return true; - if ((sleaf->flags & LYS_MAND_TRUE) || sleaf->dflt) + if (CHECK_FLAG(sleaf->flags, LYS_MAND_TRUE) + || sleaf->dflt) return false; break; case LYS_CONTAINER: @@ -973,13 +975,13 @@ bool nb_operation_is_valid(enum nb_operation operation, } return true; case NB_OP_MOVE: - if (!(snode->flags & LYS_CONFIG_W)) + if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W)) return false; switch (snode->nodetype) { case LYS_LIST: case LYS_LEAFLIST: - if (!(snode->flags & LYS_USERORDERED)) + if (!CHECK_FLAG(snode->flags, LYS_USERORDERED)) return false; break; default: @@ -987,11 +989,11 @@ bool nb_operation_is_valid(enum nb_operation operation, } return true; case NB_OP_APPLY_FINISH: - if (!(snode->flags & LYS_CONFIG_W)) + if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W)) return false; return true; case NB_OP_GET_ELEM: - if (!(snode->flags & LYS_CONFIG_R)) + if (!CHECK_FLAG(snode->flags, LYS_CONFIG_R)) return false; switch (snode->nodetype) { @@ -1009,7 +1011,7 @@ bool nb_operation_is_valid(enum nb_operation operation, case NB_OP_GET_NEXT: case NB_OP_GET_KEYS: case NB_OP_LOOKUP_ENTRY: - if (!(snode->flags & LYS_CONFIG_R)) + if (!CHECK_FLAG(snode->flags, LYS_CONFIG_R)) return false; switch (snode->nodetype) { @@ -1020,7 +1022,7 @@ bool nb_operation_is_valid(enum nb_operation operation, } return true; case NB_OP_RPC: - if (snode->flags & (LYS_CONFIG_W | LYS_CONFIG_R)) + if (CHECK_FLAG(snode->flags, LYS_CONFIG_W | LYS_CONFIG_R)) return false; switch (snode->nodetype) { diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index 8ae44e72d..c7378d244 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -359,7 +359,7 @@ static int nb_cli_show_config_libyang(struct vty *vty, LYD_FORMAT format, { struct lyd_node *dnode; char *strp; - int options; + int options = 0; dnode = yang_dnode_dup(config->dnode); if (translator @@ -371,11 +371,11 @@ static int nb_cli_show_config_libyang(struct vty *vty, LYD_FORMAT format, return CMD_WARNING; } - options = LYP_FORMAT | LYP_WITHSIBLINGS; + SET_FLAG(options, LYP_FORMAT | LYP_WITHSIBLINGS); if (with_defaults) - options |= LYP_WD_ALL; + SET_FLAG(options, LYP_WD_ALL); else - options |= LYP_WD_TRIM; + SET_FLAG(options, LYP_WD_TRIM); if (lyd_print_mem(&strp, dnode, format, options) == 0 && strp) { vty_out(vty, "%s", strp); diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c index 0912bce89..5a653b5cf 100644 --- a/lib/northbound_confd.c +++ b/lib/northbound_confd.c @@ -983,10 +983,10 @@ static void frr_confd_subscribe_state(const struct lys_node *snode, void *arg1, struct nb_node *nb_node = snode->priv; struct confd_data_cbs *data_cbs = arg1; - if (!(snode->flags & LYS_CONFIG_R)) + if (!CHECK_FLAG(snode->flags, LYS_CONFIG_R)) return; /* We only need to subscribe to the root of the state subtrees. */ - if (snode->parent && (snode->parent->flags & LYS_CONFIG_R)) + if (snode->parent && CHECK_FLAG(snode->parent->flags, LYS_CONFIG_R)) return; if (debug_northbound) diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c index 66447ad68..f109f7813 100644 --- a/lib/northbound_sysrepo.c +++ b/lib/northbound_sysrepo.c @@ -739,10 +739,10 @@ static void frr_sr_subscribe_state(const struct lys_node *snode, void *arg1, struct nb_node *nb_node; int ret; - if (!(snode->flags & LYS_CONFIG_R)) + if (!CHECK_FLAG(snode->flags, LYS_CONFIG_R)) return; /* We only need to subscribe to the root of the state subtrees. */ - if (snode->parent && (snode->parent->flags & LYS_CONFIG_R)) + if (snode->parent && CHECK_FLAG(snode->parent->flags, LYS_CONFIG_R)) return; nb_node = snode->priv; diff --git a/lib/yang.c b/lib/yang.c index 660a54a22..7daef7919 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -132,7 +132,7 @@ static void yang_snodes_iterate(const struct lys_node *snode, case LYS_CASE: case LYS_INPUT: case LYS_OUTPUT: - if (snode->flags & LYS_IMPLICIT) + if (CHECK_FLAG(snode->flags, LYS_IMPLICIT)) goto next; break; default: @@ -183,7 +183,7 @@ next: * YANG leafs and leaf-lists can't have child nodes, and trying to * access snode->child is undefined behavior. */ - if (snode->nodetype & (LYS_LEAF | LYS_LEAFLIST)) + if (CHECK_FLAG(snode->nodetype, LYS_LEAF | LYS_LEAFLIST)) return; LY_TREE_FOR (snode->child, child) { @@ -324,7 +324,7 @@ const struct lys_type *yang_snode_get_type(const struct lys_node *snode) struct lys_node_leaf *sleaf = (struct lys_node_leaf *)snode; struct lys_type *type; - if (!(sleaf->nodetype & (LYS_LEAF | LYS_LEAFLIST))) + if (!CHECK_FLAG(sleaf->nodetype, LYS_LEAF | LYS_LEAFLIST)) return NULL; type = &sleaf->type; @@ -440,7 +440,7 @@ bool yang_dnode_is_default_recursive(const struct lyd_node *dnode) struct lyd_node *root, *next, *dnode_iter; snode = dnode->schema; - if (snode->nodetype & (LYS_LEAF | LYS_LEAFLIST)) + if (CHECK_FLAG(snode->nodetype, LYS_LEAF | LYS_LEAFLIST)) return yang_dnode_is_default(dnode, NULL); if (!yang_dnode_is_default(dnode, NULL)) @@ -466,7 +466,7 @@ void yang_dnode_change_leaf(struct lyd_node *dnode, const char *value) void yang_dnode_set_entry(const struct lyd_node *dnode, void *entry) { - assert(dnode->schema->nodetype & (LYS_LIST | LYS_CONTAINER)); + assert(CHECK_FLAG(dnode->schema->nodetype, LYS_LIST | LYS_CONTAINER)); lyd_set_private(dnode, entry); } diff --git a/tools/gen_northbound_callbacks.c b/tools/gen_northbound_callbacks.c index 8ef105484..24c7aa97b 100644 --- a/tools/gen_northbound_callbacks.c +++ b/tools/gen_northbound_callbacks.c @@ -130,9 +130,9 @@ static void generate_callback_name(struct lys_node *snode, snodes = list_new(); for (; snode; snode = lys_parent(snode)) { /* Skip schema-only snodes. */ - if (snode->nodetype - & (LYS_USES | LYS_CHOICE | LYS_CASE | LYS_INPUT - | LYS_OUTPUT)) + if (CHECK_FLAG(snode->nodetype, LYS_USES | LYS_CHOICE | LYS_CASE + | LYS_INPUT + | LYS_OUTPUT)) continue; listnode_add_head(snodes, snode); -- 2.39.2