C-API: clixon_xml2file and clixon_xml2cbuf added prefix argument

Added in-mem xml diff function: `xml_tree_diff_print`
This commit is contained in:
Olof hagsand 2023-04-12 09:54:37 +02:00
parent 819a0b5a9e
commit 6335f810d3
43 changed files with 309 additions and 149 deletions

View file

@ -797,7 +797,7 @@ xmldb_get_nocache(clicon_handle h,
clicon_log(LOG_NOTICE, "%s: sort verify failed #2", __FUNCTION__);
#endif
if (clicon_debug_get()>1)
if (clixon_xml2file(stderr, xt, 0, 1, fprintf, 0, 0) < 0)
if (clixon_xml2file(stderr, xt, 0, 1, NULL, fprintf, 0, 0) < 0)
goto done;
*xtop = xt;
xt = NULL;
@ -1143,7 +1143,7 @@ xmldb_get_zerocopy(clicon_handle h,
goto done;
}
if (clicon_debug_get() > 1)
if (clixon_xml2file(stderr, x0t, 0, 1, fprintf, 0, 0) < 0)
if (clixon_xml2file(stderr, x0t, 0, 1, NULL, fprintf, 0, 0) < 0)
goto done;
*xtop = x0t;
retval = 1;

View file

@ -1328,7 +1328,7 @@ xmldb_put(clicon_handle h,
if (clixon_json2file(f, x0, pretty, fprintf, 0, 0) < 0)
goto done;
}
else if (clixon_xml2file(f, x0, 0, pretty, fprintf, 0, 0) < 0)
else if (clixon_xml2file(f, x0, 0, pretty, NULL, fprintf, 0, 0) < 0)
goto done;
/* Remove modules state after writing to file
*/
@ -1386,7 +1386,7 @@ xmldb_dump(clicon_handle h,
if (clixon_json2file(f, xt, pretty, fprintf, 0, 0) < 0)
goto done;
}
else if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0, 0) < 0)
else if (clixon_xml2file(f, xt, 0, pretty, NULL, fprintf, 0, 0) < 0)
goto done;
retval = 0;
done:

View file

