* New XML parsing API:
* `clixon_xml_parse_string()` * `clixon_xml_parse_file()` * New JSON parsing API, with same signature as XML parsing: * `clixon_json_parse_string()` * `clixon_xml_parse_file()` * XML YANG binding API have been rearranged as follows: * `xml_bind_yang_rpc()` * `xml_bind_yang_rpc_reply()` * `xml_bind_yang()` * `xml_bind_yang0()`
This commit is contained in:
parent
c4b0491754
commit
09a2e09848
54 changed files with 590 additions and 711 deletions
|
|
@ -254,12 +254,12 @@ main(int argc, char **argv)
|
|||
clicon_err(OE_UNIX, errno, "open(%s)", xmlfilename);
|
||||
goto done;
|
||||
}
|
||||
if (xml_parse_file(fd, yspec, &xt) < 0)
|
||||
if (clixon_xml_parse_file(fd, YB_MODULE, yspec, NULL, &xt, NULL) < 0)
|
||||
goto done;
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
if (xml_parse_string(argv[2], yspec, &xt) < 0)
|
||||
if (clixon_xml_parse_string(argv[2], YB_MODULE, yspec, &xt, NULL) < 0)
|
||||
goto done;
|
||||
if (xml_rootchild(xt, 0, &xt) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
* On success, nothing is printed and exitcode 0
|
||||
* On failure, an error is printed on stderr and exitcode != 0
|
||||
* Failure error prints are different, it would be nice to make them more
|
||||
* uniform. (see clicon_rpc_generate_error)
|
||||
* uniform. (see clixon_netconf_error)
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
|
|||
|
|
@ -140,19 +140,14 @@ main(int argc, char **argv)
|
|||
clicon_debug(1, "xpath:%s", xpath);
|
||||
if ((yspec = yspec_new()) == NULL)
|
||||
goto done;
|
||||
#if 1
|
||||
if (yang_spec_parse_file(h, filename, yspec) < 0)
|
||||
goto done;
|
||||
#else
|
||||
if (yang_parse_file(fd, "yang test", yspec) == NULL)
|
||||
goto done;
|
||||
#endif
|
||||
/* Parse base XML */
|
||||
if (xml_parse_string(x0str, yspec, &x0) < 0){
|
||||
if (clixon_xml_parse_string(x0str, YB_MODULE, yspec, &x0, NULL) < 0){
|
||||
clicon_err(OE_XML, 0, "Parsing base xml: %s", x0str);
|
||||
goto done;
|
||||
}
|
||||
if (xml_bind_yang(x0, yspec, NULL) < 0)
|
||||
if (xml_bind_yang(x0, YB_MODULE, yspec, NULL) < 0)
|
||||
goto done;
|
||||
if ((xb = xpath_first(x0, NULL, "%s", xpath)) == NULL){
|
||||
clicon_err(OE_XML, 0, "xpath: %s not found in x0", xpath);
|
||||
|
|
@ -163,11 +158,11 @@ main(int argc, char **argv)
|
|||
xml_print(stderr, xb);
|
||||
}
|
||||
/* Parse insert XML */
|
||||
if (xml_parse_string(xistr, yspec, &xi) < 0){
|
||||
if (clixon_xml_parse_string(xistr, YB_MODULE, yspec, &xi, NULL) < 0){
|
||||
clicon_err(OE_XML, 0, "Parsing insert xml: %s", xistr);
|
||||
goto done;
|
||||
}
|
||||
if (xml_bind_yang(xi, yspec, NULL) < 0)
|
||||
if (xml_bind_yang(xi, YB_MODULE, yspec, NULL) < 0)
|
||||
goto done;
|
||||
if ((xi = xpath_first(xi, NULL, "%s", xpath)) == NULL){
|
||||
clicon_err(OE_XML, 0, "xpath: %s not found in xi", xpath);
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ main(int argc,
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
if ((ret = json_parse_file(0, yspec, &xt, &xerr)) < 0)
|
||||
if ((ret = clixon_json_parse_file(0, yspec?YB_MODULE:YB_NONE, yspec, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
xml_print(stderr, xerr);
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ main(int argc,
|
|||
* If fd=0, then continue reading from stdin (after CR)
|
||||
* If fd>0, reading from file opened as argv[1]
|
||||
*/
|
||||
if (xml_parse_file(fd, NULL, &x) < 0){
|
||||
if (clixon_xml_parse_file(fd, YB_NONE, NULL, NULL, &x, NULL) < 0){
|
||||
fprintf(stderr, "Error: parsing: %s\n", clicon_err_reason);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -220,7 +220,7 @@ main(int argc,
|
|||
/* Validate XML as well */
|
||||
if (yang_file_dir){
|
||||
/* Populate */
|
||||
if (xml_bind_yang(x, yspec, NULL) < 0)
|
||||
if (xml_bind_yang(x, YB_MODULE, yspec, NULL) < 0)
|
||||
goto done;
|
||||
/* Add default values */
|
||||
if (xml_apply(x, CX_ELMNT, xml_default, h) < 0)
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ main(int argc,
|
|||
}
|
||||
/* 2. Parse data (xml/json) */
|
||||
if (jsonin){
|
||||
if ((ret = json_parse_file(fd, NULL, &xt, &xerr)) < 0)
|
||||
if ((ret = clixon_json_parse_file(fd, YB_NONE, NULL, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
fprintf(stderr, "Invalid JSON\n");
|
||||
|
|
@ -150,7 +150,7 @@ main(int argc,
|
|||
}
|
||||
}
|
||||
else{
|
||||
if (xml_parse_file(fd, NULL, &xt) < 0){
|
||||
if (clixon_xml_parse_file(fd, YB_NONE, NULL, NULL, &xt, NULL) < 0){
|
||||
fprintf(stderr, "xml parse error: %s\n", clicon_err_reason);
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
* On success, nothing is printed and exitcode 0
|
||||
* On failure, an error is printed on stderr and exitcode != 0
|
||||
* Failure error prints are different, it would be nice to make them more
|
||||
* uniform. (see clicon_rpc_generate_error)
|
||||
* uniform. (see clixon_netconf_error)
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
@ -161,7 +161,7 @@ main(int argc,
|
|||
char *top_path = NULL;
|
||||
cxobj *xbot; /* Place in xtop where base cxobj is parsed */
|
||||
cvec *nsc = NULL;
|
||||
enum yang_bind yb;
|
||||
yang_bind yb;
|
||||
|
||||
/* In the startup, logs to stderr & debug flag set later */
|
||||
clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
|
||||
|
|
@ -260,10 +260,14 @@ main(int argc,
|
|||
clicon_err(OE_YANG, errno, "open(%s)", top_input_filename);
|
||||
goto done;
|
||||
}
|
||||
if (xml_parse_file(tfd, yspec, &xtop) < 0){
|
||||
if ((ret = clixon_xml_parse_file(tfd, YB_MODULE, yspec, NULL, &xtop, &xerr)) < 0){
|
||||
fprintf(stderr, "xml parse error: %s\n", clicon_err_reason);
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clixon_netconf_error(OE_NETCONF, xerr, "Parse top file", NULL);
|
||||
goto done;
|
||||
}
|
||||
if (validate_tree(h, xtop, yspec) < 0)
|
||||
goto done;
|
||||
|
||||
|
|
@ -284,10 +288,10 @@ main(int argc,
|
|||
}
|
||||
/* 2. Parse data (xml/json) */
|
||||
if (jsonin){
|
||||
if ((ret = json_parse_file(fd, yspec, &xt, &xerr)) < 0)
|
||||
if ((ret = clixon_json_parse_file(fd, top_input_filename?YB_PARENT:YB_MODULE, yspec, &xt, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
clicon_rpc_generate_error(xerr, "util_xml", NULL);
|
||||
clixon_netconf_error(OE_NETCONF, xerr, "util_xml", NULL);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -295,15 +299,15 @@ main(int argc,
|
|||
if (!yang_file_dir)
|
||||
yb = YB_NONE;
|
||||
else if (xt == NULL)
|
||||
yb = YB_TOP;
|
||||
yb = YB_MODULE;
|
||||
else
|
||||
yb = YB_PARENT;
|
||||
if ((ret = xml_parse_file2(fd, yb, yspec, NULL, &xt, &xerr)) < 0){
|
||||
if ((ret = clixon_xml_parse_file(fd, yb, yspec, NULL, &xt, &xerr)) < 0){
|
||||
fprintf(stderr, "xml parse error: %s\n", clicon_err_reason);
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
clicon_rpc_generate_error(xerr, "util_xml", NULL);
|
||||
clixon_netconf_error(OE_NETCONF, xerr, "util_xml", NULL);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ main(int argc,
|
|||
* If fd=0, then continue reading from stdin (after CR)
|
||||
* If fd>0, reading from file opened as argv[1]
|
||||
*/
|
||||
if (xml_parse_file(fd, NULL, &x0) < 0){
|
||||
if (clixon_xml_parse_file(fd, YB_NONE, NULL, NULL, &x0, NULL) < 0){
|
||||
fprintf(stderr, "Error: parsing: %s\n", clicon_err_reason);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -288,7 +288,7 @@ main(int argc,
|
|||
/* Validate XML as well */
|
||||
if (yang_file_dir){
|
||||
/* Populate */
|
||||
if (xml_bind_yang(x0, yspec, NULL) < 0)
|
||||
if (xml_bind_yang(x0, YB_MODULE, yspec, NULL) < 0)
|
||||
goto done;
|
||||
/* Sort */
|
||||
if (xml_apply(x0, CX_ELMNT, xml_sort, h) < 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue