Changed C-API for xml translation/print the internal cxobj tree data structure to other formats
New API is as follows: * `clixon_xml2file()` - Print internal tree as XML to file * `clixon_xml2cbuf()` - Print internal tree as XML to buffer * `clixon_json2file()` - Print internal tree as JSON to file * `clixon_json2cbuf()` - Print internal tree as JSON to buffer * `clixon_cli2file()` - Print internal tree as CLI format to file * `clixon_txt2file()` - Print internal tree as text format to file
This commit is contained in:
parent
87719c623c
commit
0c79298e76
49 changed files with 421 additions and 503 deletions
|
|
@ -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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
goto reply;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ startup_common(clicon_handle h,
|
|||
* See similar clause below
|
||||
*/
|
||||
}
|
||||
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) < 0)
|
||||
if (clixon_xml2cbuf(cb, xrestconf, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
if ((str = strdup(cbuf_get(cb))) == NULL){
|
||||
clicon_err(OE_XML, errno, "stdup");
|
||||
|
|
|
|||
|
|
@ -256,7 +256,8 @@ 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, 0);
|
||||
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (i)
|
||||
clicon_log(level, "%s %" PRIu64 " %s del: %s",
|
||||
|
|
@ -264,7 +265,8 @@ 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, 0);
|
||||
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (i)
|
||||
clicon_log(level, "%s %" PRIu64 " %s add: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));
|
||||
|
|
@ -272,10 +274,12 @@ 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, 0);
|
||||
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
}
|
||||
xn = td->td_tcvec[i];
|
||||
clicon_xml2cbuf(cb, xn, 0, 0, -1, 0);
|
||||
if (clixon_xml2cbuf(cb, xn, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (i)
|
||||
clicon_log(level, "%s %" PRIu64 " %s change: %s", __FUNCTION__, td->td_id, op, cbuf_get(cb));
|
||||
|
|
|
|||
|
|
@ -125,115 +125,6 @@ cvec_append(cvec *cvv0,
|
|||
return cvv2;
|
||||
}
|
||||
|
||||
/*! Print an XML tree structure from an auto-cli env to stdout and encode chars "<>&"
|
||||
*
|
||||
* @param[in] xn clicon xml tree
|
||||
* @param[in] level how many spaces to insert before each line
|
||||
* @param[in] prettyprint insert \n and spaces tomake the xml more readable.
|
||||
* @param[in] fn Callback to make print function
|
||||
* @see clicon_xml2cbuf
|
||||
* One can use clicon_xml2cbuf to get common code, but using fprintf is
|
||||
* much faster than using cbuf and then printing that,...
|
||||
*/
|
||||
int
|
||||
cli_xml2file(cxobj *xn,
|
||||
int level,
|
||||
int prettyprint,
|
||||
clicon_output_cb *fn)
|
||||
{
|
||||
int retval = -1;
|
||||
char *name;
|
||||
char *namespace;
|
||||
cxobj *xc;
|
||||
int hasbody;
|
||||
int haselement;
|
||||
char *val;
|
||||
char *encstr = NULL; /* xml encoded string */
|
||||
int exist = 0;
|
||||
|
||||
if (xn == NULL)
|
||||
goto ok;
|
||||
if (yang_extension_value(xml_spec(xn), "hide-show", CLIXON_AUTOCLI_NS, &exist, NULL) < 0)
|
||||
goto done;
|
||||
if (exist)
|
||||
goto ok;
|
||||
name = xml_name(xn);
|
||||
namespace = xml_prefix(xn);
|
||||
switch(xml_type(xn)){
|
||||
case CX_BODY:
|
||||
if ((val = xml_value(xn)) == NULL) /* incomplete tree */
|
||||
break;
|
||||
if (xml_chardata_encode(&encstr, "%s", val) < 0)
|
||||
goto done;
|
||||
(*fn)(stdout, "%s", encstr);
|
||||
break;
|
||||
case CX_ATTR:
|
||||
(*fn)(stdout, " ");
|
||||
if (namespace)
|
||||
(*fn)(stdout, "%s:", namespace);
|
||||
(*fn)(stdout, "%s=\"%s\"", name, xml_value(xn));
|
||||
break;
|
||||
case CX_ELMNT:
|
||||
(*fn)(stdout, "%*s<", prettyprint?(level*3):0, "");
|
||||
if (namespace)
|
||||
(*fn)(stdout, "%s:", namespace);
|
||||
(*fn)(stdout, "%s", name);
|
||||
hasbody = 0;
|
||||
haselement = 0;
|
||||
xc = NULL;
|
||||
/* print attributes only */
|
||||
while ((xc = xml_child_each(xn, xc, -1)) != NULL) {
|
||||
switch (xml_type(xc)){
|
||||
case CX_ATTR:
|
||||
if (cli_xml2file(xc, level+1, prettyprint, fn) <0)
|
||||
goto done;
|
||||
break;
|
||||
case CX_BODY:
|
||||
hasbody=1;
|
||||
break;
|
||||
case CX_ELMNT:
|
||||
haselement=1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Check for special case <a/> instead of <a></a>:
|
||||
* Ie, no CX_BODY or CX_ELMNT child.
|
||||
*/
|
||||
if (hasbody==0 && haselement==0)
|
||||
(*fn)(stdout, "/>");
|
||||
else{
|
||||
(*fn)(stdout, ">");
|
||||
if (prettyprint && hasbody == 0)
|
||||
(*fn)(stdout, "\n");
|
||||
xc = NULL;
|
||||
while ((xc = xml_child_each(xn, xc, -1)) != NULL) {
|
||||
if (xml_type(xc) != CX_ATTR)
|
||||
if (cli_xml2file(xc, level+1, prettyprint, fn) <0)
|
||||
goto done;
|
||||
}
|
||||
if (prettyprint && hasbody==0)
|
||||
(*fn)(stdout, "%*s", level*3, "");
|
||||
(*fn)(stdout, "</");
|
||||
if (namespace)
|
||||
(*fn)(stdout, "%s:", namespace);
|
||||
(*fn)(stdout, "%s>", name);
|
||||
}
|
||||
if (prettyprint)
|
||||
(*fn)(stdout, "\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}/* switch */
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
if (encstr)
|
||||
free(encstr);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Enter a CLI edit mode
|
||||
* @param[in] h CLICON handle
|
||||
* @param[in] cvv Vector of variables from CLIgen command-line
|
||||
|
|
@ -473,7 +364,6 @@ cli_auto_show(clicon_handle h,
|
|||
pt_head *ph;
|
||||
char *xpath = NULL;
|
||||
cxobj *xp;
|
||||
cxobj *xc = NULL;
|
||||
cvec *nsc = NULL;
|
||||
yang_stmt *yspec;
|
||||
cxobj *xerr;
|
||||
|
|
@ -481,7 +371,7 @@ cli_auto_show(clicon_handle h,
|
|||
cxobj **vec = NULL;
|
||||
size_t veclen;
|
||||
int i;
|
||||
int isroot;
|
||||
int skiproot;
|
||||
int pretty;
|
||||
char *prefix = NULL;
|
||||
int state;
|
||||
|
|
@ -537,7 +427,7 @@ cli_auto_show(clicon_handle h,
|
|||
api_path = "/";
|
||||
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
|
||||
goto done;
|
||||
isroot = (xpath == NULL) || strcmp(xpath,"/")==0;
|
||||
skiproot = (xpath != NULL) && (strcmp(xpath,"/") != 0);
|
||||
if (state == 0){ /* Get configuration-only from database */
|
||||
if (clicon_rpc_get_config(h, NULL, db, xpath, nsc, &xt) < 0)
|
||||
goto done;
|
||||
|
|
@ -562,28 +452,21 @@ cli_auto_show(clicon_handle h,
|
|||
/* Print configuration according to format */
|
||||
switch (format){
|
||||
case FORMAT_XML:
|
||||
if (isroot)
|
||||
cli_xml2file(xp, 0, pretty, fprintf);
|
||||
else{
|
||||
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL)
|
||||
cli_xml2file(xc, 0, pretty, fprintf);
|
||||
}
|
||||
if (clixon_xml2file(stdout, xp, 0, pretty, fprintf, skiproot) < 0)
|
||||
goto done;
|
||||
fprintf(stdout, "\n");
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
if (xml2json_file(stdout, xp, pretty, cligen_output, !isroot) < 0)
|
||||
if (clixon_json2file(stdout, xp, pretty, cligen_output, skiproot) < 0)
|
||||
goto done;
|
||||
fprintf(stdout, "\n");
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
if (isroot)
|
||||
xml2txt(xp, cligen_output, stdout, 0); /* tree-formed text */
|
||||
else
|
||||
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL)
|
||||
xml2txt(xc, cligen_output, stdout, 0); /* tree-formed text */
|
||||
if (clixon_txt2file(stdout, xp, 0, cligen_output, skiproot) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_CLI:
|
||||
if (xml2cli(h, stdout, xp, prefix, cligen_output, !isroot) < 0)
|
||||
if (clixon_cli2file(h, stdout, xp, prefix, cligen_output, skiproot) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_NETCONF:
|
||||
|
|
@ -591,11 +474,8 @@ cli_auto_show(clicon_handle h,
|
|||
NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
|
||||
if (pretty)
|
||||
fprintf(stdout, "\n");
|
||||
if (isroot)
|
||||
cli_xml2file(xp, 2, pretty, fprintf);
|
||||
else
|
||||
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL)
|
||||
cli_xml2file(xc, 2, pretty, fprintf);
|
||||
if (clixon_xml2file(stdout, xp, 2, pretty, fprintf, skiproot) < 0)
|
||||
goto done;
|
||||
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
||||
break;
|
||||
} /* switch */
|
||||
|
|
|
|||
|
|
@ -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) < 0)
|
||||
if (clixon_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;
|
||||
|
|
@ -675,16 +675,15 @@ cli_validate(clicon_handle h,
|
|||
/*! Compare two dbs using XML. Write to file and run diff
|
||||
*/
|
||||
static int
|
||||
compare_xmls(cxobj *xc1,
|
||||
cxobj *xc2,
|
||||
int astext)
|
||||
compare_xmls(cxobj *xc1,
|
||||
cxobj *xc2,
|
||||
enum format_enum format)
|
||||
{
|
||||
int fd;
|
||||
FILE *f;
|
||||
char filename1[MAXPATHLEN];
|
||||
char filename2[MAXPATHLEN];
|
||||
int retval = -1;
|
||||
cxobj *xc;
|
||||
cbuf *cb = NULL;
|
||||
|
||||
snprintf(filename1, sizeof(filename1), "/tmp/cliconXXXXXX");
|
||||
|
|
@ -695,14 +694,17 @@ compare_xmls(cxobj *xc1,
|
|||
}
|
||||
if ((f = fdopen(fd, "w")) == NULL)
|
||||
goto done;
|
||||
xc = NULL;
|
||||
if (astext)
|
||||
while ((xc = xml_child_each(xc1, xc, -1)) != NULL)
|
||||
xml2txt(xc, cligen_output, f, 0);
|
||||
else
|
||||
while ((xc = xml_child_each(xc1, xc, -1)) != NULL)
|
||||
clicon_xml2file_cb(f, xc, 0, 1, cligen_output);
|
||||
|
||||
switch(format){
|
||||
case FORMAT_TEXT:
|
||||
if (clixon_txt2file(f, xc1, 0, cligen_output, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_XML:
|
||||
default:
|
||||
if (clixon_xml2file(f, xc1, 0, 1, cligen_output, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
fclose(f);
|
||||
close(fd);
|
||||
|
||||
|
|
@ -712,13 +714,19 @@ compare_xmls(cxobj *xc1,
|
|||
}
|
||||
if ((f = fdopen(fd, "w")) == NULL)
|
||||
goto done;
|
||||
xc = NULL;
|
||||
if (astext)
|
||||
while ((xc = xml_child_each(xc2, xc, -1)) != NULL)
|
||||
xml2txt(xc, cligen_output, f, 0);
|
||||
else
|
||||
while ((xc = xml_child_each(xc2, xc, -1)) != NULL)
|
||||
clicon_xml2file_cb(f, xc, 0, 1, cligen_output);
|
||||
|
||||
switch(format){
|
||||
case FORMAT_TEXT:
|
||||
if (clixon_txt2file(f, xc2, 0, cligen_output, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_XML:
|
||||
default:
|
||||
if (clixon_xml2file(f, xc2, 0, 1, cligen_output, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
close(fd);
|
||||
|
||||
|
|
@ -754,16 +762,16 @@ compare_dbs(clicon_handle h,
|
|||
cxobj *xc2 = NULL; /* candidate xml */
|
||||
cxobj *xerr = NULL;
|
||||
int retval = -1;
|
||||
int astext;
|
||||
enum format_enum format;
|
||||
|
||||
if (cvec_len(argv) > 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires 0 or 1 element. If given: astext flag 0|1");
|
||||
goto done;
|
||||
}
|
||||
if (cvec_len(argv))
|
||||
astext = cv_int32_get(cvec_i(argv, 0));
|
||||
if (cvec_len(argv) && cv_int32_get(cvec_i(argv, 0)) == 1)
|
||||
format = FORMAT_TEXT;
|
||||
else
|
||||
astext = 0;
|
||||
format = FORMAT_XML;
|
||||
if (clicon_rpc_get_config(h, NULL, "running", "/", NULL, &xc1) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xc1, NULL, "/rpc-error")) != NULL){
|
||||
|
|
@ -776,7 +784,7 @@ compare_dbs(clicon_handle h,
|
|||
clixon_netconf_error(xerr, "Get configuration", NULL);
|
||||
goto done;
|
||||
}
|
||||
if (compare_xmls(xc1, xc2, astext) < 0) /* astext? */
|
||||
if (compare_xmls(xc1, xc2, format) < 0) /* astext? */
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -934,7 +942,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 (clicon_xml2cbuf(cbxml, xt, 0, 0, -1, 1) < 0)
|
||||
if (clixon_xml2cbuf(cbxml, xt, 0, 0, -1, 1) < 0)
|
||||
goto done;
|
||||
if (clicon_rpc_edit_config(h, "candidate",
|
||||
replace?OP_REPLACE:OP_MERGE,
|
||||
|
|
@ -1034,26 +1042,26 @@ save_config_file(clicon_handle h,
|
|||
}
|
||||
switch (format){
|
||||
case FORMAT_XML:
|
||||
if (clicon_xml2file(f, xt, 0, pretty) < 0)
|
||||
if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
if (xml2json_file(f, xt, pretty, fprintf, 0) < 0)
|
||||
if (clixon_json2file(f, xt, pretty, fprintf, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
if (xml2txt(xt, fprintf, f, 0) < 0)
|
||||
if (clixon_txt2file(f, xt, 0, fprintf, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_CLI:
|
||||
if (xml2cli(h, f, xt, prefix, fprintf, 1) < 0)
|
||||
if (clixon_cli2file(h, f, xt, prefix, fprintf, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_NETCONF:
|
||||
fprintf(f, "<rpc xmlns=\"%s\" %s><edit-config><target><candidate/></target>",
|
||||
NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
|
||||
fprintf(f, "\n");
|
||||
if (clicon_xml2file(f, xt, 0, pretty) < 0)
|
||||
if (clixon_xml2file(f, xt, 0, pretty, fprintf, 0) < 0)
|
||||
goto done;
|
||||
fprintf(f, "</edit-config></rpc>]]>]]>\n");
|
||||
break;
|
||||
|
|
@ -1135,8 +1143,6 @@ cli_notification_cb(int s,
|
|||
int eof;
|
||||
int retval = -1;
|
||||
cxobj *xt = NULL;
|
||||
cxobj *xe;
|
||||
cxobj *x;
|
||||
enum format_enum format = (enum format_enum)arg;
|
||||
int ret;
|
||||
|
||||
|
|
@ -1159,30 +1165,19 @@ cli_notification_cb(int s,
|
|||
}
|
||||
switch (format){
|
||||
case FORMAT_JSON:
|
||||
if (xml2json_file(stdout, xt, 1, cligen_output, 1) < 0)
|
||||
if (clixon_json2file(stdout, xt, 1, cligen_output, 1) < 0)
|
||||
goto done;
|
||||
case FORMAT_TEXT:
|
||||
if (clixon_txt2file(stdout, xt, 0, cligen_output, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_XML:
|
||||
if (clixon_xml2file(stdout, xt, 0, 1, cligen_output, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if ((xe = xpath_first(xt, NULL, "//event")) != NULL){
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(xe, x, -1)) != NULL) {
|
||||
switch (format){
|
||||
case FORMAT_XML:
|
||||
if (clicon_xml2file_cb(stdout, x, 0, 1, cligen_output) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
if (xml2txt(x, cligen_output, stdout, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (cli_output_status() < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (xt)
|
||||
|
|
@ -1424,7 +1419,8 @@ 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, 0);
|
||||
if (clixon_xml2cbuf(cb, x2, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
if (clicon_rpc_edit_config(h, db, OP_MERGE, cbuf_get(cb)) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -882,7 +882,7 @@ yang2cli_container(clicon_handle h,
|
|||
goto done;
|
||||
/* If non-presence container && HIDE mode && only child is
|
||||
* a list, then skip container keyword
|
||||
* See also xml2cli
|
||||
* See also clixon_cli2file
|
||||
*/
|
||||
if (autocli_compress(h, ys, &compress) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -434,7 +434,6 @@ cli_show_config1(clicon_handle h,
|
|||
cbuf *cbxpath = NULL;
|
||||
char *val = NULL;
|
||||
cxobj *xt = NULL;
|
||||
cxobj *xc;
|
||||
cxobj *xerr;
|
||||
yang_stmt *yspec;
|
||||
char *namespace = NULL;
|
||||
|
|
@ -495,28 +494,26 @@ cli_show_config1(clicon_handle h,
|
|||
/* Print configuration according to format */
|
||||
switch (format){
|
||||
case FORMAT_XML:
|
||||
xc = NULL; /* Dont print xt itself */
|
||||
while ((xc = xml_child_each(xt, xc, -1)) != NULL)
|
||||
cli_xml2file(xc, 0, 1, cligen_output);
|
||||
if (clixon_xml2file(stdout, xt, 0, 1, cligen_output, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
xml2json_file(stdout, xt, 1, cligen_output, 0);
|
||||
if (clixon_json2file(stdout, xt, 1, cligen_output, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
xc = NULL; /* Dont print xt itself */
|
||||
while ((xc = xml_child_each(xt, xc, -1)) != NULL)
|
||||
xml2txt(xc, cligen_output, stdout, 0); /* tree-formed text */
|
||||
if (clixon_txt2file(stdout, xt, 0, cligen_output, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_CLI:
|
||||
if (xml2cli(h, stdout, xt, prefix, cligen_output, 1) < 0)
|
||||
if (clixon_cli2file(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",
|
||||
NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
|
||||
xc = NULL; /* Dont print xt itself */
|
||||
while ((xc = xml_child_each(xt, xc, -1)) != NULL)
|
||||
cli_xml2file(xc, 2, 1, cligen_output);
|
||||
if (clixon_xml2file(stdout, xt, 2, 1, cligen_output, 1) < 0)
|
||||
goto done;
|
||||
cligen_output(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
||||
break;
|
||||
}
|
||||
|
|
@ -650,7 +647,8 @@ show_conf_xpath(clicon_handle h,
|
|||
if (xpath_vec(xt, nsc, "%s", &xv, &xlen, xpath) < 0)
|
||||
goto done;
|
||||
for (i=0; i<xlen; i++)
|
||||
cli_xml2file(xv[i], 0, 1, fprintf);
|
||||
if (clixon_xml2file(stdout, xv[i], 0, 1, fprintf, 0) < 0)
|
||||
goto done;
|
||||
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -671,7 +669,7 @@ int cli_show_version(clicon_handle h,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*! Generic show configuration CLIgen callback using generated CLI syntax
|
||||
/*! Generic show configuration CLIgen callback using auto CLI syntax
|
||||
*
|
||||
* This callback can be used only in context of an autocli generated syntax tree, such as:
|
||||
* show @datamodel, cli_show_auto();
|
||||
|
|
@ -690,10 +688,10 @@ int cli_show_version(clicon_handle h,
|
|||
* @see cli_show_config1
|
||||
*/
|
||||
static int
|
||||
cli_show_generated(clicon_handle h,
|
||||
int state,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
cli_show_auto1(clicon_handle h,
|
||||
int state,
|
||||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
int retval = 1;
|
||||
yang_stmt *yspec;
|
||||
|
|
@ -705,12 +703,9 @@ cli_show_generated(clicon_handle h,
|
|||
enum format_enum format = FORMAT_XML;
|
||||
cxobj *xt = NULL;
|
||||
cxobj *xp;
|
||||
cxobj *xp_helper;
|
||||
cxobj *xerr;
|
||||
char *api_path = NULL;
|
||||
char *prefix = NULL;
|
||||
enum rfc_6020 ys_keyword;
|
||||
int i = 0;
|
||||
int cvvi = 0;
|
||||
|
||||
if (cvec_len(argv) < 3 || cvec_len(argv) > 4){
|
||||
|
|
@ -763,40 +758,28 @@ cli_show_generated(clicon_handle h,
|
|||
}
|
||||
if ((xp = xpath_first(xt, nsc, "%s", xpath)) != NULL){
|
||||
/* Print configuration according to format */
|
||||
ys_keyword = yang_keyword_get(xml_spec(xp));
|
||||
if (ys_keyword == Y_LIST)
|
||||
xp_helper = xml_child_i(xml_parent(xp), i);
|
||||
else
|
||||
xp_helper = xp;
|
||||
|
||||
switch (format){
|
||||
case FORMAT_CLI:
|
||||
if (xml2cli(h, stdout, xp, prefix, cligen_output, 0) < 0) /* cli syntax */
|
||||
if (clixon_cli2file(h, stdout, xp, prefix, cligen_output, 0) < 0) /* cli syntax */
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_NETCONF:
|
||||
fprintf(stdout, "<rpc><edit-config><target><candidate/></target><config>\n");
|
||||
cli_xml2file(xp, 2, 1, fprintf);
|
||||
if (clixon_xml2file(stdout, xp, 2, 1, fprintf, 0) < 0)
|
||||
goto done;
|
||||
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
xml2json_file(stdout, xp_helper, 1, cligen_output, 1);
|
||||
if (clixon_json2file(stdout, xp, 1, cligen_output, 1) < 0) // XXX helper?
|
||||
goto done;
|
||||
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_TEXT:
|
||||
xml2txt(xp_helper, cligen_output, stdout, 0); /* tree-formed text */
|
||||
break;
|
||||
default: /* see cli_show_config() */
|
||||
break;
|
||||
}
|
||||
if (ys_keyword != Y_LIST)
|
||||
break;
|
||||
}
|
||||
case FORMAT_TEXT:
|
||||
if (clixon_txt2file(stdout, xp, 0, cligen_output, 1) < 0) // XXX helper?
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_XML:
|
||||
if (clixon_xml2file(stdout, xp, 0, 1, fprintf, 0) < 0) // XXX helper?
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -828,7 +811,7 @@ cli_show_auto(clicon_handle h,
|
|||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
return cli_show_generated(h, 0, cvv, argv);
|
||||
return cli_show_auto1(h, 0, cvv, argv);
|
||||
}
|
||||
|
||||
/*! Generic show config and state CLIgen callback using generated CLI syntax
|
||||
|
|
@ -845,7 +828,7 @@ cli_show_auto_state(clicon_handle h,
|
|||
cvec *cvv,
|
||||
cvec *argv)
|
||||
{
|
||||
return cli_show_generated(h, 1, cvv, argv);
|
||||
return cli_show_auto1(h, 1, cvv, argv);
|
||||
}
|
||||
|
||||
/*! Show clixon configuration options as loaded
|
||||
|
|
@ -980,17 +963,21 @@ cli_pagination(clicon_handle h,
|
|||
xc = xvec[j];
|
||||
switch (format){
|
||||
case FORMAT_XML:
|
||||
clicon_xml2file_cb(stdout, xc, 0, 1, cligen_output);
|
||||
if (clixon_xml2file(stdout, xc, 0, 1, cligen_output, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_JSON:
|
||||
xml2json_file(stdout, xc, 1, cligen_output, 0);
|
||||
if (clixon_json2file(stdout, xc, 1, cligen_output, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_TEXT:
|
||||
xml2txt(xc, cligen_output, stdout, 0); /* tree-formed text */
|
||||
if (clixon_txt2file(stdout, xc, 0, cligen_output, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_CLI:
|
||||
/* hardcoded to compress and list-keyword = nokey */
|
||||
xml2cli(h, stdout, xc, NULL, cligen_output, 0);
|
||||
if (clixon_cli2file(h, stdout, xc, NULL, cligen_output, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -1155,21 +1142,24 @@ xml2cli1(clicon_handle h,
|
|||
* @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] fn File print function (if NULL, use fprintf)
|
||||
* @param[in] skiptop 0: Include top object 1: Skip top-object, only children,
|
||||
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xml2cli(clicon_handle h,
|
||||
FILE *f,
|
||||
cxobj *xn,
|
||||
char *prepend,
|
||||
clicon_output_cb *fn,
|
||||
int skiptop)
|
||||
clixon_cli2file(clicon_handle h,
|
||||
FILE *f,
|
||||
cxobj *xn,
|
||||
char *prepend,
|
||||
clicon_output_cb *fn,
|
||||
int skiptop)
|
||||
{
|
||||
int retval = 1;
|
||||
cxobj *xc;
|
||||
|
||||
if (fn == NULL)
|
||||
fn = fprintf;
|
||||
if (skiptop){
|
||||
xc = NULL;
|
||||
while ((xc = xml_child_each(xn, xc, CX_ELMNT)) != NULL)
|
||||
|
|
|
|||
|
|
@ -135,8 +135,7 @@ int cli_help(clicon_handle h, cvec *vars, cvec *argv);
|
|||
/* In cli_show.c */
|
||||
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 xml2cli(clicon_handle h, FILE *f, cxobj *xn, char *prepend, clicon_output_cb *fn, int skiptop);
|
||||
int clixon_cli2file(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);
|
||||
|
|
|
|||
|
|
@ -211,7 +211,8 @@ netconf_rpc_message(clicon_handle h,
|
|||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0);
|
||||
if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
if (netconf_output_encap(framing, cbret) < 0)
|
||||
goto done;
|
||||
if (netconf_output(1, cbret, "rpc-error") < 0)
|
||||
|
|
@ -231,7 +232,8 @@ netconf_rpc_message(clicon_handle h,
|
|||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0);
|
||||
if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
if (netconf_output_encap(framing, cbret) < 0)
|
||||
goto done;
|
||||
if (netconf_output(1, cbret, "rpc-error") < 0)
|
||||
|
|
@ -251,7 +253,8 @@ netconf_rpc_message(clicon_handle h,
|
|||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0);
|
||||
if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
if (netconf_output_encap(framing, cbret) < 0)
|
||||
goto done;
|
||||
if (netconf_output(1, cbret, "rpc-error") < 0)
|
||||
|
|
@ -266,7 +269,8 @@ 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, 0);
|
||||
if (clixon_xml2cbuf(cbret, xml_child_i(xret,0), 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
if (netconf_output_encap(framing, cbret) < 0)
|
||||
goto done;
|
||||
if (netconf_output(1, cbret, "rpc-reply") < 0)
|
||||
|
|
@ -322,7 +326,8 @@ netconf_input_packet(clicon_handle h,
|
|||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0);
|
||||
if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
if (netconf_output_encap(framing, cbret) < 0)
|
||||
goto done;
|
||||
if (netconf_output(1, cbret, "rpc-error") < 0)
|
||||
|
|
@ -435,7 +440,8 @@ netconf_input_frame(clicon_handle h,
|
|||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
clicon_xml2cbuf(cbret, xret, 0, 0, -1, 0);
|
||||
if (clixon_xml2cbuf(cbret, xret, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
if (netconf_output_encap(framing, cbret) < 0)
|
||||
goto done;
|
||||
if (netconf_output(1, cbret, "rpc-error") < 0)
|
||||
|
|
|
|||
|
|
@ -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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_xml2cbuf(cbret, xerr, 0, 0, -1, 0) < 0)
|
||||
goto done;
|
||||
clicon_log(LOG_WARNING, "Errors in output netconf %s", cbuf_get(cbret));
|
||||
goto ok;
|
||||
|
|
|
|||
|
|
@ -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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_json2cbuf(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) < 0)
|
||||
if (clixon_json2cbuf(cb, xerr, pretty, 0) < 0)
|
||||
goto done;
|
||||
cprintf(cb, "}\r\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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)
|
||||
|
|
|
|||
|
|
@ -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) < 0) /* Dont print top object? */
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_json2cbuf(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) < 0) /* Dont print top object? */
|
||||
if (clixon_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) < 0) /* Dont print top object? */
|
||||
if (clixon_xml2cbuf(cbx, xpr, 0, pretty, -1, 0) < 0) /* Dont print top object? */
|
||||
goto done;
|
||||
break;
|
||||
case YANG_DATA_JSON:
|
||||
|
|
|
|||
|
|
@ -100,9 +100,9 @@ yang_patch_op2int(char *op)
|
|||
}
|
||||
|
||||
/*! Add square brackets after the surrounding curly brackets in JSON
|
||||
* Needed, in order to modify the result of xml2json_cbuf() to be valid input
|
||||
* Needed, in order to modify the result of clixon_json2cbuf() to be valid input
|
||||
* to api_data_post() and api_data_write()
|
||||
* @param[in] x_simple_patch a cxobj to pass to xml2json_cbuf()
|
||||
* @param[in] x_simple_patch a cxobj to pass to clixon_json2cbuf()
|
||||
* @retva cbuf With the modified json
|
||||
* @retva NULL Error
|
||||
*/
|
||||
|
|
@ -119,7 +119,8 @@ 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, 0);
|
||||
if (clixon_json2cbuf(cb, x_simple_patch, 0) < 0)
|
||||
goto done;
|
||||
|
||||
// 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 +267,8 @@ yang_patch_do_replace(clicon_handle h,
|
|||
}
|
||||
}
|
||||
// Convert the data to json
|
||||
xml2json_cbuf(json_simple_patch, x_simple_patch, 0);
|
||||
if (clixon_json2cbuf(json_simple_patch, x_simple_patch, 0) < 0)
|
||||
goto done;
|
||||
|
||||
// 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 +329,7 @@ yang_patch_do_create(clicon_handle h,
|
|||
xml_addsub(x_simple_patch, value_vec_tmp);
|
||||
}
|
||||
}
|
||||
if (xml2json_cbuf(cb, x_simple_patch, 0) < 0)
|
||||
if (clixon_json2cbuf(cb, x_simple_patch, 0) < 0)
|
||||
goto done;
|
||||
if (api_data_post(h, req, cbuf_get(simple_patch_request_uri),
|
||||
pi, qvec,
|
||||
|
|
@ -477,7 +479,8 @@ 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, 0);
|
||||
if (clixon_json2cbuf(cb, x_simple_patch, 0) < 0)
|
||||
goto done;
|
||||
|
||||
if ((json_simple_patch = yang_patch_xml2json_modified_cbuf(x_simple_patch)) == NULL)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_json2cbuf(cbret, xoutput, pretty, 0) < 0)
|
||||
goto done;
|
||||
/* xoutput should now look: {"example:output": {"x":0,"y":42}} */
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_json2cbuf(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) < 0)
|
||||
if (clixon_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) < 0)
|
||||
if (clixon_json2cbuf(cb, xt, pretty, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -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) < 0)
|
||||
if (clixon_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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue