New clixon-lib@2024-01-01.yang revision
* Replaced container creators to grouping/uses
This commit is contained in:
parent
74ed09b36e
commit
ea645d1334
9 changed files with 136 additions and 56 deletions
|
|
@ -170,10 +170,10 @@ typedef struct xml cxobj; /* struct defined in clicon_xml.c */
|
|||
*
|
||||
* @param[in] x XML node
|
||||
* @param[in] arg General-purpose argument
|
||||
* @retval -1 Error, aborted at first error encounter, return -1 to end user
|
||||
* @retval 0 OK, continue
|
||||
* @retval 1 Abort, dont continue with others, return 1 to end user
|
||||
* @retval 2 Locally abort this subtree, continue with others
|
||||
* @retval 1 Abort, dont continue with others, return 1 to end user
|
||||
* @retval 0 OK, continue
|
||||
* @retval -1 Error, aborted at first error encounter, return -1 to end user
|
||||
*/
|
||||
typedef int (xml_applyfn_t)(cxobj *x, void *arg);
|
||||
|
||||
|
|
@ -239,7 +239,6 @@ size_t xml_creator_len(cxobj *xn);
|
|||
cvec *xml_creator_get(cxobj *xn);
|
||||
int xml_creator_copy_one(cxobj *x0, cxobj *x1);
|
||||
int xml_creator_copy_all(cxobj *x0, cxobj *x1);
|
||||
int xml_creator_print(FILE *f, cxobj *xn);
|
||||
|
||||
char *xml_value(cxobj *xn);
|
||||
int xml_value_set(cxobj *xn, char *val);
|
||||
|
|
|
|||
|
|
@ -77,5 +77,6 @@ int xml_rpc_isaction(cxobj *xn);
|
|||
int xml_find_action(cxobj *xn, int top, cxobj **xap);
|
||||
int purge_tagged_nodes(cxobj *xn, char *ns, char *name, char *value, int keepnode);
|
||||
int clixon_compare_xmls(cxobj *xc1, cxobj *xc2, enum format_enum format);
|
||||
int xml_creator_tree(cxobj *xt, cxobj **xcreator);
|
||||
|
||||
#endif /* _CLIXON_XML_MAP_H_ */
|
||||
|
|
|
|||
|
|
@ -819,41 +819,6 @@ xml_creator_copy_all(cxobj *x0,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Print XML and creator tags where they exists, apply help function
|
||||
*
|
||||
* @param[in] x XML tree
|
||||
* @param[in] arg FIle
|
||||
* @retval see xml_apply
|
||||
*/
|
||||
static int
|
||||
creator_print_fn(cxobj *x,
|
||||
void *arg)
|
||||
{
|
||||
FILE *f = (FILE *)arg;
|
||||
cg_var *cv;
|
||||
|
||||
if (x->x_creators == NULL)
|
||||
return 0;
|
||||
cv = NULL;
|
||||
while ((cv = cvec_each(x->x_creators, cv)) != NULL){
|
||||
fprintf(f, "%s ", cv_name_get(cv));
|
||||
}
|
||||
fprintf(f, ":\n");
|
||||
clixon_xml2file(f, x, 3, 1, NULL, cligen_output, 0, 0);
|
||||
return 2; /* Locally abort this subtree, continue with others */
|
||||
}
|
||||
|
||||
/*! Print XML and creator tags where they exists recursively, for debugging
|
||||
*
|
||||
* @param[in] xn XML tree
|
||||
* @retval see xml_apply
|
||||
*/
|
||||
int
|
||||
xml_creator_print(FILE *f,
|
||||
cxobj *xn)
|
||||
{
|
||||
return xml_apply0(xn, CX_ELMNT, creator_print_fn, f);
|
||||
}
|
||||
|
||||
/*! Get value of xnode
|
||||
*
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@
|
|||
/* Size of xml read buffer */
|
||||
#define BUFLEN 1024
|
||||
|
||||
/* Forward */
|
||||
static int xml_diff2cbuf(cbuf *cb, cxobj *x0, cxobj *x1, int level, int skiptop);
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* XML printing functions. Output a parse tree to file, string cligen buf
|
||||
*------------------------------------------------------------------------*/
|
||||
|
|
@ -1037,7 +1040,7 @@ xml_diff2cbuf_ordered_by_user(cbuf *cb,
|
|||
* @see clixon_compare_xmls which uses files and is independent of YANG
|
||||
* @see text_diff2cbuf
|
||||
*/
|
||||
int
|
||||
static int
|
||||
xml_diff2cbuf(cbuf *cb,
|
||||
cxobj *x0,
|
||||
cxobj *x1,
|
||||
|
|
|
|||
|
|
@ -2034,3 +2034,90 @@ clixon_compare_xmls(cxobj *xc1,
|
|||
unlink(filename2);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Add creator data to metadata xml object on the form name:xpath*
|
||||
*
|
||||
* Callback function type for xml_apply
|
||||
* @param[in] x XML node
|
||||
* @param[in] arg General-purpose argument
|
||||
* @retval 2 Locally abort this subtree, continue with others
|
||||
* @retval 1 Abort, dont continue with others, return 1 to end user
|
||||
* @retval 0 OK, continue
|
||||
* @retval -1 Error, aborted at first error encounter, return -1 to end user
|
||||
* On the form:
|
||||
* <creator>
|
||||
* <name>testA[name='foo']</name>
|
||||
* <xpath>...</xpath>
|
||||
* ...
|
||||
* </creator>
|
||||
*/
|
||||
static int
|
||||
xml_creator_one(cxobj *x,
|
||||
void *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xmeta = (cxobj*)arg;
|
||||
cxobj *xmc;
|
||||
cvec *cvv;
|
||||
cg_var *cv;
|
||||
char *val;
|
||||
cvec *nsc = NULL;
|
||||
char *xpath = NULL;
|
||||
|
||||
if ((cvv = xml_creator_get(x)) == NULL){
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
/* Note this requires x to have YANG spec */
|
||||
if (xml2xpath(x, nsc, 0, 0, &xpath) < 0)
|
||||
goto done;
|
||||
cv = NULL;
|
||||
while ((cv = cvec_each(cvv, cv)) != NULL){
|
||||
val = cv_name_get(cv);
|
||||
/* Find existing entry where name is val */
|
||||
xmc = NULL;
|
||||
while ((xmc = xml_child_each(xmeta, xmc, CX_ELMNT)) != NULL){
|
||||
if (strcmp(xml_find_body(xmc, "name"), val) == 0)
|
||||
break;
|
||||
}
|
||||
if (xmc != NULL){
|
||||
if (clixon_xml_parse_va(YB_NONE, NULL, &xmc, NULL, "<path>%s</path>", xpath) < 0)
|
||||
goto done;
|
||||
}
|
||||
else {
|
||||
if (clixon_xml_parse_va(YB_NONE, NULL, &xmeta, NULL,
|
||||
"<creator><name>%s</name><path>%s</path></creator>",
|
||||
val, xpath) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
retval = 2;
|
||||
done:
|
||||
if (xpath)
|
||||
free(xpath);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Create creator data tree on the form (name:xpath*)*
|
||||
*
|
||||
* @param[in] xt XML top-level node, where to look for creator attributes
|
||||
* @param[out] xcreators Created XML tree on the form <creators><creator>...
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
xml_creator_tree(cxobj *xt,
|
||||
cxobj **xcreators)
|
||||
{
|
||||
int retval = -1;
|
||||
|
||||
if ((*xcreators = xml_new("creators", NULL, CX_ELMNT)) == NULL)
|
||||
goto done;
|
||||
if (xmlns_set(*xcreators, NULL, CLIXON_LIB_NS) < 0)
|
||||
goto done;
|
||||
if (xml_apply(xt, CX_ELMNT, xml_creator_one, *xcreators) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue