* Follow-up on [restconf GET json response does not encode top level node with namespace as per rfc #303](https://github.com/clicon/clixon/issues/303)
* Load/save JSON config file did not work * Added rfc7951 parameter to `clixon_json_parse_string()` and `clixon_json_parse_file()` * If set, honor RFC 7951: JSON Encoding of Data Modeled with YANG, eg it requires module name prefixes * If not set, parse as regular JSON * Test: added test_db.sh for datastore format tests
This commit is contained in:
parent
31719b5ef4
commit
97316e0bfa
13 changed files with 281 additions and 43 deletions
|
|
@ -794,25 +794,31 @@ load_config_file(clicon_handle h,
|
|||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int ret = -1;
|
||||
struct stat st;
|
||||
char *filename = NULL;
|
||||
int replace;
|
||||
cg_var *cv;
|
||||
char *opstr;
|
||||
char *varstr;
|
||||
FILE *fp = NULL;
|
||||
cxobj *xt = NULL;
|
||||
cxobj *x;
|
||||
cbuf *cbxml;
|
||||
char *formatstr = NULL;
|
||||
enum format_enum format = FORMAT_XML;
|
||||
int ret = -1;
|
||||
struct stat st;
|
||||
char *filename = NULL;
|
||||
int replace;
|
||||
cg_var *cv;
|
||||
char *opstr;
|
||||
char *varstr;
|
||||
FILE *fp = NULL;
|
||||
cxobj *xt = NULL;
|
||||
cxobj *x;
|
||||
cbuf *cbxml;
|
||||
char *formatstr = NULL;
|
||||
enum format_enum format = FORMAT_XML;
|
||||
yang_stmt *yspec;
|
||||
cxobj *xerr = NULL;
|
||||
|
||||
if (cvec_len(argv) < 2 || cvec_len(argv) > 4){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname>,<varname>[,<format>]",
|
||||
cvec_len(argv));
|
||||
goto done;
|
||||
}
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||
goto done;
|
||||
}
|
||||
if (cvec_len(argv) > 2){
|
||||
formatstr = cv_string_get(cvec_i(argv, 2));
|
||||
if ((int)(format = format_str2int(formatstr)) < 0){
|
||||
|
|
@ -846,12 +852,20 @@ load_config_file(clicon_handle h,
|
|||
}
|
||||
switch (format){
|
||||
case FORMAT_XML:
|
||||
if (clixon_xml_parse_file(fp, YB_NONE, NULL, &xt, NULL) < 0)
|
||||
if ((ret = clixon_xml_parse_file(fp, YB_NONE, yspec, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clixon_netconf_error(xerr, "Loading", filename);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
if (clixon_json_parse_file(fp, YB_NONE, NULL, &xt, NULL) < 0)
|
||||
if ((ret = clixon_json_parse_file(fp, 1, YB_NONE, yspec, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clixon_netconf_error(xerr, "Loading", filename);
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
clicon_err(OE_PLUGIN, 0, "format: %s not implemented", formatstr);
|
||||
|
|
@ -874,9 +888,10 @@ load_config_file(clicon_handle h,
|
|||
cbuf_get(cbxml)) < 0)
|
||||
goto done;
|
||||
cbuf_free(cbxml);
|
||||
// }
|
||||
ret = 0;
|
||||
done:
|
||||
if (xerr)
|
||||
xml_free(xerr);
|
||||
if (xt)
|
||||
xml_free(xt);
|
||||
if (fp)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue