Fixed: [Backend can not read datastore with container named config #147](https://github.com/clicon/clixon/issues/147)
This commit is contained in:
parent
07d196dfd0
commit
9087694b58
9 changed files with 51 additions and 61 deletions
|
|
@ -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 /* "</config>" 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: <top><config><x>... 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: <top><config><x>... 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: <top><config><x>... 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;
|
||||
|
|
|
|||
|
|
@ -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: <top><config><x>... 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;
|
||||
|
|
|
|||
|
|
@ -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:<top> nospec
|
||||
* x: <config>
|
||||
* <a> <-- 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;
|
||||
|
|
|
|||
|
|
@ -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:<top> nospec
|
||||
* x: <a> <-- 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:<top> nospec
|
||||
* x: <config>
|
||||
* <a> <-- 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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue