C-style update: Unified comment, retvals in order, remove trailing spaces
Changed function name for `clicon_debug` functions
This commit is contained in:
parent
6e314dd96f
commit
62348fc9c7
204 changed files with 6047 additions and 4904 deletions
|
|
@ -110,6 +110,7 @@ isxmlns(cxobj *x)
|
|||
}
|
||||
|
||||
/*! Translate a single xml node to a cligen variable vector. Note not recursive
|
||||
*
|
||||
* @param[in] xt XML tree containing one top node
|
||||
* @param[in] ys Yang spec containing type specification of top-node of xt
|
||||
* @param[out] cvv CLIgen variable vector. Should be freed by cvec_free()
|
||||
|
|
@ -132,8 +133,8 @@ isxmlns(cxobj *x)
|
|||
* @see cvec2xml
|
||||
*/
|
||||
int
|
||||
xml2cvec(cxobj *xt,
|
||||
yang_stmt *yt,
|
||||
xml2cvec(cxobj *xt,
|
||||
yang_stmt *yt,
|
||||
cvec **cvv0)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -158,7 +159,7 @@ xml2cvec(cxobj *xt,
|
|||
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL){
|
||||
name = xml_name(xc);
|
||||
if ((ys = yang_find_datanode(yt, name)) == NULL){
|
||||
clicon_debug(0, "%s: yang sanity problem: %s in xml but not present in yang under %s",
|
||||
clixon_debug(0, "%s: yang sanity problem: %s in xml but not present in yang under %s",
|
||||
__FUNCTION__, name, yang_argument_get(yt));
|
||||
if ((body = xml_body(xc)) != NULL){
|
||||
if ((cv = cv_new(CGV_STRING)) == NULL){
|
||||
|
|
@ -172,7 +173,7 @@ xml2cvec(cxobj *xt,
|
|||
}
|
||||
/* If value is out-of-range, log and skip value, and continue */
|
||||
if (ret == 0){
|
||||
clicon_log(LOG_WARNING, "cv_parse %s: %s", name, reason);
|
||||
clicon_log(LOG_WARNING, "cv_parse %s: %s", name, reason);
|
||||
if (reason)
|
||||
free(reason);
|
||||
}
|
||||
|
|
@ -206,8 +207,8 @@ xml2cvec(cxobj *xt,
|
|||
}
|
||||
}
|
||||
}
|
||||
if (clicon_debug_get() > 1){
|
||||
clicon_debug(CLIXON_DBG_DETAIL, "%s cvv:\n", __FUNCTION__);
|
||||
if (clixon_debug_get() > 1){
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s cvv:\n", __FUNCTION__);
|
||||
cvec_print(stderr, cvv);
|
||||
}
|
||||
*cvv0 = cvv;
|
||||
|
|
@ -219,6 +220,7 @@ xml2cvec(cxobj *xt,
|
|||
}
|
||||
|
||||
/*! Translate a cligen variable vector to an XML tree with depth one
|
||||
*
|
||||
* @param[in] cvv CLIgen variable vector. Should be freed by cvec_free()
|
||||
* @param[in] toptag The XML tree in xt will have this XML tag
|
||||
* @param[in] xt Parent, or NULL
|
||||
|
|
@ -229,8 +231,8 @@ xml2cvec(cxobj *xt,
|
|||
* @see cvec2xml This does more but has an internal xml2cvec translation
|
||||
*/
|
||||
int
|
||||
cvec2xml_1(cvec *cvv,
|
||||
char *toptag,
|
||||
cvec2xml_1(cvec *cvv,
|
||||
char *toptag,
|
||||
cxobj *xp,
|
||||
cxobj **xt0)
|
||||
{
|
||||
|
|
@ -244,7 +246,7 @@ cvec2xml_1(cvec *cvv,
|
|||
int i;
|
||||
|
||||
cv = NULL;
|
||||
while ((cv = cvec_each(cvv, cv)) != NULL)
|
||||
while ((cv = cvec_each(cvv, cv)) != NULL)
|
||||
len++;
|
||||
if ((xt = xml_new(toptag, xp, CX_ELMNT)) == NULL)
|
||||
goto err;
|
||||
|
|
@ -275,6 +277,7 @@ cvec2xml_1(cvec *cvv,
|
|||
}
|
||||
|
||||
/*! Recursive help function to compute differences between two xml trees
|
||||
*
|
||||
* @param[in] x0 First XML tree
|
||||
* @param[in] x1 Second XML tree
|
||||
* @param[out] x0vec Pointervector to XML nodes existing in only first tree
|
||||
|
|
@ -284,6 +287,8 @@ cvec2xml_1(cvec *cvv,
|
|||
* @param[out] changed_x0 Pointervector to XML nodes changed orig value
|
||||
* @param[out] changed_x1 Pointervector to XML nodes changed wanted value
|
||||
* @param[out] changedlen Length of changed vector
|
||||
* @retval 0 Ok
|
||||
* @retval -1 Error
|
||||
* Algorithm to compare two sorted lists A, B:
|
||||
* A 0 1 2 3 5 6
|
||||
* B 0 2 4 5 6
|
||||
|
|
@ -299,7 +304,7 @@ cvec2xml_1(cvec *cvv,
|
|||
* @see xml_diff API function, this one is internal and recursive
|
||||
*/
|
||||
static int
|
||||
xml_diff1(cxobj *x0,
|
||||
xml_diff1(cxobj *x0,
|
||||
cxobj *x1,
|
||||
cxobj ***x0vec,
|
||||
int *x0veclen,
|
||||
|
|
@ -319,20 +324,20 @@ xml_diff1(cxobj *x0,
|
|||
int eq;
|
||||
|
||||
/* Traverse x0 and x1 in lock-step */
|
||||
x0c = x1c = NULL;
|
||||
x0c = x1c = NULL;
|
||||
x0c = xml_child_each(x0, x0c, CX_ELMNT);
|
||||
x1c = xml_child_each(x1, x1c, CX_ELMNT);
|
||||
for (;;){
|
||||
if (x0c == NULL && x1c == NULL)
|
||||
goto ok;
|
||||
else if (x0c == NULL){
|
||||
if (cxvec_append(x1c, x1vec, x1veclen) < 0)
|
||||
if (cxvec_append(x1c, x1vec, x1veclen) < 0)
|
||||
goto done;
|
||||
x1c = xml_child_each(x1, x1c, CX_ELMNT);
|
||||
continue;
|
||||
}
|
||||
else if (x1c == NULL){
|
||||
if (cxvec_append(x0c, x0vec, x0veclen) < 0)
|
||||
if (cxvec_append(x0c, x0vec, x0veclen) < 0)
|
||||
goto done;
|
||||
x0c = xml_child_each(x0, x0c, CX_ELMNT);
|
||||
continue;
|
||||
|
|
@ -340,13 +345,13 @@ xml_diff1(cxobj *x0,
|
|||
/* Both x0c and x1c exists, check if they are yang-equal. */
|
||||
eq = xml_cmp(x0c, x1c, 0, 0, NULL);
|
||||
if (eq < 0){
|
||||
if (cxvec_append(x0c, x0vec, x0veclen) < 0)
|
||||
if (cxvec_append(x0c, x0vec, x0veclen) < 0)
|
||||
goto done;
|
||||
x0c = xml_child_each(x0, x0c, CX_ELMNT);
|
||||
continue;
|
||||
}
|
||||
else if (eq > 0){
|
||||
if (cxvec_append(x1c, x1vec, x1veclen) < 0)
|
||||
if (cxvec_append(x1c, x1vec, x1veclen) < 0)
|
||||
goto done;
|
||||
x1c = xml_child_each(x1, x1c, CX_ELMNT);
|
||||
continue;
|
||||
|
|
@ -358,9 +363,9 @@ xml_diff1(cxobj *x0,
|
|||
yc0 = xml_spec(x0c);
|
||||
yc1 = xml_spec(x1c);
|
||||
if (yc0 && yc1 && yc0 != yc1){ /* choice */
|
||||
if (cxvec_append(x0c, x0vec, x0veclen) < 0)
|
||||
if (cxvec_append(x0c, x0vec, x0veclen) < 0)
|
||||
goto done;
|
||||
if (cxvec_append(x1c, x1vec, x1veclen) < 0)
|
||||
if (cxvec_append(x1c, x1vec, x1veclen) < 0)
|
||||
goto done;
|
||||
}
|
||||
else
|
||||
|
|
@ -371,18 +376,18 @@ xml_diff1(cxobj *x0,
|
|||
if (b0 == NULL && b1 == NULL)
|
||||
;
|
||||
else if (b0 == NULL || b1 == NULL
|
||||
|| strcmp(b0, b1) != 0
|
||||
|| strcmp(b0, b1) != 0
|
||||
){
|
||||
if (cxvec_append(x0c, changed_x0, changedlen) < 0)
|
||||
if (cxvec_append(x0c, changed_x0, changedlen) < 0)
|
||||
goto done;
|
||||
(*changedlen)--; /* append two vectors */
|
||||
if (cxvec_append(x1c, changed_x1, changedlen) < 0)
|
||||
if (cxvec_append(x1c, changed_x1, changedlen) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else if (xml_diff1(x0c, x1c,
|
||||
x0vec, x0veclen,
|
||||
x1vec, x1veclen,
|
||||
else if (xml_diff1(x0c, x1c,
|
||||
x0vec, x0veclen,
|
||||
x1vec, x1veclen,
|
||||
changed_x0, changed_x1, changedlen)< 0)
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -413,7 +418,7 @@ xml_diff1(cxobj *x0,
|
|||
* @see clixon_xml_diff_print same algorithm but print in +/- diff format
|
||||
*/
|
||||
int
|
||||
xml_diff(cxobj *x0,
|
||||
xml_diff(cxobj *x0,
|
||||
cxobj *x1,
|
||||
cxobj ***first,
|
||||
int *firstlen,
|
||||
|
|
@ -426,23 +431,23 @@ xml_diff(cxobj *x0,
|
|||
int retval = -1;
|
||||
|
||||
*firstlen = 0;
|
||||
*secondlen = 0;
|
||||
*secondlen = 0;
|
||||
*changedlen = 0;
|
||||
if (x0 == NULL && x1 == NULL)
|
||||
return 0;
|
||||
if (x1 == NULL){
|
||||
if (cxvec_append(x0, first, firstlen) < 0)
|
||||
if (cxvec_append(x0, first, firstlen) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
if (x0 == NULL){
|
||||
if (cxvec_append(x0, second, secondlen) < 0)
|
||||
if (cxvec_append(x0, second, secondlen) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
if (xml_diff1(x0, x1,
|
||||
first, firstlen,
|
||||
second, secondlen,
|
||||
first, firstlen,
|
||||
second, secondlen,
|
||||
changed_x0, changed_x1, changedlen) < 0)
|
||||
goto done;
|
||||
ok:
|
||||
|
|
@ -460,7 +465,7 @@ xml_diff(cxobj *x0,
|
|||
* @see xml_diff which returns diff sets
|
||||
*/
|
||||
int
|
||||
xml_tree_equal(cxobj *x0,
|
||||
xml_tree_equal(cxobj *x0,
|
||||
cxobj *x1)
|
||||
{
|
||||
int retval = 1; /* Not equal */
|
||||
|
|
@ -471,9 +476,9 @@ xml_tree_equal(cxobj *x0,
|
|||
char *b1;
|
||||
cxobj *x0c = NULL; /* x0 child */
|
||||
cxobj *x1c = NULL; /* x1 child */
|
||||
|
||||
|
||||
/* Traverse x0 and x1 in lock-step */
|
||||
x0c = x1c = NULL;
|
||||
x0c = x1c = NULL;
|
||||
x0c = xml_child_each(x0, x0c, CX_ELMNT);
|
||||
x1c = xml_child_each(x1, x1c, CX_ELMNT);
|
||||
for (;;){
|
||||
|
|
@ -510,7 +515,7 @@ xml_tree_equal(cxobj *x0,
|
|||
if (b0 == NULL && b1 == NULL)
|
||||
;
|
||||
else if (b0 == NULL || b1 == NULL
|
||||
|| strcmp(b0, b1) != 0
|
||||
|| strcmp(b0, b1) != 0
|
||||
){
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -536,6 +541,8 @@ xml_tree_equal(cxobj *x0,
|
|||
* @param[in] flag Which flag to test for
|
||||
* @param[in] test 1: test that flag is set, 0: test that flag is not set
|
||||
* @param[out] upmark Set if a child (recursively) has marked set.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* The function removes all branches that does not pass the test
|
||||
* Purge all nodes that dont have MARK flag set recursively.
|
||||
* Save all nodes that is MARK:ed or have at least one (grand*)child that is MARKed
|
||||
|
|
@ -546,7 +553,7 @@ xml_tree_equal(cxobj *x0,
|
|||
* @see xml_tree_prune_flagged for a simpler variant
|
||||
*/
|
||||
int
|
||||
xml_tree_prune_flagged_sub(cxobj *xt,
|
||||
xml_tree_prune_flagged_sub(cxobj *xt,
|
||||
int flag,
|
||||
int test,
|
||||
int *upmark)
|
||||
|
|
@ -607,7 +614,7 @@ xml_tree_prune_flagged_sub(cxobj *xt,
|
|||
goto done;
|
||||
x = xprev;
|
||||
}
|
||||
xprev = x;
|
||||
xprev = x;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -618,16 +625,19 @@ xml_tree_prune_flagged_sub(cxobj *xt,
|
|||
}
|
||||
|
||||
/*! Prune everything that passes test
|
||||
*
|
||||
* @param[in] xt XML tree with some node marked
|
||||
* @param[in] flag Which flag to test for
|
||||
* @param[in] test 1: test that flag is set, 0: test that flag is not set
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* The function removes all branches that does not pass test
|
||||
* @code
|
||||
* xml_tree_prune_flagged(xt, XML_FLAG_MARK, 1);
|
||||
* @endcode
|
||||
*/
|
||||
int
|
||||
xml_tree_prune_flagged(cxobj *xt,
|
||||
xml_tree_prune_flagged(cxobj *xt,
|
||||
int flag,
|
||||
int test)
|
||||
{
|
||||
|
|
@ -642,7 +652,7 @@ xml_tree_prune_flagged(cxobj *xt,
|
|||
if (xml_purge(x) < 0)
|
||||
goto done;
|
||||
x = xprev;
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
if (xml_tree_prune_flagged(x, flag, test) < 0)
|
||||
goto done;
|
||||
|
|
@ -654,9 +664,12 @@ xml_tree_prune_flagged(cxobj *xt,
|
|||
}
|
||||
|
||||
/*! Prune everything that passes test
|
||||
*
|
||||
* @param[in] xt XML tree with some node marked
|
||||
* @param[in] flags Flags set
|
||||
* @param[in] mask Which flags to test for
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* The function removes all branches that does pass test
|
||||
* @code
|
||||
* xml_tree_prune_flags(xt, XML_FLAG_MARK, XML_FLAG_MARK|XML_FLAG_DEFAULT);
|
||||
|
|
@ -699,9 +712,9 @@ xml_tree_prune_flags(cxobj *xt,
|
|||
* @param -1 Error
|
||||
*/
|
||||
int
|
||||
xml_namespace_change(cxobj *x,
|
||||
char *ns,
|
||||
char *prefix)
|
||||
xml_namespace_change(cxobj *x,
|
||||
char *ns,
|
||||
char *prefix)
|
||||
{
|
||||
int retval = -1;
|
||||
char *ns0 = NULL; /* existing namespace */
|
||||
|
|
@ -712,7 +725,7 @@ xml_namespace_change(cxobj *x,
|
|||
if (xml2ns(x, xml_prefix(x), &ns0) < 0)
|
||||
goto done;
|
||||
if (ns0 && strcmp(ns0, ns) == 0)
|
||||
goto ok; /* Already has right namespace */
|
||||
goto ok; /* Already has right namespace */
|
||||
/* Is namespace already declared? */
|
||||
if (xml2prefix(x, ns, &prefix0) == 1){
|
||||
/* Yes it is declared and the prefix is prefix0 */
|
||||
|
|
@ -728,7 +741,7 @@ xml_namespace_change(cxobj *x,
|
|||
else
|
||||
xp = xml_parent(x);
|
||||
if (xml_add_namespace(x, xp, prefix, ns) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Add prefix to x, if any */
|
||||
if (prefix && xml_prefix_set(x, prefix) < 0)
|
||||
goto done;
|
||||
|
|
@ -740,10 +753,15 @@ xml_namespace_change(cxobj *x,
|
|||
}
|
||||
|
||||
/*! Sanitize an xml tree: xml node has matching yang_stmt pointer
|
||||
* @param[in] xt XML top of tree
|
||||
*
|
||||
* @param[in] xt XML top of tree
|
||||
* @param[in] arg Not used
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
|
||||
*/
|
||||
int
|
||||
xml_sanity(cxobj *xt,
|
||||
xml_sanity(cxobj *xt,
|
||||
void *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -756,7 +774,7 @@ xml_sanity(cxobj *xt,
|
|||
}
|
||||
name = xml_name(xt);
|
||||
if (strstr(yang_argument_get(ys), name)==NULL){
|
||||
clicon_err(OE_XML, 0, "xml node name '%s' does not match yang spec arg '%s'",
|
||||
clicon_err(OE_XML, 0, "xml node name '%s' does not match yang spec arg '%s'",
|
||||
name, yang_argument_get(ys));
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -766,23 +784,24 @@ xml_sanity(cxobj *xt,
|
|||
}
|
||||
|
||||
/*! Detect state data: Either mark or break on first occurence and return xerror
|
||||
*
|
||||
* @param[in] xt XML tree
|
||||
* @param[out] xerr If set return netconf error, abort and return if a state variable found
|
||||
* @retval -1 Error
|
||||
* @retval 0 Status node found and return xerror
|
||||
* @retval 1 OK
|
||||
* @retval 0 Status node found and return xerror
|
||||
* @retval -1 Error
|
||||
* Note that the behaviour is quite different if xerr is set or not,...
|
||||
*/
|
||||
int
|
||||
xml_non_config_data(cxobj *xt,
|
||||
cxobj **xerr)
|
||||
xml_non_config_data(cxobj *xt,
|
||||
cxobj **xerr)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *x;
|
||||
yang_stmt *y;
|
||||
int ret;
|
||||
cbuf *cb = NULL;
|
||||
|
||||
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(xt, x, CX_ELMNT)) != NULL) {
|
||||
if ((y = (yang_stmt*)xml_spec(x)) == NULL)
|
||||
|
|
@ -817,7 +836,10 @@ xml_non_config_data(cxobj *xt,
|
|||
}
|
||||
|
||||
/*! Check if the module tree x is in is assigned right XML namespace, assign if not
|
||||
*
|
||||
* @param[in] x XML node
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*(0. You should probably find the XML root and apply this function to that.)
|
||||
* 1. Check which namespace x should have (via yang). This is correct namespace.
|
||||
* 2. Check which namespace x has via its XML tree
|
||||
|
|
@ -862,10 +884,11 @@ xmlns_assign(cxobj *x)
|
|||
}
|
||||
|
||||
/*! Given a src element node x0 and a target node x1, assign (optional) prefix and namespace
|
||||
*
|
||||
* @param[in] x1 XML tree
|
||||
* @param[in] x1p XML tree parent
|
||||
* @retval 0 OK
|
||||
* @retval -1 OK
|
||||
* @retval -1 Error
|
||||
* @see assign_namespace_element this is a subroutine
|
||||
*/
|
||||
static int
|
||||
|
|
@ -880,7 +903,7 @@ assign_namespace(cxobj *x1, /* target */
|
|||
char *pexist = NULL;
|
||||
cvec *nsc0 = NULL;
|
||||
cvec *nsc = NULL;
|
||||
|
||||
|
||||
/* 2a. Detect if namespace is declared in x1 target parent */
|
||||
if (xml2prefix(x1p, ns, &pexist) == 1){
|
||||
/* Yes, and it has prefix pexist */
|
||||
|
|
@ -920,7 +943,7 @@ assign_namespace(cxobj *x1, /* target */
|
|||
}
|
||||
goto ok; /* skip */
|
||||
}
|
||||
else { /* namespace does not exist in target x1,
|
||||
else { /* namespace does not exist in target x1,
|
||||
*/
|
||||
if (isroot){
|
||||
if (prefix0 && (prefix1 = strdup(prefix0)) == NULL){
|
||||
|
|
@ -929,7 +952,7 @@ assign_namespace(cxobj *x1, /* target */
|
|||
}
|
||||
}
|
||||
else{
|
||||
if (prefix0 == NULL){ /* Use default namespace, may break use of previous default
|
||||
if (prefix0 == NULL){ /* Use default namespace, may break use of previous default
|
||||
* somewhere in x1
|
||||
*/
|
||||
prefix1 = NULL;
|
||||
|
|
@ -939,7 +962,7 @@ assign_namespace(cxobj *x1, /* target */
|
|||
if (xml_add_namespace(x1, x1, prefix1, ns) < 0)
|
||||
goto done;
|
||||
if (prefix1 && xml_prefix_set(x1, prefix1) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
}
|
||||
ok:
|
||||
/* 6. Ensure x1 cache is updated (I think it is done w xmlns_set above) */
|
||||
|
|
@ -951,11 +974,12 @@ assign_namespace(cxobj *x1, /* target */
|
|||
}
|
||||
|
||||
/*! Given a src element node x0 and a target node x1, assign (optional) prefix and namespace
|
||||
*
|
||||
* @param[in] x0 Source XML tree
|
||||
* @param[in] x1 Target XML tree
|
||||
* @param[in] x1p Target XML tree parent
|
||||
* @retval 0 OK
|
||||
* @retval -1 OK
|
||||
* @retval -1 Error
|
||||
* 1. Find N=namespace(x0)
|
||||
* 2. Detect if N is declared in x1 parent
|
||||
* 3. If yes, assign prefix to x1
|
||||
|
|
@ -975,7 +999,7 @@ assign_namespace_element(cxobj *x0, /* source */
|
|||
char *namespace = NULL;
|
||||
char *prefix0 = NULL;;
|
||||
int isroot;
|
||||
|
||||
|
||||
isroot = xml_parent(x1p)==NULL &&
|
||||
xml_flag(x1p, XML_FLAG_TOP) &&
|
||||
xml_prefix(x1p)==NULL;
|
||||
|
|
@ -1007,6 +1031,8 @@ assign_namespace_element(cxobj *x0, /* source */
|
|||
*
|
||||
* @param[in] x0 Source XML
|
||||
* @param[in] x1 Destination XML
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @note "standard" namespaces, including clixon internal namespaces are removed
|
||||
*/
|
||||
int
|
||||
|
|
@ -1017,10 +1043,10 @@ assign_namespace_body(cxobj *x0, /* source */
|
|||
char *namespace = NULL;
|
||||
char *namespace1;
|
||||
char *name;
|
||||
char *prefix0;
|
||||
char *prefix1 = NULL;
|
||||
char *prefix0;
|
||||
char *prefix1 = NULL;
|
||||
cxobj *xa;
|
||||
|
||||
|
||||
xa = NULL;
|
||||
while ((xa = xml_child_each_attr(x0, xa)) != NULL) {
|
||||
prefix0 = xml_prefix(xa);
|
||||
|
|
@ -1058,6 +1084,7 @@ assign_namespace_body(cxobj *x0, /* source */
|
|||
}
|
||||
|
||||
/*! 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] y0 Yang spec corresponding to xml-node x0. NULL if x0 is NULL
|
||||
* @param[in] x0p Parent of x0
|
||||
|
|
@ -1092,7 +1119,7 @@ xml_merge1(cxobj *x0, /* the target */
|
|||
char *ns;
|
||||
char *px;
|
||||
char *pxe;
|
||||
|
||||
|
||||
if (x1 == NULL || xml_type(x1) != CX_ELMNT || y0 == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "x1 is NULL or not XML element, or lacks yang spec");
|
||||
goto done;
|
||||
|
|
@ -1131,13 +1158,13 @@ xml_merge1(cxobj *x0, /* the target */
|
|||
if (x1bstr){
|
||||
if ((x0b = xml_body_get(x0)) == NULL){
|
||||
if ((x0b = xml_new("body", x0, CX_BODY)) == NULL)
|
||||
goto done;
|
||||
goto done;
|
||||
}
|
||||
if (xml_value_set(x0b, x1bstr) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (xml_parent(x0) == NULL &&
|
||||
xml_insert(x0p, x0, INS_LAST, NULL, NULL) < 0)
|
||||
xml_insert(x0p, x0, INS_LAST, NULL, NULL) < 0)
|
||||
goto done;
|
||||
if (assign_namespace_element(x1, x0, x0p) < 0)
|
||||
goto done;
|
||||
|
|
@ -1200,7 +1227,7 @@ xml_merge1(cxobj *x0, /* the target */
|
|||
goto fail;
|
||||
}
|
||||
if (xml_parent(x0) == NULL &&
|
||||
xml_insert(x0p, x0, INS_LAST, NULL, NULL) < 0)
|
||||
xml_insert(x0p, x0, INS_LAST, NULL, NULL) < 0)
|
||||
goto done;
|
||||
} /* else Y_CONTAINER */
|
||||
ok:
|
||||
|
|
@ -1219,6 +1246,7 @@ xml_merge1(cxobj *x0, /* the target */
|
|||
}
|
||||
|
||||
/*! Merge XML trees x1 into x0 according to yang spec yspec
|
||||
*
|
||||
* @param[in] x0 Base xml tree (can be NULL in add scenarios)
|
||||
* @param[in] x1 xml tree which modifies base
|
||||
* @param[in] yspec Yang spec
|
||||
|
|
@ -1268,7 +1296,7 @@ xml_merge(cxobj *x0,
|
|||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
goto fail;
|
||||
goto fail;
|
||||
}
|
||||
/* Get yang spec of the child */
|
||||
if ((yc = yang_find_datanode(ymod, x1cname)) == NULL){
|
||||
|
|
@ -1331,6 +1359,8 @@ xml_merge(cxobj *x0,
|
|||
* @param[in] ytype YANG type noden
|
||||
* @param[in] valstr Integer string value
|
||||
* @param[out] enumstr Value of enum, dont free
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
yang_valstr2enum(yang_stmt *ytype,
|
||||
|
|
@ -1365,7 +1395,7 @@ yang_valstr2enum(yang_stmt *ytype,
|
|||
* @param[out] valstr Corresponding string containing an int (direct pointer, dont free)
|
||||
* @retval 1 OK, result in valstr
|
||||
* @retval 0 Invalid, not found
|
||||
* @retval -1 Error
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
yang_enum2valstr(yang_stmt *ytype,
|
||||
|
|
@ -1373,8 +1403,8 @@ yang_enum2valstr(yang_stmt *ytype,
|
|||
char **valstr)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yenum;
|
||||
yang_stmt *yval;
|
||||
yang_stmt *yenum;
|
||||
yang_stmt *yval;
|
||||
|
||||
if (valstr == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "valstr is NULL");
|
||||
|
|
@ -1395,6 +1425,7 @@ yang_enum2valstr(yang_stmt *ytype,
|
|||
}
|
||||
|
||||
/*! Get integer value from xml node from yang enumeration
|
||||
*
|
||||
* @param[in] node XML node in a tree
|
||||
* @param[out] val Integer value returned
|
||||
* @retval 0 OK, value parsed
|
||||
|
|
@ -1408,7 +1439,7 @@ yang_enum2valstr(yang_stmt *ytype,
|
|||
* Thanks: Matthew Smith
|
||||
*/
|
||||
int
|
||||
yang_enum_int_value(cxobj *node,
|
||||
yang_enum_int_value(cxobj *node,
|
||||
int32_t *val)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1427,7 +1458,7 @@ yang_enum_int_value(cxobj *node,
|
|||
goto done;
|
||||
if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL)
|
||||
goto done;
|
||||
if (yang_type_resolve(ys, ys, ytype, &yrestype,
|
||||
if (yang_type_resolve(ys, ys, ytype, &yrestype,
|
||||
NULL, NULL, NULL, NULL, NULL) < 0)
|
||||
goto done;
|
||||
if (yrestype == NULL){
|
||||
|
|
@ -1447,17 +1478,21 @@ done:
|
|||
}
|
||||
|
||||
/*! Given XML tree x0 with marked nodes, copy marked nodes to new tree x1
|
||||
* Two marks are used: XML_FLAG_MARK and XML_FLAG_CHANGE
|
||||
*
|
||||
* Two marks are used: XML_FLAG_MARK and XML_FLAG_CHANGE
|
||||
* The algorithm works as following:
|
||||
* (1) Copy individual nodes marked with XML_FLAG_CHANGE
|
||||
* until nodes marked with XML_FLAG_MARK are reached, where
|
||||
* (2) the complete subtree of that node is copied.
|
||||
* (3) Special case: key nodes in lists are copied if any node in list is marked
|
||||
* @param[in] x0
|
||||
* @param[in] x1
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @note you may want to check:!yang_config(ys)
|
||||
*/
|
||||
int
|
||||
xml_copy_marked(cxobj *x0,
|
||||
xml_copy_marked(cxobj *x0,
|
||||
cxobj *x1)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -1476,14 +1511,13 @@ xml_copy_marked(cxobj *x0,
|
|||
if ((prefix = xml_prefix(x0)) != NULL)
|
||||
if (xml_prefix_set(x1, prefix) < 0)
|
||||
goto done;
|
||||
|
||||
/* Copy all attributes */
|
||||
x = NULL;
|
||||
while ((x = xml_child_each_attr(x0, x)) != NULL) {
|
||||
name = xml_name(x);
|
||||
if ((xcopy = xml_new(name, x1, CX_ATTR)) == NULL)
|
||||
goto done;
|
||||
if (xml_copy(x, xcopy) < 0)
|
||||
if (xml_copy(x, xcopy) < 0)
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -1506,9 +1540,9 @@ xml_copy_marked(cxobj *x0,
|
|||
/* (2) the complete subtree of that node is copied. */
|
||||
if ((xcopy = xml_new(name, x1, CX_ELMNT)) == NULL)
|
||||
goto done;
|
||||
if (xml_copy(x, xcopy) < 0)
|
||||
if (xml_copy(x, xcopy) < 0)
|
||||
goto done;
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
if (xml_flag(x, XML_FLAG_CHANGE)){
|
||||
/* Copy individual nodes marked with XML_FLAG_CHANGE */
|
||||
|
|
@ -1526,7 +1560,7 @@ xml_copy_marked(cxobj *x0,
|
|||
if (iskey){
|
||||
if ((xcopy = xml_new(name, x1, CX_ELMNT)) == NULL)
|
||||
goto done;
|
||||
if (xml_copy(x, xcopy) < 0)
|
||||
if (xml_copy(x, xcopy) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -1545,7 +1579,7 @@ xml_copy_marked(cxobj *x0,
|
|||
* @param[out] nrp 1: when stmt evaluates to true
|
||||
* @param[out] xpathp when stmts xpath
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @retval -1 Error
|
||||
* First variants of WHEN: Augmented and uses when using special info in node
|
||||
* Second variant of when, actual "when" sub-node RFC 7950 Sec 7.21.5. Can only be one.
|
||||
*/
|
||||
|
|
@ -1659,7 +1693,7 @@ yang_xml_mandatory(cxobj *xt,
|
|||
}
|
||||
/* 3) A container node without a "presence" statement and that has at
|
||||
* least one mandatory node as a child. */
|
||||
else if (keyw == Y_CONTAINER &&
|
||||
else if (keyw == Y_CONTAINER &&
|
||||
yang_find(ys, Y_PRESENCE, NULL) == NULL){
|
||||
yc = NULL;
|
||||
while ((yc = yn_each(ys, yc)) != NULL) {
|
||||
|
|
@ -1680,6 +1714,7 @@ yang_xml_mandatory(cxobj *xt,
|
|||
}
|
||||
|
||||
/*! Is XML node (ie under <rpc>) an action, ie name action and belong to YANG_XML_NAMESPACE?
|
||||
*
|
||||
* @param[in] xn XML node
|
||||
* @retval 1 Yes, an action
|
||||
* @retval 0 No, not an action
|
||||
|
|
@ -1706,6 +1741,7 @@ xml_rpc_isaction(cxobj *xn)
|
|||
}
|
||||
|
||||
/*! Find innermost node under <action> carrying the name of the defined action
|
||||
*
|
||||
* Find innermost container or list contains an XML element
|
||||
* that carries the name of the defined action.
|
||||
* @param[in] xn XML node
|
||||
|
|
@ -1744,12 +1780,15 @@ xml_find_action(cxobj *xn,
|
|||
}
|
||||
|
||||
/*! Utility function: recursive traverse an XML tree and remove nodes based on attribute value
|
||||
*
|
||||
* Conditionally remove attribute and node
|
||||
* @param[in] xn XML node
|
||||
* @param[in] ns Namespace of attribute
|
||||
* @param[in] name Attribute name
|
||||
* @param[in] value Attribute value
|
||||
* @param[in] keepnode 0: remove node associated with attribute; 1: keep node but remove attr
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
purge_tagged_nodes(cxobj *xn,
|
||||
|
|
@ -1797,6 +1836,8 @@ purge_tagged_nodes(cxobj *xn,
|
|||
* @param[in] xc1 XML tree 1
|
||||
* @param[in] xc2 XML tree 2
|
||||
* @param[in] format "text"|"xml"|"json"|"cli"|"netconf" (see format_enum)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see clixon_xml_diff2cbuf with better XML in-mem comparison but is YANG dependent
|
||||
*/
|
||||
int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue