Skip to content

Commit

Permalink
XPath: refactored XPath match, documented localonly and prefixonly api
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Dec 17, 2024
1 parent 6c73c36 commit 081a541
Show file tree
Hide file tree
Showing 13 changed files with 383 additions and 104 deletions.
5 changes: 5 additions & 0 deletions apps/backend/backend_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ get_list_pagination(clixon_handle h,
int j;
int ret;
dispatcher_entry_t *htable = NULL;
cvec *wherens = NULL;
// int extflag = 0;
#ifdef LIST_PAGINATION_REMAINING
cxobj *xcache;
Expand Down Expand Up @@ -715,6 +716,8 @@ get_list_pagination(clixon_handle h,
(where = xml_body(x)) != NULL){
if (strcmp(where, "unfiltered") == 0)
where = NULL;
else if (xml_nsctx_node(x, &wherens) < 0)
goto done;
}
/* then the "sort-by" parameter (see Section 3.1.2) */
if ((x = xml_find_type(xe, NULL, "sort-by", CX_ELMNT)) != NULL){
Expand Down Expand Up @@ -907,6 +910,8 @@ get_list_pagination(clixon_handle h,
ok:
retval = 0;
done:
if (wherens)
cvec_free(wherens);
if (xvec)
free(xvec);
if (cbmsg)
Expand Down
10 changes: 10 additions & 0 deletions include/clixon_custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,13 @@
* worse case an overwrite.
*/
#undef SYSTEM_ONLY_CONFIG_CANDIDATE_CLEAR

/*! In full XPath namespace resolve, match even if namespace not resolved
*
* In the case of xpath lookup functions (eg xpath_vec_ctx) where nsc is defined, then
* matching with XML requires equal namespaces.
* However, some code is OK with the XPATH NSC being unresolved to NULL, even if the XML
* namespace is defined.
* This seems wrong and should be changed, but need further investigation
*/
#define XPATH_NS_ACCEPT_UNRESOLVED
2 changes: 1 addition & 1 deletion lib/clixon/clixon_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static inline int clixon_debug_isset(unsigned n)
}

/* Is detail set ?, return detail level 0-7 */
static inline int clixon_debug_detail()
static inline int clixon_debug_detail(void)
{
unsigned level = clixon_debug_get();

Expand Down
2 changes: 1 addition & 1 deletion lib/clixon/clixon_xml_nsctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int xml_nsctx_node(cxobj *x, cvec **ncp);
int xml_nsctx_yang(yang_stmt *yn, cvec **ncp);
int xml_nsctx_yangspec(yang_stmt *yspec, cvec **ncp);
int xml_nsctx_cbuf(cbuf *cb, cvec *nsc);
int xml2ns(cxobj *x, char *localname, char **ns);
int xml2ns(cxobj *x, char *prefix, char **ns);
int xml2ns_recurse(cxobj *x);
int xmlns_set(cxobj *x, char *prefix, char *ns);
int xmlns_set_all(cxobj *x, cvec *nsc);
Expand Down
2 changes: 1 addition & 1 deletion lib/clixon/clixon_xpath.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int xpath_tree_eq(xpath_tree *xt1, xpath_tree *xt2, xpath_tree ***vec, size_t
xpath_tree *xpath_tree_traverse(xpath_tree *xt, ...);
int xpath_tree_free(xpath_tree *xs);
int xpath_parse(const char *xpath, xpath_tree **xptree);
int xpath_vec_ctx(cxobj *xcur, cvec *nsc, const char *xpath, int localonly, xp_ctx **xrp);
int xpath_vec_ctx(cxobj *xcur, cvec *nsc, const char *xpath, int localonly, xp_ctx **xrp);

int xpath_vec_bool(cxobj *xcur, cvec *nsc, const char *xpformat, ...) __attribute__ ((format (printf, 3, 4)));
int xpath_vec_flag(cxobj *xcur, cvec *nsc, const char *xpformat, uint16_t flags,
Expand Down
4 changes: 3 additions & 1 deletion lib/clixon/clixon_xpath_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ enum xp_objtype{
XT_STRING
};

/* Expression evaluation occurs with respect to a context. XSLT and XPointer specify how the
/*! XPath context and result
*
* Expression evaluation occurs with respect to a context. XSLT and XPointer specify how the
* context is determined for XPath expressions used in XSLT and XPointer respectively. The
* context consists of:
* a node (the context node)
Expand Down
11 changes: 7 additions & 4 deletions lib/src/clixon_xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@
* of the xpath-tree, which is context-dependent.
* Best is to send it as a (read-only) parameter to the xp_eval family of functions
* as an exlicit namespace context.
*
* 3) localonly flag refers to https://www.w3.org/TR/REC-xml-names/, where :
* PrefixedName ::= Prefix ':' LocalPart
* "localonly" means to skip the "Prefix" part, ie namespaces
* see nodetest_eval_node() for the semantics of prefix/namespace processing
*/
#ifdef HAVE_CONFIG_H
#include "clixon_config.h" /* generated by config & autoconf */
Expand Down Expand Up @@ -328,8 +331,8 @@ xpath_tree2cbuf(xpath_tree *xs,
cprintf(xcb, "%s", clicon_int2str(xpopmap, xs->xs_int));
break;
case XP_PATHEXPR:
/* [19] PathExpr ::= | FilterExpr '/' RelativeLocationPath
| FilterExpr '//' RelativeLocationPath
/* [19] PathExpr ::= | FilterExpr '/' RelativeLocationPath
| FilterExpr '//' RelativeLocationPath
*/
if (xs->xs_s0)
cprintf(xcb, "%s", xs->xs_s0);
Expand Down Expand Up @@ -608,7 +611,7 @@ xpath_parse(const char *xpath,
* @param[in] xcur XML-tree where to search
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpath String with XPath 1.0 syntax
* @param[in] localonly Skip prefix and namespace tests (non-standard)
* @param[in] localonly Skip prefix and namespace tests
* @param[out] xrp Return XPath context
* @retval 0 OK
* @retval -1 Error
Expand Down
Loading

0 comments on commit 081a541

Please sign in to comment.