- Rewrite of netconf get/get-config code
- Unified get and get-config code to single function get_common - Integrated list-pagination code - Moved get code to new files backend_get.[ch]
This commit is contained in:
parent
b03cf426a4
commit
c9843b34a6
11 changed files with 1382 additions and 1246 deletions
|
|
@ -688,6 +688,7 @@ xml_diff(yang_stmt *yspec,
|
|||
}
|
||||
|
||||
/*! Prune everything that does not pass test or have at least a child* does not
|
||||
*
|
||||
* @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
|
||||
|
|
@ -701,7 +702,6 @@ xml_diff(yang_stmt *yspec,
|
|||
* @note This function seems a little too complex semantics
|
||||
* @see xml_tree_prune_flagged for a simpler variant
|
||||
*/
|
||||
#if 1
|
||||
int
|
||||
xml_tree_prune_flagged_sub(cxobj *xt,
|
||||
int flag,
|
||||
|
|
@ -773,97 +773,6 @@ xml_tree_prune_flagged_sub(cxobj *xt,
|
|||
*upmark = mark;
|
||||
return retval;
|
||||
}
|
||||
#else
|
||||
/* This is optimized in the sense that xml_purge is replaced with xml_child_rm but it leaks memory,
|
||||
* in poarticualr attributes and namespace caches
|
||||
*/
|
||||
int
|
||||
xml_tree_prune_flagged_sub(cxobj *xt,
|
||||
int flag,
|
||||
int test,
|
||||
int *upmark)
|
||||
{
|
||||
int retval = -1;
|
||||
int submark;
|
||||
int mark;
|
||||
cxobj *x;
|
||||
cxobj *xprev;
|
||||
int iskey;
|
||||
int anykey=0;
|
||||
yang_stmt *yt;
|
||||
int i;
|
||||
|
||||
mark = 0;
|
||||
yt = xml_spec(xt); /* xan be null */
|
||||
x = NULL;
|
||||
xprev = x = NULL;
|
||||
i = 0;
|
||||
while ((x = xml_child_each(xt, x, -1)) != NULL) {
|
||||
i++;
|
||||
if (xml_type(x) != CX_ELMNT){
|
||||
xprev = x;
|
||||
continue;
|
||||
}
|
||||
if (xml_flag(x, flag) == test?flag:0){
|
||||
/* Pass test */
|
||||
mark++;
|
||||
xprev = x;
|
||||
continue; /* mark and stop here */
|
||||
}
|
||||
/* If it is key dont remove it yet (see second round) */
|
||||
if (yt){
|
||||
if ((iskey = yang_key_match(yt, xml_name(x))) < 0)
|
||||
goto done;
|
||||
if (iskey){
|
||||
anykey++;
|
||||
xprev = x; /* skip if this is key */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (xml_tree_prune_flagged_sub(x, flag, test, &submark) < 0)
|
||||
goto done;
|
||||
/* if xt is list and submark anywhere, then key subs are also marked
|
||||
*/
|
||||
if (submark)
|
||||
mark++;
|
||||
else{ /* Safe with xml_child_each if last */
|
||||
if (xml_child_rm(xt, i-1) < 0)
|
||||
goto done;
|
||||
i--;
|
||||
x = xprev;
|
||||
}
|
||||
xprev = x;
|
||||
}
|
||||
/* Second round: if any keys were found, and no marks detected, purge now */
|
||||
if (anykey && !mark){
|
||||
x = NULL;
|
||||
xprev = x = NULL;
|
||||
i = 0;
|
||||
while ((x = xml_child_each(xt, x, -1)) != NULL) {
|
||||
i++;
|
||||
if (xml_type(x) != CX_ELMNT){
|
||||
xprev = x;
|
||||
continue;
|
||||
}
|
||||
/* If it is key remove it here */
|
||||
if (yt){
|
||||
if ((iskey = yang_key_match(yt, xml_name(x))) < 0)
|
||||
goto done;
|
||||
if (xml_child_rm(xt, i-1) < 0)
|
||||
goto done;
|
||||
i--;
|
||||
x = xprev;
|
||||
}
|
||||
xprev = x;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (upmark)
|
||||
*upmark = mark;
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! Prune everything that passes test
|
||||
* @param[in] xt XML tree with some node marked
|
||||
|
|
|
|||
|
|
@ -150,6 +150,7 @@ xp_yang_eval_step(xp_yang_ctx *xy0,
|
|||
char *prefix;
|
||||
yang_stmt *ys;
|
||||
xp_yang_ctx *xy = NULL;
|
||||
yang_stmt *ys1 = NULL;
|
||||
|
||||
/* Create new xy */
|
||||
if ((xy = xy_dup(xy0)) == NULL)
|
||||
|
|
@ -164,9 +165,12 @@ xp_yang_eval_step(xp_yang_ctx *xy0,
|
|||
switch (nodetest->xs_type){
|
||||
case XP_NODE:
|
||||
if ((prefix = nodetest->xs_s0) != NULL){
|
||||
if (yang_keyword_get(ys) == Y_MODULE){ /* This means top */
|
||||
yang_stmt *ys1 = NULL;
|
||||
/* XXX: Kludge with prefixes */
|
||||
/* XXX: Kludge with prefixes */
|
||||
if (yang_keyword_get(ys) == Y_SPEC){ /* This means top */
|
||||
if ((ys1 = yang_find_module_by_prefix_yspec(ys, prefix)) != NULL)
|
||||
ys = ys1;
|
||||
}
|
||||
else if (yang_keyword_get(ys) == Y_MODULE){ /* This means top */
|
||||
if ((ys1 = yang_find_module_by_prefix(ys, prefix)) == NULL)
|
||||
ys1 = yang_find_module_by_prefix_yspec(ys_spec(ys), prefix);
|
||||
if (ys1 != NULL)
|
||||
|
|
@ -323,9 +327,15 @@ xp_yang_eval(xp_yang_ctx *xy,
|
|||
}
|
||||
}
|
||||
break;
|
||||
case XP_PRIME_STR:
|
||||
if ((*xyr = xy_dup(xy)) == NULL)
|
||||
goto done;
|
||||
goto ok;
|
||||
break;
|
||||
case XP_ABSPATH:
|
||||
/* Set context node to top node, and nodeset to that node only */
|
||||
xy->xy_node = ys_module(xy->xy_node);
|
||||
if (yang_keyword_get(xy->xy_node) != Y_SPEC)
|
||||
xy->xy_node = ys_module(xy->xy_node);
|
||||
break;
|
||||
case XP_PRED:
|
||||
if (xp_yang_eval_predicate(xy, xptree, xyr) < 0)
|
||||
|
|
@ -419,15 +429,24 @@ xp_yang_eval(xp_yang_ctx *xy,
|
|||
* Leafrefs have a path arguments that are used both for finding referred XML node instances as well
|
||||
* as finding a referred YANG node for typechecks.
|
||||
* Such a path-arg is defined as:
|
||||
* The syntax for a path argument is a subset of the XPath abbreviated
|
||||
* The syntax for a path argument is a subset of the XPath abbreviated
|
||||
* syntax. Predicates are used only for constraining the values for the
|
||||
* key nodes for list entries. Each predicate consists of exactly one
|
||||
* equality test per key, and multiple adjacent predicates MAY be
|
||||
* present if a list has multiple keys.
|
||||
* @param[in] ys YANG referring leaf node
|
||||
* @param[in] path_arg Leafref path-arg
|
||||
* @param[in] ys YANG referring node
|
||||
* @param[in] path_arg path-arg
|
||||
* @param[out] yref YANG referred node
|
||||
* @note this function uses XPATH parser, which is (much too) general
|
||||
* @code
|
||||
* yang_stmt *ys; // source / referring node
|
||||
* yang_stmt *yref = NULL; // target / referred node
|
||||
* char *path_arg="../config/name";
|
||||
*
|
||||
* if (yang_path_arg(ys, path_arg, &yref) < 0)
|
||||
* err;
|
||||
* @endcode
|
||||
|
||||
* @see rfc7950 Sec 9.9.2
|
||||
* @see rfc7950 Sec 14 (leafref path)
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue