* Removed endtag parameter of clixon_xml_parse_file()

This commit is contained in:
Olof hagsand 2021-03-15 13:24:27 +01:00
parent f536b1dc67
commit fb9917e81e
15 changed files with 19 additions and 27 deletions

View file

@ -48,6 +48,7 @@ Expected: April
Developers may need to change their code Developers may need to change their code
* Removed `endtag` parameter of `clixon_xml_parse_file()`
* Restconf authentication callback (ca_auth) signature changed (again) * Restconf authentication callback (ca_auth) signature changed (again)
* Minor modification to 5.0 change: userp removed. * Minor modification to 5.0 change: userp removed.
* New version is: `int ca_auth(h, req, auth_type, authp)`, where * New version is: `int ca_auth(h, req, auth_type, authp)`, where

View file

@ -226,7 +226,7 @@ nacm_load_external(clicon_handle h)
if (yang_spec_parse_module(h, "ietf-netconf-acm", NULL, yspec) < 0) if (yang_spec_parse_module(h, "ietf-netconf-acm", NULL, yspec) < 0)
goto done; goto done;
/* Read configfile */ /* 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; goto done;
if (xt == NULL){ if (xt == NULL){
clicon_err(OE_XML, 0, "No xml tree in %s", filename); clicon_err(OE_XML, 0, "No xml tree in %s", filename);

View file

@ -182,7 +182,7 @@ load_extraxml(clicon_handle h,
} }
yspec = clicon_dbspec_yang(h); yspec = clicon_dbspec_yang(h);
/* No yang check yet because it has <config> as top symbol, do it later after that is removed */ /* No yang check yet because it has <config> 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; goto done;
/* Replace parent w first child */ /* Replace parent w first child */
if (xml_rootchild(xt, 0, &xt) < 0) if (xml_rootchild(xt, 0, &xt) < 0)

View file

@ -826,7 +826,7 @@ load_config_file(clicon_handle h,
clicon_err(OE_UNIX, errno, "open(%s)", filename); clicon_err(OE_UNIX, errno, "open(%s)", filename);
goto done; 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; goto done;
if (xt == NULL) if (xt == NULL)
goto done; goto done;

View file

@ -408,7 +408,7 @@ example_statedata(clicon_handle h,
} }
if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL) if ((xt = xml_new("config", NULL, CX_ELMNT)) == NULL)
goto done; 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; goto done;
if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath) < 0) if (xpath_vec(xt, nsc, "%s", &xvec, &xlen, xpath) < 0)
goto done; goto done;
@ -991,7 +991,7 @@ example_daemon(clicon_handle h)
clicon_err(OE_UNIX, errno, "open(%s)", _state_file); clicon_err(OE_UNIX, errno, "open(%s)", _state_file);
goto done; 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; goto done;
if (ret == 0){ if (ret == 0){
fprintf(stderr, "%s error\n", __FUNCTION__); fprintf(stderr, "%s error\n", __FUNCTION__);

View file

@ -50,7 +50,7 @@ int clicon_xml2cbuf(cbuf *cb, cxobj *x, int level, int prettyprint, int32_t dept
char *clicon_xml2str(cxobj *x); char *clicon_xml2str(cxobj *x);
int xmltree2cbuf(cbuf *cb, cxobj *x, int level); 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); int clixon_xml_parse_string(const char *str, yang_bind yb, yang_stmt *yspec, cxobj **xt, cxobj **xerr);
#if defined(__GNUC__) && __GNUC__ >= 3 #if defined(__GNUC__) && __GNUC__ >= 3

View file

@ -463,7 +463,7 @@ xmldb_readfile(clicon_handle h,
goto done; goto done;
} }
else { 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; goto done;
} }
} }

View file

@ -216,7 +216,7 @@ parse_configfile_one(const char *filename,
return -1; return -1;
} }
clicon_debug(2, "%s: Reading config file %s", __FUNCTION__, filename); 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; goto done;
if (ret == 0){ if (ret == 0){
if ((cbret = cbuf_new()) ==NULL){ if ((cbret = cbuf_new()) ==NULL){

View file

@ -449,7 +449,7 @@ clixon_xml_changelog_init(clicon_handle h)
clicon_err(OE_UNIX, errno, "fopen(%s)", filename); clicon_err(OE_UNIX, errno, "fopen(%s)", filename);
goto done; 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; goto done;
if (xml_rootchild(xt, 0, &xt) < 0) if (xml_rootchild(xt, 0, &xt) < 0)
goto done; goto done;

View file

@ -572,8 +572,8 @@ FSM(char *tag,
* @param[in] fd A file descriptor containing the XML file (as ASCII characters) * @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] 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] 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[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 1 Parse OK and all yang assignment made
* @retval 0 Parse OK but yang assigment not made (or only partial) and xerr set * @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 * @retval -1 Error with clicon_err called. Includes parse error
@ -584,7 +584,7 @@ FSM(char *tag,
* FILE *f; * FILE *f;
* if ((f = fopen(filename, "r")) == NULL) * if ((f = fopen(filename, "r")) == NULL)
* err; * err;
* if ((ret = clixon_xml_parse_file(f, YB_MODULE, yspec, "</config>", &xt, &xerr)) < 0) * if ((ret = clixon_xml_parse_file(f, YB_MODULE, yspec, &xt, &xerr)) < 0)
* err; * err;
* xml_free(xt); * xml_free(xt);
* @endcode * @endcode
@ -597,7 +597,6 @@ int
clixon_xml_parse_file(FILE *fp, clixon_xml_parse_file(FILE *fp,
yang_bind yb, yang_bind yb,
yang_stmt *yspec, yang_stmt *yspec,
char *endtag,
cxobj **xt, cxobj **xt,
cxobj **xerr) cxobj **xerr)
{ {
@ -608,8 +607,6 @@ clixon_xml_parse_file(FILE *fp,
char *xmlbuf = NULL; char *xmlbuf = NULL;
char *ptr; char *ptr;
int xmlbuflen = BUFLEN; /* start size */ int xmlbuflen = BUFLEN; /* start size */
int endtaglen = 0;
int state = 0;
int oldxmlbuflen; int oldxmlbuflen;
int failed = 0; 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"); clicon_err(OE_XML, EINVAL, "yspec is required if yb == YB_MODULE");
return -1; return -1;
} }
if (endtag != NULL)
endtaglen = strlen(endtag);
if ((xmlbuf = malloc(xmlbuflen)) == NULL){ if ((xmlbuf = malloc(xmlbuflen)) == NULL){
clicon_err(OE_XML, errno, "malloc"); clicon_err(OE_XML, errno, "malloc");
goto done; goto done;
@ -635,13 +630,9 @@ clixon_xml_parse_file(FILE *fp,
break; break;
} }
if (ret != 0){ if (ret != 0){
if (endtag)
state = FSM(endtag, ch, state);
xmlbuf[len++] = ch; xmlbuf[len++] = ch;
} }
if (ret == 0 || if (ret == 0) {
(endtag && (state == endtaglen))){
state = 0;
if (*xt == NULL) if (*xt == NULL)
if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL) if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
goto done; goto done;

View file

@ -257,7 +257,7 @@ main(int argc, char **argv)
clicon_err(OE_UNIX, errno, "fopen(%s)", xmlfilename); clicon_err(OE_UNIX, errno, "fopen(%s)", xmlfilename);
goto done; 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; goto done;
fclose(fp); fclose(fp);
} }

View file

@ -215,7 +215,7 @@ main(int argc,
* If fp=stdin, then continue reading from stdin (after CR) * If fp=stdin, then continue reading from stdin (after CR)
* XXX Note 0 above, stdin here * 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); fprintf(stderr, "Error: parsing: %s\n", clicon_err_reason);
return -1; return -1;
} }

View file

@ -156,7 +156,7 @@ main(int argc,
} }
} }
else{ 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); fprintf(stderr, "xml parse error: %s\n", clicon_err_reason);
goto done; goto done;
} }

View file

@ -267,7 +267,7 @@ main(int argc,
clicon_err(OE_YANG, errno, "fopen(%s)", top_input_filename); clicon_err(OE_YANG, errno, "fopen(%s)", top_input_filename);
goto done; 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); fprintf(stderr, "xml parse error: %s\n", clicon_err_reason);
goto done; goto done;
} }
@ -309,7 +309,7 @@ main(int argc,
yb = YB_MODULE; yb = YB_MODULE;
else else
yb = YB_PARENT; 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); fprintf(stderr, "xml parse error: %s\n", clicon_err_reason);
goto done; goto done;
} }

View file

@ -298,7 +298,7 @@ main(int argc,
* If fp=stdin, then continue reading from stdin (after CR) * If fp=stdin, then continue reading from stdin (after CR)
* XXX Note 0 above, stdin here * 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); fprintf(stderr, "Error: parsing: %s\n", clicon_err_reason);
return -1; return -1;
} }