New XMLDB_FORMAT added: tree. An experimental record-based tree database for direct access of records.

This commit is contained in:
Olof hagsand 2019-04-26 13:38:55 +02:00
parent 7847e74c5e
commit 50ca7b7845
10 changed files with 692 additions and 86 deletions

View file

@ -80,7 +80,7 @@
#include "clixon_datastore.h"
#include "clixon_datastore_write.h"
#include "clixon_datastore_read.h"
#include "clixon_datastore_tree.h"
/*! Modify a base tree x0 with x1 with yang spec y according to operation op
* @param[in] th Datastore text handle
@ -730,17 +730,26 @@ xmldb_put(clicon_handle h,
if (xml_addsub(x0, xmodst) < 0)
goto done;
}
if ((f = fopen(dbfile, "w")) == NULL){
clicon_err(OE_CFG, errno, "Creating file %s", dbfile);
if ((format = clicon_option_str(h, "CLICON_XMLDB_FORMAT")) == NULL){
clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT");
goto done;
}
format = clicon_option_str(h, "CLICON_XMLDB_FORMAT");
if (format && strcmp(format,"json")==0){
if (xml2json(f, x0, clicon_option_bool(h, "CLICON_XMLDB_PRETTY")) < 0)
goto done;
}
else if (clicon_xml2file(f, x0, 0, clicon_option_bool(h, "CLICON_XMLDB_PRETTY")) < 0)
goto done;
if (strcmp(format, "tree") == 0){
if (datastore_tree_write(h, dbfile, x0) < 0)
goto done;
}
else{
if ((f = fopen(dbfile, "w")) == NULL){
clicon_err(OE_CFG, errno, "Creating file %s", dbfile);
goto done;
}
if (strcmp(format,"json")==0){
if (xml2json(f, x0, clicon_option_bool(h, "CLICON_XMLDB_PRETTY")) < 0)
goto done;
}
else if (clicon_xml2file(f, x0, 0, clicon_option_bool(h, "CLICON_XMLDB_PRETTY")) < 0)
goto done;
}
/* Remove modules state after writing to file
*/
if (xmodst && xml_purge(xmodst) < 0)