Added option to treat unknown XML (wrt YANG) as anydata.

This commit is contained in:
Olof hagsand 2020-05-03 22:03:33 +02:00
parent 12d1b67250
commit dafc6d10e0
15 changed files with 80 additions and 8 deletions

View file

@ -555,7 +555,7 @@ clicon_option_int_set(clicon_handle h,
*/
int
clicon_option_bool(clicon_handle h,
const char *name)
const char *name)
{
char *s;
@ -563,7 +563,9 @@ clicon_option_bool(clicon_handle h,
return 0;
if (strcmp(s,"true")==0)
return 1;
return 0; /* Hopefully false, but anything else than "true" */
if (strcmp(s,"1")==0)
return 1;
return 0; /* Hopefully false, but anything else than "true" or "one" */
}
/*! Set option given as bool
@ -578,8 +580,14 @@ clicon_option_bool_set(clicon_handle h,
{
char s[64];
if (snprintf(s, sizeof(s)-1, "%u", val) < 0)
if (val != 0 && val != 1){
clicon_err(OE_CFG, EINVAL, "val is %d, 0 or 1 expected", val);
return -1;
}
if (snprintf(s, sizeof(s)-1, "%s", val?"true":"false") < 0){
clicon_err(OE_CFG, errno, "snprintf");
return -1;
}
return clicon_option_str_set(h, name, s);
}

View file

@ -1091,15 +1091,17 @@ xml_yang_validate_all(clicon_handle h,
and !Node has a config sub-statement and it is false */
ys=xml_spec(xt);
if (ys==NULL){
if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1)
goto ok;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
if (xml2ns(xt, xml_prefix(xt), &namespace) < 0)
goto done;
cprintf(cb, "Failed to find YANG spec of XML node: %s", xml_name(xt));
if ((xp = xml_parent(xt)) != NULL)
cprintf(cb, " with parent: %s", xml_name(xp));
if (xml2ns(xt, xml_prefix(xt), &namespace) < 0)
goto done;
if (namespace)
cprintf(cb, " in namespace: %s", namespace);
if (netconf_unknown_element_xml(xret, "application", xml_name(xt), cbuf_get(cb)) < 0)

View file

@ -79,6 +79,21 @@
#include "clixon_yang_type.h"
#include "clixon_xml_bind.h"
/*
* Local variables
*/
static int _yang_unknown_anydata = 0;
/*! Kludge to equate unknown XML with anydata
* The problem with this is that its global and shuld be bound to a handle
*/
int
xml_bind_yang_unknown_anydata(int bool)
{
_yang_unknown_anydata = bool;
return 0;
}
/*! After yang binding, bodies of containers and lists are stripped from XML bodies
* May apply to other nodes?
*/
@ -156,6 +171,10 @@ populate_self_parent(cxobj *xt,
if (xml2ns(xt, xml_prefix(xt), &ns) < 0)
goto done;
if ((y = yang_find_datanode(yparent, name)) == NULL){
if (_yang_unknown_anydata){
retval = 2; /* treat as anydata */
goto done;
}
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
@ -244,6 +263,10 @@ populate_self_top(cxobj *xt,
if (xml2ns(xt, xml_prefix(xt), &ns) < 0)
goto done;
if ((y = yang_find_schemanode(ymod, name)) == NULL){ /* also rpc */
if (_yang_unknown_anydata){
retval = 2; /* treat as anydata */
goto done;
}
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;