@ -212,7 +212,7 @@ netconf_invalid_value(cbuf *cb,
if (netconf_invalid_value_xml(&xret, type, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -332,7 +332,7 @@ netconf_missing_attribute(cbuf *cb,
if (netconf_missing_attribute_xml(&xret, type, attr, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -361,7 +361,7 @@ netconf_bad_attribute(cbuf *cb,
if (netconf_bad_attribute_xml(&xret, type, info, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -538,7 +538,7 @@ netconf_missing_element(cbuf *cb,
if (netconf_common_xml(&xret, type, "missing-element",
"bad-element", element, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -584,7 +584,7 @@ netconf_bad_element(cbuf *cb,
if (netconf_common_xml(&xret, type, "bad-element",
"bad-element",element, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -622,7 +622,7 @@ netconf_unknown_element(cbuf *cb,
if (netconf_common_xml(&xret, type, "unknown-element",
"bad-element", element, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -669,7 +669,7 @@ netconf_unknown_namespace(cbuf *cb,
if (netconf_common_xml(&xret, type, "unknown-namespace",
"bad-namespace", ns, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -707,7 +707,7 @@ netconf_access_denied(cbuf *cb,
if (netconf_access_denied_xml(&xret, type, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -948,7 +948,7 @@ netconf_data_missing(cbuf *cb,
if (netconf_data_missing_xml(&xret, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -1153,7 +1153,7 @@ netconf_operation_not_supported(cbuf *cb,
if (netconf_operation_not_supported_xml(&xret, type, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -1181,7 +1181,7 @@ netconf_operation_failed(cbuf *cb,
if (netconf_operation_failed_xml(&xret, type, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -1266,7 +1266,7 @@ netconf_malformed_message(cbuf *cb,
if (netconf_malformed_message_xml(&xret, message) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -1351,7 +1351,7 @@ netconf_data_not_unique(cbuf *cb,
if (netconf_data_not_unique_xml(&xret, x, cvk) < 0)
goto done;
if (clixon_xml2cbuf(cb, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
retval = 0;
done:
@ -1704,7 +1704,7 @@ netconf_err2cb(cxobj *xerr,
cprintf(cberr, "%s ", xml_body(x));
if ((x=xpath_first(xerr, NULL, "//error-info")) != NULL &&
xml_child_nr(x) > 0){
if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cberr, xml_child_i(x, 0), 0, 0, NULL, -1, 0) < 0)
goto done;
}
if ((x=xpath_first(xerr, NULL, "//error-app-tag"))!=NULL)
@ -2160,7 +2160,7 @@ netconf_output(int s,
{
cxobj *xt = NULL;
if (clixon_xml_parse_string(buf, YB_NONE, NULL, &xt, NULL) == 0){
if (clixon_xml2file(stderr, xml_child_i(xt, 0), 0, 0, fprintf, 0, 0) < 0)
if (clixon_xml2file(stderr, xml_child_i(xt, 0), 0, 0, NULL, fprintf, 0, 0) < 0)
goto done;
fprintf(stderr, "\n");
xml_free(xt);

View file

@ -805,7 +805,7 @@ send_msg_notify_xml(clicon_handle h,
clicon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
}
if (clixon_xml2cbuf(cb, xev, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xev, 0, 0, NULL, -1, 0) < 0)
goto done;
if (send_msg_notify(s, cbuf_get(cb)) < 0)
goto done;

View file

@ -450,7 +450,7 @@ clicon_rpc_netconf_xml(clicon_handle h,
goto done;
}
rpcname = xml_name(xname); /* Store rpc name and use in yang binding after reply */
if (clixon_xml2cbuf(cb, xml, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, xml, 0, 0, NULL, -1, 0) < 0)
goto done;
if (clicon_rpc_netconf(h, cbuf_get(cb), xret, sp) < 0)
goto done;
@ -502,10 +502,6 @@ clicon_rpc_netconf_xml(clicon_handle h,
* err;
* if (clicon_rpc_get_config(h, NULL, "running", "/hello/world", nsc, "explicit", &xt) < 0)
* err;
* if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
* clixon_netconf_error(xerr, "msg", "/hello/world");
* err;
* }
* if (xt)
* xml_free(xt);
* if (nsc)

View file

@ -991,7 +991,7 @@ stream_publish_cb(clicon_handle h,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (clixon_xml2cbuf(d, event, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(d, event, 0, 0, NULL, -1, 0) < 0)
goto done;
if (url_post(cbuf_get(u), /* url+stream */
cbuf_get(d), /* postfields */

View file

@ -1439,7 +1439,7 @@ rpc_reply_check(clicon_handle h,
if (ret == 0){
clicon_debug(1, "%s failure when validating:%s", __FUNCTION__, cbuf_get(cbret));
cbuf_reset(cbret);
if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
goto fail;
}
@ -1448,7 +1448,7 @@ rpc_reply_check(clicon_handle h,
if (ret == 0){
clicon_debug(1, "%s failure when validating:%s", __FUNCTION__, cbuf_get(cbret));
cbuf_reset(cbret);
if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0)
goto done;
goto fail;
}

View file

@ -2466,7 +2466,7 @@ clicon_log_xml(int level,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (clixon_xml2cbuf(cb, x, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, x, 0, 0, NULL, -1, 0) < 0)
goto done;
/* first round: compute length of debug message */
va_start(args, format);
@ -2532,7 +2532,7 @@ clicon_debug_xml(int dbglevel,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (clixon_xml2cbuf(cb, x, 0, 0, -1, 0) < 0)
if (clixon_xml2cbuf(cb, x, 0, 0, NULL, -1, 0) < 0)
goto done;
/* first round: compute length of debug message */
va_start(args, format);

View file

@ -90,6 +90,7 @@
* @param[in] xn Clicon xml tree
* @param[in] level How many spaces to insert before each line
* @param[in] pretty Insert \n and spaces to make the xml more readable.
* @param[in] prefix Add string to beginning of each line (if pretty)
* @param[in] fn Callback to make print function
* @param[in] autocliext How to handle autocli extensions: 0: ignore 1: follow
* @retval 0 OK
@ -104,22 +105,27 @@ xml2file_recurse(FILE *f,
cxobj *x,
int level,
int pretty,
char *prefix,
clicon_output_cb *fn,
int autocliext)
{
int retval = -1;
char *name;
char *namespace;
cxobj *xc;
int hasbody;
int haselement;
char *val;
char *encstr = NULL; /* xml encoded string */
int exist = 0;
int retval = -1;
char *name;
char *namespace;
cxobj *xc;
int hasbody;
int haselement;
char *val;
char *encstr = NULL; /* xml encoded string */
int exist = 0;
yang_stmt *y;
int level1;
if (x == NULL)
goto ok;
level1 = level*PRETTYPRINT_INDENT;
if (prefix)
level1 -= strlen(prefix);
if (autocliext &&
(y = xml_spec(x)) != NULL){
if (yang_extension_value(y, "hide-show", CLIXON_AUTOCLI_NS, &exist, NULL) < 0)
@ -144,7 +150,9 @@ xml2file_recurse(FILE *f,
(*fn)(f, "%s=\"%s\"", name, xml_value(x));
break;
case CX_ELMNT:
(*fn)(f, "%*s<", pretty?(level*PRETTYPRINT_INDENT):0, "");
if (pretty && prefix)
(*fn)(f, "%s", prefix);
(*fn)(f, "%*s<", pretty?level1:0, "");
if (namespace)
(*fn)(f, "%s:", namespace);
(*fn)(f, "%s", name);
@ -155,7 +163,7 @@ xml2file_recurse(FILE *f,
while ((xc = xml_child_each(x, xc, -1)) != NULL) {
switch (xml_type(xc)){
case CX_ATTR:
if (xml2file_recurse(f, xc, level+1, pretty, fn, autocliext) <0)
if (xml2file_recurse(f, xc, level+1, pretty, prefix, fn, autocliext) <0)
goto done;
break;
case CX_BODY:
@ -175,23 +183,28 @@ xml2file_recurse(FILE *f,
(*fn)(f, "/>");
else{
(*fn)(f, ">");
if (pretty && hasbody == 0)
if (pretty && hasbody == 0){
(*fn)(f, "\n");
}
xc = NULL;
while ((xc = xml_child_each(x, xc, -1)) != NULL) {
if (xml_type(xc) != CX_ATTR)
if (xml2file_recurse(f, xc, level+1, pretty, fn, autocliext) <0)
if (xml2file_recurse(f, xc, level+1, pretty, prefix, fn, autocliext) <0)
goto done;
}
if (pretty && hasbody==0)
(*fn)(f, "%*s", level*PRETTYPRINT_INDENT, "");
if (pretty && hasbody==0){
if (pretty && prefix)
(*fn)(f, "%s", prefix);
(*fn)(f, "%*s", level1, "");
}
(*fn)(f, "</");
if (namespace)
(*fn)(f, "%s:", namespace);
(*fn)(f, "%s>", name);
}
if (pretty)
if (pretty){
(*fn)(f, "\n");
}
break;
default:
break;
@ -210,7 +223,8 @@ xml2file_recurse(FILE *f,
* @param[in] xn XML tree
* @param[in] level How many spaces to insert before each line
* @param[in] pretty Insert \n and spaces to make the xml more readable.
* @param[in] fn File print function (if NULL, use fprintf)
* @param[in] prefix Add string to beginning of each line (if pretty)
* @param[in] fn File print function (if NULL, use fprintf)
* @param[in] skiptop 0: Include top object 1: Skip top-object, only children,
* @param[in] autocliext How to handle autocli extensions: 0: ignore 1: follow
* @retval 0 OK
@ -224,6 +238,7 @@ clixon_xml2file(FILE *f,
cxobj *xn,
int level,
int pretty,
char *prefix,
clicon_output_cb *fn,
int skiptop,
int autocliext)
@ -236,11 +251,11 @@ clixon_xml2file(FILE *f,
if (skiptop){
xc = NULL;
while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL)
if (xml2file_recurse(f, xc, level, pretty, fn, autocliext) < 0)
if (xml2file_recurse(f, xc, level, pretty, prefix, fn, autocliext) < 0)
goto done;
}
else {
if (xml2file_recurse(f, xn, level, pretty, fn, autocliext) < 0)
if (xml2file_recurse(f, xn, level, pretty, prefix, fn, autocliext) < 0)
goto done;
}
retval = 0;
@ -260,7 +275,7 @@ int
xml_print(FILE *f,
cxobj *x)
{
return xml2file_recurse(f, x, 0, 1, fprintf, 0);
return xml2file_recurse(f, x, 0, 1, NULL, fprintf, 0);
}
/*! Dump cxobj structure with pointers and flags for debugging, internal function
@ -314,6 +329,7 @@ xml_dump(FILE *f,
* @param[in] xn Clixon xml tree
* @param[in] level Indentation level for prettyprint
* @param[in] pretty Insert \n and spaces to make the xml more readable.
* @param[in] prefix Add string to beginning of each line (if pretty)
* @param[in] depth Limit levels of child resources: -1 is all, 0 is none, 1 is node itself
*/
static int
@ -321,6 +337,7 @@ clixon_xml2cbuf1(cbuf *cb,
cxobj *x,
int level,
int pretty,
char *prefix,
int32_t depth)
{
int retval = -1;
@ -330,9 +347,13 @@ clixon_xml2cbuf1(cbuf *cb,
int haselement;
char *namespace;
char *val;
int level1;
if (depth == 0)
goto ok;
level1 = level*PRETTYPRINT_INDENT;
if (prefix)
level1 -= strlen(prefix);
name = xml_name(x);
namespace = xml_prefix(x);
switch(xml_type(x)){
@ -351,8 +372,11 @@ clixon_xml2cbuf1(cbuf *cb,
cprintf(cb, "%s=\"%s\"", name, xml_value(x));
break;
case CX_ELMNT:
if (pretty)
cprintf(cb, "%*s<", level*PRETTYPRINT_INDENT, "");
if (pretty){
if (prefix)
cprintf(cb, "%s", prefix);
cprintf(cb, "%*s<", level1, "");
}
else
cbuf_append_str(cb, "<");
if (namespace){
@ -367,7 +391,7 @@ clixon_xml2cbuf1(cbuf *cb,
while ((xc = xml_child_each(x, xc, -1)) != NULL)
switch (xml_type(xc)){
case CX_ATTR:
if (clixon_xml2cbuf1(cb, xc, level+1, pretty, -1) < 0)
if (clixon_xml2cbuf1(cb, xc, level+1, pretty, prefix, -1) < 0)
goto done;
break;
case CX_BODY:
@ -389,10 +413,13 @@ clixon_xml2cbuf1(cbuf *cb,
xc = NULL;
while ((xc = xml_child_each(x, xc, -1)) != NULL)
if (xml_type(xc) != CX_ATTR)
if (clixon_xml2cbuf1(cb, xc, level+1, pretty, depth-1) < 0)
if (clixon_xml2cbuf1(cb, xc, level+1, pretty, prefix, depth-1) < 0)
goto done;
if (pretty && hasbody == 0)
cprintf(cb, "%*s", level*PRETTYPRINT_INDENT, "");
if (pretty && hasbody == 0){
if (prefix)
cprintf(cb, "%s", prefix);
cprintf(cb, "%*s", level1, "");
}
cbuf_append_str(cb, "</");
if (namespace){
cbuf_append_str(cb, namespace);
@ -419,6 +446,7 @@ clixon_xml2cbuf1(cbuf *cb,
* @param[in] xn Top-level xml object
* @param[in] level Indentation level for pretty
* @param[in] pretty Insert \n and spaces to make the xml more readable.
* @param[in] prefix Add string to beginning of each line (if pretty)
* @param[in] depth Limit levels of child resources: -1: all, 0: none, 1: node itself
* @param[in] skiptop 0: Include top object 1: Skip top-object, only children,
* @retval 0 OK
@ -426,7 +454,7 @@ clixon_xml2cbuf1(cbuf *cb,
* Depth is used in NACM
* @code
* cbuf *cb = cbuf_new();
* if (clixon_xml2cbuf(cb, xn, 0, 1, -1, 0) < 0)
* if (clixon_xml2cbuf(cb, xn, 0, 1, NULL, -1, 0) < 0)
* goto err;
* fprintf(stderr, "%s", cbuf_get(cb));
* cbuf_free(cb);
@ -434,10 +462,11 @@ clixon_xml2cbuf1(cbuf *cb,
* @see clixon_xml2file
*/
int
clixon_xml2cbuf(cbuf *cb,
clixon_xml2cbuf(cbuf *cb,
cxobj *xn,
int level,
int pretty,
char *prefix,
int32_t depth,
int skiptop)
{
@ -447,11 +476,11 @@ clixon_xml2cbuf(cbuf *cb,
if (skiptop){
xc = NULL;
while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL)
if (clixon_xml2cbuf1(cb, xc, level, pretty, depth) < 0)
if (clixon_xml2cbuf1(cb, xc, level, pretty, prefix, depth) < 0)
goto done;
}
else {
if (clixon_xml2cbuf1(cb, xn, level, pretty, depth) < 0)
if (clixon_xml2cbuf1(cb, xn, level, pretty, prefix, depth) < 0)
goto done;
}
retval = 0;

View file

@ -456,7 +456,7 @@ xml_diff(cxobj *x0,
* @param[in] x1 Second XML tree
* @retval 1 Not equal
* @retval 0 Equal
* @see xml_diff
* @see xml_diff which returns diff sets
*/
int
xml_tree_equal(cxobj *x0,
@ -1791,24 +1791,23 @@ purge_tagged_nodes(cxobj *xn,
return retval;
}
/*! Compare two dbs using XML. Write to file and run diff
/*! Compare two dbs using XML. Write to file and run diff. Independent of YANG
*
* @param[in] xc1 XML tree 1
* @param[in] xc2 XML tree 2
* @param[in] format "text"|"xml"|"json"|"cli"|"netconf" (see format_enum)
* @param[in] fn File print function (if NULL, use fprintf)
* @see xml_tree_diff_print with better XML in-mem comparison but is YANG dependent
*/
int
clixon_compare_xmls(cxobj *xc1,
cxobj *xc2,
enum format_enum format,
clicon_output_cb *fn)
enum format_enum format)
{
int retval = -1;
int fd;
FILE *f;
char filename1[MAXPATHLEN];
char filename2[MAXPATHLEN];
int retval = -1;
cbuf *cb = NULL;
snprintf(filename1, sizeof(filename1), "/tmp/cliconXXXXXX");
@ -1826,7 +1825,7 @@ clixon_compare_xmls(cxobj *xc1,
break;
case FORMAT_XML:
default:
if (clixon_xml2file(f, xc1, 0, 1, cligen_output, 1, 1) < 0)
if (clixon_xml2file(f, xc1, 0, 1, NULL, cligen_output, 1, 1) < 0)
goto done;
break;
}
@ -1847,11 +1846,10 @@ clixon_compare_xmls(cxobj *xc1,
break;
case FORMAT_XML:
default:
if (clixon_xml2file(f, xc2, 0, 1, cligen_output, 1, 1) < 0)
if (clixon_xml2file(f, xc2, 0, 1, NULL, cligen_output, 1, 1) < 0)
goto done;
break;
}
fclose(f);
close(fd);
@ -1872,3 +1870,126 @@ clixon_compare_xmls(cxobj *xc1,
unlink(filename2);
return retval;
}
/*! Print diff of two XML trees in memory. YANG dependent
*
* Uses underlying XML diff algorithm with better result than clixon_compare_xmls
* @param[in] cb CLIgen buffer
* @param[in] level How many spaces to insert before each line
* @param[in] x0 First XML tree
* @param[in] x1 Second XML tree
* @param[in] format "text"|"xml"|"json"|"cli"|"netconf" (NYI: only xml)
* @retval 0 Ok
* @retval -1 Error
* @see xml_diff which returns diff sets
* @see clixon_compare_xmls which uses files and is independent of YANG
*/
int
xml_tree_diff_print(cbuf *cb,
int level,
cxobj *x0,
cxobj *x1,
enum format_enum format)
{
int retval = -1;
cxobj *x0c = NULL; /* x0 child */
cxobj *x1c = NULL; /* x1 child */
yang_stmt *yc0;
yang_stmt *yc1;
char *b0;
char *b1;
int eq;
int nr=0;
/* Traverse x0 and x1 in lock-step */
x0c = x1c = NULL;
x0c = xml_child_each(x0, x0c, CX_ELMNT);
x1c = xml_child_each(x1, x1c, CX_ELMNT);
for (;;){
if (x0c == NULL && x1c == NULL)
goto ok;
else if (x0c == NULL){
if (nr==0)
cprintf(cb, "%*s%s>\n", level*PRETTYPRINT_INDENT, "<", xml_name(x1));
nr++;
if (clixon_xml2cbuf(cb, x1c, level+1, 1, "+", -1, 0) < 0)
goto done;
x1c = xml_child_each(x1, x1c, CX_ELMNT);
continue;
}
else if (x1c == NULL){
if (nr==0)
cprintf(cb, "%*s%s>\n", level*PRETTYPRINT_INDENT, "<", xml_name(x0));
nr++;
if (clixon_xml2cbuf(cb, x0c, level+1, 1, "-", -1, 0) < 0)
goto done;
x0c = xml_child_each(x0, x0c, CX_ELMNT);
continue;
}
/* Both x0c and x1c exists, check if they are yang-equal. */
eq = xml_cmp(x0c, x1c, 0, 0, NULL);
if (eq < 0){
if (nr==0)
cprintf(cb, "%*s%s>\n", level*PRETTYPRINT_INDENT, "<", xml_name(x0));
nr++;
if (clixon_xml2cbuf(cb, x0c, level+1, 1, "-", -1, 0) < 0)
goto done;
x0c = xml_child_each(x0, x0c, CX_ELMNT);
continue;
}
else if (eq > 0){
if (nr==0)
cprintf(cb, "%*s%s>\n", level*PRETTYPRINT_INDENT, "<", xml_name(x1));
nr++;
if (clixon_xml2cbuf(cb, x1c, level+1, 1, "+", -1, 0) < 0)
goto done;
x1c = xml_child_each(x1, x1c, CX_ELMNT);
continue;
}
else{ /* equal */
/* xml-spec NULL could happen with anydata children for example,
* if so, continute compare children but without yang
*/
yc0 = xml_spec(x0c);
yc1 = xml_spec(x1c);
if (yc0 && yc1 && yc0 != yc1){ /* choice */
if (nr==0)
cprintf(cb, "%*s%s>\n", level*PRETTYPRINT_INDENT, "<", xml_name(x0));
nr++;
if (clixon_xml2cbuf(cb, x0c, level+1, 1, "-", -1, 0) < 0)
goto done;
if (clixon_xml2cbuf(cb, x1c, level+1, 1, "+", -1, 0) < 0)
goto done;
}
else
if (yc0 && yang_keyword_get(yc0) == Y_LEAF){
/* if x0c and x1c are leafs w bodies, then they may be changed */
b0 = xml_body(x0c);
b1 = xml_body(x1c);
if (b0 == NULL && b1 == NULL)
;
else if (b0 == NULL || b1 == NULL
|| strcmp(b0, b1) != 0
){
if (nr==0)
cprintf(cb, "%*s%s>\n", level*PRETTYPRINT_INDENT, "<", xml_name(x0));
nr++;
cprintf(cb, "-%*s%s>%s</%s>\n", (level*PRETTYPRINT_INDENT-1), "<",
xml_name(x0c), b0, xml_name(x0c));
cprintf(cb, "+%*s%s>%s</%s>\n", (level*PRETTYPRINT_INDENT-1), "<",
xml_name(x1c), b1, xml_name(x1c));
}
}
else if (xml_tree_diff_print(cb, level+1, x0c, x1c, format) < 0)
goto done;
}
x0c = xml_child_each(x0, x0c, CX_ELMNT);
x1c = xml_child_each(x1, x1c, CX_ELMNT);
}
ok:
if (nr)
cprintf(cb, "%*s/%s>\n", level*PRETTYPRINT_INDENT, "<", xml_name(x0));
retval = 0;
done:
return retval;
}

View file

@ -376,7 +376,7 @@ clixon_xvec_print(FILE *f,
int i;
for (i=0; i<xv->xv_len; i++)
if (clixon_xml2file(f, xv->xv_vec[i], 0, 1, fprintf, 0, 0) < 0)
if (clixon_xml2file(f, xv->xv_vec[i], 0, 1, NULL, fprintf, 0, 0) < 0)
return -1;
return 0;
}