diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c index 7b0cce6b..c51b6f79 100644 --- a/apps/cli/cli_auto.c +++ b/apps/cli/cli_auto.c @@ -171,7 +171,7 @@ cli_xml2file(cxobj *xn, if (xn == NULL) goto ok; /* Look for autocli-op defined in clixon-lib.yang */ - if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, &opext) < 0) { + if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0) { goto ok; } if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){ @@ -273,13 +273,13 @@ cli_xml2txt(cxobj *xn, clicon_err(OE_XML, EINVAL, "xn or fn is NULL"); goto done; } - /* Look for autocli-op defined in clixon-lib.yang */ - if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, &opext) < 0) { - goto ok; - } - if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){ - goto ok; - } + /* Look for autocli-op defined in clixon-lib.yang */ + if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0) { + goto ok; + } + if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){ + goto ok; + } xc = NULL; /* count children (elements and bodies, not attributes) */ while ((xc = xml_child_each(xn, xc, -1)) != NULL) if (xml_type(xc) == CX_ELMNT || xml_type(xc) == CX_BODY) @@ -342,7 +342,7 @@ cli_xml2cli(cxobj *xn, if ((ys = xml_spec(xn)) == NULL) goto ok; /* Look for autocli-op defined in clixon-lib.yang */ - if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, &opext) < 0) { + if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0) { goto ok; } if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){ diff --git a/apps/cli/cli_generate.c b/apps/cli/cli_generate.c index fe365836..ac6527df 100644 --- a/apps/cli/cli_generate.c +++ b/apps/cli/cli_generate.c @@ -121,7 +121,7 @@ cli_expand_var_generate(clicon_handle h, int retval = -1; char *api_path_fmt = NULL, *opext = NULL; - if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0) + if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0) goto done; if (opext && strcmp(opext, "hide-database") == 0) { retval = 1; @@ -762,7 +762,7 @@ yang2cli_leaf(clicon_handle h, } cprintf(cb, "%*s", level*3, ""); /* Look for autocli-op defined in clixon-lib.yang */ - if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0) + if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0) goto done; if (gt == GT_VARS|| gt == GT_ALL || gt == GT_HIDE){ cprintf(cb, "%s", yang_argument_get(ys)); @@ -839,7 +839,7 @@ yang2cli_container(clicon_handle h, * a list, then skip container keyword * See also xml2cli */ - if ((hide = yang_container_cli_hide(ys, gt)) == 0){ + if ((hide = yang_container_cli_hide(ys, gt)) == 0){ cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys)); if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){ if ((helptext = strdup(yang_argument_get(yd))) == NULL){ @@ -853,14 +853,14 @@ yang2cli_container(clicon_handle h, if (cli_callback_generate(h, ys, cb) < 0) goto done; - /* Look for autocli-op defined in clixon-lib.yang */ - if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0) - goto done; - if (opext != NULL && strcmp(opext, "hide") == 0){ - cprintf(cb, ",hide"); - } + /* Look for autocli-op defined in clixon-lib.yang */ + if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0) + goto done; + if (opext != NULL && strcmp(opext, "hide") == 0){ + cprintf(cb, ",hide"); + } if (opext != NULL && strcmp(opext, "hide-database-auto-completion") == 0){ - cprintf(cb, ",hide-database-auto-completion"); + cprintf(cb, ",hide-database-auto-completion"); } cprintf(cb, ";{\n"); } @@ -868,11 +868,11 @@ yang2cli_container(clicon_handle h, yc = NULL; while ((yc = yn_each(ys, yc)) != NULL) if (yang2cli_stmt(h, yc, gt, level+1, state, show_tree, cb) < 0) - goto done; + goto done; if (hide == 0) cprintf(cb, "%*s}\n", level*3, ""); retval = 0; - done: + done: if (helptext) free(helptext); return retval; @@ -920,7 +920,7 @@ yang2cli_list(clicon_handle h, yang2cli_helptext(cb, helptext); } /* Look for autocli-op defined in clixon-lib.yang */ - if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0) + if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0) goto done; if (opext != NULL && strcmp(opext, "hide") == 0){ cprintf(cb, ",hide"); diff --git a/lib/clixon/clixon_yang.h b/lib/clixon/clixon_yang.h index 879e6b8c..96084036 100644 --- a/lib/clixon/clixon_yang.h +++ b/lib/clixon/clixon_yang.h @@ -270,6 +270,6 @@ int yang_type_cache_get(yang_stmt *ytype, yang_stmt **resolved, int *opti int yang_type_cache_set(yang_stmt *ys, yang_stmt *resolved, int options, cvec *cvv, cvec *patterns, uint8_t fraction); yang_stmt *yang_anydata_add(yang_stmt *yp, char *name); -int yang_extension_value(yang_stmt *ys, char *name, char *ns, char **value); +int yang_extension_value(yang_stmt *ys, char *name, char *ns, int *exist, char **value); #endif /* _CLIXON_YANG_H_ */ diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 6f3b45ab..d4e70dea 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -3553,15 +3553,20 @@ yang_anydata_add(yang_stmt *yp, return ys; } -/*! Find extension argument and return extension argument value +/*! Find extension argument and return if extension exists and its argument value + * * @param[in] ys Yang statement * @param[in] name Name of the extension * @param[in] ns The namespace + * @param[out] exist The extension exists. * @param[out] value clispec operator (hide/none) - direct pointer into yang, dont free + * @retval 0 OK: Look in exist and value for return value + * @retval -1 Error * This is for extensions with an argument * @code * char *value = NULL; - * if (yang_extension_value(ys, "mymode", "urn:example:lib", &value) < 0) + * int exist = 0; + * if (yang_extension_value(ys, "mymode", "urn:example:lib", &exist, &value) < 0) * err; * if (value != NULL){ * // use extension value @@ -3572,6 +3577,7 @@ int yang_extension_value(yang_stmt *ys, char *name, char *ns, + int *exist, char **value) { int retval = -1; @@ -3593,15 +3599,17 @@ yang_extension_value(yang_stmt *ys, continue; if (yang_find_prefix_by_namespace(ymod, ns, &prefix) < 0) goto ok; + cbuf_reset(cb); cprintf(cb, "%s:%s", prefix, name); if (strcmp(yang_argument_get(yext), cbuf_get(cb)) != 0) continue; break; } if (yext != NULL){ /* Found */ - if ((cv = yang_cv_get(yext)) == NULL) - goto ok; - if (value) + if (exist) + *exist = 1; + if (value && + (cv = yang_cv_get(yext)) != NULL) *value = cv_string_get(cv); } ok: