C-style update: Unified comment, retvals in order, remove trailing spaces

Changed function name for `clicon_debug` functions
This commit is contained in:
Olof hagsand 2023-10-22 18:04:47 +02:00
parent 6e314dd96f
commit 62348fc9c7
204 changed files with 6047 additions and 4904 deletions

View file

@ -32,7 +32,7 @@
***** END LICENSE BLOCK *****
* Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10
* Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10
*
* Some notes on namespace extensions in Netconf/Yang
* RFC6241 8.9.1
@ -90,7 +90,7 @@
#include "clixon_xpath_function.h"
#include "clixon_xpath_eval.h"
/* Mapping between XPATH operator string <--> int */
/* Mapping between XPath operator string <--> int */
const map_str2int xpopmap[] = {
{"and", XO_AND},
{"or", XO_OR},
@ -105,14 +105,15 @@ const map_str2int xpopmap[] = {
{"<=", XO_LE},
{"<", XO_LT},
{">", XO_GT},
{"|", XO_UNION},
{"|", XO_UNION},
{NULL, -1}
};
/*! Eval an XPATH nodetest
* @retval -1 Error XXX: retval -1 not properly handled
* @retval 0 No match
/*! Eval an XPath nodetest
*
* @retval 1 Match
* @retval 0 No match
* @retval -1 Error XXX: retval -1 not properly handled
*/
static int
nodetest_eval_node(cxobj *x,
@ -140,7 +141,7 @@ nodetest_eval_node(cxobj *x,
retval = 0; /* no match */
goto done;
}
/* Here names are equal
/* Here names are equal
* Now look for namespaces
* 1) prefix1 and prefix2 point to same namespace <<-- try this first
* 2) prefix1 is equal to prefix2 <<-- then try this
@ -156,7 +157,7 @@ nodetest_eval_node(cxobj *x,
* This can happen in eg augments and ../foo, where foo is
* augmented from another namespace
*/
retval = 1;
retval = 1;
}
else
retval = (nsxml == nsxpath); /* True only if both are NULL */
@ -181,7 +182,8 @@ nodetest_eval_node(cxobj *x,
return retval;
}
/*! Eval an XPATH nodetest but skip prefix and namespace tests
/*! Eval an XPath nodetest but skip prefix and namespace tests
*
* This is NOT according to standard
*/
static int
@ -210,13 +212,14 @@ nodetest_eval_node_localonly(cxobj *x,
}
/*! Make a nodetest
*
* @param[in] x XML node
* @param[in] xs XPATH stack of type XP_NODE or XP_NODE_FN
* @param[in] xs XPath stack of type XP_NODE or XP_NODE_FN
* @param[in] nsc XML Namespace context
* @param[in] localonly Skip prefix and namespace tests (non-standard)
* @retval -1 Error
* @retval 0 No match
* @retval 1 Match
* @retval 0 No match
* @retval -1 Error
* - node() is true for any node of any type whatsoever.
* - text() is true for any text node.
*/
@ -248,18 +251,21 @@ nodetest_eval(cxobj *x,
return retval;
}
/*!
/*! test node recursive
*
* @param[in] xn
* @param[in] nodetest XPATH stack
* @param[in] nodetest XPath stack
* @param[in] node_type
* @param[in] flags
* @param[in] nsc XML Namespace context
* @param[in] localonly Skip prefix and namespace tests (non-standard)
* @param[out] vec0
* @param[out] vec0len
* @retval 0 OK
* @retval -1 Error
*/
int
nodetest_recursive(cxobj *xn,
nodetest_recursive(cxobj *xn,
xpath_tree *nodetest,
int node_type,
uint16_t flags,
@ -269,14 +275,14 @@ nodetest_recursive(cxobj *xn,
int *vec0len)
{
int retval = -1;
cxobj *xsub;
cxobj *xsub;
cxobj **vec = *vec0;
int veclen = *vec0len;
xsub = NULL;
while ((xsub = xml_child_each(xn, xsub, node_type)) != NULL) {
if (nodetest_eval(xsub, nodetest, nsc, localonly) == 1){
clicon_debug(CLIXON_DBG_DETAIL, "%s %x %x", __FUNCTION__, flags, xml_flag(xsub, flags));
clixon_debug(CLIXON_DBG_DETAIL, "%s %x %x", __FUNCTION__, flags, xml_flag(xsub, flags));
if (flags==0x0 || xml_flag(xsub, flags))
if (cxvec_append(xsub, &vec, &veclen) < 0)
goto done;
@ -294,11 +300,13 @@ nodetest_recursive(cxobj *xn,
/*! Evaluate xpath step rule of an XML tree
*
* @param[in] xc0 Incoming context
* @param[in] xs XPATH node tree
* @param[in] nsc XML Namespace context
* @param[in] xc0 Incoming context
* @param[in] xs XPath node tree
* @param[in] nsc XML Namespace context
* @param[in] localonly Skip prefix and namespace tests (non-standard)
* @param[out] xrp Resulting context
* @param[out] xrp Resulting context
* @retval 0 OK
* @retval -1 Error
*
* - A node test that is a QName is true if and only if the type of the node (see [5 Data Model])
* is the principal node type and has an expanded-name equal to the expanded-name specified by the QName.
@ -323,7 +331,7 @@ xp_eval_step(xp_ctx *xc0,
xpath_tree *nodetest = xs->xs_c0;
xp_ctx *xc = NULL;
int ret;
/* Create new xc */
if ((xc = ctx_dup(xc0)) == NULL)
goto done;
@ -344,9 +352,9 @@ xp_eval_step(xp_ctx *xc0,
xc->xc_descendant = 0;
}
else{
for (i=0; i<xc->xc_size; i++){
for (i=0; i<xc->xc_size; i++){
xv = xc->xc_nodeset[i];
x = NULL;
x = NULL;
if ((ret = xpath_optimize_check(xs, xv, &vec, &veclen)) < 0)
goto done;
if (ret == 0){/* regular code, no optimization made */
@ -358,7 +366,7 @@ xp_eval_step(xp_ctx *xc0,
goto done;
}
}
}
}
}
}
ctx_nodeset_replace(xc, vec, veclen);
@ -447,11 +455,13 @@ xp_eval_step(xp_ctx *xc0,
/*! Evaluate xpath predicates rule
*
* pred -> pred expr
* @param[in] xc Incoming context
* @param[in] xs XPATH node tree
* @param[in] nsc XML Namespace context
* @param[in] xc Incoming context
* @param[in] xs XPath node tree
* @param[in] nsc XML Namespace context
* @param[in] localonly Skip prefix and namespace tests (non-standard)
* @param[out] xrp Resulting context
* @param[out] xrp Resulting context
* @retval 0 OK
* @retval -1 Error
*
* A predicate filters a node-set with respect to an axis to produce a new
* node-set. For each node in the node-set to be filtered, the PredicateExpr is
@ -482,10 +492,10 @@ xp_eval_predicate(xp_ctx *xc,
int i;
cxobj *x;
xp_ctx *xcc = NULL;
if (xs->xs_c0 != NULL){ /* eval previous predicates */
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
goto done;
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
goto done;
}
else{ /* empty */
if ((xr0 = ctx_dup(xc)) == NULL)
@ -529,14 +539,14 @@ xp_eval_predicate(xp_ctx *xc,
if the number is equal to the context position */
if ((int)xrc->xc_number == i)
if (cxvec_append(x, &xr1->xc_nodeset, &xr1->xc_size) < 0)
goto done;
goto done;
}
else {
/* if PredicateExpr evaluates to true for that node, the node is
/* if PredicateExpr evaluates to true for that node, the node is
included in the new node-set */
if (ctx2boolean(xrc))
if (cxvec_append(x, &xr1->xc_nodeset, &xr1->xc_size) < 0)
goto done;
goto done;
}
if (xrc)
ctx_free(xrc);
@ -565,7 +575,8 @@ xp_eval_predicate(xp_ctx *xc,
return retval;
}
/*! Given two XPATH contexts, eval logical operations: or,and
/*! Given two XPath contexts, eval logical operations: or,and
*
* The logical operators convert their operands to booleans
* @param[in] xc1 Context of operand1
* @param[in] xc2 Context of operand2
@ -584,7 +595,7 @@ xp_logop(xp_ctx *xc1,
xp_ctx *xr = NULL;
int b1;
int b2;
if ((xr = malloc(sizeof(*xr))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
@ -614,7 +625,8 @@ xp_logop(xp_ctx *xc1,
return retval;
}
/*! Given two XPATH contexts, eval numeric operations: +-*,div,mod
/*! Given two XPath contexts, eval numeric operations: +-*,div,mod
*
* The numeric operators convert their operands to numbers as if by
* calling the number function.
* @param[in] xc1 Context of operand1
@ -634,7 +646,7 @@ xp_numop(xp_ctx *xc1,
xp_ctx *xr = NULL;
double n1;
double n2;
if ((xr = malloc(sizeof(*xr))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
@ -677,6 +689,7 @@ xp_numop(xp_ctx *xc1,
}
/*! Get xml body value as cligen variable
*
* @param[in] x XML node (body and leaf/leaf-list)
* @param[out] cvp Pointer to cligen variable containing value of x body
* @retval 0 OK, cvp contains cv or NULL
@ -700,7 +713,7 @@ xml_cv_cache(cxobj *x,
int options = 0;
uint8_t fraction = 0;
char *body;
if ((body = xml_body(x)) == NULL)
body="";
if ((cv = xml_cv(x)) != NULL)
@ -723,7 +736,6 @@ xml_cv_cache(cxobj *x,
}
if (cvtype == CGV_DEC64)
cv_dec64_n_set(cv, fraction);
if ((ret = cv_parse1(body, cv, &reason)) < 0){
clicon_err(OE_YANG, errno, "cv_parse1");
goto done;
@ -746,7 +758,8 @@ xml_cv_cache(cxobj *x,
return retval;
}
/*! Given two XPATH contexts, eval relational operations: <>=
/*! Given two XPath contexts, eval relational operations: <>=
*
* A RelationalExpr is evaluated by comparing the objects that result from
* evaluating the two operands.
* This is covered:
@ -755,7 +768,7 @@ xml_cv_cache(cxobj *x,
* (c) One is nodeset and other is INT or STRING. Result type is nodeset
* (d) All others (eg two nodesets, BOOL+STRING) are not supported.
* Op is = EQ
* From XPATH 1.0 standard, the evaluation has three variants:
* From XPath 1.0 standard, the evaluation has three variants:
* (1) comparisons that involve node-sets are defined in terms of comparisons that
* do not involve node-sets; this is defined uniformly for =, !=, <=, <, >= and >.
* (2) comparisons that do not involve node-sets are defined for = and !=.
@ -788,7 +801,7 @@ xp_relop(xp_ctx *xc1,
char *xb;
cg_var *cv1, *cv2;
int ret;
if (xc1 == NULL || xc2 == NULL){
clicon_err(OE_UNIX, EINVAL, "xc1 or xc2 NULL");
goto done;
@ -1056,7 +1069,8 @@ xp_relop(xp_ctx *xc1,
return retval;
}
/*! Given two XPATH contexts, eval union operation
/*! Given two XPath contexts, eval union operation
*
* Both operands must be nodesets, otherwise empty nodeset is returned
* @param[in] xc1 Context of operand1
* @param[in] xc2 Context of operand2
@ -1074,7 +1088,7 @@ xp_union(xp_ctx *xc1,
int retval = -1;
xp_ctx *xr = NULL;
int i;
if (op != XO_UNION){
clicon_err(OE_UNIX, errno, "%s:Invalid operator %s in this context",
__FUNCTION__, clicon_int2str(xpopmap,op));
@ -1101,12 +1115,12 @@ xp_union(xp_ctx *xc1,
return retval;
}
/*! Evaluate an XPATH on an XML tree
/*! Evaluate an XPath on an XML tree
*
* The initial sequence of steps selects a set of nodes relative to a context node.
* Each node in that set is used as a context node for the following step.
* @param[in] xc Incoming context
* @param[in] xs XPATH node tree
* @param[in] xs XPath node tree
* @param[in] nsc XML Namespace context
* @param[in] localonly Skip prefix and namespace tests (non-standard)
* @param[out] xrp Resulting context
@ -1126,7 +1140,7 @@ xp_eval(xp_ctx *xc,
xp_ctx *xr1 = NULL;
xp_ctx *xr2 = NULL;
int use_xr0 = 0; /* In 2nd child use transitively result of 1st child */
// ctx_print(stderr, xc, xpath_tree_int2str(xs->xs_type));
/* Pre-actions before check first child c0
*/
@ -1231,7 +1245,7 @@ xp_eval(xp_ctx *xc,
goto ok;
break;
default:
clicon_err(OE_XML, EFAULT, "XPATH function not implemented: %s", xs->xs_s0);
clicon_err(OE_XML, EFAULT, "XPath function not implemented: %s", xs->xs_s0);
goto done;
break;
}
@ -1243,7 +1257,7 @@ xp_eval(xp_ctx *xc,
/* Eval first child c0
*/
if (xs->xs_c0){
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
goto done;
}
/* Actions between first and second child
@ -1327,7 +1341,7 @@ xp_eval(xp_ctx *xc,
* Note, some operators like locationpath, need transitive context (use_xr0)
*/
if (xs->xs_c1){
if (xp_eval(use_xr0?xr0:xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
if (xp_eval(use_xr0?xr0:xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
goto done;
/* Actions after second child
*/