From fb9917e81e12eb7f0e675ba1c7ecc18317923fdf Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 15 Mar 2021 13:24:27 +0100 Subject: [PATCH] * Removed `endtag` parameter of `clixon_xml_parse_file()` --- CHANGELOG.md | 1 + apps/backend/backend_main.c | 2 +- apps/backend/backend_startup.c | 2 +- apps/cli/cli_common.c | 2 +- example/main/example_backend.c | 4 ++-- lib/clixon/clixon_xml_io.h | 2 +- lib/src/clixon_datastore_read.c | 2 +- lib/src/clixon_options.c | 2 +- lib/src/clixon_xml_changelog.c | 2 +- lib/src/clixon_xml_io.c | 15 +++------------ util/clixon_util_datastore.c | 2 +- util/clixon_util_path.c | 2 +- util/clixon_util_socket.c | 2 +- util/clixon_util_xml.c | 4 ++-- util/clixon_util_xpath.c | 2 +- 15 files changed, 19 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f560b1c..5ff026ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ Expected: April Developers may need to change their code +* Removed `endtag` parameter of `clixon_xml_parse_file()` * Restconf authentication callback (ca_auth) signature changed (again) * Minor modification to 5.0 change: userp removed. * New version is: `int ca_auth(h, req, auth_type, authp)`, where diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index 83d205f4..ad0c3299 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -226,7 +226,7 @@ nacm_load_external(clicon_handle h) if (yang_spec_parse_module(h, "ietf-netconf-acm", NULL, yspec) < 0) goto done; /* Read configfile */ - if (clixon_xml_parse_file(f, YB_MODULE, yspec, NULL, &xt, NULL) < 0) + if (clixon_xml_parse_file(f, YB_MODULE, yspec, &xt, NULL) < 0) goto done; if (xt == NULL){ clicon_err(OE_XML, 0, "No xml tree in %s", filename); diff --git a/apps/backend/backend_startup.c b/apps/backend/backend_startup.c index f7ff0b1d..b4a82014 100644 --- a/apps/backend/backend_startup.c +++ b/apps/backend/backend_startup.c @@ -182,7 +182,7 @@ load_extraxml(clicon_handle h, } yspec = clicon_dbspec_yang(h); /* No yang check yet because it has as top symbol, do it later after that is removed */ - if (clixon_xml_parse_file(fp, YB_NONE, yspec, NULL, &xt, &xerr) < 0) + if (clixon_xml_parse_file(fp, YB_NONE, yspec, &xt, &xerr) < 0) goto done; /* Replace parent w first child */ if (xml_rootchild(xt, 0, &xt) < 0) diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 15346b16..b2be4f3f 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -826,7 +826,7 @@ load_config_file(clicon_handle h, clicon_err(OE_UNIX, errno, "open(%s)", filename); goto done; } - if (clixon_xml_parse_file(fp, YB_NONE, NULL, NULL, &xt, NULL) < 0) + if (clixon_xml_parse_file(fp, YB_NONE, NULL, &xt, NULL) < 0) goto done; if (xt == NULL) goto done; diff --git a/example/main/example_backend.c b/example/main/example_backend.c index 7f402e1e..9d7d757d 100644 --- a/example/main/example_backend.c +++ b/example/main/example_backend.c @@ -408,7 +408,7 @@ example_statedata(clicon_handle h, } if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL) goto done; - if (clixon_xml_parse_file(fp, YB_MODULE, yspec, NULL, &xt, NULL) < 0) + if (clixon_xml_parse_file(fp, YB_MODULE, yspec, &xt, NULL) < 0) goto done; if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath) < 0) goto done; @@ -991,7 +991,7 @@ example_daemon(clicon_handle h) clicon_err(OE_UNIX, errno, "open(%s)", _state_file); goto done; } - if ((ret = clixon_xml_parse_file(fp, YB_MODULE, yspec, NULL, &_state_xstate, NULL)) < 0) + if ((ret = clixon_xml_parse_file(fp, YB_MODULE, yspec, &_state_xstate, NULL)) < 0) goto done; if (ret == 0){ fprintf(stderr, "%s error\n", __FUNCTION__); diff --git a/lib/clixon/clixon_xml_io.h b/lib/clixon/clixon_xml_io.h index 338ef8ca..4863ea68 100644 --- a/lib/clixon/clixon_xml_io.h +++ b/lib/clixon/clixon_xml_io.h @@ -50,7 +50,7 @@ int clicon_xml2cbuf(cbuf *cb, cxobj *x, int level, int prettyprint, int32_t dept char *clicon_xml2str(cxobj *x); int xmltree2cbuf(cbuf *cb, cxobj *x, int level); -int clixon_xml_parse_file(FILE *f, yang_bind yb, yang_stmt *yspec, char *endtag, cxobj **xt, cxobj **xerr); +int clixon_xml_parse_file(FILE *f, yang_bind yb, yang_stmt *yspec, cxobj **xt, cxobj **xerr); int clixon_xml_parse_string(const char *str, yang_bind yb, yang_stmt *yspec, cxobj **xt, cxobj **xerr); #if defined(__GNUC__) && __GNUC__ >= 3 diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c index 2f7ebf6f..1932f65c 100644 --- a/lib/src/clixon_datastore_read.c +++ b/lib/src/clixon_datastore_read.c @@ -463,7 +463,7 @@ xmldb_readfile(clicon_handle h, goto done; } else { - if ((ret = clixon_xml_parse_file(fp, yb, yspec, NULL, &x0, NULL)) < 0){ + if ((ret = clixon_xml_parse_file(fp, yb, yspec, &x0, NULL)) < 0){ goto done; } } diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index f966e7e7..e4904cd1 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -216,7 +216,7 @@ parse_configfile_one(const char *filename, return -1; } clicon_debug(2, "%s: Reading config file %s", __FUNCTION__, filename); - if ((ret = clixon_xml_parse_file(fp, yspec?YB_MODULE:YB_NONE, yspec, NULL, &xt, &xerr)) < 0) + if ((ret = clixon_xml_parse_file(fp, yspec?YB_MODULE:YB_NONE, yspec, &xt, &xerr)) < 0) goto done; if (ret == 0){ if ((cbret = cbuf_new()) ==NULL){ diff --git a/lib/src/clixon_xml_changelog.c b/lib/src/clixon_xml_changelog.c index 34ac09fb..3b15155a 100644 --- a/lib/src/clixon_xml_changelog.c +++ b/lib/src/clixon_xml_changelog.c @@ -449,7 +449,7 @@ clixon_xml_changelog_init(clicon_handle h) clicon_err(OE_UNIX, errno, "fopen(%s)", filename); goto done; } - if (clixon_xml_parse_file(fp, YB_MODULE, yspec, NULL, &xt, NULL) < 0) + if (clixon_xml_parse_file(fp, YB_MODULE, yspec, &xt, NULL) < 0) goto done; if (xml_rootchild(xt, 0, &xt) < 0) goto done; diff --git a/lib/src/clixon_xml_io.c b/lib/src/clixon_xml_io.c index ddfb414c..f383bd43 100644 --- a/lib/src/clixon_xml_io.c +++ b/lib/src/clixon_xml_io.c @@ -572,8 +572,8 @@ FSM(char *tag, * @param[in] fd A file descriptor containing the XML file (as ASCII characters) * @param[in] yb How to bind yang to XML top-level when parsing * @param[in] yspec Yang specification (only if bind is TOP or CONFIG) - * @param[in] endtag Read until encounter "endtag" in the stream, or NULL * @param[in,out] xt Pointer to XML parse tree. If empty, create. + * @param[out] xerr Pointer to XML error tree, if retval is 0 * @retval 1 Parse OK and all yang assignment made * @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set * @retval -1 Error with clicon_err called. Includes parse error @@ -584,7 +584,7 @@ FSM(char *tag, * FILE *f; * if ((f = fopen(filename, "r")) == NULL) * err; - * if ((ret = clixon_xml_parse_file(f, YB_MODULE, yspec, "", &xt, &xerr)) < 0) + * if ((ret = clixon_xml_parse_file(f, YB_MODULE, yspec, &xt, &xerr)) < 0) * err; * xml_free(xt); * @endcode @@ -597,7 +597,6 @@ int clixon_xml_parse_file(FILE *fp, yang_bind yb, yang_stmt *yspec, - char *endtag, cxobj **xt, cxobj **xerr) { @@ -608,8 +607,6 @@ clixon_xml_parse_file(FILE *fp, char *xmlbuf = NULL; char *ptr; int xmlbuflen = BUFLEN; /* start size */ - int endtaglen = 0; - int state = 0; int oldxmlbuflen; int failed = 0; @@ -621,8 +618,6 @@ clixon_xml_parse_file(FILE *fp, clicon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE"); return -1; } - if (endtag != NULL) - endtaglen = strlen(endtag); if ((xmlbuf = malloc(xmlbuflen)) == NULL){ clicon_err(OE_XML, errno, "malloc"); goto done; @@ -635,13 +630,9 @@ clixon_xml_parse_file(FILE *fp, break; } if (ret != 0){ - if (endtag) - state = FSM(endtag, ch, state); xmlbuf[len++] = ch; } - if (ret == 0 || - (endtag && (state == endtaglen))){ - state = 0; + if (ret == 0) { if (*xt == NULL) if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL) goto done; diff --git a/util/clixon_util_datastore.c b/util/clixon_util_datastore.c index a1245202..7d792031 100644 --- a/util/clixon_util_datastore.c +++ b/util/clixon_util_datastore.c @@ -257,7 +257,7 @@ main(int argc, char **argv) clicon_err(OE_UNIX, errno, "fopen(%s)", xmlfilename); goto done; } - if (clixon_xml_parse_file(fp, YB_MODULE, yspec, NULL, &xt, NULL) < 0) + if (clixon_xml_parse_file(fp, YB_MODULE, yspec, &xt, NULL) < 0) goto done; fclose(fp); } diff --git a/util/clixon_util_path.c b/util/clixon_util_path.c index 70a2e17c..d07f6bdb 100644 --- a/util/clixon_util_path.c +++ b/util/clixon_util_path.c @@ -215,7 +215,7 @@ main(int argc, * If fp=stdin, then continue reading from stdin (after CR) * XXX Note 0 above, stdin here */ - if (clixon_xml_parse_file(fp, YB_NONE, NULL, NULL, &x, NULL) < 0){ + if (clixon_xml_parse_file(fp, YB_NONE, NULL, &x, NULL) < 0){ fprintf(stderr, "Error: parsing: %s\n", clicon_err_reason); return -1; } diff --git a/util/clixon_util_socket.c b/util/clixon_util_socket.c index 75a8992e..28ce05b0 100644 --- a/util/clixon_util_socket.c +++ b/util/clixon_util_socket.c @@ -156,7 +156,7 @@ main(int argc, } } else{ - if (clixon_xml_parse_file(fp, YB_NONE, NULL, NULL, &xt, NULL) < 0){ + if (clixon_xml_parse_file(fp, YB_NONE, NULL, &xt, NULL) < 0){ fprintf(stderr, "xml parse error: %s\n", clicon_err_reason); goto done; } diff --git a/util/clixon_util_xml.c b/util/clixon_util_xml.c index 83d76bdd..87a35d9c 100644 --- a/util/clixon_util_xml.c +++ b/util/clixon_util_xml.c @@ -267,7 +267,7 @@ main(int argc, clicon_err(OE_YANG, errno, "fopen(%s)", top_input_filename); goto done; } - if ((ret = clixon_xml_parse_file(tfp, YB_MODULE, yspec, NULL, &xtop, &xerr)) < 0){ + if ((ret = clixon_xml_parse_file(tfp, YB_MODULE, yspec, &xtop, &xerr)) < 0){ fprintf(stderr, "xml parse error: %s\n", clicon_err_reason); goto done; } @@ -309,7 +309,7 @@ main(int argc, yb = YB_MODULE; else yb = YB_PARENT; - if ((ret = clixon_xml_parse_file(fp, yb, yspec, NULL, &xt, &xerr)) < 0){ + if ((ret = clixon_xml_parse_file(fp, yb, yspec, &xt, &xerr)) < 0){ fprintf(stderr, "xml parse error: %s\n", clicon_err_reason); goto done; } diff --git a/util/clixon_util_xpath.c b/util/clixon_util_xpath.c index dab86fd3..a0ec6368 100644 --- a/util/clixon_util_xpath.c +++ b/util/clixon_util_xpath.c @@ -298,7 +298,7 @@ main(int argc, * If fp=stdin, then continue reading from stdin (after CR) * XXX Note 0 above, stdin here */ - if (clixon_xml_parse_file(fp, YB_NONE, NULL, NULL, &x0, NULL) < 0){ + if (clixon_xml_parse_file(fp, YB_NONE, NULL, &x0, NULL) < 0){ fprintf(stderr, "Error: parsing: %s\n", clicon_err_reason); return -1; }