Added "exist" parameter to yang_extension_value()
This commit is contained in:
parent
448aa4c994
commit
063e6d6faa
4 changed files with 36 additions and 28 deletions
|
|
@ -171,7 +171,7 @@ cli_xml2file(cxobj *xn,
|
||||||
if (xn == NULL)
|
if (xn == NULL)
|
||||||
goto ok;
|
goto ok;
|
||||||
/* Look for autocli-op defined in clixon-lib.yang */
|
/* 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;
|
goto ok;
|
||||||
}
|
}
|
||||||
if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){
|
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");
|
clicon_err(OE_XML, EINVAL, "xn or fn is NULL");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
/* Look for autocli-op defined in clixon-lib.yang */
|
/* 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;
|
goto ok;
|
||||||
}
|
}
|
||||||
if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){
|
if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){
|
||||||
goto ok;
|
goto ok;
|
||||||
}
|
}
|
||||||
xc = NULL; /* count children (elements and bodies, not attributes) */
|
xc = NULL; /* count children (elements and bodies, not attributes) */
|
||||||
while ((xc = xml_child_each(xn, xc, -1)) != NULL)
|
while ((xc = xml_child_each(xn, xc, -1)) != NULL)
|
||||||
if (xml_type(xc) == CX_ELMNT || xml_type(xc) == CX_BODY)
|
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)
|
if ((ys = xml_spec(xn)) == NULL)
|
||||||
goto ok;
|
goto ok;
|
||||||
/* Look for autocli-op defined in clixon-lib.yang */
|
/* 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;
|
goto ok;
|
||||||
}
|
}
|
||||||
if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){
|
if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ cli_expand_var_generate(clicon_handle h,
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
char *api_path_fmt = NULL, *opext = NULL;
|
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;
|
goto done;
|
||||||
if (opext && strcmp(opext, "hide-database") == 0) {
|
if (opext && strcmp(opext, "hide-database") == 0) {
|
||||||
retval = 1;
|
retval = 1;
|
||||||
|
|
@ -762,7 +762,7 @@ yang2cli_leaf(clicon_handle h,
|
||||||
}
|
}
|
||||||
cprintf(cb, "%*s", level*3, "");
|
cprintf(cb, "%*s", level*3, "");
|
||||||
/* Look for autocli-op defined in clixon-lib.yang */
|
/* 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;
|
goto done;
|
||||||
if (gt == GT_VARS|| gt == GT_ALL || gt == GT_HIDE){
|
if (gt == GT_VARS|| gt == GT_ALL || gt == GT_HIDE){
|
||||||
cprintf(cb, "%s", yang_argument_get(ys));
|
cprintf(cb, "%s", yang_argument_get(ys));
|
||||||
|
|
@ -839,7 +839,7 @@ yang2cli_container(clicon_handle h,
|
||||||
* a list, then skip container keyword
|
* a list, then skip container keyword
|
||||||
* See also xml2cli
|
* 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));
|
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
|
||||||
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
|
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
|
||||||
if ((helptext = strdup(yang_argument_get(yd))) == 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)
|
if (cli_callback_generate(h, ys, cb) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
/* Look for autocli-op defined in clixon-lib.yang */
|
/* 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;
|
goto done;
|
||||||
if (opext != NULL && strcmp(opext, "hide") == 0){
|
if (opext != NULL && strcmp(opext, "hide") == 0){
|
||||||
cprintf(cb, ",hide");
|
cprintf(cb, ",hide");
|
||||||
}
|
}
|
||||||
if (opext != NULL && strcmp(opext, "hide-database-auto-completion") == 0){
|
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");
|
cprintf(cb, ";{\n");
|
||||||
}
|
}
|
||||||
|
|
@ -868,11 +868,11 @@ yang2cli_container(clicon_handle h,
|
||||||
yc = NULL;
|
yc = NULL;
|
||||||
while ((yc = yn_each(ys, yc)) != NULL)
|
while ((yc = yn_each(ys, yc)) != NULL)
|
||||||
if (yang2cli_stmt(h, yc, gt, level+1, state, show_tree, cb) < 0)
|
if (yang2cli_stmt(h, yc, gt, level+1, state, show_tree, cb) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (hide == 0)
|
if (hide == 0)
|
||||||
cprintf(cb, "%*s}\n", level*3, "");
|
cprintf(cb, "%*s}\n", level*3, "");
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
if (helptext)
|
if (helptext)
|
||||||
free(helptext);
|
free(helptext);
|
||||||
return retval;
|
return retval;
|
||||||
|
|
@ -920,7 +920,7 @@ yang2cli_list(clicon_handle h,
|
||||||
yang2cli_helptext(cb, helptext);
|
yang2cli_helptext(cb, helptext);
|
||||||
}
|
}
|
||||||
/* Look for autocli-op defined in clixon-lib.yang */
|
/* 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;
|
goto done;
|
||||||
if (opext != NULL && strcmp(opext, "hide") == 0){
|
if (opext != NULL && strcmp(opext, "hide") == 0){
|
||||||
cprintf(cb, ",hide");
|
cprintf(cb, ",hide");
|
||||||
|
|
|
||||||
|
|
@ -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,
|
int yang_type_cache_set(yang_stmt *ys, yang_stmt *resolved, int options, cvec *cvv,
|
||||||
cvec *patterns, uint8_t fraction);
|
cvec *patterns, uint8_t fraction);
|
||||||
yang_stmt *yang_anydata_add(yang_stmt *yp, char *name);
|
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_ */
|
#endif /* _CLIXON_YANG_H_ */
|
||||||
|
|
|
||||||
|
|
@ -3553,15 +3553,20 @@ yang_anydata_add(yang_stmt *yp,
|
||||||
return ys;
|
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] ys Yang statement
|
||||||
* @param[in] name Name of the extension
|
* @param[in] name Name of the extension
|
||||||
* @param[in] ns The namespace
|
* @param[in] ns The namespace
|
||||||
|
* @param[out] exist The extension exists.
|
||||||
* @param[out] value clispec operator (hide/none) - direct pointer into yang, dont free
|
* @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
|
* This is for extensions with an argument
|
||||||
* @code
|
* @code
|
||||||
* char *value = NULL;
|
* 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;
|
* err;
|
||||||
* if (value != NULL){
|
* if (value != NULL){
|
||||||
* // use extension value
|
* // use extension value
|
||||||
|
|
@ -3572,6 +3577,7 @@ int
|
||||||
yang_extension_value(yang_stmt *ys,
|
yang_extension_value(yang_stmt *ys,
|
||||||
char *name,
|
char *name,
|
||||||
char *ns,
|
char *ns,
|
||||||
|
int *exist,
|
||||||
char **value)
|
char **value)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
@ -3593,15 +3599,17 @@ yang_extension_value(yang_stmt *ys,
|
||||||
continue;
|
continue;
|
||||||
if (yang_find_prefix_by_namespace(ymod, ns, &prefix) < 0)
|
if (yang_find_prefix_by_namespace(ymod, ns, &prefix) < 0)
|
||||||
goto ok;
|
goto ok;
|
||||||
|
cbuf_reset(cb);
|
||||||
cprintf(cb, "%s:%s", prefix, name);
|
cprintf(cb, "%s:%s", prefix, name);
|
||||||
if (strcmp(yang_argument_get(yext), cbuf_get(cb)) != 0)
|
if (strcmp(yang_argument_get(yext), cbuf_get(cb)) != 0)
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (yext != NULL){ /* Found */
|
if (yext != NULL){ /* Found */
|
||||||
if ((cv = yang_cv_get(yext)) == NULL)
|
if (exist)
|
||||||
goto ok;
|
*exist = 1;
|
||||||
if (value)
|
if (value &&
|
||||||
|
(cv = yang_cv_get(yext)) != NULL)
|
||||||
*value = cv_string_get(cv);
|
*value = cv_string_get(cv);
|
||||||
}
|
}
|
||||||
ok:
|
ok:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue