code cleanup
This commit is contained in:
parent
7db1de19de
commit
f65187df7f
1 changed files with 47 additions and 82 deletions
|
|
@ -88,9 +88,6 @@
|
||||||
#include "clixon_xml_sort.h"
|
#include "clixon_xml_sort.h"
|
||||||
#include "clixon_xml_map.h"
|
#include "clixon_xml_map.h"
|
||||||
|
|
||||||
/* Something to do with reverse engineering of junos syntax? */
|
|
||||||
#undef SPECIAL_TREATMENT_OF_NAME
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A node is a leaf if it contains a body.
|
* A node is a leaf if it contains a body.
|
||||||
*/
|
*/
|
||||||
|
|
@ -131,9 +128,6 @@ xml2txt(FILE *f,
|
||||||
char *term = NULL;
|
char *term = NULL;
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
int encr=0;
|
int encr=0;
|
||||||
#ifdef SPECIAL_TREATMENT_OF_NAME
|
|
||||||
cxobj *xname;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
xe = NULL; /* count children */
|
xe = NULL; /* count children */
|
||||||
while ((xe = xml_child_each(x, xe, -1)) != NULL)
|
while ((xe = xml_child_each(x, xe, -1)) != NULL)
|
||||||
|
|
@ -157,32 +151,11 @@ xml2txt(FILE *f,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
fprintf(f, "%*s", 4*level, "");
|
fprintf(f, "%*s", 4*level, "");
|
||||||
|
fprintf(f, "%s ", xml_name(x));
|
||||||
#ifdef SPECIAL_TREATMENT_OF_NAME
|
if (!tleaf(x))
|
||||||
if (strcmp(xml_name(x), "name") != 0)
|
fprintf(f, "{\n");
|
||||||
fprintf(f, "%s ", xml_name(x));
|
|
||||||
if ((xname = xml_find(x, "name")) != NULL){
|
|
||||||
if (children > 1)
|
|
||||||
fprintf(f, "%s ", xml_body(xname));
|
|
||||||
if (!tleaf(x))
|
|
||||||
fprintf(f, "{\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (!tleaf(x))
|
|
||||||
fprintf(f, "{\n");
|
|
||||||
#else
|
|
||||||
fprintf(f, "%s ", xml_name(x));
|
|
||||||
if (!tleaf(x))
|
|
||||||
fprintf(f, "{\n");
|
|
||||||
#endif /* SPECIAL_TREATMENT_OF_NAME */
|
|
||||||
|
|
||||||
xe = NULL;
|
xe = NULL;
|
||||||
while ((xe = xml_child_each(x, xe, -1)) != NULL){
|
while ((xe = xml_child_each(x, xe, -1)) != NULL){
|
||||||
#ifdef SPECIAL_TREATMENT_OF_NAME
|
|
||||||
if (xml_type(xe) == CX_ELMNT && (strcmp(xml_name(xe), "name")==0) &&
|
|
||||||
(children > 1)) /* skip if this is a name element (unless 0 children) */
|
|
||||||
continue;
|
|
||||||
#endif
|
|
||||||
if (xml2txt(f, xe, level+1) < 0)
|
if (xml2txt(f, xe, level+1) < 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -870,9 +843,18 @@ yang2api_path_fmt(yang_stmt *ys,
|
||||||
* @param[out] yang_arg yang-stmt argument name. Free after use
|
* @param[out] yang_arg yang-stmt argument name. Free after use
|
||||||
* @note first and last elements of cvv are not used,..
|
* @note first and last elements of cvv are not used,..
|
||||||
* @see api_path_fmt2xpath
|
* @see api_path_fmt2xpath
|
||||||
*
|
* @example
|
||||||
* /interfaces/interface=%s/name --> /interfaces/interface/name
|
* api_path_fmt: /interfaces/interface=%s/name
|
||||||
* /interfaces/interface=%s/ipv4/address=%s --> /interfaces/interface=e/ipv4/address
|
* cvv: -
|
||||||
|
* api_path: /interfaces/interface/name
|
||||||
|
* @example
|
||||||
|
* api_path_fmt: /interfaces/interface=%s/name
|
||||||
|
* cvv: e0
|
||||||
|
* api_path: /interfaces/interface=e0/name
|
||||||
|
* @example
|
||||||
|
* api_path_fmt: /subif-entry=%s,%s/subid
|
||||||
|
* cvv: foo
|
||||||
|
* api_path: /subif-entry=foo/subid
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
api_path_fmt2api_path(char *api_path_fmt,
|
api_path_fmt2api_path(char *api_path_fmt,
|
||||||
|
|
@ -889,20 +871,6 @@ api_path_fmt2api_path(char *api_path_fmt,
|
||||||
char *strenc=NULL;
|
char *strenc=NULL;
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
|
|
||||||
#if 0 /* XXX Does not work in expansion case */
|
|
||||||
/* Sanity check */
|
|
||||||
j = 0; /* Count % */
|
|
||||||
for (i=0; i<strlen(api_path_fmt); i++)
|
|
||||||
if (api_path_fmt[i] == '%')
|
|
||||||
j++;
|
|
||||||
if (j > cvec_len(cvv)) { //cvec_len can be longer
|
|
||||||
clicon_log(LOG_WARNING, "%s api_path_fmt number of %% is %d, does not match number of cvv entries %d",
|
|
||||||
api_path_fmt,
|
|
||||||
j,
|
|
||||||
cvec_len(cvv));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if ((cb = cbuf_new()) == NULL){
|
if ((cb = cbuf_new()) == NULL){
|
||||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -953,18 +921,22 @@ api_path_fmt2api_path(char *api_path_fmt,
|
||||||
|
|
||||||
/*! Transform an xml key format and a vector of values to an XML path
|
/*! Transform an xml key format and a vector of values to an XML path
|
||||||
* Used to input xmldb_get() or xmldb_get_vec
|
* Used to input xmldb_get() or xmldb_get_vec
|
||||||
* Add .* in last %s position.
|
|
||||||
* Example:
|
|
||||||
* api_path_fmt: /interface/%s/address/%s
|
|
||||||
* cvv: name=eth0
|
|
||||||
* xmlkey: /interface/[name=eth0]/address
|
|
||||||
* Example2:
|
|
||||||
* xmlkeyfmt: /ip/me/%s (if key)
|
|
||||||
* cvv: -
|
|
||||||
* xmlkey: /ipv4/me/a
|
|
||||||
* @param[in] api_path_fmt XML key format
|
* @param[in] api_path_fmt XML key format
|
||||||
* @param[in] cvv cligen variable vector, one for every wildchar in api_path_fmt
|
* @param[in] cvv cligen variable vector, one for every wildchar in api_path_fmt
|
||||||
* @param[out] xpath XPATH
|
* @param[out] xpath XPATH
|
||||||
|
* Add .* in last %s position.
|
||||||
|
* @example
|
||||||
|
* api_path_fmt: /interface/%s/address/%s
|
||||||
|
* cvv: name=eth0
|
||||||
|
* xpath: /interface/[name=eth0]/address
|
||||||
|
* @example
|
||||||
|
* api_path_fmt: /ip/me/%s (if key)
|
||||||
|
* cvv: -
|
||||||
|
* xpath: /ipv4/me/a
|
||||||
|
* @example
|
||||||
|
* api_path_fmt: /subif-entry=%s,%s/subid
|
||||||
|
* cvv: foo
|
||||||
|
* xpath: /subif-entry[if-name=foo]/subid"
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
api_path_fmt2xpath(char *api_path_fmt,
|
api_path_fmt2xpath(char *api_path_fmt,
|
||||||
|
|
@ -980,21 +952,6 @@ api_path_fmt2xpath(char *api_path_fmt,
|
||||||
char *str;
|
char *str;
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
|
|
||||||
/* Sanity check: count '%' */
|
|
||||||
#if 0 /* XXX Does not work in expansion case */
|
|
||||||
j = 0; /* Count % */
|
|
||||||
for (i=0; i<strlen(api_path_fmt); i++)
|
|
||||||
if (api_path_fmt[i] == '%')
|
|
||||||
j++;
|
|
||||||
if (j > cvec_len(cvv)) {
|
|
||||||
clicon_log(LOG_WARNING, "%s xmlkey format string mismatch(j=%d, cvec_len=%d): %s",
|
|
||||||
api_path_fmt,
|
|
||||||
j,
|
|
||||||
cvec_len(cvv),
|
|
||||||
cv_string_get(cvec_i(cvv, 0)));
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if ((cb = cbuf_new()) == NULL){
|
if ((cb = cbuf_new()) == NULL){
|
||||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -1624,20 +1581,29 @@ api_path2xml_vec(char **vec,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Create xml tree from api-path
|
/*! Create xml tree from api-path
|
||||||
* @param[in] api_path API-path as defined in RFC 8040
|
* @param[in] api_path API-path as defined in RFC 8040
|
||||||
* @param[in] yspec Yang spec
|
* @param[in] yspec Yang spec
|
||||||
* @param[in] schemanode If set use schema nodes otherwise data nodes.
|
* @param[in,out] xtop Incoming XML tree
|
||||||
* @param[out] xpathp Resulting xml tree
|
* @param[in] schemanode If set use schema nodes otherwise data nodes.
|
||||||
* @param[out] ypathp Yang spec matching xpathp
|
* @param[out] xbotp Resulting xml tree (end of xpath)
|
||||||
|
* @param[out] ybotp Yang spec matching xbotp
|
||||||
* @see api_path2xml_vec
|
* @see api_path2xml_vec
|
||||||
|
* @example
|
||||||
|
* api_path: /subif-entry=foo/subid
|
||||||
|
* xtop[in] <config/>
|
||||||
|
* xtop[out]:<config/> <subif-entry>
|
||||||
|
* <if-name>foo<if-name><subid/>>
|
||||||
|
* </subif-entry></config>
|
||||||
|
* xbotp: <subid/>
|
||||||
|
* ybotp: Y_LEAF subid
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
api_path2xml(char *api_path,
|
api_path2xml(char *api_path,
|
||||||
yang_spec *yspec,
|
yang_spec *yspec,
|
||||||
cxobj *xpath,
|
cxobj *xtop,
|
||||||
int schemanode,
|
int schemanode,
|
||||||
cxobj **xpathp,
|
cxobj **xbotp,
|
||||||
yang_node **ypathp)
|
yang_node **ybotp)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
char **vec = NULL;
|
char **vec = NULL;
|
||||||
|
|
@ -1659,8 +1625,8 @@ api_path2xml(char *api_path,
|
||||||
}
|
}
|
||||||
nvec--; /* NULL-terminated */
|
nvec--; /* NULL-terminated */
|
||||||
if (api_path2xml_vec(vec+1, nvec,
|
if (api_path2xml_vec(vec+1, nvec,
|
||||||
xpath, (yang_node*)yspec, schemanode,
|
xtop, (yang_node*)yspec, schemanode,
|
||||||
xpathp, ypathp) < 0)
|
xbotp, ybotp) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -1669,7 +1635,6 @@ api_path2xml(char *api_path,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! Merge a base tree x0 with x1 with yang spec y
|
/*! Merge a base tree x0 with x1 with yang spec y
|
||||||
* @param[in] x0 Base xml tree (can be NULL in add scenarios)
|
* @param[in] x0 Base xml tree (can be NULL in add scenarios)
|
||||||
* @param[in] y0 Yang spec corresponding to xml-node x0. NULL if x0 is NULL
|
* @param[in] y0 Yang spec corresponding to xml-node x0. NULL if x0 is NULL
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue