Skip to content

Commit eb60859

Browse files
committed
XPath functions, allow localname()
1 parent f636dc2 commit eb60859

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

lib/src/clixon_xpath_function.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,13 @@ xp_function_count(xp_ctx *xc,
655655
* or the first node has no expanded-name, an empty string is returned. If the argument is
656656
* omitted, it defaults to a node-set with the context node as its only member.
657657
* Signature: string local-name(node-set?)
658+
* @param[in] xc Incoming context
659+
* @param[in] xs XPath node tree
660+
* @param[in] nsc XML Namespace context
661+
* @param[in] localonly Skip prefix and namespace tests (non-standard)
662+
* @param[out] xrp Resulting context
663+
* @retval 0 OK
664+
* @retval -1 Error
658665
*/
659666
int
660667
xp_function_local_name(xp_ctx *xc,
@@ -672,12 +679,16 @@ xp_function_local_name(xp_ctx *xc,
672679
char *name;
673680
char *local_name;
674681

675-
if (xs == NULL || xs->xs_c0 == NULL){
676-
clixon_err(OE_XML, EINVAL, "not expects but did not get one argument");
677-
goto done;
682+
if (xs != NULL && xs->xs_c0){
683+
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
684+
goto done;
685+
}
686+
else{
687+
/* If the argument is omitted, it defaults to a node-set with the context node
688+
as its only member.*/
689+
if ((xr0 = ctx_dup(xc)) == NULL)
690+
goto done;
678691
}
679-
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
680-
goto done;
681692
if ((xr = malloc(sizeof(*xr))) == NULL){
682693
clixon_err(OE_UNIX, errno, "malloc");
683694
goto done;
@@ -846,8 +857,7 @@ xp_function_concat(xp_ctx *xc,
846857
int localonly,
847858
xp_ctx **xrp)
848859
{
849-
int retval = -1;
850-
860+
int retval = -1;
851861
xp_ctx *xr0 = NULL;
852862
xp_ctx *xr1 = NULL;
853863
xp_ctx *xr = NULL;
@@ -857,10 +867,10 @@ xp_function_concat(xp_ctx *xc,
857867
cbuf *cb = NULL;
858868

859869
if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){
860-
clixon_err(OE_XML, EINVAL, "contain expects but did not get at least two arguments");
870+
clixon_err(OE_XML, EINVAL, "concat expects but did not get at least two arguments");
861871
goto done;
862872
}
863-
/* contains two arguments in xs: boolean contains(string, string) */
873+
/* contains two arguments in xs: cncat contains(string, string) */
864874
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
865875
goto done;
866876
if (ctx2string(xr0, &s0) < 0)

0 commit comments

Comments
 (0)