From 6335f810d310ab0800fd44f44c8522cdd169ff55 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Wed, 12 Apr 2023 09:54:37 +0200 Subject: [PATCH] C-API: `clixon_xml2file` and `clixon_xml2cbuf` added `prefix` argument Added in-mem xml diff function: `xml_tree_diff_print` --- CHANGELOG.md | 6 + apps/backend/backend_client.c | 10 +- apps/backend/backend_commit.c | 16 +-- apps/backend/backend_get.c | 10 +- apps/backend/backend_plugin_restconf.c | 2 +- apps/backend/clixon_backend_transaction.c | 16 +-- apps/cli/cli_common.c | 14 +-- apps/cli/cli_show.c | 6 +- apps/netconf/netconf_main.c | 12 +- apps/netconf/netconf_rpc.c | 4 +- apps/restconf/restconf_err.c | 4 +- apps/restconf/restconf_methods.c | 4 +- apps/restconf/restconf_methods_get.c | 6 +- apps/restconf/restconf_methods_post.c | 4 +- apps/restconf/restconf_root.c | 4 +- apps/restconf/restconf_stream_fcgi.c | 2 +- apps/snmp/snmp_handler.c | 4 +- example/main/example_backend.c | 2 +- example/main/example_cli.c | 4 +- example/main/example_netconf.c | 2 +- example/main/example_restconf.c | 2 +- lib/clixon/clixon_xml_io.h | 4 +- lib/clixon/clixon_xml_map.h | 3 +- lib/src/clixon_datastore_read.c | 4 +- lib/src/clixon_datastore_write.c | 4 +- lib/src/clixon_netconf_lib.c | 30 ++--- lib/src/clixon_proto.c | 2 +- lib/src/clixon_proto_client.c | 6 +- lib/src/clixon_stream.c | 2 +- lib/src/clixon_validate.c | 4 +- lib/src/clixon_xml.c | 4 +- lib/src/clixon_xml_io.c | 89 +++++++++----- lib/src/clixon_xml_map.c | 139 ++++++++++++++++++++-- lib/src/clixon_xml_vec.c | 2 +- test/config.sh.in | 4 +- util/clixon_util_datastore.c | 4 +- util/clixon_util_json.c | 2 +- util/clixon_util_path.c | 2 +- util/clixon_util_socket.c | 2 +- util/clixon_util_xml.c | 2 +- util/clixon_util_xml_mod.c | 4 +- util/clixon_util_xpath.c | 2 +- yang/clixon/clixon-config@2023-03-01.yang | 9 +- 43 files changed, 309 insertions(+), 149 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd2ff317..5cb84392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Users may have to change how they access the system * New `clixon-config@2023-03-01.yang` revision * Added options: `CLICON_RESTCONF_NOALPN_DEFAULT` + * Extended datastore-format with CLI and text * New `clixon-lib@2023-03-01.yang` revision * Added creator meta-object @@ -57,6 +58,11 @@ Users may have to change how they access the system Developers may need to change their code * C-API + * `clixon_xml2file` and `clixon_xml2cbuf` added `prefix` argument + * Example application is to add "+"/"-" for diffs + * Example change: + * `clixon_xml2file(f,x,p,f,s,a)` -> `clixon_xml2file(f,x,p,NULL,f,s,a)` + * `clixon_xml2cbuf(c,x,l,p,d,s)` -> `clixon_xml2cbuf(c,x,l,p,NULL,d,s)` * `xmldb_validate` is removed. Yang checks should be enough, remnant of time before YANG checks. * `xml_diff`: removed 1st `yspec` parameter * `xml2xpath()`: Added `int apostrophe` as 4th parameter, default 0 diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 9c9893a1..31cdf977 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -491,7 +491,7 @@ from_client_edit_config(clicon_handle h, if ((ret = xml_bind_yang(h, xc, YB_MODULE, yspec, &xret)) < 0) goto done; if (ret == 0){ - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; goto ok; } @@ -499,7 +499,7 @@ from_client_edit_config(clicon_handle h, if ((ret = xml_non_config_data(xc, &xret)) < 0) goto done; if (ret == 0){ - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; goto ok; } @@ -516,7 +516,7 @@ from_client_edit_config(clicon_handle h, if (ret==1 && (ret = xml_yang_validate_list_key_only(xc, &xret)) < 0) goto done; if (ret == 0){ - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; goto ok; } @@ -1529,7 +1529,7 @@ from_client_msg(clicon_handle h, goto reply; } if (ret == 0){ - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; goto reply; } @@ -1609,7 +1609,7 @@ from_client_msg(clicon_handle h, goto done; } if (ret == 0){ - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; ce->ce_in_bad_rpcs++; netconf_monitoring_counter_inc(h, "in-bad-rpcs"); diff --git a/apps/backend/backend_commit.c b/apps/backend/backend_commit.c index e642a6ec..d017b3d6 100644 --- a/apps/backend/backend_commit.c +++ b/apps/backend/backend_commit.c @@ -193,7 +193,7 @@ startup_common(clicon_handle h, * See similar clause below */ } - if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) goto done; goto fail; } @@ -262,7 +262,7 @@ startup_common(clicon_handle h, if ((ret = xml_bind_yang(h, xt, YB_MODULE, yspec, &xret)) < 0) goto done; if (ret == 0){ - 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; } @@ -270,7 +270,7 @@ startup_common(clicon_handle h, if ((ret = xml_non_config_data(xt, &xret)) < 0) goto done; if (ret == 0){ - 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; } @@ -305,7 +305,7 @@ startup_common(clicon_handle h, if ((ret = generic_validate(h, yspec, td, &xret)) < 0) goto done; if (ret == 0){ - 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; /* STARTUP_INVALID */ } @@ -612,7 +612,7 @@ candidate_validate(clicon_handle h, clicon_err(OE_CFG, EINVAL, "xret is NULL"); goto done; } - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; if (!cbuf_len(cbret) && netconf_operation_failed(cbret, "application", clicon_err_reason)< 0) @@ -702,7 +702,7 @@ candidate_commit(clicon_handle h, goto done; } if (ret == 0){ - 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; } @@ -969,7 +969,7 @@ from_client_restart_one(clicon_handle h, if ((ret = xml_yang_validate_all_top(h, td->td_target, &xerr)) < 0) goto done; if (ret == 0){ - if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) goto done; goto fail; } @@ -1018,7 +1018,7 @@ from_client_restart_one(clicon_handle h, if ((ret = generic_validate(h, yspec, td, &xerr)) < 0) goto done; if (ret == 0){ - if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) goto done; goto fail; } diff --git a/apps/backend/backend_get.c b/apps/backend/backend_get.c index 86253b42..59d17977 100644 --- a/apps/backend/backend_get.c +++ b/apps/backend/backend_get.c @@ -478,7 +478,7 @@ get_nacm_and_reply(clicon_handle h, if (xml_name_set(xret, NETCONF_OUTPUT_DATA) < 0) goto done; /* Top level is data, so add 1 to depth if significant */ - if (clixon_xml2cbuf(cbret, xret, 0, 0, depth>0?depth+1:depth, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, depth>0?depth+1:depth, 0) < 0) goto done; } cprintf(cbret, ""); @@ -755,7 +755,7 @@ get_list_pagination(clicon_handle h, clicon_err_reason); if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0) goto done; - if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) goto done; goto ok; } @@ -769,7 +769,7 @@ get_list_pagination(clicon_handle h, ". Internal error, state callback returned invalid XML", NULL) < 0) goto done; - if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) goto done; goto ok; } @@ -1001,7 +1001,7 @@ get_common(clicon_handle h, if ((ret = get_statedata(h, xpath?xpath:"/", nsc, wdef, &xret)) < 0) goto done; if (ret == 0){ /* Error from callback (error in xret) */ - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; goto ok; } @@ -1024,7 +1024,7 @@ get_common(clicon_handle h, ". Internal error, state callback returned invalid XML", NULL) < 0) goto done; - if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) goto done; goto ok; } diff --git a/apps/backend/backend_plugin_restconf.c b/apps/backend/backend_plugin_restconf.c index 0b681894..8bac90ad 100644 --- a/apps/backend/backend_plugin_restconf.c +++ b/apps/backend/backend_plugin_restconf.c @@ -163,7 +163,7 @@ restconf_pseudo_set_inline(clicon_handle h, clicon_err(OE_XML, errno, "cbuf_new"); goto done; } - if (clixon_xml2cbuf(cb, xrestconf, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xrestconf, 0, 0, NULL, -1, 0) < 0) goto done; if ((str = strdup(cbuf_get(cb))) == NULL){ clicon_err(OE_XML, errno, "stdup"); diff --git a/apps/backend/clixon_backend_transaction.c b/apps/backend/clixon_backend_transaction.c index 57d71c7c..b40c8652 100644 --- a/apps/backend/clixon_backend_transaction.c +++ b/apps/backend/clixon_backend_transaction.c @@ -263,7 +263,7 @@ transaction_dbg(clicon_handle h, } for (i=0; itd_dlen; i++){ xn = td->td_dvec[i]; - if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0) goto done; } if (i) @@ -272,7 +272,7 @@ transaction_dbg(clicon_handle h, cbuf_reset(cb); for (i=0; itd_alen; i++){ xn = td->td_avec[i]; - if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0) goto done; } if (i) @@ -282,11 +282,11 @@ transaction_dbg(clicon_handle h, for (i=0; itd_clen; i++){ if (td->td_scvec){ xn = td->td_scvec[i]; - if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0) goto done; } xn = td->td_tcvec[i]; - if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0) goto done; } if (i) @@ -319,7 +319,7 @@ transaction_log(clicon_handle h, } for (i=0; itd_dlen; i++){ xn = td->td_dvec[i]; - if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0) goto done; } if (i) @@ -328,7 +328,7 @@ transaction_log(clicon_handle h, cbuf_reset(cb); for (i=0; itd_alen; i++){ xn = td->td_avec[i]; - if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0) goto done; } if (i) @@ -337,11 +337,11 @@ transaction_log(clicon_handle h, for (i=0; itd_clen; i++){ if (td->td_scvec){ xn = td->td_scvec[i]; - if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0) goto done; } xn = td->td_tcvec[i]; - if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0) goto done; } if (i) diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index d04f8578..ff555f2e 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -472,7 +472,7 @@ cli_dbxml(clicon_handle h, clicon_err(OE_XML, errno, "cbuf_new"); goto done; } - if (clixon_xml2cbuf(cb, xtop, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xtop, 0, 0, NULL, -1, 0) < 0) goto done; if (clicon_rpc_edit_config(h, "candidate", OP_NONE, cbuf_get(cb)) < 0) goto done; @@ -865,7 +865,7 @@ compare_db_names(clicon_handle h, clixon_netconf_error(xerr, "Get configuration", NULL); goto done; } - if (clixon_compare_xmls(xc1, xc2, format, cligen_output) < 0) /* astext? */ + if (clixon_compare_xmls(xc1, xc2, format) < 0) /* astext? */ goto done; retval = 0; done: @@ -1055,7 +1055,7 @@ load_config_file(clicon_handle h, /* Read as datastore-top but transformed into an edit-config "config" */ xml_name_set(x, NETCONF_INPUT_CONFIG); } - if (clixon_xml2cbuf(cbxml, xt, 0, 0, -1, 1) < 0) + if (clixon_xml2cbuf(cbxml, xt, 0, 0, NULL, -1, 1) < 0) goto done; if (clicon_rpc_edit_config(h, "candidate", replace?OP_REPLACE:OP_MERGE, @@ -1158,7 +1158,7 @@ save_config_file(clicon_handle h, } switch (format){ case FORMAT_XML: - if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0, 1) < 0) + if (clixon_xml2file(f, xt, 0, pretty, NULL, fprintf, 0, 1) < 0) goto done; break; case FORMAT_JSON: @@ -1177,7 +1177,7 @@ save_config_file(clicon_handle h, fprintf(f, "", NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR); fprintf(f, "\n"); - if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0, 1) < 0) + if (clixon_xml2file(f, xt, 0, pretty, NULL, fprintf, 0, 1) < 0) goto done; fprintf(f, "]]>]]>\n"); break; @@ -1288,7 +1288,7 @@ cli_notification_cb(int s, goto done; break; case FORMAT_XML: - if (clixon_xml2file(stdout, xt, 0, 1, cligen_output, 1, 1) < 0) + if (clixon_xml2file(stdout, xt, 0, 1, NULL, cligen_output, 1, 1) < 0) goto done; break; default: @@ -1535,7 +1535,7 @@ cli_copy_config(clicon_handle h, /* resuse cb */ cbuf_reset(cb); /* create xml copy tree and merge it with database configuration */ - if (clixon_xml2cbuf(cb, x2, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, x2, 0, 0, NULL, -1, 0) < 0) goto done; if (clicon_rpc_edit_config(h, db, OP_MERGE, cbuf_get(cb)) < 0) goto done; diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index 446f6e41..9e8e4b5d 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -511,7 +511,7 @@ cli_show_common(clicon_handle h, /* Print configuration according to format */ switch (format){ case FORMAT_XML: - if (clixon_xml2file(stdout, xp, 0, pretty, cligen_output, skiptop, 1) < 0) + if (clixon_xml2file(stdout, xp, 0, pretty, NULL, cligen_output, skiptop, 1) < 0) goto done; if (!pretty && i == veclen-1) cligen_output(stdout, "\n"); @@ -531,7 +531,7 @@ cli_show_common(clicon_handle h, if (pretty) cligen_output(stdout, "\n"); } - if (clixon_xml2file(stdout, xp, 2, pretty, cligen_output, skiptop, 1) < 0) + if (clixon_xml2file(stdout, xp, 2, pretty, NULL, cligen_output, skiptop, 1) < 0) goto done; if (i == veclen-1) cligen_output(stdout, "]]>]]>\n"); @@ -1219,7 +1219,7 @@ cli_pagination(clicon_handle h, xc = xvec[j]; switch (format){ case FORMAT_XML: - if (clixon_xml2file(stdout, xc, 0, 1, cligen_output, 0, 1) < 0) + if (clixon_xml2file(stdout, xc, 0, 1, NULL, cligen_output, 0, 1) < 0) goto done; break; case FORMAT_JSON: diff --git a/apps/netconf/netconf_main.c b/apps/netconf/netconf_main.c index a35548b5..ed45fe8a 100644 --- a/apps/netconf/netconf_main.c +++ b/apps/netconf/netconf_main.c @@ -220,7 +220,7 @@ netconf_rpc_message(clicon_handle h, clicon_err(OE_XML, errno, "cbuf_new"); goto done; } - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; if (netconf_output_encap(framing, cbret) < 0) goto done; @@ -241,7 +241,7 @@ netconf_rpc_message(clicon_handle h, clicon_err(OE_XML, errno, "cbuf_new"); goto done; } - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; if (netconf_output_encap(framing, cbret) < 0) goto done; @@ -262,7 +262,7 @@ netconf_rpc_message(clicon_handle h, clicon_err(OE_XML, errno, "cbuf_new"); goto done; } - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; if (netconf_output_encap(framing, cbret) < 0) goto done; @@ -278,7 +278,7 @@ netconf_rpc_message(clicon_handle h, clicon_err(OE_XML, errno, "cbuf_new"); goto done; } - if (clixon_xml2cbuf(cbret, xml_child_i(xret,0), 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xml_child_i(xret,0), 0, 0, NULL, -1, 0) < 0) goto done; if (netconf_output_encap(framing, cbret) < 0) goto done; @@ -335,7 +335,7 @@ netconf_input_packet(clicon_handle h, clicon_err(OE_XML, errno, "cbuf_new"); goto done; } - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; if (netconf_output_encap(framing, cbret) < 0) goto done; @@ -451,7 +451,7 @@ netconf_input_frame(clicon_handle h, clicon_err(OE_XML, errno, "cbuf_new"); goto done; } - if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xret, 0, 0, NULL, -1, 0) < 0) goto done; if (netconf_output_encap(framing, cbret) < 0) goto done; diff --git a/apps/netconf/netconf_rpc.c b/apps/netconf/netconf_rpc.c index d11b9d2d..1d03c23b 100644 --- a/apps/netconf/netconf_rpc.c +++ b/apps/netconf/netconf_rpc.c @@ -479,7 +479,7 @@ netconf_notification_cb(int s, clicon_err(OE_PLUGIN, errno, "cbuf_new"); goto done; } - if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xn, 0, 0, NULL, -1, 0) < 0) goto done; /* Send it to listening client on stdout */ if (netconf_output_encap(clicon_option_int(h, "netconf-framing"), cb) < 0){ @@ -657,7 +657,7 @@ netconf_application_rpc(clicon_handle h, if (ret > 0 && (ret = xml_yang_validate_add(h, xoutput, &xerr)) < 0) goto done; if (ret == 0){ - if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xerr, 0, 0, NULL, -1, 0) < 0) goto done; clicon_log(LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret)); goto ok; diff --git a/apps/restconf/restconf_err.c b/apps/restconf/restconf_err.c index 6a685af5..2908712d 100644 --- a/apps/restconf/restconf_err.c +++ b/apps/restconf/restconf_err.c @@ -278,13 +278,13 @@ api_return_err(clicon_handle h, clicon_debug(1, "%s code:%d", __FUNCTION__, code); if (pretty){ cprintf(cb, " \n"); - if (clixon_xml2cbuf(cb, xerr, 2, pretty, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xerr, 2, pretty, NULL, -1, 0) < 0) goto done; cprintf(cb, " \r\n"); } else { cprintf(cb, ""); - if (clixon_xml2cbuf(cb, xerr, 2, pretty, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xerr, 2, pretty, NULL, -1, 0) < 0) goto done; cprintf(cb, "\r\n"); } diff --git a/apps/restconf/restconf_methods.c b/apps/restconf/restconf_methods.c index 781af9e7..b6ba23a3 100644 --- a/apps/restconf/restconf_methods.c +++ b/apps/restconf/restconf_methods.c @@ -532,7 +532,7 @@ api_data_write(clicon_handle h, CLIXON_LIB_PREFIX, CLIXON_LIB_PREFIX, CLIXON_LIB_NS); cprintf(cbx, ">"); cprintf(cbx, "none"); - if (clixon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbx, xtop, 0, 0, NULL, -1, 0) < 0) goto done; cprintf(cbx, ""); clicon_debug(1, "%s xml: %s api_path:%s",__FUNCTION__, cbuf_get(cbx), api_path); @@ -782,7 +782,7 @@ api_data_delete(clicon_handle h, CLIXON_LIB_PREFIX, CLIXON_LIB_PREFIX, CLIXON_LIB_NS); cprintf(cbx, ">"); cprintf(cbx, "none"); - if (clixon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbx, xtop, 0, 0, NULL, -1, 0) < 0) goto done; cprintf(cbx, ""); if (clicon_rpc_netconf(h, cbuf_get(cbx), &xret, NULL) < 0) diff --git a/apps/restconf/restconf_methods_get.c b/apps/restconf/restconf_methods_get.c index 3b492e49..957c42d6 100644 --- a/apps/restconf/restconf_methods_get.c +++ b/apps/restconf/restconf_methods_get.c @@ -231,7 +231,7 @@ api_data_get2(clicon_handle h, if (xpath==NULL || strcmp(xpath,"/")==0){ /* Special case: data root */ switch (media_out){ case YANG_DATA_XML: - if (clixon_xml2cbuf(cbx, xret, 0, pretty, -1, 0) < 0) /* Dont print top object? */ + if (clixon_xml2cbuf(cbx, xret, 0, pretty, NULL, -1, 0) < 0) /* Dont print top object? */ goto done; break; case YANG_DATA_JSON: @@ -275,7 +275,7 @@ api_data_get2(clicon_handle h, cvec_free(nscd); nscd = NULL; } - if (clixon_xml2cbuf(cbx, x, 0, pretty, -1, 0) < 0) /* Dont print top object? */ + if (clixon_xml2cbuf(cbx, x, 0, pretty, NULL, -1, 0) < 0) /* Dont print top object? */ goto done; } break; @@ -541,7 +541,7 @@ api_data_pagination(clicon_handle h, if (xml_insert(xpr, xp, INS_LAST, NULL, NULL) < 0) goto done; } - if (clixon_xml2cbuf(cbx, xpr, 0, pretty, -1, 0) < 0) /* Dont print top object? */ + if (clixon_xml2cbuf(cbx, xpr, 0, pretty, NULL, -1, 0) < 0) /* Dont print top object? */ goto done; break; case YANG_DATA_JSON: diff --git a/apps/restconf/restconf_methods_post.c b/apps/restconf/restconf_methods_post.c index 4e70fbc2..9486781a 100644 --- a/apps/restconf/restconf_methods_post.c +++ b/apps/restconf/restconf_methods_post.c @@ -362,7 +362,7 @@ api_data_post(clicon_handle h, CLIXON_LIB_PREFIX, CLIXON_LIB_PREFIX, CLIXON_LIB_NS); cprintf(cbx, ">"); cprintf(cbx, "none"); - if (clixon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cbx, xtop, 0, 0, NULL, -1, 0) < 0) goto done; cprintf(cbx, ""); clicon_debug(1, "%s xml: %s api_path:%s",__FUNCTION__, cbuf_get(cbx), api_path); @@ -871,7 +871,7 @@ api_operations_post(clicon_handle h, cbuf_reset(cbret); switch (media_out){ case YANG_DATA_XML: - if (clixon_xml2cbuf(cbret, xoutput, 0, pretty, -1, 0) < 0) + if (clixon_xml2cbuf(cbret, xoutput, 0, pretty, NULL, -1, 0) < 0) goto done; /* xoutput should now look: 0 */ break; diff --git a/apps/restconf/restconf_root.c b/apps/restconf/restconf_root.c index 92a09a53..faf989ce 100644 --- a/apps/restconf/restconf_root.c +++ b/apps/restconf/restconf_root.c @@ -204,7 +204,7 @@ api_root_restconf_exact(clicon_handle h, switch (media_out){ case YANG_DATA_XML: case YANG_PATCH_XML: - if (clixon_xml2cbuf(cb, xt, 0, pretty, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xt, 0, pretty, NULL, -1, 0) < 0) goto done; break; case YANG_DATA_JSON: @@ -288,7 +288,7 @@ api_yang_library_version(clicon_handle h, switch (media_out){ case YANG_DATA_XML: case YANG_PATCH_XML: - if (clixon_xml2cbuf(cb, xt, 0, pretty, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xt, 0, pretty, NULL, -1, 0) < 0) goto done; break; case YANG_DATA_JSON: diff --git a/apps/restconf/restconf_stream_fcgi.c b/apps/restconf/restconf_stream_fcgi.c index 764a2675..4462083c 100644 --- a/apps/restconf/restconf_stream_fcgi.c +++ b/apps/restconf/restconf_stream_fcgi.c @@ -254,7 +254,7 @@ restconf_stream_cb(int s, FCGX_FPrintF(r->out, "M#id: %02d:0\r\n", tv.tv_sec); } #endif - if (clixon_xml2cbuf(cb, xn, 0, pretty, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xn, 0, pretty, NULL, -1, 0) < 0) goto done; FCGX_FPrintF(r->out, "data: %s\r\n", cbuf_get(cb)); FCGX_FPrintF(r->out, "\r\n"); diff --git a/apps/snmp/snmp_handler.c b/apps/snmp/snmp_handler.c index ee314906..d1886303 100644 --- a/apps/snmp/snmp_handler.c +++ b/apps/snmp/snmp_handler.c @@ -430,7 +430,7 @@ snmp_scalar_set(clicon_handle h, clicon_err(OE_UNIX, errno, "cbuf_new"); goto done; } - if (clixon_xml2cbuf(cb, xtop, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xtop, 0, 0, NULL, -1, 0) < 0) goto done; if (clicon_rpc_edit_config(h, "candidate", op, cbuf_get(cb)) < 0) goto done; @@ -500,7 +500,7 @@ snmp_cache_row_op(clicon_handle h, clicon_err(OE_UNIX, errno, "cbuf_new"); goto done; } - if (clixon_xml2cbuf(cb, xtop, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xtop, 0, 0, NULL, -1, 0) < 0) goto done; if (clicon_rpc_edit_config(h, "candidate", OP_NONE, cbuf_get(cb)) < 0) goto done; diff --git a/example/main/example_backend.c b/example/main/example_backend.c index e267ab06..0340189f 100644 --- a/example/main/example_backend.c +++ b/example/main/example_backend.c @@ -373,7 +373,7 @@ example_rpc(clicon_handle h, /* Clicon handle */ if (xmlns_set(x, NULL, namespace) < 0) goto done; } - if (clixon_xml2cbuf(cbret, xe, 0, 0, -1, 1) < 0) + if (clixon_xml2cbuf(cbret, xe, 0, 0, NULL, -1, 1) < 0) goto done; } cprintf(cbret, ""); diff --git a/example/main/example_cli.c b/example/main/example_cli.c index b0082fb4..1bfcd58c 100644 --- a/example/main/example_cli.c +++ b/example/main/example_cli.c @@ -74,7 +74,7 @@ mycallback(clicon_handle h, cvec *cvv, cvec *argv) nsc, NULL, &xret) < 0) goto done; - if (clixon_xml2file(stdout, xret, 0, 1, cligen_output, 0, 1) < 0) + if (clixon_xml2file(stdout, xret, 0, 1, NULL, cligen_output, 0, 1) < 0) goto done; retval = 0; done: @@ -119,7 +119,7 @@ example_client_rpc(clicon_handle h, goto done; } /* Print result */ - if (clixon_xml2file(stdout, xml_child_i(xret, 0), 0, 0, cligen_output, 0, 1) < 0) + if (clixon_xml2file(stdout, xml_child_i(xret, 0), 0, 0, NULL, cligen_output, 0, 1) < 0) goto done; fprintf(stdout,"\n"); diff --git a/example/main/example_netconf.c b/example/main/example_netconf.c index c59a8255..b56020f1 100644 --- a/example/main/example_netconf.c +++ b/example/main/example_netconf.c @@ -90,7 +90,7 @@ netconf_client_rpc(clicon_handle h, if (xmlns_set(x, NULL, namespace) < 0) goto done; } - if (clixon_xml2cbuf(cbret, xe, 0, 0, -1, 1) < 0) + if (clixon_xml2cbuf(cbret, xe, 0, 0, NULL, -1, 1) < 0) goto done; } cprintf(cbret, ""); diff --git a/example/main/example_restconf.c b/example/main/example_restconf.c index 5ca4a4dc..699c1ddd 100644 --- a/example/main/example_restconf.c +++ b/example/main/example_restconf.c @@ -330,7 +330,7 @@ restconf_client_rpc(clicon_handle h, if (xmlns_set(x, NULL, namespace) < 0) goto done; } - if (clixon_xml2cbuf(cbret, xe, 0, 0, -1, 1) < 0) + if (clixon_xml2cbuf(cbret, xe, 0, 0, NULL, -1, 1) < 0) goto done; } cprintf(cbret, ""); diff --git a/lib/clixon/clixon_xml_io.h b/lib/clixon/clixon_xml_io.h index 1c2421db..fdd9a770 100644 --- a/lib/clixon/clixon_xml_io.h +++ b/lib/clixon/clixon_xml_io.h @@ -43,10 +43,10 @@ /* * Prototypes */ -int clixon_xml2file(FILE *f, cxobj *xn, int level, int pretty, clicon_output_cb *fn, int skiptop, int autocliext); +int clixon_xml2file(FILE *f, cxobj *xn, int level, int pretty, char *prefix, clicon_output_cb *fn, int skiptop, int autocliext); int xml_print(FILE *f, cxobj *xn); int xml_dump(FILE *f, cxobj *x); -int clixon_xml2cbuf(cbuf *cb, cxobj *x, int level, int prettyprint, int32_t depth, int skiptop); +int clixon_xml2cbuf(cbuf *cb, cxobj *x, int level, int prettyprint, char *prefix, int32_t depth, int skiptop); int xmltree2cbuf(cbuf *cb, cxobj *x, int level); 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); diff --git a/lib/clixon/clixon_xml_map.h b/lib/clixon/clixon_xml_map.h index fd381707..07673104 100644 --- a/lib/clixon/clixon_xml_map.h +++ b/lib/clixon/clixon_xml_map.h @@ -76,6 +76,7 @@ int yang_xml_mandatory(cxobj *xt, yang_stmt *ys); int xml_rpc_isaction(cxobj *xn); int xml_find_action(cxobj *xn, int top, cxobj **xap); int purge_tagged_nodes(cxobj *xn, char *ns, char *name, char *value, int keepnode); -int clixon_compare_xmls(cxobj *xc1, cxobj *xc2, enum format_enum format, clicon_output_cb *fn); +int clixon_compare_xmls(cxobj *xc1, cxobj *xc2, enum format_enum format); +int xml_tree_diff_print(cbuf *cb, int level, cxobj *x0, cxobj *x1, enum format_enum format); #endif /* _CLIXON_XML_MAP_H_ */ diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c index 5caca7b7..19cf890d 100644 --- a/lib/src/clixon_datastore_read.c +++ b/lib/src/clixon_datastore_read.c @@ -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; diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index 9cde6d39..be251e59 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -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: diff --git a/lib/src/clixon_netconf_lib.c b/lib/src/clixon_netconf_lib.c index 186cfa63..3b9e00f2 100644 --- a/lib/src/clixon_netconf_lib.c +++ b/lib/src/clixon_netconf_lib.c @@ -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); diff --git a/lib/src/clixon_proto.c b/lib/src/clixon_proto.c index 4fc9a7f9..7e194c81 100644 --- a/lib/src/clixon_proto.c +++ b/lib/src/clixon_proto.c @@ -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; diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index 18a6916d..9311bb1b 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -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) diff --git a/lib/src/clixon_stream.c b/lib/src/clixon_stream.c index 1c36fc27..bcd5eb8a 100644 --- a/lib/src/clixon_stream.c +++ b/lib/src/clixon_stream.c @@ -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 */ diff --git a/lib/src/clixon_validate.c b/lib/src/clixon_validate.c index fe7c1c7a..b62550ab 100644 --- a/lib/src/clixon_validate.c +++ b/lib/src/clixon_validate.c @@ -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; } diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c index 8f78100c..00e7a194 100644 --- a/lib/src/clixon_xml.c +++ b/lib/src/clixon_xml.c @@ -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); diff --git a/lib/src/clixon_xml_io.c b/lib/src/clixon_xml_io.c index 106caf77..6756327e 100644 --- a/lib/src/clixon_xml_io.c +++ b/lib/src/clixon_xml_io.c @@ -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, "", 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, "\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\n", (level*PRETTYPRINT_INDENT-1), "<", + xml_name(x0c), b0, xml_name(x0c)); + cprintf(cb, "+%*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; +} diff --git a/lib/src/clixon_xml_vec.c b/lib/src/clixon_xml_vec.c index 150a4dbf..875de3e9 100644 --- a/lib/src/clixon_xml_vec.c +++ b/lib/src/clixon_xml_vec.c @@ -376,7 +376,7 @@ clixon_xvec_print(FILE *f, int i; for (i=0; ixv_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; } diff --git a/test/config.sh.in b/test/config.sh.in index 8b5e0913..2bac50f0 100755 --- a/test/config.sh.in +++ b/test/config.sh.in @@ -73,8 +73,8 @@ DATASTORE_TOP="config" # clixon yang revisions occuring in tests (see eg yang/clixon/Makefile.in) CLIXON_AUTOCLI_REV="2022-02-11" -CLIXON_LIB_REV="2022-12-01" -CLIXON_CONFIG_REV="2022-12-01" +CLIXON_LIB_REV="2023-03-01" +CLIXON_CONFIG_REV="2023-03-01" CLIXON_RESTCONF_REV="2022-08-01" CLIXON_EXAMPLE_REV="2022-11-01" diff --git a/util/clixon_util_datastore.c b/util/clixon_util_datastore.c index 5402437b..7d5827e7 100644 --- a/util/clixon_util_datastore.c +++ b/util/clixon_util_datastore.c @@ -216,7 +216,7 @@ main(int argc, char **argv) xpath = "/"; if (xmldb_get(h, db, NULL, xpath, &xt) < 0) goto done; - if (clixon_xml2file(stdout, xt, 0, 0, fprintf, 0, 0) < 0) + if (clixon_xml2file(stdout, xt, 0, 0, NULL, fprintf, 0, 0) < 0) goto done; fprintf(stdout, "\n"); if (xt){ @@ -240,7 +240,7 @@ main(int argc, char **argv) clicon_err(OE_DB, 0, "xt is NULL"); goto done; } - if (clixon_xml2file(stdout, xt, 0, 0, fprintf, 0, 0) < 0) + if (clixon_xml2file(stdout, xt, 0, 0, NULL, fprintf, 0, 0) < 0) goto done; if (xt){ xml_free(xt); diff --git a/util/clixon_util_json.c b/util/clixon_util_json.c index b9a9e8a5..585f6843 100644 --- a/util/clixon_util_json.c +++ b/util/clixon_util_json.c @@ -147,7 +147,7 @@ main(int argc, if (clixon_json2cbuf(cb, xt, pretty, 1, 0) < 0) goto done; } - else if (clixon_xml2cbuf(cb, xt, 0, pretty, -1, 1) < 0) + else if (clixon_xml2cbuf(cb, xt, 0, pretty, NULL, -1, 1) < 0) goto done; fprintf(stdout, "%s", cbuf_get(cb)); fflush(stdout); diff --git a/util/clixon_util_path.c b/util/clixon_util_path.c index 298a2451..fecf3d6a 100644 --- a/util/clixon_util_path.c +++ b/util/clixon_util_path.c @@ -281,7 +281,7 @@ main(int argc, for (i = 0; i < xlen; i++){ xc = xvec[i]; fprintf(stdout, "%d: ", i); - clixon_xml2file(stdout, xc, 0, 0, fprintf, 0, 0); + clixon_xml2file(stdout, xc, 0, 0, NULL, fprintf, 0, 0); fprintf(stdout, "\n"); fflush(stdout); } diff --git a/util/clixon_util_socket.c b/util/clixon_util_socket.c index 558b1333..4a78efa5 100644 --- a/util/clixon_util_socket.c +++ b/util/clixon_util_socket.c @@ -167,7 +167,7 @@ main(int argc, fprintf(stderr, "No xml\n"); goto done; } - if (clixon_xml2cbuf(cb, xc, 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xc, 0, 0, NULL, -1, 0) < 0) goto done; if ((msg = clicon_msg_encode(getpid(), "%s", cbuf_get(cb))) < 0) goto done; diff --git a/util/clixon_util_xml.c b/util/clixon_util_xml.c index 70a607d6..3dcc1af4 100644 --- a/util/clixon_util_xml.c +++ b/util/clixon_util_xml.c @@ -341,7 +341,7 @@ main(int argc, if (clixon_json2cbuf(cb, xt, pretty, 1, 0) < 0) goto done; } - else if (clixon_xml2cbuf(cb, xt, 0, pretty, -1, 1) < 0) + else if (clixon_xml2cbuf(cb, xt, 0, pretty, NULL, -1, 1) < 0) goto done; fprintf(stdout, "%s", cbuf_get(cb)); fflush(stdout); diff --git a/util/clixon_util_xml_mod.c b/util/clixon_util_xml_mod.c index 68f7a16d..b283d44e 100644 --- a/util/clixon_util_xml_mod.c +++ b/util/clixon_util_xml_mod.c @@ -282,11 +282,11 @@ main(int argc, char **argv) if (sort) xml_sort_recurse(xb); if (strcmp(xml_name(xb),"top")==0){ - if (clixon_xml2file(stdout, xb, 0, 0, fprintf, 1, 0) < 0) + if (clixon_xml2file(stdout, xb, 0, 0, NULL, fprintf, 1, 0) < 0) goto done; } else{ - if (clixon_xml2file(stdout, xb, 0, 0, fprintf, 0, 0) < 0) + if (clixon_xml2file(stdout, xb, 0, 0, NULL, fprintf, 0, 0) < 0) goto done; } fprintf(stdout, "\n"); diff --git a/util/clixon_util_xpath.c b/util/clixon_util_xpath.c index 44ddcb04..42da5002 100644 --- a/util/clixon_util_xpath.c +++ b/util/clixon_util_xpath.c @@ -99,7 +99,7 @@ ctx_print2(cbuf *cb, case XT_NODESET: for (i=0; ixc_size; i++){ cprintf(cb, "%d:", i); - if (clixon_xml2cbuf(cb, xc->xc_nodeset[i], 0, 0, -1, 0) < 0) + if (clixon_xml2cbuf(cb, xc->xc_nodeset[i], 0, 0, NULL, -1, 0) < 0) goto done; } break; diff --git a/yang/clixon/clixon-config@2023-03-01.yang b/yang/clixon/clixon-config@2023-03-01.yang index 1cca5dc6..3851572f 100644 --- a/yang/clixon/clixon-config@2023-03-01.yang +++ b/yang/clixon/clixon-config@2023-03-01.yang @@ -50,6 +50,7 @@ module clixon-config { description "Added options: CLICON_RESTCONF_NOALPN_DEFAULT + Extended datastore-format with CLI and text Released in Clixon 6.2"; } revision 2022-12-01 { @@ -275,7 +276,7 @@ module clixon-config { } typedef datastore_format{ description - "Datastore format."; + "Datastore format (only xml and json implemented in actual data."; type enumeration{ enum xml{ description @@ -286,6 +287,12 @@ module clixon-config { enum json{ description "Save and load xmldb as JSON"; } + enum text{ + description "'Curly' C-like text format"; + } + enum cli{ + description "CLI format"; + } } } typedef datastore_cache{