Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 1 | /** |
| 2 | * @file xpath.h |
| 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * @brief YANG XPath evaluation functions header |
| 5 | * |
Michal Vasko | 306e283 | 2022-07-25 09:15:17 +0200 | [diff] [blame] | 6 | * Copyright (c) 2015 - 2022 CESNET, z.s.p.o. |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
Michal Vasko | 1467635 | 2020-05-29 11:35:55 +0200 | [diff] [blame] | 15 | #ifndef LY_XPATH_H |
| 16 | #define LY_XPATH_H |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 17 | |
Radek Krejci | ad97c5f | 2020-06-30 09:19:28 +0200 | [diff] [blame] | 18 | #include <stddef.h> |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 19 | #include <stdint.h> |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 20 | |
Michal Vasko | c5a2283 | 2020-08-20 13:21:33 +0200 | [diff] [blame] | 21 | #include "compat.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 22 | #include "log.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 23 | #include "tree.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 24 | #include "tree_schema.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 25 | |
| 26 | struct ly_ctx; |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 27 | struct lyd_node; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 28 | |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 29 | /** |
| 30 | * @internal |
| 31 | * @page internals |
| 32 | * @section internalsXpath XPath Implementation |
| 33 | * |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 34 | * XPath evaluator fully compliant with http://www.w3.org/TR/1999/REC-xpath-19991116/ |
| 35 | * except the following restrictions in the grammar. |
| 36 | * |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 37 | * @subsection internalsXpathGrammar Parsed Grammar |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 38 | * |
| 39 | * Full axes are not supported, abbreviated forms must be used, |
aPiecek | fba7536 | 2021-10-07 12:39:48 +0200 | [diff] [blame] | 40 | * "id()" function is not supported, and processing instruction and comment nodes are not supported, |
| 41 | * which is also reflected in the grammar. Undefined rules and constants are tokens. |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 42 | * |
| 43 | * Modified full grammar: |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 44 | * @code |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 45 | * [1] Expr ::= OrExpr // just an alias |
| 46 | * |
| 47 | * [2] LocationPath ::= RelativeLocationPath | AbsoluteLocationPath |
| 48 | * [3] AbsoluteLocationPath ::= '/' RelativeLocationPath? | '//' RelativeLocationPath |
| 49 | * [4] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | RelativeLocationPath '//' Step |
Michal Vasko | 49fec8e | 2022-05-24 10:28:33 +0200 | [diff] [blame] | 50 | * [5] Step ::= (AxisName '::' | '@')? NodeTest Predicate* | '.' | '..' |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 51 | * [6] NodeTest ::= NameTest | NodeType '(' ')' |
Michal Vasko | d367889 | 2020-05-21 10:06:58 +0200 | [diff] [blame] | 52 | * [7] NameTest ::= '*' | NCName ':' '*' | QName |
| 53 | * [8] NodeType ::= 'text' | 'node' |
| 54 | * [9] Predicate ::= '[' Expr ']' |
aPiecek | fba7536 | 2021-10-07 12:39:48 +0200 | [diff] [blame] | 55 | * [10] PrimaryExpr ::= VariableReference | '(' Expr ')' | Literal | Number | FunctionCall |
Michal Vasko | d367889 | 2020-05-21 10:06:58 +0200 | [diff] [blame] | 56 | * [11] FunctionCall ::= FunctionName '(' ( Expr ( ',' Expr )* )? ')' |
| 57 | * [12] PathExpr ::= LocationPath | PrimaryExpr Predicate* |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 58 | * | PrimaryExpr Predicate* '/' RelativeLocationPath |
| 59 | * | PrimaryExpr Predicate* '//' RelativeLocationPath |
Michal Vasko | d367889 | 2020-05-21 10:06:58 +0200 | [diff] [blame] | 60 | * [13] OrExpr ::= AndExpr | OrExpr 'or' AndExpr |
| 61 | * [14] AndExpr ::= EqualityExpr | AndExpr 'and' EqualityExpr |
| 62 | * [15] EqualityExpr ::= RelationalExpr | EqualityExpr '=' RelationalExpr |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 63 | * | EqualityExpr '!=' RelationalExpr |
Michal Vasko | d367889 | 2020-05-21 10:06:58 +0200 | [diff] [blame] | 64 | * [16] RelationalExpr ::= AdditiveExpr |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 65 | * | RelationalExpr '<' AdditiveExpr |
| 66 | * | RelationalExpr '>' AdditiveExpr |
| 67 | * | RelationalExpr '<=' AdditiveExpr |
| 68 | * | RelationalExpr '>=' AdditiveExpr |
Michal Vasko | d367889 | 2020-05-21 10:06:58 +0200 | [diff] [blame] | 69 | * [17] AdditiveExpr ::= MultiplicativeExpr |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 70 | * | AdditiveExpr '+' MultiplicativeExpr |
| 71 | * | AdditiveExpr '-' MultiplicativeExpr |
Michal Vasko | d367889 | 2020-05-21 10:06:58 +0200 | [diff] [blame] | 72 | * [18] MultiplicativeExpr ::= UnaryExpr |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 73 | * | MultiplicativeExpr '*' UnaryExpr |
| 74 | * | MultiplicativeExpr 'div' UnaryExpr |
| 75 | * | MultiplicativeExpr 'mod' UnaryExpr |
Michal Vasko | d367889 | 2020-05-21 10:06:58 +0200 | [diff] [blame] | 76 | * [19] UnaryExpr ::= UnionExpr | '-' UnaryExpr |
| 77 | * [20] UnionExpr ::= PathExpr | UnionExpr '|' PathExpr |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 78 | * @endcode |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 79 | */ |
| 80 | |
| 81 | /* expression tokens allocation */ |
| 82 | #define LYXP_EXPR_SIZE_START 10 |
| 83 | #define LYXP_EXPR_SIZE_STEP 5 |
| 84 | |
| 85 | /* XPath matches allocation */ |
Michal Vasko | 871df52 | 2022-04-06 12:14:41 +0200 | [diff] [blame] | 86 | #define LYXP_SET_SIZE_START 4 |
| 87 | #define LYXP_SET_SIZE_MUL_STEP 2 |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 88 | |
| 89 | /* building string when casting */ |
| 90 | #define LYXP_STRING_CAST_SIZE_START 64 |
| 91 | #define LYXP_STRING_CAST_SIZE_STEP 16 |
| 92 | |
aPiecek | bf968d9 | 2021-05-27 14:35:05 +0200 | [diff] [blame] | 93 | /* Maximum number of nested expressions. */ |
| 94 | #define LYXP_MAX_BLOCK_DEPTH 100 |
| 95 | |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 96 | /** |
| 97 | * @brief Tokens that can be in an XPath expression. |
| 98 | */ |
| 99 | enum lyxp_token { |
| 100 | LYXP_TOKEN_NONE = 0, |
| 101 | LYXP_TOKEN_PAR1, /* '(' */ |
| 102 | LYXP_TOKEN_PAR2, /* ')' */ |
| 103 | LYXP_TOKEN_BRACK1, /* '[' */ |
| 104 | LYXP_TOKEN_BRACK2, /* ']' */ |
| 105 | LYXP_TOKEN_DOT, /* '.' */ |
| 106 | LYXP_TOKEN_DDOT, /* '..' */ |
| 107 | LYXP_TOKEN_AT, /* '@' */ |
| 108 | LYXP_TOKEN_COMMA, /* ',' */ |
Michal Vasko | 49fec8e | 2022-05-24 10:28:33 +0200 | [diff] [blame] | 109 | LYXP_TOKEN_DCOLON, /* '::' */ |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 110 | LYXP_TOKEN_NAMETEST, /* NameTest */ |
| 111 | LYXP_TOKEN_NODETYPE, /* NodeType */ |
aPiecek | fba7536 | 2021-10-07 12:39:48 +0200 | [diff] [blame] | 112 | LYXP_TOKEN_VARREF, /* VariableReference */ |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 113 | LYXP_TOKEN_FUNCNAME, /* FunctionName */ |
Michal Vasko | 3e48bf3 | 2020-06-01 08:39:07 +0200 | [diff] [blame] | 114 | LYXP_TOKEN_OPER_LOG, /* Operator 'and', 'or' */ |
| 115 | LYXP_TOKEN_OPER_EQUAL, /* Operator '=' */ |
| 116 | LYXP_TOKEN_OPER_NEQUAL, /* Operator '!=' */ |
| 117 | LYXP_TOKEN_OPER_COMP, /* Operator '<', '<=', '>', '>=' */ |
| 118 | LYXP_TOKEN_OPER_MATH, /* Operator '+', '-', '*', 'div', 'mod', '-' (unary) */ |
| 119 | LYXP_TOKEN_OPER_UNI, /* Operator '|' */ |
| 120 | LYXP_TOKEN_OPER_PATH, /* Operator '/' */ |
| 121 | LYXP_TOKEN_OPER_RPATH, /* Operator '//' (recursive path) */ |
Michal Vasko | 49fec8e | 2022-05-24 10:28:33 +0200 | [diff] [blame] | 122 | LYXP_TOKEN_AXISNAME, /* AxisName */ |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 123 | LYXP_TOKEN_LITERAL, /* Literal - with either single or double quote */ |
| 124 | LYXP_TOKEN_NUMBER /* Number */ |
| 125 | }; |
| 126 | |
| 127 | /** |
Michal Vasko | 49fec8e | 2022-05-24 10:28:33 +0200 | [diff] [blame] | 128 | * @brief XPath Axes types. |
| 129 | */ |
| 130 | enum lyxp_axis { |
| 131 | LYXP_AXIS_ANCESTOR, |
| 132 | LYXP_AXIS_ANCESTOR_OR_SELF, |
| 133 | LYXP_AXIS_ATTRIBUTE, |
| 134 | LYXP_AXIS_CHILD, |
| 135 | LYXP_AXIS_DESCENDANT, |
| 136 | LYXP_AXIS_DESCENDANT_OR_SELF, |
| 137 | LYXP_AXIS_FOLLOWING, |
| 138 | LYXP_AXIS_FOLLOWING_SIBLING, |
| 139 | // LYXP_AXIS_NAMESPACE, /* not supported */ |
| 140 | LYXP_AXIS_PARENT, |
| 141 | LYXP_AXIS_PRECEDING, |
| 142 | LYXP_AXIS_PRECEDING_SIBLING, |
| 143 | LYXP_AXIS_SELF |
| 144 | }; |
| 145 | |
| 146 | /** |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 147 | * @brief XPath (sub)expressions that can be repeated. |
| 148 | */ |
| 149 | enum lyxp_expr_type { |
| 150 | LYXP_EXPR_NONE = 0, |
| 151 | LYXP_EXPR_OR, |
| 152 | LYXP_EXPR_AND, |
| 153 | LYXP_EXPR_EQUALITY, |
| 154 | LYXP_EXPR_RELATIONAL, |
| 155 | LYXP_EXPR_ADDITIVE, |
| 156 | LYXP_EXPR_MULTIPLICATIVE, |
| 157 | LYXP_EXPR_UNARY, |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 158 | LYXP_EXPR_UNION |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | /** |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 162 | * @brief Types of context nodes, #LYXP_NODE_ROOT_CONFIG used only in when or must conditions. |
| 163 | */ |
| 164 | enum lyxp_node_type { |
Michal Vasko | 2caefc1 | 2019-11-14 16:07:56 +0100 | [diff] [blame] | 165 | LYXP_NODE_NONE, /* invalid node type */ |
| 166 | |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 167 | /* XML document roots */ |
| 168 | LYXP_NODE_ROOT, /* access to all the data (node value first top-level node) */ |
| 169 | LYXP_NODE_ROOT_CONFIG, /* <running> data context, no state data (node value first top-level node) */ |
| 170 | |
| 171 | /* XML elements */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 172 | LYXP_NODE_ELEM, /* YANG data element (most common) */ |
| 173 | LYXP_NODE_TEXT, /* YANG data text element (extremely specific use, unlikely to be ever needed) */ |
| 174 | LYXP_NODE_META /* YANG metadata (do not use for the context node) */ |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | /** |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 178 | * @brief Structure holding a parsed XPath expression. |
| 179 | */ |
| 180 | struct lyxp_expr { |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 181 | enum lyxp_token *tokens; /**< Array of tokens. */ |
Michal Vasko | dd528af | 2022-08-08 14:35:07 +0200 | [diff] [blame] | 182 | uint32_t *tok_pos; /**< Array of the token offsets in expr. */ |
| 183 | uint32_t *tok_len; /**< Array of token lengths in expr. */ |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 184 | enum lyxp_expr_type **repeat; /**< Array of expression types that this token begins and is repeated ended with 0, |
| 185 | more in the comment after this declaration. */ |
Michal Vasko | dd528af | 2022-08-08 14:35:07 +0200 | [diff] [blame] | 186 | uint32_t used; /**< Used array items. */ |
| 187 | uint32_t size; /**< Allocated array items. */ |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 188 | |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 189 | const char *expr; /**< The original XPath expression. */ |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | /* |
| 193 | * lyxp_expr repeat |
| 194 | * |
| 195 | * This value is NULL for all the tokens that do not begin an |
| 196 | * expression which can be repeated. Otherwise it is an array |
| 197 | * of expression types that this token begins. These values |
| 198 | * are used during evaluation to know whether we need to |
| 199 | * duplicate the current context or not and to decide what |
| 200 | * the current expression is (for example, if we are only |
| 201 | * starting the parsing and the first token has no repeat, |
| 202 | * we do not parse it as an OrExpr but directly as PathExpr). |
| 203 | * Examples: |
| 204 | * |
aPiecek | ff49d76 | 2021-10-11 10:25:27 +0200 | [diff] [blame] | 205 | * Expr: "/ *[key1 and key2 or key1 < key2]" |
| 206 | * Tokens: '/' '*' '[' NameTest 'and' NameTest 'or' NameTest '<' NameTest ']' |
| 207 | * Repeat: NULL NULL NULL _ NULL NULL NULL _ NULL NULL NULL |
| 208 | * | v |
| 209 | * v RelationalExpr 0 |
| 210 | * AndExpr OrExpr 0 |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 211 | * |
aPiecek | ff49d76 | 2021-10-11 10:25:27 +0200 | [diff] [blame] | 212 | * Expr: "//node[key and node2]/key | /cont" |
| 213 | * Tokens: '//' NameTest '[' NameTest 'and' NameTest ']' '/' NameTest '|' '/' NameTest |
| 214 | * Repeat: _ NULL NULL _ NULL NULL NULL NULL NULL NULL NULL NULL |
| 215 | * | v |
| 216 | * v AndExpr 0 |
| 217 | * UnionExpr 0 |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 218 | * |
| 219 | * Operators between expressions which this concerns: |
| 220 | * 'or', 'and', '=', '!=', '<', '>', '<=', '>=', '+', '-', '*', 'div', 'mod', '|' |
| 221 | */ |
| 222 | |
| 223 | /** |
| 224 | * @brief Supported types of (partial) XPath results. |
| 225 | */ |
| 226 | enum lyxp_set_type { |
Michal Vasko | d367889 | 2020-05-21 10:06:58 +0200 | [diff] [blame] | 227 | LYXP_SET_NODE_SET = 0, |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 228 | LYXP_SET_SCNODE_SET, |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 229 | LYXP_SET_BOOLEAN, |
| 230 | LYXP_SET_NUMBER, |
| 231 | LYXP_SET_STRING |
| 232 | }; |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 233 | |
| 234 | /** |
| 235 | * @brief Item stored in an XPath set hash table. |
| 236 | */ |
| 237 | struct lyxp_set_hash_node { |
| 238 | struct lyd_node *node; |
| 239 | enum lyxp_node_type type; |
| 240 | } _PACKED; |
| 241 | |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 242 | /** |
aPiecek | df23eee | 2021-10-07 12:21:50 +0200 | [diff] [blame] | 243 | * @brief XPath variable bindings. |
| 244 | */ |
| 245 | struct lyxp_var { |
| 246 | char *name; /**< Variable name. In the XPath expression, the name is preceded by a '$' character. */ |
| 247 | char *value; /**< The value of a variable is an object, which can be of any of the type that are possible |
| 248 | for the value of an expression. */ |
| 249 | }; |
| 250 | |
| 251 | /** |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 252 | * @brief XPath set - (partial) result. |
| 253 | */ |
| 254 | struct lyxp_set { |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 255 | enum lyxp_set_type type; /**< Type of the object (value). */ |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 256 | |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 257 | union { |
| 258 | struct lyxp_set_node { |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 259 | struct lyd_node *node; /**< Data node. */ |
| 260 | enum lyxp_node_type type; /**< Type of the node. */ |
| 261 | uint32_t pos; /**< Unique node position in the data. */ |
| 262 | } *nodes; /**< Set of data nodes. */ |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 263 | struct lyxp_set_scnode { |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 264 | struct lysc_node *scnode; /**< Compiled YANG node. */ |
| 265 | enum lyxp_node_type type; /**< Type of the node. */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 266 | |
Michal Vasko | d97959c | 2020-12-10 12:18:28 +0100 | [diff] [blame] | 267 | /* _START and _ATOM values should have grouped values */ |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 268 | #define LYXP_SET_SCNODE_START -2 /**< scnode not traversed, currently (the only node) in context */ |
| 269 | #define LYXP_SET_SCNODE_START_USED -1 /**< scnode not traversed except for the eval start, not currently in the context */ |
Michal Vasko | 1a09b21 | 2021-05-06 13:00:10 +0200 | [diff] [blame] | 270 | #define LYXP_SET_SCNODE_ATOM_NODE 0 /**< scnode was traversed, but not currently in the context */ |
| 271 | #define LYXP_SET_SCNODE_ATOM_VAL 1 /**< scnode was traversed and its value used, but not currently in the context */ |
| 272 | #define LYXP_SET_SCNODE_ATOM_CTX 2 /**< scnode currently in context */ |
| 273 | #define LYXP_SET_SCNODE_ATOM_NEW_CTX 3 /**< scnode in context and just added, so skip it for the current operation */ |
| 274 | #define LYXP_SET_SCNODE_ATOM_PRED_CTX 4 /**< includes any higher value - scnode is not in context because we are in |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 275 | a predicate and this scnode was used/will be used later */ |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 276 | int32_t in_ctx; /**< Flag specifies the state of the node in context. Values are defined |
| 277 | as LYXP_SET_SCNODE_* */ |
Michal Vasko | 7333cb3 | 2022-07-29 16:30:29 +0200 | [diff] [blame] | 278 | enum lyxp_axis axis; /**< Axis defines on what axis was this schema node reached. */ |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 279 | } *scnodes; /**< Set of compiled YANG data nodes. */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 280 | struct lyxp_set_meta { |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 281 | struct lyd_meta *meta; /**< Node that provides information about metadata of a data element. */ |
| 282 | enum lyxp_node_type type; /**< Type of the node. */ |
| 283 | uint32_t pos; /**< Unique node position in the data. if node_type is LYXP_SET_NODE_META, |
| 284 | it is the parent node position */ |
| 285 | } *meta; /**< Set of YANG metadata objects. */ |
| 286 | char *str; /**< String object. */ |
| 287 | long double num; /**< Object of the floating-point number. */ |
| 288 | ly_bool bln; /**< Boolean object. */ |
| 289 | } val; /**< Evaluated object (value). */ |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 290 | |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 291 | /* this is valid only for type LYXP_SET_NODE_SET and LYXP_SET_SCNODE_SET */ |
Michal Vasko | 306e283 | 2022-07-25 09:15:17 +0200 | [diff] [blame] | 292 | uint32_t used; /**< Number of nodes in the set. */ |
| 293 | uint32_t size; /**< Allocated size for the set. */ |
| 294 | struct hash_table *ht; /**< Hash table for quick determination of whether a node is in the set. */ |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 295 | |
| 296 | /* XPath context information, this is valid only for type LYXP_SET_NODE_SET */ |
Michal Vasko | 306e283 | 2022-07-25 09:15:17 +0200 | [diff] [blame] | 297 | uint32_t ctx_pos; /**< Position of the current examined node in the set. */ |
| 298 | uint32_t ctx_size; /**< Position of the last node at the time the node was examined. */ |
| 299 | ly_bool non_child_axis; /**< Whether any node change was performed on a non-child axis. */ |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 300 | |
| 301 | /* general context */ |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 302 | struct ly_ctx *ctx; /**< General context for logging. */ |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 303 | |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 304 | union { |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 305 | const struct lyd_node *cur_node; /**< Current (original context) node. */ |
| 306 | const struct lysc_node *cur_scnode; /**< Current (original context) compiled node. */ |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 307 | }; |
aPiecek | 6da713d | 2021-10-11 12:50:28 +0200 | [diff] [blame] | 308 | enum lyxp_node_type root_type; /**< Type of root node. */ |
| 309 | const struct lysc_node *context_op; /**< Schema of the current node. */ |
| 310 | const struct lyd_node *tree; /**< Data tree on which to perform the evaluation. */ |
| 311 | const struct lys_module *cur_mod; /**< Current module for the expression (where it was "instantiated"). */ |
| 312 | LY_VALUE_FORMAT format; /**< Format of the XPath expression. */ |
| 313 | void *prefix_data; /**< Format-specific prefix data (see ::ly_resolve_prefix). */ |
aPiecek | fba7536 | 2021-10-07 12:39:48 +0200 | [diff] [blame] | 314 | const struct lyxp_var *vars; /**< XPath variables. [Sized array](@ref sizedarrays). |
| 315 | Set of variable bindings. */ |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | /** |
Michal Vasko | 49fec8e | 2022-05-24 10:28:33 +0200 | [diff] [blame] | 319 | * @brief Get string format of an XPath token. |
Michal Vasko | 24cddf8 | 2020-06-01 08:17:01 +0200 | [diff] [blame] | 320 | * |
Michal Vasko | 49fec8e | 2022-05-24 10:28:33 +0200 | [diff] [blame] | 321 | * @param[in] tok Token to transform. |
Michal Vasko | 24cddf8 | 2020-06-01 08:17:01 +0200 | [diff] [blame] | 322 | * @return Token type string. |
| 323 | */ |
Michal Vasko | 49fec8e | 2022-05-24 10:28:33 +0200 | [diff] [blame] | 324 | const char *lyxp_token2str(enum lyxp_token tok); |
Michal Vasko | 24cddf8 | 2020-06-01 08:17:01 +0200 | [diff] [blame] | 325 | |
| 326 | /** |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 327 | * @brief Evaluate an XPath expression on data. Be careful when using this function, the result can often |
| 328 | * be confusing without thorough understanding of XPath evaluation rules defined in RFC 7950. |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 329 | * |
Michal Vasko | 400e967 | 2021-01-11 13:39:17 +0100 | [diff] [blame] | 330 | * @param[in] ctx libyang context to use. |
Michal Vasko | ecd62de | 2019-11-13 12:35:11 +0100 | [diff] [blame] | 331 | * @param[in] exp Parsed XPath expression to be evaluated. |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 332 | * @param[in] cur_mod Current module for the expression (where it was "instantiated"). |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 333 | * @param[in] format Format of the XPath expression (more specifically, of any used prefixes). |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 334 | * @param[in] prefix_data Format-specific prefix data (see ::ly_resolve_prefix). |
Michal Vasko | a3e92bc | 2022-07-29 14:56:23 +0200 | [diff] [blame] | 335 | * @param[in] cur_node Current data node, NULL in case of the root node. Equal to @p ctx_node unless a |
| 336 | * subexpression is being evaluated. |
| 337 | * @param[in] ctx_node Starting context data node, NULL in case of the root node. Equal to @p cur_node unless a |
| 338 | * subexpression is being evaluated. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 339 | * @param[in] tree Data tree on which to perform the evaluation, it must include all the available data (including |
Michal Vasko | d3bb12f | 2020-12-04 14:33:09 +0100 | [diff] [blame] | 340 | * the tree of @p ctx_node). Can be any node of the tree, it is adjusted. |
aPiecek | fba7536 | 2021-10-07 12:39:48 +0200 | [diff] [blame] | 341 | * @param[in] vars [Sized array](@ref sizedarrays) of XPath variables. |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 342 | * @param[out] set Result set. |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 343 | * @param[in] options Whether to apply some evaluation restrictions. |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 344 | * @return LY_EVALID for invalid argument types/count, |
| 345 | * @return LY_EINCOMPLETE for unresolved when, |
| 346 | * @return LY_EINVAL, LY_EMEM, LY_EINT for other errors. |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 347 | */ |
Michal Vasko | 400e967 | 2021-01-11 13:39:17 +0100 | [diff] [blame] | 348 | LY_ERR lyxp_eval(const struct ly_ctx *ctx, const struct lyxp_expr *exp, const struct lys_module *cur_mod, |
Michal Vasko | a3e92bc | 2022-07-29 14:56:23 +0200 | [diff] [blame] | 349 | LY_VALUE_FORMAT format, void *prefix_data, const struct lyd_node *cur_node, const struct lyd_node *ctx_node, |
| 350 | const struct lyd_node *tree, const struct lyxp_var *vars, struct lyxp_set *set, uint32_t options); |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 351 | |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 352 | /** |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 353 | * @brief Get all the partial XPath nodes (atoms) that are required for @p exp to be evaluated. |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 354 | * |
Michal Vasko | 400e967 | 2021-01-11 13:39:17 +0100 | [diff] [blame] | 355 | * @param[in] ctx libyang context to use. |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 356 | * @param[in] exp Parsed XPath expression to be evaluated. |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 357 | * @param[in] cur_mod Current module for the expression (where it was "instantiated"). |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 358 | * @param[in] format Format of the XPath expression (more specifically, of any used prefixes). |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 359 | * @param[in] prefix_data Format-specific prefix data (see ::ly_resolve_prefix). |
Michal Vasko | a3e92bc | 2022-07-29 14:56:23 +0200 | [diff] [blame] | 360 | * @param[in] cur_scnode Current schema node, NULL in case of the root node. Equal to @p ctx_scnode unless a |
| 361 | * subexpression is being atomized. |
| 362 | * @param[in] ctx_scnode Starting context schema node, NULL in case of the root node. Equal to @p cur_scnode unless a |
| 363 | * subexpression is being atomized. |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 364 | * @param[out] set Result set. |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 365 | * @param[in] options Whether to apply some evaluation restrictions, one flag must always be used. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 366 | * @return LY_ERR (same as ::lyxp_eval()). |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 367 | */ |
Michal Vasko | 400e967 | 2021-01-11 13:39:17 +0100 | [diff] [blame] | 368 | LY_ERR lyxp_atomize(const struct ly_ctx *ctx, const struct lyxp_expr *exp, const struct lys_module *cur_mod, |
Michal Vasko | a3e92bc | 2022-07-29 14:56:23 +0200 | [diff] [blame] | 369 | LY_VALUE_FORMAT format, void *prefix_data, const struct lysc_node *cur_scnode, |
| 370 | const struct lysc_node *ctx_scnode, struct lyxp_set *set, uint32_t options); |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 371 | |
Michal Vasko | 4ad69e7 | 2021-10-26 16:25:55 +0200 | [diff] [blame] | 372 | /** used only internally, maps with @ref findxpathoptions */ |
Michal Vasko | a27245c | 2022-05-02 09:01:35 +0200 | [diff] [blame] | 373 | #define LYXP_IGNORE_WHEN 0x01 /**< Ignore unevaluated when in data nodes and do not return ::LY_EINCOMPLETE. */ |
| 374 | #define LYXP_SCHEMA 0x02 /**< Apply data node access restrictions defined for 'when' and 'must' evaluation. */ |
| 375 | #define LYXP_SCNODE 0x04 /**< No special tree access modifiers. */ |
| 376 | #define LYXP_SCNODE_SCHEMA LYS_FIND_XP_SCHEMA /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */ |
| 377 | #define LYXP_SCNODE_OUTPUT LYS_FIND_XP_OUTPUT /**< Search RPC/action output nodes instead of input ones. */ |
| 378 | #define LYXP_SCNODE_ALL 0x1C /**< mask for all the LYXP_* values */ |
| 379 | #define LYXP_SKIP_EXPR 0x20 /**< The rest of the expression will not be evaluated (lazy evaluation) */ |
| 380 | #define LYXP_SCNODE_ERROR LYS_FIND_NO_MATCH_ERROR /**< Return error if a path segment matches no nodes, otherwise only |
| 381 | warning is printed. */ |
| 382 | #define LYXP_ACCESS_TREE_ALL 0x80 /**< Explicit accessible tree of all the nodes. */ |
| 383 | #define LYXP_ACCESS_TREE_CONFIG 0x0100 /**< Explicit accessible tree of only configuration data. */ |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 384 | |
| 385 | /** |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 386 | * @brief Cast XPath set to another type. |
| 387 | * Indirectly context position aware. |
| 388 | * |
| 389 | * @param[in] set Set to cast. |
| 390 | * @param[in] target Target type to cast \p set into. |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 391 | * @return LY_ERR |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 392 | */ |
Michal Vasko | 5e0e6eb | 2019-11-06 15:47:50 +0100 | [diff] [blame] | 393 | LY_ERR lyxp_set_cast(struct lyxp_set *set, enum lyxp_set_type target); |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 394 | |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 395 | /** |
Michal Vasko | d367889 | 2020-05-21 10:06:58 +0200 | [diff] [blame] | 396 | * @brief Free dynamic content of a set. |
| 397 | * |
| 398 | * @param[in] set Set to modify. |
| 399 | */ |
| 400 | void lyxp_set_free_content(struct lyxp_set *set); |
| 401 | |
| 402 | /** |
Michal Vasko | ecd62de | 2019-11-13 12:35:11 +0100 | [diff] [blame] | 403 | * @brief Check for duplicates in a schema node set. |
| 404 | * |
| 405 | * @param[in] set Set to check. |
| 406 | * @param[in] node Node to look for in @p set. |
| 407 | * @param[in] node_type Type of @p node. |
| 408 | * @param[in] skip_idx Index from @p set to skip. |
Radek Krejci | aa6b53f | 2020-08-27 15:19:03 +0200 | [diff] [blame] | 409 | * @param[out] index_p Optional pointer to store index if the node is found. |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 410 | * @return Boolean value whether the @p node found or not. |
Michal Vasko | ecd62de | 2019-11-13 12:35:11 +0100 | [diff] [blame] | 411 | */ |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 412 | ly_bool lyxp_set_scnode_contains(struct lyxp_set *set, const struct lysc_node *node, enum lyxp_node_type node_type, |
Radek Krejci | aa6b53f | 2020-08-27 15:19:03 +0200 | [diff] [blame] | 413 | int skip_idx, uint32_t *index_p); |
Michal Vasko | ecd62de | 2019-11-13 12:35:11 +0100 | [diff] [blame] | 414 | |
| 415 | /** |
| 416 | * @brief Merge 2 schema node sets. |
| 417 | * |
| 418 | * @param[in] set1 Set to merge into. |
| 419 | * @param[in] set2 Set to merge. Its content is freed. |
| 420 | */ |
| 421 | void lyxp_set_scnode_merge(struct lyxp_set *set1, struct lyxp_set *set2); |
| 422 | |
| 423 | /** |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 424 | * @brief Parse an XPath expression into a structure of tokens. |
| 425 | * Logs directly. |
| 426 | * |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 427 | * https://www.w3.org/TR/1999/REC-xpath-19991116/#exprlex |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 428 | * |
| 429 | * @param[in] ctx Context for errors. |
Radek Krejci | f03a9e2 | 2020-09-18 20:09:31 +0200 | [diff] [blame] | 430 | * @param[in] expr_str XPath expression to parse. It is duplicated. |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 431 | * @param[in] expr_len Length of @p expr, can be 0 if @p expr is 0-terminated. |
| 432 | * @param[in] reparse Whether to re-parse the expression to finalize full XPath parsing and fill |
| 433 | * information about expressions and their operators (fill repeat). |
Radek Krejci | f03a9e2 | 2020-09-18 20:09:31 +0200 | [diff] [blame] | 434 | * @param[out] expr_p Pointer to return the filled expression structure. |
| 435 | * @return LY_SUCCESS in case of success. |
| 436 | * @return LY_EMEM in case of memory allocation failure. |
| 437 | * @return LY_EVALID in case of invalid XPath expression in @p expr_str. |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 438 | */ |
Michal Vasko | ee38a5d | 2020-11-09 21:02:18 +0100 | [diff] [blame] | 439 | LY_ERR lyxp_expr_parse(const struct ly_ctx *ctx, const char *expr_str, size_t expr_len, ly_bool reparse, |
| 440 | struct lyxp_expr **expr_p); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 441 | |
| 442 | /** |
| 443 | * @brief Duplicate parsed XPath expression. |
| 444 | * |
Michal Vasko | e33134a | 2022-07-29 14:54:40 +0200 | [diff] [blame] | 445 | * If @p start_idx and @p end_idx are both 0, the whole expression is duplicated. |
| 446 | * |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 447 | * @param[in] ctx Context with a dictionary. |
| 448 | * @param[in] exp Parsed expression. |
Michal Vasko | e33134a | 2022-07-29 14:54:40 +0200 | [diff] [blame] | 449 | * @param[in] start_idx Starting @p exp index to duplicate. |
| 450 | * @param[in] end_idx Last @p exp index to duplicate. |
Michal Vasko | 1734be9 | 2020-09-22 08:55:10 +0200 | [diff] [blame] | 451 | * @param[out] dup Duplicated structure. |
| 452 | * @return LY_ERR value. |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 453 | */ |
Michal Vasko | dd528af | 2022-08-08 14:35:07 +0200 | [diff] [blame] | 454 | LY_ERR lyxp_expr_dup(const struct ly_ctx *ctx, const struct lyxp_expr *exp, uint32_t start_idx, uint32_t end_idx, |
Michal Vasko | e33134a | 2022-07-29 14:54:40 +0200 | [diff] [blame] | 455 | struct lyxp_expr **dup); |
Michal Vasko | 1467635 | 2020-05-29 11:35:55 +0200 | [diff] [blame] | 456 | |
| 457 | /** |
| 458 | * @brief Look at the next token and check its kind. |
| 459 | * |
| 460 | * @param[in] ctx Context for logging, not logged if NULL. |
| 461 | * @param[in] exp Expression to use. |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 462 | * @param[in] tok_idx Token index in the expression \p exp. |
Michal Vasko | 1467635 | 2020-05-29 11:35:55 +0200 | [diff] [blame] | 463 | * @param[in] want_tok Expected token. |
| 464 | * @return LY_EINCOMPLETE on EOF, |
| 465 | * @return LY_ENOT on non-matching token, |
| 466 | * @return LY_SUCCESS on success. |
| 467 | */ |
Michal Vasko | dd528af | 2022-08-08 14:35:07 +0200 | [diff] [blame] | 468 | LY_ERR lyxp_check_token(const struct ly_ctx *ctx, const struct lyxp_expr *exp, uint32_t tok_idx, enum lyxp_token want_tok); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 469 | |
| 470 | /** |
| 471 | * @brief Look at the next token and skip it if it matches the expected one. |
| 472 | * |
| 473 | * @param[in] ctx Context for logging, not logged if NULL. |
| 474 | * @param[in] exp Expression to use. |
| 475 | * @param[in,out] tok_idx Token index in the expression \p exp, is updated. |
| 476 | * @param[in] want_tok Expected token. |
| 477 | * @return LY_EINCOMPLETE on EOF, |
| 478 | * @return LY_ENOT on non-matching token, |
| 479 | * @return LY_SUCCESS on success. |
| 480 | */ |
Michal Vasko | dd528af | 2022-08-08 14:35:07 +0200 | [diff] [blame] | 481 | LY_ERR lyxp_next_token(const struct ly_ctx *ctx, const struct lyxp_expr *exp, uint32_t *tok_idx, enum lyxp_token want_tok); |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 482 | |
| 483 | /** |
Michal Vasko | 4911eeb | 2021-06-28 11:23:05 +0200 | [diff] [blame] | 484 | * @brief Look at the next token and skip it if it matches either of the 2 expected ones. |
| 485 | * |
| 486 | * @param[in] ctx Context for logging, not logged if NULL. |
| 487 | * @param[in] exp Expression to use. |
| 488 | * @param[in,out] tok_idx Token index in the expression \p exp, is updated. |
| 489 | * @param[in] want_tok1 Expected token 1. |
| 490 | * @param[in] want_tok2 Expected token 2. |
| 491 | * @return LY_EINCOMPLETE on EOF, |
| 492 | * @return LY_ENOT on non-matching token, |
| 493 | * @return LY_SUCCESS on success. |
| 494 | */ |
Michal Vasko | dd528af | 2022-08-08 14:35:07 +0200 | [diff] [blame] | 495 | LY_ERR lyxp_next_token2(const struct ly_ctx *ctx, const struct lyxp_expr *exp, uint32_t *tok_idx, |
Michal Vasko | 4911eeb | 2021-06-28 11:23:05 +0200 | [diff] [blame] | 496 | enum lyxp_token want_tok1, enum lyxp_token want_tok2); |
| 497 | |
| 498 | /** |
aPiecek | df23eee | 2021-10-07 12:21:50 +0200 | [diff] [blame] | 499 | * @brief Find variable named @name in @p vars. |
| 500 | * |
| 501 | * @param[in] vars [Sized array](@ref sizedarrays) of XPath variables. |
| 502 | * @param[in] name Name of the variable being searched. |
| 503 | * @param[in] name_len Name length can be set to 0 if @p name is terminated by null byte. |
| 504 | * @param[out] var Variable that was found. The parameter is optional. |
| 505 | * @return LY_SUCCESS if the variable was found, otherwise LY_ENOTFOUND. |
| 506 | */ |
| 507 | LY_ERR lyxp_vars_find(struct lyxp_var *vars, const char *name, size_t name_len, struct lyxp_var **var); |
| 508 | |
| 509 | /** |
Michal Vasko | 03ff5a7 | 2019-09-11 13:49:33 +0200 | [diff] [blame] | 510 | * @brief Frees a parsed XPath expression. @p expr should not be used afterwards. |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 511 | * |
| 512 | * @param[in] ctx libyang context of the expression. |
| 513 | * @param[in] expr Expression to free. |
| 514 | */ |
Michal Vasko | 1467635 | 2020-05-29 11:35:55 +0200 | [diff] [blame] | 515 | void lyxp_expr_free(const struct ly_ctx *ctx, struct lyxp_expr *expr); |
Radek Krejci | b1646a9 | 2018-11-02 16:08:26 +0100 | [diff] [blame] | 516 | |
Michal Vasko | 1467635 | 2020-05-29 11:35:55 +0200 | [diff] [blame] | 517 | #endif /* LY_XPATH_H */ |