diff --git a/CHANGELOG.md b/CHANGELOG.md index ae81a95b..5c53fce3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,7 @@ Developers may need to change their code ### Corrected Bugs +* Fixed: [Backend can not read datastore with container named "config" #147](https://github.com/clicon/clixon/issues/147) * Fixed: [The config false leaf shouldn't be configed in startup stage #189](https://github.com/clicon/clixon/issues/189) * Fixed: [CLIXON is not waiting for the hello message #184](https://github.com/clicon/clixon/issues/184) * See also API changes diff --git a/apps/restconf/restconf_methods.c b/apps/restconf/restconf_methods.c index 0f3bfdc2..ed14a95e 100644 --- a/apps/restconf/restconf_methods.c +++ b/apps/restconf/restconf_methods.c @@ -340,7 +340,7 @@ api_data_write(clicon_handle h, } /* Create a dummy data tree parent to hook in the parsed data. */ - if ((xdata0 = xml_new("data0", NULL, CX_ELMNT)) == NULL) + if ((xdata0 = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL) goto done; if (api_path){ /* XXX mv to copy? */ cxobj *xfrom; @@ -357,8 +357,12 @@ api_data_write(clicon_handle h, goto done; } } - if (xml_spec(xdata0)==NULL) - yb = YB_MODULE; + if (xml_spec(xdata0)==NULL){ + if (api_path==NULL) + yb = YB_MODULE_NEXT; /* data is eg: */ + else + yb = YB_MODULE; /* data is eg: */ + } else yb = YB_PARENT; diff --git a/include/clixon_custom.h b/include/clixon_custom.h index 3ae8dcf2..08fa1031 100644 --- a/include/clixon_custom.h +++ b/include/clixon_custom.h @@ -72,16 +72,6 @@ */ #define XML_EXPLICIT_INDEX -/*! Treat and specially in a xmldb datastore. - * config/data is treated as a "neutral" tag that does not have a yang spec. - * In particular when binding xml to yang, if is encountered as top-of-tree, do not - * try to bind a yang-spec to this symbol. - * The root of this is GET and PUT commands where the and tag belongs to the - * RPC rather than the data. - * This is a hack, there must be a way to make this more generic - */ -#define XMLDB_CONFIG_HACK - /*! Let state data be ordered-by system * RFC 7950 is cryptic about this * It says in 7.7.7: @@ -97,6 +87,5 @@ * This is traditionally same as NETCONF_INPUT_CONFIG ("config") but can be different * If you change this, you need to change test shell variable in lib.sh: DATASTORE_TOP * Consider making this an option or configure option - * see XMLDB_CONFIG_HACK */ #define DATASTORE_TOP_SYMBOL "config" diff --git a/lib/clixon/clixon_xml.h b/lib/clixon/clixon_xml.h index 93c9410a..1c073767 100644 --- a/lib/clixon/clixon_xml.h +++ b/lib/clixon/clixon_xml.h @@ -125,7 +125,14 @@ enum cxobj_type {CX_ERROR=-1, */ enum yang_bind{ YB_NONE=0, /* Dont do Yang binding */ - YB_MODULE, /* Search for matching yang binding among top-level symbols of Yang modules */ + YB_MODULE, /* Search for matching yang binding among top-level symbols of Yang modules of direct + * children + * Ie, xml looks like: ... where "x" is a top-level symbol in a module + */ + YB_MODULE_NEXT, /* Search for matching yang binding among top-level symbols of Yang modules of + * next-level children + * Ie, xml looks like: ... where "x" is a top-level symbol in a module + */ YB_PARENT, /* Assume yang binding of existing parent and match its children by name */ YB_RPC, /* Assume top-level xml is an netconf RPC message (or hello) */ diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c index bc8f9a84..2f7ebf6f 100644 --- a/lib/src/clixon_datastore_read.c +++ b/lib/src/clixon_datastore_read.c @@ -442,7 +442,7 @@ xmldb_readfile(clicon_handle h, FILE *fp = NULL; char *format; int ret; - + if (xmldb_db2file(h, db, &dbfile) < 0) goto done; if (dbfile==NULL){ @@ -462,8 +462,11 @@ xmldb_readfile(clicon_handle h, if ((ret = clixon_json_parse_file(fp, yb, yspec, &x0, NULL)) < 0) /* XXX: ret == 0*/ goto done; } - else if ((ret = clixon_xml_parse_file(fp, yb, yspec, NULL /* "" XXX */, &x0, NULL)) < 0) - goto done; + else { + if ((ret = clixon_xml_parse_file(fp, yb, yspec, NULL, &x0, NULL)) < 0){ + goto done; + } + } #ifdef XMLDB_READFILE_FAIL /* The functions calling this function cannot handle a failed parse yet */ if (ret == 0) goto fail; @@ -553,7 +556,10 @@ xmldb_get_nocache(clicon_handle h, clicon_err(OE_YANG, ENOENT, "No yang spec"); goto done; } - if ((ret = xmldb_readfile(h, db, YB_MODULE, yspec, &xt, &de0, msdiff)) < 0) + /* xml looks like: ... where "x" is a top-level symbol in a module */ + if ((ret = xmldb_readfile(h, db, + yb==YB_MODULE?YB_MODULE_NEXT:yb, + yspec, &xt, &de0, msdiff)) < 0) goto done; if (ret == 0) goto fail; @@ -664,7 +670,10 @@ xmldb_get_cache(clicon_handle h, de = clicon_db_elmnt_get(h, db); if (de == NULL || de->de_xml == NULL){ /* Cache miss, read XML from file */ /* If there is no xml x0 tree (in cache), then read it from file */ - if ((ret = xmldb_readfile(h, db, yb, yspec, &x0t, &de0, msdiff)) < 0) + /* xml looks like: ... where "x" is a top-level symbol in a module */ + if ((ret = xmldb_readfile(h, db, + yb==YB_MODULE?YB_MODULE_NEXT:yb, + yspec, &x0t, &de0, msdiff)) < 0) goto done; if (ret == 0) goto fail; @@ -808,7 +817,10 @@ xmldb_get_zerocopy(clicon_handle h, de = clicon_db_elmnt_get(h, db); if (de == NULL || de->de_xml == NULL){ /* Cache miss, read XML from file */ /* If there is no xml x0 tree (in cache), then read it from file */ - if ((ret = xmldb_readfile(h, db, yb, yspec, &x0t, &de0, msdiff)) < 0) + /* xml looks like: ... where "x" is a top-level symbol in a module */ + if ((ret = xmldb_readfile(h, db, + yb==YB_MODULE?YB_MODULE_NEXT:yb, + yspec, &x0t, &de0, msdiff)) < 0) goto done; if (ret == 0) goto fail; diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index abecfbd9..68468a65 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -947,7 +947,8 @@ xmldb_put(clicon_handle h, /* If there is no xml x0 tree (in cache), then read it from file */ if (x0 == NULL){ firsttime++; /* to avoid leakage on error, see fail from text_modify */ - if ((ret = xmldb_readfile(h, db, YB_MODULE, yspec, &x0, de, NULL)) < 0) + /* xml looks like: ... where "x" is a top-level symbol in a module */ + if ((ret = xmldb_readfile(h, db, YB_MODULE_NEXT, yspec, &x0, de, NULL)) < 0) goto done; if (ret == 0) goto fail; diff --git a/lib/src/clixon_json.c b/lib/src/clixon_json.c index 46e9a433..b27733b4 100644 --- a/lib/src/clixon_json.c +++ b/lib/src/clixon_json.c @@ -1231,10 +1231,7 @@ _json_parse(char *str, * members of a top-level JSON object */ if (yspec && xml_prefix(x) == NULL -#ifdef XMLDB_CONFIG_HACK - // && !xml_flag(x, XML_FLAG_TOP) - && strcmp(xml_name(x), DATASTORE_TOP_SYMBOL) != 0 -#endif + /* && yb != YB_MODULE_NEXT XXX Dont know what this is for */ ){ if ((cberr = cbuf_new()) == NULL){ clicon_err(OE_UNIX, errno, "cbuf_new"); @@ -1260,24 +1257,15 @@ _json_parse(char *str, if (ret == 0) failed++; break; + case YB_MODULE_NEXT: + if ((ret = xml_bind_yang(x, YB_MODULE, yspec, xerr)) < 0) + goto done; + if (ret == 0) + failed++; + break; case YB_MODULE: -#ifdef XMLDB_CONFIG_HACK - if ( - // xml_flag(x, XML_FLAG_TOP) - strcmp(xml_name(x), DATASTORE_TOP_SYMBOL) == 0 - || strcmp(xml_name(x), NETCONF_OUTPUT_DATA) == 0 - ){ - /* xt: nospec - * x: - * <-- populate from modules - */ - if ((ret = xml_bind_yang(x, yb, yspec, xerr)) < 0) - goto done; - } - else -#endif - if ((ret = xml_bind_yang0(x, yb, yspec, xerr)) < 0) - goto done; + if ((ret = xml_bind_yang0(x, yb, yspec, xerr)) < 0) + goto done; if (ret == 0) failed++; break; diff --git a/lib/src/clixon_xml_io.c b/lib/src/clixon_xml_io.c index 00062bd4..ddfb414c 100644 --- a/lib/src/clixon_xml_io.c +++ b/lib/src/clixon_xml_io.c @@ -508,25 +508,16 @@ _xml_parse(const char *str, failed++; break; + case YB_MODULE_NEXT: + if ((ret = xml_bind_yang(x, YB_MODULE, yspec, xerr)) < 0) + goto done; + if (ret == 0) + failed++; + break; case YB_MODULE: /* xt: nospec * x: <-- populate from modules */ -#ifdef XMLDB_CONFIG_HACK - if ( - // xml_flag(x, XML_FLAG_TOP) - strcmp(xml_name(x), DATASTORE_TOP_SYMBOL) == 0 - || strcmp(xml_name(x), NETCONF_OUTPUT_DATA) == 0 - ){ - /* xt: nospec - * x: - * <-- populate from modules - */ - if ((ret = xml_bind_yang(x, YB_MODULE, yspec, xerr)) < 0) - goto done; - } - else -#endif if ((ret = xml_bind_yang0(x, YB_MODULE, yspec, xerr)) < 0) goto done; if (ret == 0) diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index 1b0c2890..848f4ebf 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -1762,9 +1762,6 @@ assign_namespace_element(cxobj *x0, /* source */ char *prefix0 = NULL;; int isroot; - /* XXX: need to identify root better than hiereustics and strcmp,... - * see XMLDB_CONFIG_HACK - */ isroot = xml_parent(x1p)==NULL && xml_flag(x1p, XML_FLAG_TOP) && xml_prefix(x1p)==NULL;