New clixon-lib@2023-03-01.yang revision
* Added creator meta-object
This commit is contained in:
parent
45d8e5b6ce
commit
819a0b5a9e
7 changed files with 179 additions and 32 deletions
|
|
@ -92,7 +92,7 @@
|
|||
* If such an attribute its found, its string value is returned.
|
||||
* @param[in] x XML node (where to look for attribute)
|
||||
* @param[in] name Attribute name
|
||||
* @param[in] ns (Expected)Namespace of attribute
|
||||
* @param[in] ns (Expected) Namespace of attribute
|
||||
* @param[out] cbret Error message (if retval=0)
|
||||
* @param[out] valp Malloced value (if retval=1)
|
||||
* @retval -1 Error
|
||||
|
|
@ -489,6 +489,7 @@ text_modify(clicon_handle h,
|
|||
char *restype;
|
||||
int ismount = 0;
|
||||
yang_stmt *mount_yspec = NULL;
|
||||
char *creator = NULL;
|
||||
|
||||
if (x1 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "x1 is missing");
|
||||
|
|
@ -511,6 +512,7 @@ text_modify(clicon_handle h,
|
|||
goto done;
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
|
||||
if (createstr != NULL &&
|
||||
(op == OP_REPLACE || op == OP_MERGE || op == OP_CREATE)){
|
||||
if (x0 == NULL || xml_defaults_nopresence(x0, 0)){ /* does not exist or is default */
|
||||
|
|
@ -529,6 +531,11 @@ text_modify(clicon_handle h,
|
|||
clicon_data_set(h, "objectexisted", "true");
|
||||
}
|
||||
}
|
||||
/* Special clixon-lib attribute for keeping track of creator of objects */
|
||||
if ((ret = attr_ns_value(x1, "creator", CLIXON_LIB_NS, cbret, &creator)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
x1name = xml_name(x1);
|
||||
|
||||
if (yang_keyword_get(y0) == Y_LEAF_LIST ||
|
||||
|
|
@ -932,12 +939,17 @@ text_modify(clicon_handle h,
|
|||
if (ret == 0)
|
||||
goto fail;
|
||||
}
|
||||
if (creator){
|
||||
if (xml_creator_add(x0, creator) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (changed){
|
||||
#ifdef XML_PARENT_CANDIDATE
|
||||
xml_parent_candidate_set(x0, NULL);
|
||||
#endif
|
||||
if (xml_insert(x0p, x0, insert, keystr, nscx1) < 0)
|
||||
goto done;
|
||||
|
||||
}
|
||||
break;
|
||||
case OP_DELETE:
|
||||
|
|
@ -972,6 +984,8 @@ text_modify(clicon_handle h,
|
|||
free(instr);
|
||||
if (opstr)
|
||||
free(opstr);
|
||||
if (creator)
|
||||
free(creator);
|
||||
if (createstr)
|
||||
free(createstr);
|
||||
if (nscx1)
|
||||
|
|
|
|||
|
|
@ -180,11 +180,11 @@ struct xml{
|
|||
int x_childvec_len;/* Number of children */
|
||||
int x_childvec_max;/* Length of allocated vector */
|
||||
|
||||
|
||||
cvec *x_ns_cache; /* Cached vector of namespaces (set by bind-yang) */
|
||||
yang_stmt *x_spec; /* Pointer to specification, eg yang,
|
||||
by reference, dont free */
|
||||
cg_var *x_cv; /* Cached value as cligen variable (set by xml_cmp) */
|
||||
cvec *x_creators; /* Support clixon-lib creator annotation */
|
||||
#ifdef XML_EXPLICIT_INDEX
|
||||
struct search_index *x_search_index; /* explicit search index vectors */
|
||||
#endif
|
||||
|
|
@ -617,6 +617,72 @@ xml_flag_reset(cxobj *xn,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*! Add a creator string
|
||||
*/
|
||||
int
|
||||
xml_creator_add(cxobj *xn,
|
||||
char *str)
|
||||
{
|
||||
int retval = -1;
|
||||
cg_var *cv;
|
||||
|
||||
if (!is_element(xn))
|
||||
return 0;
|
||||
if (xn->x_creators == NULL){
|
||||
if ((xn->x_creators = cvec_new(0)) == NULL){
|
||||
clicon_err(OE_XML, errno, "cvec_new");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if ((cv = cvec_find(xn->x_creators, str)) == NULL)
|
||||
cvec_add_string(xn->x_creators, str, NULL);
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Remove a creator string
|
||||
*/
|
||||
int
|
||||
xml_creator_rm(cxobj *xn,
|
||||
char *str)
|
||||
{
|
||||
cg_var *cv;
|
||||
|
||||
if (!is_element(xn))
|
||||
return 0;
|
||||
if ((cv = cvec_find(xn->x_creators, str)) == NULL)
|
||||
return 0;
|
||||
return cvec_del(xn->x_creators, cv);
|
||||
}
|
||||
|
||||
/*! Find a creator string
|
||||
*/
|
||||
int
|
||||
xml_creator_find(cxobj *xn,
|
||||
char *str)
|
||||
{
|
||||
if (!is_element(xn))
|
||||
return 0;
|
||||
if (xn->x_creators != NULL &&
|
||||
cvec_find(xn->x_creators, str) != NULL)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Get number of creator strings
|
||||
*/
|
||||
size_t
|
||||
xml_creator_len(cxobj *xn)
|
||||
{
|
||||
if (!is_element(xn))
|
||||
return 0;
|
||||
if (xn->x_creators)
|
||||
return cvec_len(xn->x_creators);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Get value of xnode
|
||||
* @param[in] xn xml node
|
||||
* @retval value of xml node
|
||||
|
|
@ -1874,6 +1940,8 @@ xml_free(cxobj *x)
|
|||
#ifdef XML_EXPLICIT_INDEX
|
||||
xml_search_index_free(x);
|
||||
#endif
|
||||
if (x->x_creators)
|
||||
cvec_free(x->x_creators);
|
||||
break;
|
||||
case CX_BODY:
|
||||
case CX_ATTR:
|
||||
|
|
@ -1915,6 +1983,11 @@ xml_copy_one(cxobj *x0,
|
|||
switch (xml_type(x0)){
|
||||
case CX_ELMNT:
|
||||
xml_spec_set(x1, xml_spec(x0));
|
||||
if (x0->x_creators)
|
||||
if ((x1->x_creators = cvec_dup(x0->x_creators)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
break;
|
||||
case CX_BODY:
|
||||
case CX_ATTR:
|
||||
|
|
@ -2069,6 +2142,7 @@ cxvec_prepend(cxobj *x,
|
|||
|
||||
|
||||
/*! Apply a function call recursively on all xml node children recursively
|
||||
*
|
||||
* Recursively traverse all xml nodes in a parse-tree and apply fn(arg) for
|
||||
* each object found. The function is called with the xml node and an
|
||||
* argument as args.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue