completing the function of hide for autocli-op in the yang files
This commit is contained in:
parent
3736927efa
commit
33ad428854
14 changed files with 153 additions and 59 deletions
|
|
@ -120,6 +120,114 @@ cvec_append(cvec *cvv0,
|
||||||
return cvv2;
|
return cvv2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Print an XML tree structure to an output stream 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 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 */
|
||||||
|
char *opext = NULL;
|
||||||
|
|
||||||
|
if (x == NULL)
|
||||||
|
goto ok;
|
||||||
|
/* Look for autocli-op defined in clixon-lib.yang */
|
||||||
|
if (yang_extension_value(xml_spec(x), "autocli-op", CLIXON_LIB_NS, &opext) < 0) {
|
||||||
|
goto ok;
|
||||||
|
}
|
||||||
|
if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){
|
||||||
|
goto ok;
|
||||||
|
}
|
||||||
|
name = xml_name(x);
|
||||||
|
namespace = xml_prefix(x);
|
||||||
|
switch(xml_type(x)){
|
||||||
|
case CX_BODY:
|
||||||
|
if ((val = xml_value(x)) == 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(x));
|
||||||
|
break;
|
||||||
|
case CX_ELMNT:
|
||||||
|
(*fn)(stdout, "%*s<", prettyprint?(level*XML_INDENT):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(x, xc, -1)) != NULL) {
|
||||||
|
switch (xml_type(xc)){
|
||||||
|
case CX_ATTR:
|
||||||
|
if (xml2file(xc, level+1, prettyprint, fprintf) <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(x, xc, -1)) != NULL) {
|
||||||
|
if (xml_type(xc) != CX_ATTR)
|
||||||
|
if (xml2file(xc, level+1, prettyprint, fprintf) <0)
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if (prettyprint && hasbody==0)
|
||||||
|
(*fn)(stdout, "%*s", level*XML_INDENT, "");
|
||||||
|
(*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
|
/*! Enter a CLI edit mode
|
||||||
* @param[in] h CLICON handle
|
* @param[in] h CLICON handle
|
||||||
* @param[in] cvv Vector of variables from CLIgen command-line
|
* @param[in] cvv Vector of variables from CLIgen command-line
|
||||||
|
|
@ -413,10 +521,10 @@ cli_auto_show(clicon_handle h,
|
||||||
switch (format){
|
switch (format){
|
||||||
case FORMAT_XML:
|
case FORMAT_XML:
|
||||||
if (isroot)
|
if (isroot)
|
||||||
clicon_xml2file(stdout, xp, 0, pretty, 1);
|
stdout(xp, 0, pretty, 1);
|
||||||
else{
|
else{
|
||||||
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL)
|
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL)
|
||||||
clicon_xml2file(stdout, xc, 0, pretty, 1);
|
stdout(xc, 0, pretty, 1);
|
||||||
}
|
}
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
break;
|
break;
|
||||||
|
|
@ -451,10 +559,10 @@ cli_auto_show(clicon_handle h,
|
||||||
if (pretty)
|
if (pretty)
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
if (isroot)
|
if (isroot)
|
||||||
clicon_xml2file(stdout, xp, 2, pretty, 1);
|
xml2file(xp, 2, pretty, fprintf);
|
||||||
else
|
else
|
||||||
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL)
|
while ((xc = xml_child_each(xp, xc, CX_ELMNT)) != NULL)
|
||||||
clicon_xml2file(stdout, xc, 2, pretty, 1);
|
xml2file(xc, 2, pretty, fprintf);
|
||||||
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
||||||
break;
|
break;
|
||||||
} /* switch */
|
} /* switch */
|
||||||
|
|
|
||||||
|
|
@ -676,7 +676,7 @@ compare_xmls(cxobj *xc1,
|
||||||
xml2txt_cb(f, xc, cligen_output);
|
xml2txt_cb(f, xc, cligen_output);
|
||||||
else
|
else
|
||||||
while ((xc = xml_child_each(xc1, xc, -1)) != NULL)
|
while ((xc = xml_child_each(xc1, xc, -1)) != NULL)
|
||||||
clicon_xml2file_cb(f, xc, 0, 1, cligen_output, 0);
|
clicon_xml2file_cb(f, xc, 0, 1, cligen_output);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
@ -693,7 +693,7 @@ compare_xmls(cxobj *xc1,
|
||||||
xml2txt_cb(f, xc, cligen_output);
|
xml2txt_cb(f, xc, cligen_output);
|
||||||
else
|
else
|
||||||
while ((xc = xml_child_each(xc2, xc, -1)) != NULL)
|
while ((xc = xml_child_each(xc2, xc, -1)) != NULL)
|
||||||
clicon_xml2file_cb(f, xc, 0, 1, cligen_output, 0);
|
clicon_xml2file_cb(f, xc, 0, 1, cligen_output);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
|
@ -923,7 +923,7 @@ save_config_file(clicon_handle h,
|
||||||
clicon_err(OE_CFG, errno, "Creating file %s", filename);
|
clicon_err(OE_CFG, errno, "Creating file %s", filename);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (clicon_xml2file(f, xt, 0, 1, 0) < 0)
|
if (clicon_xml2file(f, xt, 0, 1) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
|
|
@ -1029,7 +1029,7 @@ cli_notification_cb(int s,
|
||||||
while ((x = xml_child_each(xe, x, -1)) != NULL) {
|
while ((x = xml_child_each(xe, x, -1)) != NULL) {
|
||||||
switch (format){
|
switch (format){
|
||||||
case FORMAT_XML:
|
case FORMAT_XML:
|
||||||
if (clicon_xml2file_cb(stdout, x, 0, 1, cligen_output, 0) < 0)
|
if (clicon_xml2file_cb(stdout, x, 0, 1, cligen_output) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
break;
|
break;
|
||||||
case FORMAT_TEXT:
|
case FORMAT_TEXT:
|
||||||
|
|
|
||||||
|
|
@ -836,6 +836,15 @@ yang2cli_list(clicon_handle h,
|
||||||
char *opext = NULL;
|
char *opext = NULL;
|
||||||
|
|
||||||
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
|
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
|
||||||
|
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
|
||||||
|
if ((helptext = strdup(yang_argument_get(yd))) == NULL){
|
||||||
|
clicon_err(OE_UNIX, errno, "strdup");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if ((s = strstr(helptext, "\n\n")) != NULL)
|
||||||
|
*s = '\0';
|
||||||
|
yang2cli_helptext(cb, helptext);
|
||||||
|
}
|
||||||
/* Look for autocli-op defined in clixon-lib.yang */
|
/* Look for autocli-op defined in clixon-lib.yang */
|
||||||
if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0)
|
if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -847,15 +856,6 @@ yang2cli_list(clicon_handle h,
|
||||||
cprintf(cb, ",hide-database-auto-completion");
|
cprintf(cb, ",hide-database-auto-completion");
|
||||||
extralevel = 1;
|
extralevel = 1;
|
||||||
}
|
}
|
||||||
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
|
|
||||||
if ((helptext = strdup(yang_argument_get(yd))) == NULL){
|
|
||||||
clicon_err(OE_UNIX, errno, "strdup");
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
if ((s = strstr(helptext, "\n\n")) != NULL)
|
|
||||||
*s = '\0';
|
|
||||||
yang2cli_helptext(cb, helptext);
|
|
||||||
}
|
|
||||||
/* Loop over all key variables */
|
/* Loop over all key variables */
|
||||||
cvk = yang_cvec_get(ys); /* Use Y_LIST cache, see ys_populate_list() */
|
cvk = yang_cvec_get(ys); /* Use Y_LIST cache, see ys_populate_list() */
|
||||||
cvi = NULL;
|
cvi = NULL;
|
||||||
|
|
|
||||||
|
|
@ -476,7 +476,7 @@ cli_show_config1(clicon_handle h,
|
||||||
case FORMAT_XML:
|
case FORMAT_XML:
|
||||||
xc = NULL; /* Dont print xt itself */
|
xc = NULL; /* Dont print xt itself */
|
||||||
while ((xc = xml_child_each(xt, xc, -1)) != NULL)
|
while ((xc = xml_child_each(xt, xc, -1)) != NULL)
|
||||||
clicon_xml2file_cb(stdout, xc, 0, 1, cligen_output, 1);
|
xml2file(xc, 0, 1, cligen_output);
|
||||||
break;
|
break;
|
||||||
case FORMAT_JSON:
|
case FORMAT_JSON:
|
||||||
xml2json_cb(stdout, xt, 1, cligen_output);
|
xml2json_cb(stdout, xt, 1, cligen_output);
|
||||||
|
|
@ -499,7 +499,7 @@ cli_show_config1(clicon_handle h,
|
||||||
NETCONF_BASE_NAMESPACE);
|
NETCONF_BASE_NAMESPACE);
|
||||||
xc = NULL; /* Dont print xt itself */
|
xc = NULL; /* Dont print xt itself */
|
||||||
while ((xc = xml_child_each(xt, xc, -1)) != NULL)
|
while ((xc = xml_child_each(xt, xc, -1)) != NULL)
|
||||||
clicon_xml2file_cb(stdout, xc, 2, 1, cligen_output, 1);
|
xml2file(xc, 2, 1, cligen_output);
|
||||||
cligen_output(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
cligen_output(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -623,7 +623,7 @@ show_conf_xpath(clicon_handle h,
|
||||||
if (xpath_vec(xt, nsc, "%s", &xv, &xlen, xpath) < 0)
|
if (xpath_vec(xt, nsc, "%s", &xv, &xlen, xpath) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
for (i=0; i<xlen; i++)
|
for (i=0; i<xlen; i++)
|
||||||
xml_print(stdout, xv[i]);
|
xml2file(xv[i], 0, 1, fprintf);
|
||||||
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -747,14 +747,14 @@ cli_show_auto1(clicon_handle h,
|
||||||
break;
|
break;
|
||||||
case FORMAT_NETCONF:
|
case FORMAT_NETCONF:
|
||||||
fprintf(stdout, "<rpc><edit-config><target><candidate/></target><config>\n");
|
fprintf(stdout, "<rpc><edit-config><target><candidate/></target><config>\n");
|
||||||
clicon_xml2file(stdout, xp, 2, 1, 1);
|
xml2file(xp, 2, 1, fprintf);
|
||||||
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
for (; i < xml_child_nr(xml_parent(xp)) ; ++i, xp_helper = xml_child_i(xml_parent(xp), i)) {
|
for (; i < xml_child_nr(xml_parent(xp)) ; ++i, xp_helper = xml_child_i(xml_parent(xp), i)) {
|
||||||
switch (format){
|
switch (format){
|
||||||
case FORMAT_XML:
|
case FORMAT_XML:
|
||||||
clicon_xml2file(stdout, xp_helper, 0, 1, 1);
|
xml2file(xp_helper, 0, 1, fprintf);
|
||||||
break;
|
break;
|
||||||
case FORMAT_JSON:
|
case FORMAT_JSON:
|
||||||
xml2json_cb(stdout, xp_helper, 1, cligen_output);
|
xml2json_cb(stdout, xp_helper, 1, cligen_output);
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ int cli_help(clicon_handle h, cvec *vars, cvec *argv);
|
||||||
/* In cli_show.c */
|
/* In cli_show.c */
|
||||||
int expand_dbvar(void *h, char *name, cvec *cvv, cvec *argv,
|
int expand_dbvar(void *h, char *name, cvec *cvv, cvec *argv,
|
||||||
cvec *commands, cvec *helptexts);
|
cvec *commands, cvec *helptexts);
|
||||||
|
int xml2file (cxobj *xn, int level, int prettyprint, clicon_output_cb *fn);
|
||||||
|
|
||||||
/* cli_show.c: CLIgen new vector arg callbacks */
|
/* cli_show.c: CLIgen new vector arg callbacks */
|
||||||
int show_yang(clicon_handle h, cvec *vars, cvec *argv);
|
int show_yang(clicon_handle h, cvec *vars, cvec *argv);
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ netconf_output(int s,
|
||||||
if (clicon_debug_get() > 1){ /* XXX: below only works to stderr, clicon_debug may log to syslog */
|
if (clicon_debug_get() > 1){ /* XXX: below only works to stderr, clicon_debug may log to syslog */
|
||||||
cxobj *xt = NULL;
|
cxobj *xt = NULL;
|
||||||
if (clixon_xml_parse_string(buf, YB_NONE, NULL, &xt, NULL) == 0){
|
if (clixon_xml_parse_string(buf, YB_NONE, NULL, &xt, NULL) == 0){
|
||||||
clicon_xml2file(stderr, xml_child_i(xt, 0), 0, 0, 0);
|
clicon_xml2file(stderr, xml_child_i(xt, 0), 0, 0);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
xml_free(xt);
|
xml_free(xt);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -485,7 +485,7 @@ Suppose you want to print all added interfaces:
|
||||||
cxobj *target = transaction_target(td); # wanted XML tree
|
cxobj *target = transaction_target(td); # wanted XML tree
|
||||||
vec = xpath_vec_flag(target, NULL, "//interface", &len, XML_FLAG_ADD); /* Get added i/fs */
|
vec = xpath_vec_flag(target, NULL, "//interface", &len, XML_FLAG_ADD); /* Get added i/fs */
|
||||||
for (i=0; i<len; i++) /* Loop over added i/fs */
|
for (i=0; i<len; i++) /* Loop over added i/fs */
|
||||||
clicon_xml2file(stdout, vec[i], 0, 1, 0); /* Print the added interface */
|
clicon_xml2file(stdout, vec[i], 0, 1); /* Print the added interface */
|
||||||
```
|
```
|
||||||
You can look for added, deleted and changed entries in this way.
|
You can look for added, deleted and changed entries in this way.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ mycallback(clicon_handle h, cvec *cvv, cvec *argv)
|
||||||
nsc,
|
nsc,
|
||||||
&xret) < 0)
|
&xret) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
clicon_xml2file_cb(stdout, xret, 0, 1, cligen_output, 0);
|
clicon_xml2file_cb(stdout, xret, 0, 1, cligen_output);
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
if (nsc)
|
if (nsc)
|
||||||
|
|
@ -117,7 +117,7 @@ example_client_rpc(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
/* Print result */
|
/* Print result */
|
||||||
clicon_xml2file_cb(stdout, xml_child_i(xret, 0), 0, 0, cligen_output, 0);
|
clicon_xml2file_cb(stdout, xml_child_i(xret, 0), 0, 0, cligen_output);
|
||||||
fprintf(stdout,"\n");
|
fprintf(stdout,"\n");
|
||||||
|
|
||||||
/* pretty-print:
|
/* pretty-print:
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@
|
||||||
/*
|
/*
|
||||||
* Prototypes
|
* Prototypes
|
||||||
*/
|
*/
|
||||||
int clicon_xml2file_cb(FILE *f, cxobj *x, int level, int prettyprint, clicon_output_cb *fn, int used_for_show_command);
|
int clicon_xml2file_cb(FILE *f, cxobj *x, int level, int prettyprint, clicon_output_cb *fn);
|
||||||
int clicon_xml2file(FILE *f, cxobj *x, int level, int prettyprint, int used_for_show_command);
|
int clicon_xml2file(FILE *f, cxobj *x, int level, int prettyprint);
|
||||||
int xml_print(FILE *f, cxobj *xn);
|
int xml_print(FILE *f, cxobj *xn);
|
||||||
int clicon_xml2cbuf(cbuf *cb, cxobj *x, int level, int prettyprint, int32_t depth);
|
int clicon_xml2cbuf(cbuf *cb, cxobj *x, int level, int prettyprint, int32_t depth);
|
||||||
char *clicon_xml2str(cxobj *x);
|
char *clicon_xml2str(cxobj *x);
|
||||||
|
|
|
||||||
|
|
@ -713,7 +713,7 @@ xmldb_get_nocache(clicon_handle h,
|
||||||
clicon_log(LOG_NOTICE, "%s: sort verify failed #2", __FUNCTION__);
|
clicon_log(LOG_NOTICE, "%s: sort verify failed #2", __FUNCTION__);
|
||||||
#endif
|
#endif
|
||||||
if (clicon_debug_get()>1)
|
if (clicon_debug_get()>1)
|
||||||
clicon_xml2file(stderr, xt, 0, 1, 0);
|
clicon_xml2file(stderr, xt, 0, 1);
|
||||||
*xtop = xt;
|
*xtop = xt;
|
||||||
xt = NULL;
|
xt = NULL;
|
||||||
retval = 1;
|
retval = 1;
|
||||||
|
|
@ -872,7 +872,7 @@ xmldb_get_cache(clicon_handle h,
|
||||||
* If cache was empty, also update to datastore cache
|
* If cache was empty, also update to datastore cache
|
||||||
*/
|
*/
|
||||||
if (clicon_debug_get()>1)
|
if (clicon_debug_get()>1)
|
||||||
clicon_xml2file(stderr, x1t, 0, 1, 0);
|
clicon_xml2file(stderr, x1t, 0, 1);
|
||||||
*xtop = x1t;
|
*xtop = x1t;
|
||||||
retval = 1;
|
retval = 1;
|
||||||
done:
|
done:
|
||||||
|
|
@ -971,7 +971,7 @@ xmldb_get_zerocopy(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (clicon_debug_get()>1)
|
if (clicon_debug_get()>1)
|
||||||
clicon_xml2file(stderr, x0t, 0, 1, 0);
|
clicon_xml2file(stderr, x0t, 0, 1);
|
||||||
*xtop = x0t;
|
*xtop = x0t;
|
||||||
retval = 1;
|
retval = 1;
|
||||||
done:
|
done:
|
||||||
|
|
|
||||||
|
|
@ -104,8 +104,7 @@ xml2file_recurse(FILE *f,
|
||||||
cxobj *x,
|
cxobj *x,
|
||||||
int level,
|
int level,
|
||||||
int prettyprint,
|
int prettyprint,
|
||||||
clicon_output_cb *fn,
|
clicon_output_cb *fn)
|
||||||
int used_for_show_command)
|
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
@ -115,17 +114,8 @@ xml2file_recurse(FILE *f,
|
||||||
int haselement;
|
int haselement;
|
||||||
char *val;
|
char *val;
|
||||||
char *encstr = NULL; /* xml encoded string */
|
char *encstr = NULL; /* xml encoded string */
|
||||||
char *opext = NULL;
|
|
||||||
|
|
||||||
if (x == NULL)
|
if (x == NULL)
|
||||||
goto ok;
|
goto ok;
|
||||||
/* Look for autocli-op defined in clixon-lib.yang */
|
|
||||||
if (yang_extension_value(xml_spec(x), "autocli-op", CLIXON_LIB_NS, &opext) < 0) {
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
if ((used_for_show_command == 1) && (opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
name = xml_name(x);
|
name = xml_name(x);
|
||||||
namespace = xml_prefix(x);
|
namespace = xml_prefix(x);
|
||||||
switch(xml_type(x)){
|
switch(xml_type(x)){
|
||||||
|
|
@ -154,7 +144,7 @@ xml2file_recurse(FILE *f,
|
||||||
while ((xc = xml_child_each(x, xc, -1)) != NULL) {
|
while ((xc = xml_child_each(x, xc, -1)) != NULL) {
|
||||||
switch (xml_type(xc)){
|
switch (xml_type(xc)){
|
||||||
case CX_ATTR:
|
case CX_ATTR:
|
||||||
if (xml2file_recurse(f, xc, level+1, prettyprint, fn, used_for_show_command) <0)
|
if (xml2file_recurse(f, xc, level+1, prettyprint, fn) <0)
|
||||||
goto done;
|
goto done;
|
||||||
break;
|
break;
|
||||||
case CX_BODY:
|
case CX_BODY:
|
||||||
|
|
@ -179,7 +169,7 @@ xml2file_recurse(FILE *f,
|
||||||
xc = NULL;
|
xc = NULL;
|
||||||
while ((xc = xml_child_each(x, xc, -1)) != NULL) {
|
while ((xc = xml_child_each(x, xc, -1)) != NULL) {
|
||||||
if (xml_type(xc) != CX_ATTR)
|
if (xml_type(xc) != CX_ATTR)
|
||||||
if (xml2file_recurse(f, xc, level+1, prettyprint, fn, used_for_show_command) <0)
|
if (xml2file_recurse(f, xc, level+1, prettyprint, fn) <0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (prettyprint && hasbody==0)
|
if (prettyprint && hasbody==0)
|
||||||
|
|
@ -209,7 +199,6 @@ xml2file_recurse(FILE *f,
|
||||||
* @param[in] xn clicon xml tree
|
* @param[in] xn clicon xml tree
|
||||||
* @param[in] level how many spaces to insert before each line
|
* @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] prettyprint insert \n and spaces tomake the xml more readable.
|
||||||
* @param[in] used_for_show_command is the function used for a cli show command.
|
|
||||||
* @see clicon_xml2cbuf print to a cbuf string
|
* @see clicon_xml2cbuf print to a cbuf string
|
||||||
* @see clicon_xml2cbuf_cb print using a callback
|
* @see clicon_xml2cbuf_cb print using a callback
|
||||||
*/
|
*/
|
||||||
|
|
@ -217,10 +206,9 @@ int
|
||||||
clicon_xml2file(FILE *f,
|
clicon_xml2file(FILE *f,
|
||||||
cxobj *x,
|
cxobj *x,
|
||||||
int level,
|
int level,
|
||||||
int prettyprint,
|
int prettyprint)
|
||||||
int used_for_show_command)
|
|
||||||
{
|
{
|
||||||
return xml2file_recurse(f, x, level, prettyprint, fprintf, used_for_show_command);
|
return xml2file_recurse(f, x, level, prettyprint, fprintf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Print an XML tree structure to an output stream and encode chars "<>&"
|
/*! Print an XML tree structure to an output stream and encode chars "<>&"
|
||||||
|
|
@ -229,7 +217,6 @@ clicon_xml2file(FILE *f,
|
||||||
* @param[in] xn clicon xml tree
|
* @param[in] xn clicon xml tree
|
||||||
* @param[in] level how many spaces to insert before each line
|
* @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] prettyprint insert \n and spaces tomake the xml more readable.
|
||||||
* @param[in] used_for_show_command is the function used for a cli show command.
|
|
||||||
* @see clicon_xml2cbuf
|
* @see clicon_xml2cbuf
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
|
|
@ -237,10 +224,9 @@ clicon_xml2file_cb(FILE *f,
|
||||||
cxobj *x,
|
cxobj *x,
|
||||||
int level,
|
int level,
|
||||||
int prettyprint,
|
int prettyprint,
|
||||||
clicon_output_cb *fn,
|
clicon_output_cb *fn)
|
||||||
int used_for_show_command)
|
|
||||||
{
|
{
|
||||||
return xml2file_recurse(f, x, level, prettyprint, fn, used_for_show_command);
|
return xml2file_recurse(f, x, level, prettyprint, fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Print an XML tree structure to an output stream
|
/*! Print an XML tree structure to an output stream
|
||||||
|
|
@ -249,7 +235,6 @@ clicon_xml2file_cb(FILE *f,
|
||||||
*
|
*
|
||||||
* @param[in] f UNIX output stream
|
* @param[in] f UNIX output stream
|
||||||
* @param[in] xn clicon xml tree
|
* @param[in] xn clicon xml tree
|
||||||
* used_for_show_command
|
|
||||||
* @see clicon_xml2cbuf
|
* @see clicon_xml2cbuf
|
||||||
* @see clicon_xml2cbuf_cb print using a callback
|
* @see clicon_xml2cbuf_cb print using a callback
|
||||||
*/
|
*/
|
||||||
|
|
@ -257,7 +242,7 @@ int
|
||||||
xml_print(FILE *f,
|
xml_print(FILE *f,
|
||||||
cxobj *x)
|
cxobj *x)
|
||||||
{
|
{
|
||||||
return xml2file_recurse(f, x, 0, 1, fprintf, 0);
|
return xml2file_recurse(f, x, 0, 1, fprintf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Print an XML tree structure to a cligen buffer and encode chars "<>&"
|
/*! Print an XML tree structure to a cligen buffer and encode chars "<>&"
|
||||||
|
|
|
||||||
|
|
@ -341,7 +341,7 @@ clixon_xvec_print(FILE *f,
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=0; i<xv->xv_len; i++)
|
for (i=0; i<xv->xv_len; i++)
|
||||||
clicon_xml2file(f, xv->xv_vec[i], 0, 1, 0);
|
clicon_xml2file(f, xv->xv_vec[i], 0, 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -279,7 +279,7 @@ main(int argc,
|
||||||
for (i = 0; i < xlen; i++){
|
for (i = 0; i < xlen; i++){
|
||||||
xc = xvec[i];
|
xc = xvec[i];
|
||||||
fprintf(stdout, "%d: ", i);
|
fprintf(stdout, "%d: ", i);
|
||||||
clicon_xml2file(stdout, xc, 0, 0, 0);
|
clicon_xml2file(stdout, xc, 0, 0);
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -281,9 +281,9 @@ main(int argc, char **argv)
|
||||||
if (sort)
|
if (sort)
|
||||||
xml_sort_recurse(xb);
|
xml_sort_recurse(xb);
|
||||||
if (strcmp(xml_name(xb),"top")==0)
|
if (strcmp(xml_name(xb),"top")==0)
|
||||||
clicon_xml2file(stdout, xml_child_i_type(xb, 0, CX_ELMNT), 0, 0, 0);
|
clicon_xml2file(stdout, xml_child_i_type(xb, 0, CX_ELMNT), 0, 0);
|
||||||
else
|
else
|
||||||
clicon_xml2file(stdout, xb, 0, 0, 0);
|
clicon_xml2file(stdout, xb, 0, 0);
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue