1 /* 2 * 3 ***** BEGIN LICENSE BLOCK ***** 4 5 Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren 6 Copyright (C) 2017-2020 Olof Hagsand 7 8 This file is part of CLIXON. 9 10 Licensed under the Apache License, Version 2.0 (the "License"); 11 you may not use this file except in compliance with the License. 12 You may obtain a copy of the License at 13 14 http://www.apache.org/licenses/LICENSE-2.0 15 16 Unless required by applicable law or agreed to in writing, software 17 distributed under the License is distributed on an "AS IS" BASIS, 18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 See the License for the specific language governing permissions and 20 limitations under the License. 21 22 Alternatively, the contents of this file may be used under the terms of 23 the GNU General Public License Version 3 or later (the "GPL"), 24 in which case the provisions of the GPL are applicable instead 25 of those above. If you wish to allow use of your version of this file only 26 under the terms of the GPL, and not to allow others to 27 use your version of this file under the terms of Apache License version 2, 28 indicate your decision by deleting the provisions above and replace them with 29 the notice and other provisions required by the GPL. If you do not delete 30 the provisions above, a recipient may use your version of this file under 31 the terms of any one of the Apache License version 2 or the GPL. 32 33 ***** END LICENSE BLOCK ***** 34 35 * Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10 36 * This file defines XPATH contexts using in traversing the XPATH parse tree. 37 */ 38 #ifndef _CLIXON_XPATH_CTX_H 39 #define _CLIXON_XPATH_CTX_H 40 41 /* 42 * Types 43 */ 44 45 /*! XPATH expression type 46 * An expression is evaluated to yield an object, which has one of the following four basic types: 47 * node-set (an unordered collection of nodes without duplicates) 48 * boolean (true or false) 49 * number (a floating-point number) 50 * string (a sequence of UCS characters) 51 */ 52 enum xp_objtype{ 53 XT_NODESET, 54 XT_BOOL, 55 XT_NUMBER, 56 XT_STRING 57 }; 58 59 /* Expression evaluation occurs with respect to a context. XSLT and XPointer specify how the 60 * context is determined for XPath expressions used in XSLT and XPointer respectively. The 61 * context consists of: 62 * a node (the context node) 63 * a pair of non-zero positive integers (the context position and the context size) 64 * a set of variable bindings 65 * a function library 66 * the set of namespace declarations in scope for the expression 67 68 * For each node in the node-set to be filtered, the PredicateExpr is 69 * evaluated with that node as the context node, with the number of nodes 70 * in the node-set as the context size, and with the proximity position 71 * of the node in the node-set with respect to the axis as the context 72 * position; if PredicateExpr evaluates to true for that node, the node 73 * is included in the new node-set; otherwise, it is not included. 74 */ 75 struct xp_ctx{ 76 enum xp_objtype xc_type; 77 cxobj **xc_nodeset; /* if type XT_NODESET */ 78 int xc_size; /* Length of nodeset */ 79 int xc_bool; /* if xc_type XT_BOOL */ 80 double xc_number; /* if xc_type XT_NUMBER */ 81 char *xc_string; /* if xc_type XT_STRING */ 82 cxobj *xc_node; /* Node in nodeset XXX maybe not needed*/ 83 cxobj *xc_initial; /* RFC 7960 10.1.1 extension: for current() */ 84 int xc_descendant; /* // */ 85 /* NYI: a set of variable bindings, set of namespace declarations */ 86 }; 87 typedef struct xp_ctx xp_ctx; 88 89 /* 90 * Variables 91 */ 92 extern const map_str2int ctxmap[]; 93 94 /* 95 * Prototypes 96 */ 97 int ctx_free(xp_ctx *xc); 98 xp_ctx *ctx_dup(xp_ctx *xc); 99 int ctx_nodeset_replace(xp_ctx *xc, cxobj **vec, size_t veclen); 100 int ctx_print_cb(cbuf *cb, xp_ctx *xc, int indent, char *str); 101 int ctx_print(FILE *f, xp_ctx *xc, char *str); 102 int ctx2boolean(xp_ctx *xc); 103 int ctx2string(xp_ctx *xc, char **str0); 104 int ctx2number(xp_ctx *xc, double *n0); 105 106 #endif /* _CLIXON_XPATH_CTX_H */ 107