Fixed: ["autocli:hide-show" extension cause bug in xmldb_put method #343](https://github.com/clicon/clixon/issues/343)

As a side-effect, added extra "autocliext" parameter to:
- clixon_xml2file()
- clixon_json2file()
- clixon_json2cbuf()
- clixon_txt2file()
This commit is contained in:
Olof hagsand 2022-07-22 15:56:06 +02:00
parent e724dd7f40
commit 4514f2a538
26 changed files with 213 additions and 144 deletions

View file

@ -452,17 +452,17 @@ cli_auto_show(clicon_handle h,
/* Print configuration according to format */
switch (format){
case FORMAT_XML:
if (clixon_xml2file(stdout, xp, 0, pretty, cligen_output, skiproot) < 0)
if (clixon_xml2file(stdout, xp, 0, pretty, cligen_output, skiproot, 1) < 0)
goto done;
fprintf(stdout, "\n");
break;
case FORMAT_JSON:
if (clixon_json2file(stdout, xp, pretty, cligen_output, skiproot) < 0)
if (clixon_json2file(stdout, xp, pretty, cligen_output, skiproot, 1) < 0)
goto done;
fprintf(stdout, "\n");
break;
case FORMAT_TEXT:
if (clixon_txt2file(stdout, xp, 0, cligen_output, skiproot) < 0)
if (clixon_txt2file(stdout, xp, 0, cligen_output, skiproot, 1) < 0)
goto done;
break;
case FORMAT_CLI:
@ -474,7 +474,7 @@ cli_auto_show(clicon_handle h,
NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
if (pretty)
fprintf(stdout, "\n");
if (clixon_xml2file(stdout, xp, 2, pretty, cligen_output, skiproot) < 0)
if (clixon_xml2file(stdout, xp, 2, pretty, cligen_output, skiproot, 1) < 0)
goto done;
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
break;

View file

@ -696,12 +696,12 @@ compare_xmls(cxobj *xc1,
goto done;
switch(format){
case FORMAT_TEXT:
if (clixon_txt2file(f, xc1, 0, cligen_output, 1) < 0)
if (clixon_txt2file(f, xc1, 0, cligen_output, 1, 1) < 0)
goto done;
break;
case FORMAT_XML:
default:
if (clixon_xml2file(f, xc1, 0, 1, cligen_output, 1) < 0)
if (clixon_xml2file(f, xc1, 0, 1, cligen_output, 1, 1) < 0)
goto done;
break;
}
@ -717,12 +717,12 @@ compare_xmls(cxobj *xc1,
switch(format){
case FORMAT_TEXT:
if (clixon_txt2file(f, xc2, 0, cligen_output, 1) < 0)
if (clixon_txt2file(f, xc2, 0, cligen_output, 1, 1) < 0)
goto done;
break;
case FORMAT_XML:
default:
if (clixon_xml2file(f, xc2, 0, 1, cligen_output, 1) < 0)
if (clixon_xml2file(f, xc2, 0, 1, cligen_output, 1, 1) < 0)
goto done;
break;
}
@ -1048,15 +1048,15 @@ save_config_file(clicon_handle h,
}
switch (format){
case FORMAT_XML:
if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0) < 0)
if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0, 1) < 0)
goto done;
break;
case FORMAT_JSON:
if (clixon_json2file(f, xt, pretty, fprintf, 0) < 0)
if (clixon_json2file(f, xt, pretty, fprintf, 0, 1) < 0)
goto done;
break;
case FORMAT_TEXT:
if (clixon_txt2file(f, xt, 0, fprintf, 0) < 0)
if (clixon_txt2file(f, xt, 0, fprintf, 0, 1) < 0)
goto done;
break;
case FORMAT_CLI:
@ -1067,7 +1067,7 @@ save_config_file(clicon_handle h,
fprintf(f, "<rpc xmlns=\"%s\" %s><edit-config><target><candidate/></target>",
NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
fprintf(f, "\n");
if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0) < 0)
if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0, 1) < 0)
goto done;
fprintf(f, "</edit-config></rpc>]]>]]>\n");
break;
@ -1171,14 +1171,14 @@ cli_notification_cb(int s,
}
switch (format){
case FORMAT_JSON:
if (clixon_json2file(stdout, xt, 1, cligen_output, 1) < 0)
if (clixon_json2file(stdout, xt, 1, cligen_output, 1, 1) < 0)
goto done;
case FORMAT_TEXT:
if (clixon_txt2file(stdout, xt, 0, cligen_output, 1) < 0)
if (clixon_txt2file(stdout, xt, 0, cligen_output, 1, 1) < 0)
goto done;
break;
case FORMAT_XML:
if (clixon_xml2file(stdout, xt, 0, 1, cligen_output, 1) < 0)
if (clixon_xml2file(stdout, xt, 0, 1, cligen_output, 1, 1) < 0)
goto done;
break;
default:

View file

@ -494,15 +494,15 @@ cli_show_config1(clicon_handle h,
/* Print configuration according to format */
switch (format){
case FORMAT_XML:
if (clixon_xml2file(stdout, xt, 0, 1, cligen_output, 1) < 0)
if (clixon_xml2file(stdout, xt, 0, 1, cligen_output, 1, 1) < 0)
goto done;
break;
case FORMAT_JSON:
if (clixon_json2file(stdout, xt, 1, cligen_output, 0) < 0)
if (clixon_json2file(stdout, xt, 1, cligen_output, 0, 1) < 0)
goto done;
break;
case FORMAT_TEXT:
if (clixon_txt2file(stdout, xt, 0, cligen_output, 1) < 0)
if (clixon_txt2file(stdout, xt, 0, cligen_output, 1, 1) < 0)
goto done;
break;
case FORMAT_CLI:
@ -512,7 +512,7 @@ cli_show_config1(clicon_handle h,
case FORMAT_NETCONF:
cligen_output(stdout, "<rpc xmlns=\"%s\" %s><edit-config><target><candidate/></target><config>\n",
NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
if (clixon_xml2file(stdout, xt, 2, 1, cligen_output, 1) < 0)
if (clixon_xml2file(stdout, xt, 2, 1, cligen_output, 1, 1) < 0)
goto done;
cligen_output(stdout, "</config></edit-config></rpc>]]>]]>\n");
break;
@ -647,7 +647,7 @@ show_conf_xpath(clicon_handle h,
if (xpath_vec(xt, nsc, "%s", &xv, &xlen, xpath) < 0)
goto done;
for (i=0; i<xlen; i++)
if (clixon_xml2file(stdout, xv[i], 0, 1, fprintf, 0) < 0)
if (clixon_xml2file(stdout, xv[i], 0, 1, fprintf, 0, 1) < 0)
goto done;
retval = 0;
@ -765,20 +765,20 @@ cli_show_auto1(clicon_handle h,
break;
case FORMAT_NETCONF:
fprintf(stdout, "<rpc><edit-config><target><candidate/></target><config>\n");
if (clixon_xml2file(stdout, xp, 2, 1, fprintf, 0) < 0)
if (clixon_xml2file(stdout, xp, 2, 1, fprintf, 0, 1) < 0)
goto done;
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
break;
case FORMAT_JSON:
if (clixon_json2file(stdout, xp, 1, cligen_output, 1) < 0) // XXX helper?
if (clixon_json2file(stdout, xp, 1, cligen_output, 1, 1) < 0)
goto done;
break;
case FORMAT_TEXT:
if (clixon_txt2file(stdout, xp, 0, cligen_output, 1) < 0) // XXX helper?
if (clixon_txt2file(stdout, xp, 0, cligen_output, 1, 1) < 0)
goto done;
break;
case FORMAT_XML:
if (clixon_xml2file(stdout, xp, 0, 1, fprintf, 0) < 0) // XXX helper?
if (clixon_xml2file(stdout, xp, 0, 1, fprintf, 0, 1) < 0)
goto done;
break;
}
@ -970,15 +970,15 @@ cli_pagination(clicon_handle h,
xc = xvec[j];
switch (format){
case FORMAT_XML:
if (clixon_xml2file(stdout, xc, 0, 1, cligen_output, 0) < 0)
if (clixon_xml2file(stdout, xc, 0, 1, cligen_output, 0, 1) < 0)
goto done;
break;
case FORMAT_JSON:
if (clixon_json2file(stdout, xc, 1, cligen_output, 0) < 0)
if (clixon_json2file(stdout, xc, 1, cligen_output, 0, 1) < 0)
goto done;
break;
case FORMAT_TEXT:
if (clixon_txt2file(stdout, xc, 0, cligen_output, 0) < 0)
if (clixon_txt2file(stdout, xc, 0, cligen_output, 0, 1) < 0)
goto done;
break;
case FORMAT_CLI:

View file

@ -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 (clixon_json2cbuf(cb, xerr, pretty, 0) < 0)
if (clixon_json2cbuf(cb, xerr, pretty, 0, 0) < 0)
goto done;
cprintf(cb, "\n}\r\n");
}
else{
cprintf(cb, "{");
cprintf(cb, "\"ietf-restconf:errors\":");
if (clixon_json2cbuf(cb, xerr, pretty, 0) < 0)
if (clixon_json2cbuf(cb, xerr, pretty, 0, 0) < 0)
goto done;
cprintf(cb, "}\r\n");
}

View file

@ -229,7 +229,7 @@ api_data_get2(clicon_handle h,
goto done;
break;
case YANG_DATA_JSON:
if (clixon_json2cbuf(cbx, xret, pretty, 0) < 0)
if (clixon_json2cbuf(cbx, xret, pretty, 0, 0) < 0)
goto done;
break;
default:

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();
if (clixon_json2cbuf(cb, x_simple_patch, 0) < 0)
if (clixon_json2cbuf(cb, x_simple_patch, 0, 0) < 0)
goto done;
// Insert a '[' after the first '{' to get the JSON to match what api_data_post/write() expect
@ -267,7 +267,7 @@ yang_patch_do_replace(clicon_handle h,
}
}
// Convert the data to json
if (clixon_json2cbuf(json_simple_patch, x_simple_patch, 0) < 0)
if (clixon_json2cbuf(json_simple_patch, x_simple_patch, 0, 0) < 0)
goto done;
// Send the POST request
@ -329,7 +329,7 @@ yang_patch_do_create(clicon_handle h,
xml_addsub(x_simple_patch, value_vec_tmp);
}
}
if (clixon_json2cbuf(cb, x_simple_patch, 0) < 0)
if (clixon_json2cbuf(cb, x_simple_patch, 0, 0) < 0)
goto done;
if (api_data_post(h, req, cbuf_get(simple_patch_request_uri),
pi, qvec,
@ -479,7 +479,7 @@ yang_patch_do_merge(clicon_handle h,
xml_addsub(x_simple_patch, value_vec_tmp);
}
cbuf_reset(cb); /* reuse cb */
if (clixon_json2cbuf(cb, x_simple_patch, 0) < 0)
if (clixon_json2cbuf(cb, x_simple_patch, 0, 0) < 0)
goto done;
if ((json_simple_patch = yang_patch_xml2json_modified_cbuf(x_simple_patch)) == NULL)

View file

@ -879,7 +879,7 @@ api_operations_post(clicon_handle h,
/* xoutput should now look: <output xmlns="uri"><x>0</x></output> */
break;
case YANG_DATA_JSON:
if (clixon_json2cbuf(cbret, xoutput, pretty, 0) < 0)
if (clixon_json2cbuf(cbret, xoutput, pretty, 0, 0) < 0)
goto done;
/* xoutput should now look: {"example:output": {"x":0,"y":42}} */
break;

View file

@ -209,7 +209,7 @@ api_root_restconf_exact(clicon_handle h,
break;
case YANG_DATA_JSON:
case YANG_PATCH_JSON:
if (clixon_json2cbuf(cb, xt, pretty, 0) < 0)
if (clixon_json2cbuf(cb, xt, pretty, 0, 0) < 0)
goto done;
break;
default:
@ -293,7 +293,7 @@ api_yang_library_version(clicon_handle h,
break;
case YANG_DATA_JSON:
case YANG_PATCH_JSON:
if (clixon_json2cbuf(cb, xt, pretty, 0) < 0)
if (clixon_json2cbuf(cb, xt, pretty, 0, 0) < 0)
goto done;
break;
default: