Changed C-API for xml translation/print to other formats.

* Added `skiptop` parameter, if set only apply to children of a node, skip top node
    * default is 0
* Functions are merged, ie removed and replaced with more generic functions
* `xml2json_cbuf()`: Added `skiptop` parameter: `xml2json_cbuf(..., int skiptop)`
* `xml2json()` and `xml2json_cb()` merged into `xml2json_file()` with `skiptop`
    * Replace `xml2json(...)` with `xml2json_file(..., stdout, 0)`
    * Replace `xml2json_cb(...)` with `xml2json_file(..., 0)`
* `clicon_xml2cbuf()`: Added `skiptop` parameter: `clicon_xml2cbuf(..., int skiptop)`
* `xml2cli()`: Added `skiptop` parameter: `xml2cli(..., int skiptop)`
This commit is contained in:
Olof hagsand 2022-06-01 10:48:39 +02:00
parent 724b94137f
commit 43a57dad79
39 changed files with 306 additions and 481 deletions

View file

@ -366,7 +366,7 @@ from_client_edit_config(clicon_handle h,
if ((ret = xml_bind_yang(xc, YB_MODULE, yspec, &xret)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
goto done;
goto ok;
}
@ -374,7 +374,7 @@ from_client_edit_config(clicon_handle h,
if ((ret = xml_non_config_data(xc, &xret)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
goto done;
goto ok;
}
@ -387,7 +387,7 @@ from_client_edit_config(clicon_handle h,
if ((ret = xml_yang_validate_list_key_only(xc, &xret)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
goto done;
goto ok;
}
@ -1241,7 +1241,7 @@ from_client_msg(clicon_handle h,
goto reply;
}
if (ret == 0){
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
goto done;
goto reply;
}
@ -1303,7 +1303,7 @@ from_client_msg(clicon_handle h,
if ((ret = xml_yang_validate_rpc(h, x, &xret)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
goto done;
goto reply;
}

View file

@ -216,7 +216,7 @@ startup_common(clicon_handle h,
* See similar clause below
*/
}
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
goto done;
goto fail;
}
@ -276,7 +276,7 @@ startup_common(clicon_handle h,
if ((ret = xml_bind_yang(xt, YB_MODULE, yspec, &xret)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
goto done;
goto fail;
}
@ -284,7 +284,7 @@ startup_common(clicon_handle h,
if ((ret = xml_non_config_data(xt, &xret)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
goto done;
goto fail;
}
@ -319,7 +319,7 @@ startup_common(clicon_handle h,
if ((ret = generic_validate(h, yspec, td, &xret)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
goto done;
goto fail; /* STARTUP_INVALID */
}
@ -625,7 +625,7 @@ candidate_validate(clicon_handle h,
clicon_err(OE_CFG, EINVAL, "xret is NULL");
goto done;
}
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
goto done;
if (!cbuf_len(cbret) &&
netconf_operation_failed(cbret, "application", clicon_err_reason)< 0)
@ -685,7 +685,7 @@ candidate_commit(clicon_handle h,
if ((ret = validate_common(h, db, td, &xret)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
goto done;
goto fail;
}
@ -957,7 +957,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 (clicon_xml2cbuf(cbret, xerr, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
goto done;
goto fail;
}
@ -1007,7 +1007,7 @@ from_client_restart_one(clicon_handle h,
if ((ret = generic_validate(h, yspec, td, &xerr)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
goto done;
goto fail;
}

View file

@ -365,7 +365,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 (clicon_xml2cbuf(cbret, xret, 0, 0, depth>0?depth+1:depth) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, depth>0?depth+1:depth, 0) < 0)
goto done;
}
cprintf(cbret, "</rpc-reply>");
@ -605,7 +605,7 @@ get_list_pagination(clicon_handle h,
clicon_err_reason);
if (netconf_operation_failed_xml(&xerr, "application", cbuf_get(cberr)) < 0)
goto done;
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
goto done;
goto ok;
}
@ -620,7 +620,7 @@ get_list_pagination(clicon_handle h,
". Internal error, state callback returned invalid XML",
NULL) < 0)
goto done;
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
goto done;
goto ok;
}
@ -832,7 +832,7 @@ get_common(clicon_handle h,
if ((ret = get_client_statedata(h, xpath?xpath:"/", nsc, &xret)) < 0)
goto done;
if (ret == 0){ /* Error from callback (error in xret) */
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
goto done;
goto ok;
}
@ -857,7 +857,7 @@ get_common(clicon_handle h,
". Internal error, state callback returned invalid XML",
NULL) < 0)
goto done;
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
goto done;
goto ok;
}

View file

@ -163,7 +163,7 @@ restconf_pseudo_set_inline(clicon_handle h,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (clicon_xml2cbuf(cb, xrestconf, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cb, xrestconf, 0, 0, -1, 0) < 0)
goto done;
if ((str = strdup(cbuf_get(cb))) == NULL){
clicon_err(OE_XML, errno, "stdup");

View file

@ -256,7 +256,7 @@ transaction_log(clicon_handle h,
}
for (i=0; i<td->td_dlen; i++){
xn = td->td_dvec[i];
clicon_xml2cbuf(cb, xn, 0, 0, -1);
clicon_xml2cbuf(cb, xn, 0, 0, -1, 0);
}
if (i)
clicon_log(level, "%s %" PRIu64 " %s del: %s",
@ -264,7 +264,7 @@ transaction_log(clicon_handle h,
cbuf_reset(cb);
for (i=0; i<td->td_alen; i++){
xn = td->td_avec[i];
clicon_xml2cbuf(cb, xn, 0, 0, -1);
clicon_xml2cbuf(cb, xn, 0, 0, -1, 0);
}
if (i)
clicon_log(level, "%s %" PRIu64 " %s add: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));
@ -272,10 +272,10 @@ transaction_log(clicon_handle h,
for (i=0; i<td->td_clen; i++){
if (td->td_scvec){
xn = td->td_scvec[i];
clicon_xml2cbuf(cb, xn, 0, 0, -1);
clicon_xml2cbuf(cb, xn, 0, 0, -1, 0);
}
xn = td->td_tcvec[i];
clicon_xml2cbuf(cb, xn, 0, 0, -1);
clicon_xml2cbuf(cb, xn, 0, 0, -1, 0);
}
if (i)
clicon_log(level, "%s %" PRIu64 " %s change: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));

View file

@ -651,12 +651,8 @@ cli_auto_show(clicon_handle h,
fprintf(stdout, "\n");
break;
case FORMAT_JSON:
if (isroot)
xml2json_cb(stdout, xp, pretty, cligen_output);
else{
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL)
xml2json_cb(stdout, xc, pretty, cligen_output);
}
if (xml2json_file(stdout, xp, pretty, cligen_output, !isroot) < 0)
goto done;
fprintf(stdout, "\n");
break;
case FORMAT_TEXT:
@ -667,11 +663,8 @@ cli_auto_show(clicon_handle h,
cli_xml2txt(xc, cligen_output, 0); /* tree-formed text */
break;
case FORMAT_CLI:
if (isroot)
xml2cli(h, stdout, xp, prefix, cligen_output);
else
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL)
xml2cli(h, stdout, xc, prefix, cligen_output);
if (xml2cli(h, stdout, xp, prefix, cligen_output, !isroot) < 0)
goto done;
break;
case FORMAT_NETCONF:
fprintf(stdout, "<rpc xmlns=\"%s\" %s><edit-config><target><candidate/></target><config>",

View file

@ -325,7 +325,7 @@ cli_dbxml(clicon_handle h,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (clicon_xml2cbuf(cb, xtop, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cb, xtop, 0, 0, -1, 0) < 0)
goto done;
if (clicon_rpc_edit_config(h, "candidate", OP_NONE, cbuf_get(cb)) < 0)
goto done;
@ -925,9 +925,9 @@ load_config_file(clicon_handle h,
while ((x = xml_child_each(xt, x, -1)) != NULL) {
/* Read as datastore-top but transformed into an edit-config "config" */
xml_name_set(x, NETCONF_INPUT_CONFIG);
if (clicon_xml2cbuf(cbxml, x, 0, 0, -1) < 0)
goto done;
}
if (clicon_xml2cbuf(cbxml, xt, 0, 0, -1, 1) < 0)
goto done;
if (clicon_rpc_edit_config(h, "candidate",
replace?OP_REPLACE:OP_MERGE,
cbuf_get(cbxml)) < 0)
@ -973,7 +973,6 @@ save_config_file(clicon_handle h,
char *dbstr;
char *varstr;
cxobj *xt = NULL;
cxobj *x;
cxobj *xerr;
FILE *f = NULL;
char *formatstr;
@ -1031,7 +1030,7 @@ save_config_file(clicon_handle h,
goto done;
break;
case FORMAT_JSON:
if (xml2json(f, xt, pretty) < 0)
if (xml2json_file(f, xt, pretty, fprintf, 0) < 0)
goto done;
break;
case FORMAT_TEXT:
@ -1039,11 +1038,8 @@ save_config_file(clicon_handle h,
goto done;
break;
case FORMAT_CLI:
x = NULL;
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
if (xml2cli(h, f, x, prefix, fprintf) < 0)
goto done;
}
if (xml2cli(h, f, xt, prefix, fprintf, 1) < 0)
goto done;
break;
case FORMAT_NETCONF:
fprintf(f, "<rpc xmlns=\"%s\" %s><edit-config><target><candidate/></target>",
@ -1153,6 +1149,13 @@ cli_notification_cb(int s,
clicon_err(OE_NETCONF, EFAULT, "Notification malformed");
goto done;
}
switch (format){
case FORMAT_JSON:
if (xml2json_file(stdout, xt, 1, cligen_output, 1) < 0)
goto done;
default:
break;
}
if ((xe = xpath_first(xt, NULL, "//event")) != NULL){
x = NULL;
while ((x = xml_child_each(xe, x, -1)) != NULL) {
@ -1165,10 +1168,6 @@ cli_notification_cb(int s,
if (xml2txt_cb(stdout, x, cligen_output) < 0)
goto done;
break;
case FORMAT_JSON:
if (xml2json_cb(stdout, x, 1, cligen_output) < 0)
goto done;
break;
default:
break;
}
@ -1417,7 +1416,7 @@ cli_copy_config(clicon_handle h,
/* resuse cb */
cbuf_reset(cb);
/* create xml copy tree and merge it with database configuration */
clicon_xml2cbuf(cb, x2, 0, 0, -1);
clicon_xml2cbuf(cb, x2, 0, 0, -1, 0);
if (clicon_rpc_edit_config(h, db, OP_MERGE, cbuf_get(cb)) < 0)
goto done;
retval = 0;

View file

@ -500,7 +500,7 @@ cli_show_config1(clicon_handle h,
cli_xml2file(xc, 0, 1, cligen_output);
break;
case FORMAT_JSON:
xml2json_cb(stdout, xt, 1, cligen_output);
xml2json_file(stdout, xt, 1, cligen_output, 0);
break;
case FORMAT_TEXT:
xc = NULL; /* Dont print xt itself */
@ -508,10 +508,8 @@ cli_show_config1(clicon_handle h,
cli_xml2txt(xc, cligen_output, 0); /* tree-formed text */
break;
case FORMAT_CLI:
xc = NULL; /* Dont print xt itself */
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL)
if (xml2cli(h, stdout, xc, prefix, cligen_output) < 0)
goto done;
if (xml2cli(h, stdout, xt, prefix, cligen_output, 1) < 0)
goto done;
break;
case FORMAT_NETCONF:
cligen_output(stdout, "<rpc xmlns=\"%s\" %s><edit-config><target><candidate/></target><config>\n",
@ -773,7 +771,7 @@ cli_show_generated(clicon_handle h,
switch (format){
case FORMAT_CLI:
if (xml2cli(h, stdout, xp, prefix, cligen_output) < 0) /* cli syntax */
if (xml2cli(h, stdout, xp, prefix, cligen_output, 0) < 0) /* cli syntax */
goto done;
break;
case FORMAT_NETCONF:
@ -781,15 +779,15 @@ cli_show_generated(clicon_handle h,
cli_xml2file(xp, 2, 1, fprintf);
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
break;
case FORMAT_JSON:
xml2json_file(stdout, xp_helper, 1, cligen_output, 1);
break;
default:
for (; i < xml_child_nr(xml_parent(xp)) ; ++i, xp_helper = xml_child_i(xml_parent(xp), i)) {
switch (format){
case FORMAT_XML:
cli_xml2file(xp_helper, 0, 1, fprintf);
break;
case FORMAT_JSON:
xml2json_cb(stdout, xp_helper, 1, cligen_output);
break;
case FORMAT_TEXT:
cli_xml2txt(xp_helper, cligen_output, 0); /* tree-formed text */
break;
@ -985,14 +983,14 @@ cli_pagination(clicon_handle h,
clicon_xml2file_cb(stdout, xc, 0, 1, cligen_output);
break;
case FORMAT_JSON:
xml2json_cb(stdout, xc, 1, cligen_output);
xml2json_file(stdout, xc, 1, cligen_output, 0);
break;
case FORMAT_TEXT:
xml2txt_cb(stdout, xc, cligen_output); /* tree-formed text */
break;
case FORMAT_CLI:
/* hardcoded to compress and list-keyword = nokey */
xml2cli(h, stdout, xc, NULL, cligen_output);
xml2cli(h, stdout, xc, NULL, cligen_output, 0);
break;
default:
break;
@ -1028,7 +1026,7 @@ cli_pagination(clicon_handle h,
return retval;
}
/*! Translate from XML to CLI commands
/*! Translate from XML to CLI commands, internal
*
* Howto: join strings and pass them down.
* Identify unique/index keywords for correct set syntax.
@ -1037,14 +1035,13 @@ cli_pagination(clicon_handle h,
* @param[in] xn XML Parse-tree (to translate)
* @param[in] prepend Print this text in front of all commands.
* @param[in] fn Callback to make print function
* @see xml2cli XXX should probably use the generic function
*/
int
xml2cli(clicon_handle h,
FILE *f,
cxobj *xn,
char *prepend,
clicon_output_cb *fn)
static int
xml2cli1(clicon_handle h,
FILE *f,
cxobj *xn,
char *prepend,
clicon_output_cb *fn)
{
int retval = -1;
cxobj *xe = NULL;
@ -1139,7 +1136,7 @@ xml2cli(clicon_handle h,
if (match)
continue; /* Not key itself */
}
if (xml2cli(h, f, xe, cbuf_get(cbpre), fn) < 0)
if (xml2cli1(h, f, xe, cbuf_get(cbpre), fn) < 0)
goto done;
}
ok:
@ -1149,3 +1146,41 @@ xml2cli(clicon_handle h,
cbuf_free(cbpre);
return retval;
}
/*! Translate from XML to CLI commands
*
* Howto: join strings and pass them down.
* Identify unique/index keywords for correct set syntax.
* @param[in] h Clicon handle
* @param[in] f Output FILE (eg stdout)
* @param[in] xn XML Parse-tree (to translate)
* @param[in] prepend Print this text in front of all commands.
* @param[in] fn Callback to make print function
* @param[in] skiptop 0: Include top object 1: Skip top-object, only children,
*/
int
xml2cli(clicon_handle h,
FILE *f,
cxobj *xn,
char *prepend,
clicon_output_cb *fn,
int skiptop)
{
int retval = 1;
cxobj *xc;
if (skiptop){
xc = NULL;
while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL)
if (xml2cli1(h, f, xc, prepend, fn) < 0)
goto done;
}
else {
if (xml2cli1(h, f, xn, prepend, fn) < 0)
goto done;
}
retval = 0;
done:
return retval;
}

View file

@ -137,7 +137,7 @@ int expand_dbvar(void *h, char *name, cvec *cvv, cvec *argv,
cvec *commands, cvec *helptexts);
int cli_xml2file (cxobj *xn, int level, int prettyprint, clicon_output_cb *fn);
int cli_xml2txt(cxobj *xn, clicon_output_cb *fn, int level);
int xml2cli(clicon_handle h, FILE *f, cxobj *xn, char *prepend, clicon_output_cb *fn);
int xml2cli(clicon_handle h, FILE *f, cxobj *xn, char *prepend, clicon_output_cb *fn, int skiptop);
/* cli_show.c: CLIgen new vector arg callbacks */
int show_yang(clicon_handle h, cvec *vars, cvec *argv);

View file

@ -211,7 +211,7 @@ netconf_rpc_message(clicon_handle h,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
clicon_xml2cbuf(cbret, xret, 0, 0, -1);
clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0);
if (netconf_output_encap(framing, cbret) < 0)
goto done;
if (netconf_output(1, cbret, "rpc-error") < 0)
@ -231,7 +231,7 @@ netconf_rpc_message(clicon_handle h,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
clicon_xml2cbuf(cbret, xret, 0, 0, -1);
clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0);
if (netconf_output_encap(framing, cbret) < 0)
goto done;
if (netconf_output(1, cbret, "rpc-error") < 0)
@ -251,7 +251,7 @@ netconf_rpc_message(clicon_handle h,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
clicon_xml2cbuf(cbret, xret, 0, 0, -1);
clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0);
if (netconf_output_encap(framing, cbret) < 0)
goto done;
if (netconf_output(1, cbret, "rpc-error") < 0)
@ -266,7 +266,7 @@ netconf_rpc_message(clicon_handle h,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
clicon_xml2cbuf(cbret, xml_child_i(xret,0), 0, 0, -1);
clicon_xml2cbuf(cbret, xml_child_i(xret,0), 0, 0, -1, 0);
if (netconf_output_encap(framing, cbret) < 0)
goto done;
if (netconf_output(1, cbret, "rpc-reply") < 0)
@ -322,7 +322,7 @@ netconf_input_packet(clicon_handle h,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
clicon_xml2cbuf(cbret, xret, 0, 0, -1);
clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0);
if (netconf_output_encap(framing, cbret) < 0)
goto done;
if (netconf_output(1, cbret, "rpc-error") < 0)
@ -435,7 +435,7 @@ netconf_input_frame(clicon_handle h,
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
clicon_xml2cbuf(cbret, xret, 0, 0, -1);
clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0);
if (netconf_output_encap(framing, cbret) < 0)
goto done;
if (netconf_output(1, cbret, "rpc-error") < 0)

View file

@ -481,7 +481,7 @@ netconf_notification_cb(int s,
clicon_err(OE_PLUGIN, errno, "cbuf_new");
goto done;
}
if (clicon_xml2cbuf(cb, xn, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
goto done;
/* Send it to listening client on stdout */
if (netconf_output_encap(clicon_option_int(h, "netconf-framing"), cb) < 0){
@ -659,7 +659,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 (clicon_xml2cbuf(cbret, xerr, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
goto done;
clicon_log(LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret));
goto ok;

View file

@ -279,13 +279,13 @@ api_return_err(clicon_handle h,
clicon_debug(1, "%s code:%d", __FUNCTION__, code);
if (pretty){
cprintf(cb, " <errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\">\n");
if (clicon_xml2cbuf(cb, xerr, 2, pretty, -1) < 0)
if (clicon_xml2cbuf(cb, xerr, 2, pretty, -1, 0) < 0)
goto done;
cprintf(cb, " </errors>\r\n");
}
else {
cprintf(cb, "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\">");
if (clicon_xml2cbuf(cb, xerr, 2, pretty, -1) < 0)
if (clicon_xml2cbuf(cb, xerr, 2, pretty, -1, 0) < 0)
goto done;
cprintf(cb, "</errors>\r\n");
}
@ -295,14 +295,14 @@ api_return_err(clicon_handle h,
clicon_debug(1, "%s code:%d", __FUNCTION__, code);
if (pretty){
cprintf(cb, "{\n\"ietf-restconf:errors\" : ");
if (xml2json_cbuf(cb, xerr, pretty) < 0)
if (xml2json_cbuf(cb, xerr, pretty, 0) < 0)
goto done;
cprintf(cb, "\n}\r\n");
}
else{
cprintf(cb, "{");
cprintf(cb, "\"ietf-restconf:errors\":");
if (xml2json_cbuf(cb, xerr, pretty) < 0)
if (xml2json_cbuf(cb, xerr, pretty, 0) < 0)
goto done;
cprintf(cb, "}\r\n");
}

View file

@ -537,7 +537,7 @@ api_data_write(clicon_handle h,
cprintf(cbx, " autocommit=\"true\"");
cprintf(cbx, "><target><candidate /></target>");
cprintf(cbx, "<default-operation>none</default-operation>");
if (clicon_xml2cbuf(cbx, xtop, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0)
goto done;
cprintf(cbx, "</edit-config></rpc>");
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,
cprintf(cbx, " autocommit=\"true\"");
cprintf(cbx, "><target><candidate /></target>");
cprintf(cbx, "<default-operation>none</default-operation>");
if (clicon_xml2cbuf(cbx, xtop, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0)
goto done;
cprintf(cbx, "</edit-config></rpc>");
if (clicon_rpc_netconf(h, cbuf_get(cbx), &xret, NULL) < 0)

View file

@ -225,11 +225,11 @@ api_data_get2(clicon_handle h,
if (xpath==NULL || strcmp(xpath,"/")==0){ /* Special case: data root */
switch (media_out){
case YANG_DATA_XML:
if (clicon_xml2cbuf(cbx, xret, 0, pretty, -1) < 0) /* Dont print top object? */
if (clicon_xml2cbuf(cbx, xret, 0, pretty, -1, 0) < 0) /* Dont print top object? */
goto done;
break;
case YANG_DATA_JSON:
if (xml2json_cbuf(cbx, xret, pretty) < 0)
if (xml2json_cbuf(cbx, xret, pretty, 0) < 0)
goto done;
break;
default:
@ -270,7 +270,7 @@ api_data_get2(clicon_handle h,
if (namespace && xmlns_set(x, prefix, namespace) < 0)
goto done;
}
if (clicon_xml2cbuf(cbx, x, 0, pretty, -1) < 0) /* Dont print top object? */
if (clicon_xml2cbuf(cbx, x, 0, pretty, -1, 0) < 0) /* Dont print top object? */
goto done;
}
break;
@ -535,7 +535,7 @@ api_data_pagination(clicon_handle h,
if (xml_insert(xpr, xp, INS_LAST, NULL, NULL) < 0)
goto done;
}
if (clicon_xml2cbuf(cbx, xpr, 0, pretty, -1) < 0) /* Dont print top object? */
if (clicon_xml2cbuf(cbx, xpr, 0, pretty, -1, 0) < 0) /* Dont print top object? */
goto done;
break;
case YANG_DATA_JSON:

View file

@ -119,7 +119,7 @@ yang_patch_xml2json_modified_cbuf(cxobj *x_simple_patch)
if (json_simple_patch == NULL)
return NULL;
cb = cbuf_new();
xml2json_cbuf(cb, x_simple_patch, 1);
xml2json_cbuf(cb, x_simple_patch, 0);
// Insert a '[' after the first '{' to get the JSON to match what api_data_post/write() expect
json_simple_patch_tmp = cbuf_get(cb);
@ -266,7 +266,7 @@ yang_patch_do_replace(clicon_handle h,
}
}
// Convert the data to json
xml2json_cbuf(json_simple_patch, x_simple_patch, 1);
xml2json_cbuf(json_simple_patch, x_simple_patch, 0);
// Send the POST request
if (api_data_post(h, req, cbuf_get(simple_patch_request_uri), pi, qvec, cbuf_get(json_simple_patch), pretty, YANG_DATA_JSON, media_out, ds ) < 0)
@ -327,7 +327,7 @@ yang_patch_do_create(clicon_handle h,
xml_addsub(x_simple_patch, value_vec_tmp);
}
}
if (xml2json_cbuf(cb, x_simple_patch, 1) < 0)
if (xml2json_cbuf(cb, x_simple_patch, 0) < 0)
goto done;
if (api_data_post(h, req, cbuf_get(simple_patch_request_uri),
pi, qvec,
@ -477,7 +477,7 @@ yang_patch_do_merge(clicon_handle h,
xml_addsub(x_simple_patch, value_vec_tmp);
}
cbuf_reset(cb); /* reuse cb */
xml2json_cbuf(cb, x_simple_patch, 1);
xml2json_cbuf(cb, x_simple_patch, 0);
if ((json_simple_patch = yang_patch_xml2json_modified_cbuf(x_simple_patch)) == NULL)
goto done;

View file

@ -360,7 +360,7 @@ api_data_post(clicon_handle h,
cprintf(cbx, " autocommit=\"true\"");
cprintf(cbx, "><target><candidate /></target>");
cprintf(cbx, "<default-operation>none</default-operation>");
if (clicon_xml2cbuf(cbx, xtop, 0, 0, -1) < 0)
if (clicon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0)
goto done;
cprintf(cbx, "</edit-config></rpc>");
clicon_debug(1, "%s xml: %s api_path:%s",__FUNCTION__, cbuf_get(cbx), api_path);
@ -874,12 +874,12 @@ api_operations_post(clicon_handle h,
cbuf_reset(cbret);
switch (media_out){
case YANG_DATA_XML:
if (clicon_xml2cbuf(cbret, xoutput, 0, pretty, -1) < 0)
if (clicon_xml2cbuf(cbret, xoutput, 0, pretty, -1, 0) < 0)
goto done;
/* xoutput should now look: <output xmlns="uri"><x>0</x></output> */
break;
case YANG_DATA_JSON:
if (xml2json_cbuf(cbret, xoutput, pretty) < 0)
if (xml2json_cbuf(cbret, xoutput, pretty, 0) < 0)
goto done;
/* xoutput should now look: {"example:output": {"x":0,"y":42}} */
break;

View file

@ -204,12 +204,12 @@ api_root_restconf_exact(clicon_handle h,
switch (media_out){
case YANG_DATA_XML:
case YANG_PATCH_XML:
if (clicon_xml2cbuf(cb, xt, 0, pretty, -1) < 0)
if (clicon_xml2cbuf(cb, xt, 0, pretty, -1, 0) < 0)
goto done;
break;
case YANG_DATA_JSON:
case YANG_PATCH_JSON:
if (xml2json_cbuf(cb, xt, pretty) < 0)
if (xml2json_cbuf(cb, xt, pretty, 0) < 0)
goto done;
break;
default:
@ -288,12 +288,12 @@ api_yang_library_version(clicon_handle h,
switch (media_out){
case YANG_DATA_XML:
case YANG_PATCH_XML:
if (clicon_xml2cbuf(cb, xt, 0, pretty, -1) < 0)
if (clicon_xml2cbuf(cb, xt, 0, pretty, -1, 0) < 0)
goto done;
break;
case YANG_DATA_JSON:
case YANG_PATCH_JSON:
if (xml2json_cbuf(cb, xt, pretty) < 0)
if (xml2json_cbuf(cb, xt, pretty, 0) < 0)
goto done;
break;
default:

View file

@ -254,7 +254,7 @@ restconf_stream_cb(int s,
FCGX_FPrintF(r->out, "M#id: %02d:0\r\n", tv.tv_sec);
}
#endif
if (clicon_xml2cbuf(cb, xn, 0, pretty, -1) < 0)
if (clicon_xml2cbuf(cb, xn, 0, pretty, -1, 0) < 0)
goto done;
FCGX_FPrintF(r->out, "data: %s\r\n", cbuf_get(cb));
FCGX_FPrintF(r->out, "\r\n");