Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file xpath.h |
| 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * @brief YANG XPath evaluation functions header |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 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 |
Michal Vasko | 8de098c | 2016-02-26 10:00:25 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef _XPATH_H |
| 16 | #define _XPATH_H |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | |
Michal Vasko | fcd974b | 2017-08-22 10:17:49 +0200 | [diff] [blame] | 20 | #include "libyang.h" |
Michal Vasko | fd76bd1 | 2015-09-24 15:49:57 +0200 | [diff] [blame] | 21 | #include "tree_schema.h" |
| 22 | #include "tree_data.h" |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * XPath evaluator fully compliant with http://www.w3.org/TR/1999/REC-xpath-19991116/ |
| 26 | * except the following restrictions in the grammar. |
| 27 | * |
| 28 | * PARSED GRAMMAR |
| 29 | * |
| 30 | * Full axes are not supported, abbreviated forms must be used, |
Michal Vasko | 9390977 | 2016-10-26 10:32:10 +0200 | [diff] [blame] | 31 | * variables are not supported, "id()" function is not supported, |
| 32 | * and processing instruction and comment nodes are not supported, |
| 33 | * which is also reflected in the grammar. Undefined rules and |
| 34 | * constants are tokens. |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 35 | * |
| 36 | * Modified full grammar: |
| 37 | * |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 38 | * [1] Expr ::= OrExpr // just an alias |
| 39 | * |
| 40 | * [2] LocationPath ::= RelativeLocationPath | AbsoluteLocationPath |
| 41 | * [3] AbsoluteLocationPath ::= '/' RelativeLocationPath? | '//' RelativeLocationPath |
| 42 | * [4] RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | RelativeLocationPath '//' Step |
| 43 | * [5] Step ::= '@'? NodeTest Predicate* | '.' | '..' |
| 44 | * [6] NodeTest ::= NameTest | NodeType '(' ')' |
| 45 | * [7] Predicate ::= '[' Expr ']' |
| 46 | * [8] PrimaryExpr ::= '(' Expr ')' | Literal | Number | FunctionCall |
| 47 | * [9] FunctionCall ::= FunctionName '(' ( Expr ( ',' Expr )* )? ')' |
| 48 | * [10] PathExpr ::= LocationPath | PrimaryExpr Predicate* |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 49 | * | PrimaryExpr Predicate* '/' RelativeLocationPath |
| 50 | * | PrimaryExpr Predicate* '//' RelativeLocationPath |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 51 | * [11] OrExpr ::= AndExpr | OrExpr 'or' AndExpr |
| 52 | * [12] AndExpr ::= EqualityExpr | AndExpr 'and' EqualityExpr |
| 53 | * [13] EqualityExpr ::= RelationalExpr | EqualityExpr '=' RelationalExpr |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 54 | * | EqualityExpr '!=' RelationalExpr |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 55 | * [14] RelationalExpr ::= AdditiveExpr |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 56 | * | RelationalExpr '<' AdditiveExpr |
| 57 | * | RelationalExpr '>' AdditiveExpr |
| 58 | * | RelationalExpr '<=' AdditiveExpr |
| 59 | * | RelationalExpr '>=' AdditiveExpr |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 60 | * [15] AdditiveExpr ::= MultiplicativeExpr |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 61 | * | AdditiveExpr '+' MultiplicativeExpr |
| 62 | * | AdditiveExpr '-' MultiplicativeExpr |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 63 | * [16] MultiplicativeExpr ::= UnaryExpr |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 64 | * | MultiplicativeExpr '*' UnaryExpr |
| 65 | * | MultiplicativeExpr 'div' UnaryExpr |
| 66 | * | MultiplicativeExpr 'mod' UnaryExpr |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 67 | * [17] UnaryExpr ::= UnionExpr | '-' UnaryExpr |
| 68 | * [18] UnionExpr ::= PathExpr | UnionExpr '|' PathExpr |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 69 | */ |
| 70 | |
| 71 | /* expression tokens allocation */ |
| 72 | #define LYXP_EXPR_SIZE_START 10 |
| 73 | #define LYXP_EXPR_SIZE_STEP 5 |
| 74 | |
| 75 | /* XPath matches allocation */ |
| 76 | #define LYXP_SET_SIZE_START 2 |
| 77 | #define LYXP_SET_SIZE_STEP 2 |
| 78 | |
| 79 | /* building string when casting */ |
| 80 | #define LYXP_STRING_CAST_SIZE_START 64 |
| 81 | #define LYXP_STRING_CAST_SIZE_STEP 16 |
| 82 | |
| 83 | /** |
| 84 | * @brief Tokens that can be in an XPath expression. |
| 85 | */ |
| 86 | enum lyxp_token { |
| 87 | LYXP_TOKEN_NONE = 0, |
| 88 | LYXP_TOKEN_PAR1, /* '(' */ |
| 89 | LYXP_TOKEN_PAR2, /* ')' */ |
| 90 | LYXP_TOKEN_BRACK1, /* '[' */ |
| 91 | LYXP_TOKEN_BRACK2, /* ']' */ |
| 92 | LYXP_TOKEN_DOT, /* '.' */ |
| 93 | LYXP_TOKEN_DDOT, /* '..' */ |
| 94 | LYXP_TOKEN_AT, /* '@' */ |
| 95 | LYXP_TOKEN_COMMA, /* ',' */ |
| 96 | /* LYXP_TOKEN_DCOLON, * '::' * axes not supported */ |
| 97 | LYXP_TOKEN_NAMETEST, /* NameTest */ |
| 98 | LYXP_TOKEN_NODETYPE, /* NodeType */ |
| 99 | LYXP_TOKEN_FUNCNAME, /* FunctionName */ |
| 100 | LYXP_TOKEN_OPERATOR_LOG, /* Operator 'and', 'or' */ |
| 101 | LYXP_TOKEN_OPERATOR_COMP, /* Operator '=', '!=', '<', '<=', '>', '>=' */ |
| 102 | LYXP_TOKEN_OPERATOR_MATH, /* Operator '+', '-', '*', 'div', 'mod', '-' (unary) */ |
| 103 | LYXP_TOKEN_OPERATOR_UNI, /* Operator '|' */ |
| 104 | LYXP_TOKEN_OPERATOR_PATH, /* Operator '/', '//' */ |
| 105 | /* LYXP_TOKEN_AXISNAME, * AxisName * axes not supported */ |
| 106 | LYXP_TOKEN_LITERAL, /* Literal - with either single or double quote */ |
| 107 | LYXP_TOKEN_NUMBER /* Number */ |
| 108 | }; |
| 109 | |
| 110 | /** |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 111 | * @brief XPath (sub)expressions that can be repeated. |
| 112 | */ |
| 113 | enum lyxp_expr_type { |
| 114 | LYXP_EXPR_NONE = 0, |
| 115 | LYXP_EXPR_OR, |
| 116 | LYXP_EXPR_AND, |
| 117 | LYXP_EXPR_EQUALITY, |
| 118 | LYXP_EXPR_RELATIONAL, |
| 119 | LYXP_EXPR_ADDITIVE, |
| 120 | LYXP_EXPR_MULTIPLICATIVE, |
| 121 | LYXP_EXPR_UNION, |
| 122 | }; |
| 123 | |
| 124 | /** |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 125 | * @brief Structure holding a parsed XPath expression. |
| 126 | */ |
| 127 | struct lyxp_expr { |
| 128 | enum lyxp_token *tokens; /* array of tokens */ |
| 129 | uint16_t *expr_pos; /* array of pointers to the expression in expr (idx of the beginning) */ |
| 130 | uint8_t *tok_len; /* array of token lengths in expr */ |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 131 | enum lyxp_expr_type **repeat; /* array of expression types that this token begins and is repeated ended with 0, |
| 132 | more in the comment after this declaration */ |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 133 | uint16_t used; /* used array items */ |
| 134 | uint16_t size; /* allocated array items */ |
| 135 | |
Michal Vasko | 2b84ea7 | 2016-05-05 17:56:58 +0200 | [diff] [blame] | 136 | char *expr; /* the original XPath expression */ |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | /* |
| 140 | * lyxp_expr repeat |
| 141 | * |
| 142 | * This value is NULL for all the tokens that do not begin an |
| 143 | * expression which can be repeated. Otherwise it is an array |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 144 | * of expression types that this token begins. These values |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 145 | * are used during evaluation to know whether we need to |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 146 | * duplicate the current context or not and to decide what |
| 147 | * the current expression is (for example, if we are only |
| 148 | * starting the parsing and the first token has no repeat, |
| 149 | * we do not parse it as an OrExpr but directly as PathExpr). |
| 150 | * Examples: |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 151 | * |
| 152 | * Expression: "/ *[key1 and key2 or key1 < key2]" |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 153 | * Tokens: '/', '*', '[', NameTest, 'and', NameTest, 'or', NameTest, '<', NameTest, ']' |
| 154 | * Repeat: NULL, NULL, NULL, [AndExpr, NULL, NULL, NULL, [RelationalExpr, NULL, NULL, NULL |
| 155 | * OrExpr, 0], |
| 156 | * 0], |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 157 | * |
| 158 | * Expression: "//node[key and node2]/key | /cont" |
Michal Vasko | 764c8c4 | 2017-11-07 15:43:06 +0100 | [diff] [blame^] | 159 | * Tokens: '//', 'NameTest', '[', 'NameTest', 'and', 'NameTest', ']', '/', 'NameTest', '|', '/', 'NameTest' |
| 160 | * Repeat: [UnionExpr, NULL, NULL, [AndExpr, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL |
| 161 | * 0], 0], |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 162 | * |
Michal Vasko | 56d082c | 2016-10-25 14:00:42 +0200 | [diff] [blame] | 163 | * Operators between expressions which this concerns: |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 164 | * 'or', 'and', '=', '!=', '<', '>', '<=', '>=', '+', '-', '*', 'div', 'mod', '|' |
| 165 | */ |
| 166 | |
| 167 | /** |
| 168 | * @brief Supported types of (partial) XPath results. |
| 169 | */ |
| 170 | enum lyxp_set_type { |
| 171 | LYXP_SET_EMPTY = 0, |
| 172 | LYXP_SET_NODE_SET, |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 173 | LYXP_SET_SNODE_SET, |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 174 | LYXP_SET_BOOLEAN, |
| 175 | LYXP_SET_NUMBER, |
| 176 | LYXP_SET_STRING |
| 177 | }; |
| 178 | |
| 179 | /** |
Michal Vasko | 8146d4c | 2016-05-09 15:50:29 +0200 | [diff] [blame] | 180 | * @brief XPath set - (partial) result. |
| 181 | */ |
| 182 | struct lyxp_set { |
| 183 | enum lyxp_set_type type; |
| 184 | union { |
| 185 | struct lyxp_set_nodes { |
| 186 | struct lyd_node *node; |
| 187 | enum lyxp_node_type type; |
| 188 | uint32_t pos; |
| 189 | } *nodes; |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 190 | struct lyxp_set_snodes { |
| 191 | struct lys_node *snode; |
| 192 | enum lyxp_node_type type; |
| 193 | /* 0 - snode was traversed, but not currently in the context, |
| 194 | * 1 - snode currently in context, |
| 195 | * 2 - snode in context and just added, so skip it for the current operation, |
| 196 | * >=3 - snode is not in context because we are in a predicate and this snode was used/will be used later */ |
| 197 | uint32_t in_ctx; |
| 198 | } *snodes; |
Michal Vasko | 8146d4c | 2016-05-09 15:50:29 +0200 | [diff] [blame] | 199 | struct lyxp_set_attrs { |
| 200 | struct lyd_attr *attr; |
| 201 | enum lyxp_node_type type; |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 202 | uint32_t pos; /* if node_type is LYXP_SET_NODE_ATTR, it is the parent node position */ |
Michal Vasko | 8146d4c | 2016-05-09 15:50:29 +0200 | [diff] [blame] | 203 | } *attrs; |
Michal Vasko | 40afe1a | 2016-08-22 14:20:43 +0200 | [diff] [blame] | 204 | char *str; |
Michal Vasko | 8146d4c | 2016-05-09 15:50:29 +0200 | [diff] [blame] | 205 | long double num; |
| 206 | int bool; |
| 207 | } val; |
| 208 | |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 209 | /* this is valid only for type LYXP_SET_NODE_SET and LYXP_SET_SNODE_SET */ |
Michal Vasko | 8146d4c | 2016-05-09 15:50:29 +0200 | [diff] [blame] | 210 | uint32_t used; |
| 211 | uint32_t size; |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 212 | /* this is valid only for type LYXP_SET_NODE_SET */ |
Michal Vasko | db86ff4 | 2016-05-13 15:50:11 +0200 | [diff] [blame] | 213 | uint32_t ctx_pos; |
| 214 | uint32_t ctx_size; |
Michal Vasko | 8146d4c | 2016-05-09 15:50:29 +0200 | [diff] [blame] | 215 | }; |
| 216 | |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 217 | /** |
Michal Vasko | 6ed199c | 2016-02-04 12:07:19 +0100 | [diff] [blame] | 218 | * @brief Evaluate the XPath expression \p expr on data. Be careful when using this function, the result can often |
| 219 | * be confusing without thorough understanding of XPath evaluation rules defined in RFC 6020. |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 220 | * |
Michal Vasko | 30646e6 | 2015-10-09 14:02:09 +0200 | [diff] [blame] | 221 | * @param[in] expr XPath expression to evaluate. Must be in JSON format (prefixes are model names). |
Michal Vasko | fdb73ae | 2016-08-24 16:02:12 +0200 | [diff] [blame] | 222 | * @param[in] cur_node Current (context) data node. If the node has #LYD_VAL_INUSE flag, it is considered dummy (intended |
| 223 | * for but not restricted to evaluation with the LYXP_WHEN flag). |
Michal Vasko | b5157df | 2016-08-23 13:19:41 +0200 | [diff] [blame] | 224 | * @param[in] cur_node_type Current (context) data node type. For every standard case use #LYXP_NODE_ELEM. But there are |
| 225 | * cases when the context node \p cur_node is actually supposed to be the XML root, there is no such data node. So, in |
Michal Vasko | b94a5e4 | 2016-09-08 14:01:56 +0200 | [diff] [blame] | 226 | * this case just pass the first top-level node into \p cur_node and use an enum value for this kind of root |
| 227 | * (#LYXP_NODE_ROOT_CONFIG if \p cur_node has config true, otherwise #LYXP_NODE_ROOT). #LYXP_NODE_TEXT and #LYXP_NODE_ATTR can also be used, |
Michal Vasko | b5157df | 2016-08-23 13:19:41 +0200 | [diff] [blame] | 228 | * but there are no use-cases in YANG. |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 229 | * @param[in] local_mod Local module relative to the \p expr. Used only to determine the internal canonical value for identities. |
Michal Vasko | 488590f | 2016-03-29 12:23:25 +0200 | [diff] [blame] | 230 | * @param[out] set Result set. Must be valid and in the same libyang context as \p cur_node. |
| 231 | * To be safe, always either zero or cast the \p set to empty. After done using, either cast |
| 232 | * the \p set to empty (if allocated statically) or free it (if allocated dynamically) to |
| 233 | * prevent memory leaks. |
Michal Vasko | a87d258 | 2016-03-16 15:37:45 +0100 | [diff] [blame] | 234 | * @param[in] options Whether to apply some evaluation restrictions. |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 235 | * LYXP_MUST - apply must data tree access restrictions. |
| 236 | * LYXP_WHEN - apply when data tree access restrictions and consider LYD_WHEN flags in data nodes. |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 237 | * |
Michal Vasko | a87d258 | 2016-03-16 15:37:45 +0100 | [diff] [blame] | 238 | * @return EXIT_SUCCESS on success, EXIT_FAILURE on unresolved when dependency, -1 on error. |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 239 | */ |
Michal Vasko | a59495d | 2016-08-22 09:18:58 +0200 | [diff] [blame] | 240 | int lyxp_eval(const char *expr, const struct lyd_node *cur_node, enum lyxp_node_type cur_node_type, |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 241 | const struct lys_module *local_mod, struct lyxp_set *set, int options); |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 242 | |
Michal Vasko | 5fb299e | 2015-10-06 15:44:55 +0200 | [diff] [blame] | 243 | /** |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 244 | * @brief Get all the partial XPath nodes (atoms) that are required for \p expr to be evaluated. |
| 245 | * |
Michal Vasko | f96dfb6 | 2017-08-17 12:23:49 +0200 | [diff] [blame] | 246 | * If any LYXP_SNODE* options is set, only fatal errors are printed, otherwise they are downgraded |
| 247 | * to warnings. |
| 248 | * |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 249 | * @param[in] expr XPath expression to be evaluated. Must be in JSON format (prefixes are model names). |
| 250 | * @param[in] cur_snode Current (context) schema node. |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 251 | * @param[in] cur_snode_type Current (context) schema node type. |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 252 | * @param[out] set Result set. Must be valid and in the same libyang context as \p cur_snode. |
| 253 | * To be safe, always either zero or cast the \p set to empty. After done using, either cast |
| 254 | * the \p set to empty (if allocated statically) or free it (if allocated dynamically) to |
| 255 | * prevent memory leaks. |
| 256 | * @param[in] options Whether to apply some evaluation restrictions, one flag must always be used. |
| 257 | * LYXP_SNODE - no special data tree access modifiers. |
| 258 | * LYXP_SNODE_MUST - apply must data tree access restrictions. |
| 259 | * LYXP_SNODE_WHEN - apply when data tree access restrictions. |
Michal Vasko | b94a5e4 | 2016-09-08 14:01:56 +0200 | [diff] [blame] | 260 | * LYXP_SNODE_OUTPUT - search RPC/action output instead input |
Michal Vasko | 41cb7c3 | 2017-07-03 12:59:56 +0200 | [diff] [blame] | 261 | * @param[out] ctx_snode Actual context node for the expression (it often changes for "when" expressions). |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 262 | * |
| 263 | * @return EXIT_SUCCESS on success, -1 on error. |
| 264 | */ |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 265 | int lyxp_atomize(const char *expr, const struct lys_node *cur_snode, enum lyxp_node_type cur_snode_type, |
Michal Vasko | 41cb7c3 | 2017-07-03 12:59:56 +0200 | [diff] [blame] | 266 | struct lyxp_set *set, int options, const struct lys_node **ctx_snode); |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 267 | |
| 268 | /* these are used only internally */ |
| 269 | #define LYXP_SNODE 0x04 |
| 270 | #define LYXP_SNODE_MUST 0x08 |
| 271 | #define LYXP_SNODE_WHEN 0x10 |
Michal Vasko | db1da03 | 2016-09-08 10:07:38 +0200 | [diff] [blame] | 272 | #define LYXP_SNODE_OUTPUT 0x20 |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 273 | |
| 274 | #define LYXP_SNODE_ALL 0x1C |
| 275 | |
| 276 | /** |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 277 | * @brief Works like lyxp_atomize(), but it is executed on all the when and must expressions |
| 278 | * which the node has. |
Michal Vasko | 7e18c45 | 2015-10-07 09:34:36 +0200 | [diff] [blame] | 279 | * |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 280 | * @param[in] node Node to examine. |
| 281 | * @param[in,out] set Resulting set of atoms merged from all the expressions. |
| 282 | * Will be cleared before use. |
Michal Vasko | 0b96311 | 2017-08-11 12:45:36 +0200 | [diff] [blame] | 283 | * @param[in] set_ext_dep_flags Set #LYS_XPATH_DEP for conditions that require foreign subtree and |
| 284 | * also for the node itself, if it has any such condition. |
Michal Vasko | 7e18c45 | 2015-10-07 09:34:36 +0200 | [diff] [blame] | 285 | * |
Michal Vasko | f96dfb6 | 2017-08-17 12:23:49 +0200 | [diff] [blame] | 286 | * @return EXIT_SUCCESS on success, -1 on error. |
Michal Vasko | 7e18c45 | 2015-10-07 09:34:36 +0200 | [diff] [blame] | 287 | */ |
Michal Vasko | f96dfb6 | 2017-08-17 12:23:49 +0200 | [diff] [blame] | 288 | int lyxp_node_atomize(const struct lys_node *node, struct lyxp_set *set, int set_ext_dep_flags); |
Michal Vasko | 7e18c45 | 2015-10-07 09:34:36 +0200 | [diff] [blame] | 289 | |
| 290 | /** |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 291 | * @brief Check syntax of all the XPath expressions of the node. |
| 292 | * |
| 293 | * @param[in] node Node to examine. |
| 294 | * |
| 295 | * @return EXIT_SUCCESS on success, -1 on error. |
| 296 | */ |
| 297 | int lyxp_node_check_syntax(const struct lys_node *node); |
| 298 | |
| 299 | /** |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 300 | * @brief Cast XPath set to another type. |
| 301 | * Indirectly context position aware. |
| 302 | * |
| 303 | * @param[in] set Set to cast. |
| 304 | * @param[in] target Target type to cast \p set into. |
Michal Vasko | 488590f | 2016-03-29 12:23:25 +0200 | [diff] [blame] | 305 | * @param[in] cur_node Current (context) data node. Cannot be NULL. |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 306 | * @param[in] local_mod Local expression module. |
Michal Vasko | a87d258 | 2016-03-16 15:37:45 +0100 | [diff] [blame] | 307 | * @param[in] options Whether to apply some evaluation restrictions. |
Michal Vasko | fdb73ae | 2016-08-24 16:02:12 +0200 | [diff] [blame] | 308 | * |
| 309 | * @return EXIT_SUCCESS on success, -1 on error. |
Michal Vasko | cf02470 | 2015-10-08 15:01:42 +0200 | [diff] [blame] | 310 | */ |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 311 | int lyxp_set_cast(struct lyxp_set *set, enum lyxp_set_type target, const struct lyd_node *cur_node, |
| 312 | const struct lys_module *local_mod, int options); |
Michal Vasko | 0485489 | 2015-10-06 15:45:43 +0200 | [diff] [blame] | 313 | |
| 314 | /** |
Michal Vasko | 5fb299e | 2015-10-06 15:44:55 +0200 | [diff] [blame] | 315 | * @brief Free contents of an XPath \p set. |
| 316 | * |
| 317 | * @param[in] set Set to free. |
Michal Vasko | 5fb299e | 2015-10-06 15:44:55 +0200 | [diff] [blame] | 318 | */ |
Michal Vasko | 40afe1a | 2016-08-22 14:20:43 +0200 | [diff] [blame] | 319 | void lyxp_set_free(struct lyxp_set *set); |
Michal Vasko | 5fb299e | 2015-10-06 15:44:55 +0200 | [diff] [blame] | 320 | |
Michal Vasko | 56d082c | 2016-10-25 14:00:42 +0200 | [diff] [blame] | 321 | /** |
| 322 | * @brief Parse an XPath expression into a structure of tokens. |
| 323 | * Logs directly. |
| 324 | * |
| 325 | * http://www.w3.org/TR/1999/REC-xpath-19991116/ section 3.7 |
| 326 | * |
| 327 | * @param[in] expr XPath expression to parse. It is duplicated. |
| 328 | * |
| 329 | * @return Filled expression structure or NULL on error. |
| 330 | */ |
| 331 | struct lyxp_expr *lyxp_parse_expr(const char *expr); |
| 332 | |
| 333 | /** |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 334 | * @brief Frees a parsed XPath expression. \p expr should not be used afterwards. |
| 335 | * |
| 336 | * @param[in] expr Expression to free. |
| 337 | */ |
| 338 | void lyxp_expr_free(struct lyxp_expr *expr); |
Michal Vasko | 56d082c | 2016-10-25 14:00:42 +0200 | [diff] [blame] | 339 | |
Michal Vasko | 2589505 | 2015-09-21 11:41:12 +0200 | [diff] [blame] | 340 | #endif /* _XPATH_H */ |