From 465a5999fe069c22ad5792d4880d5d15e8e59288 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Wed, 17 Jan 2024 13:06:56 +0100 Subject: [PATCH] Changed function name: `choice_case_get()` -> `yang_choice_case_get()` Rewrote yang_choice() --- CHANGELOG.md | 1 + lib/clixon/clixon_yang.h | 2 +- lib/src/clixon_datastore_write.c | 10 +++++----- lib/src/clixon_xml_default.c | 2 +- lib/src/clixon_yang.c | 34 +++++++++++++++----------------- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9396112..c101f0cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Expected: February 2024 ### C/CLI-API changes on existing features Developers may need to change their code +* Changed function name: `choice_case_get()` -> `yang_choice_case_get()` * New `clixon-lib@2024-01-01.yang` revision * Replaced container creators to grouping/uses * Changed ca_errmsg callback to a more generic variant diff --git a/lib/clixon/clixon_yang.h b/lib/clixon/clixon_yang.h index 51914ba3..34813977 100644 --- a/lib/clixon/clixon_yang.h +++ b/lib/clixon/clixon_yang.h @@ -291,7 +291,7 @@ char *yang_find_mynamespace(yang_stmt *ys); int yang_find_prefix_by_namespace(yang_stmt *ys, char *ns, char **prefix); int yang_find_namespace_by_prefix(yang_stmt *ys, char *prefix, char **ns); yang_stmt *yang_myroot(yang_stmt *ys); -int choice_case_get(yang_stmt *yc, yang_stmt **ycase, yang_stmt **ychoice); +int yang_choice_case_get(yang_stmt *yc, yang_stmt **ycase, yang_stmt **ychoice); yang_stmt *yang_choice(yang_stmt *y); int yang_order(yang_stmt *y); int yang_print_cb(FILE *f, yang_stmt *yn, clicon_output_cb *fn); diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index 6650bec8..deccfb34 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -357,13 +357,13 @@ choice_is_other(yang_stmt *y0c, } else { /* First recurse y0 */ - if (choice_case_get(y0choice, &ycase, &ychoice)){ + if (yang_choice_case_get(y0choice, &ycase, &ychoice)){ if (choice_is_other(y0choice, ycase, ychoice, y1c, y1case, y1choice) == 1) return 1; } - /* Second recurse y1 */ - if (choice_case_get(y1choice, &ycase, &ychoice)){ + /* Second recurse y1 */ + if (yang_choice_case_get(y1choice, &ycase, &ychoice)){ if (choice_is_other(y0choice, y0case, y0choice, y1choice, ycase, ychoice) == 1) return 1; @@ -402,7 +402,7 @@ choice_delete_other(cxobj *x0, yang_stmt *y1case = NULL; yang_stmt *y1choice = NULL; - if (choice_case_get(y1c, &y1case, &y1choice) == 0) + if (yang_choice_case_get(y1c, &y1case, &y1choice) == 0) goto ok; x0prev = NULL; x0c = NULL; @@ -412,7 +412,7 @@ choice_delete_other(cxobj *x0, x0prev = x0c; continue; } - if (choice_case_get(y0c, &y0case, &y0choice) == 0){ + if (yang_choice_case_get(y0c, &y0case, &y0choice) == 0){ x0prev = x0c; continue; } diff --git a/lib/src/clixon_xml_default.c b/lib/src/clixon_xml_default.c index 51d0aada..298a1b8a 100644 --- a/lib/src/clixon_xml_default.c +++ b/lib/src/clixon_xml_default.c @@ -187,7 +187,7 @@ xml_default_choice(yang_stmt *yc, continue; /* Check if this child is a child of yc */ yca = ych = NULL; - if (choice_case_get(y, &yca, &ych) == 1 && + if (yang_choice_case_get(y, &yca, &ych) == 1 && ych == yc){ x0 = x; break; diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 2ef0ec6a..0a614de9 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -1544,12 +1544,18 @@ yang_myroot(yang_stmt *ys) return NULL; } -/*! Get closest yang case and choice, if any +/*! Given a YANG node, return closest yang case and choice, if any + * + * @param[in] yc Yang node + * @param[out] ycase case parent of yc + * @param[out] ychoice choice parent of yc (or grandparent) + * @retval 1 yc has case or choice parent (or both) as returned in ycase/ychoice + * @retval 0 yc has no parent or parent is neither case or choice */ int -choice_case_get(yang_stmt *yc, - yang_stmt **ycase, - yang_stmt **ychoice) +yang_choice_case_get(yang_stmt *yc, + yang_stmt **ycase, + yang_stmt **ychoice) { yang_stmt *yp; @@ -1571,25 +1577,17 @@ choice_case_get(yang_stmt *yc, } /*! If a given yang stmt has a choice/case as parent, return the choice statement + * + * + * @see yang_choice_case_get */ yang_stmt * yang_choice(yang_stmt *y) { - yang_stmt *yp; + yang_stmt *yp = NULL; - if ((yp = y->ys_parent) != NULL){ - switch (yang_keyword_get(yp)){ - case Y_CHOICE: - return yp; - break; - case Y_CASE: - return yang_parent_get(yp); - break; - default: - break; - } - } - return NULL; + yang_choice_case_get(y, NULL, &yp); + return yp; } /*! Find matching y in yp:s children, "yang order" of y when y is choice