Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file schema_compile_node.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame^] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 5 | * @brief Header for schema compilation of common nodes. |
| 6 | * |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame^] | 7 | * Copyright (c) 2015 - 2022 CESNET, z.s.p.o. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
| 15 | |
| 16 | #ifndef LY_SCHEMA_COMPILE_NODE_H_ |
| 17 | #define LY_SCHEMA_COMPILE_NODE_H_ |
| 18 | |
| 19 | #include <stddef.h> |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 20 | #include <stdint.h> |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 21 | |
| 22 | #include "log.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 23 | #include "tree.h" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 24 | #include "tree_schema.h" |
| 25 | |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 26 | struct ly_ctx; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 27 | struct ly_set; |
| 28 | struct lysc_ctx; |
| 29 | |
| 30 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 31 | * @brief Compile information from the when statement by either standard compilation or by reusing |
| 32 | * another compiled when structure. |
| 33 | * |
| 34 | * @param[in] ctx Compile context. |
| 35 | * @param[in] when_p Parsed when structure. |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame^] | 36 | * @param[in] inherited_flags Inherited flags from a schema-only statement. |
| 37 | * @param[in] parent Parent node, if any. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 38 | * @param[in] ctx_node Context node for the when statement. |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame^] | 39 | * @param[in] node Compiled node to which to add the compiled when. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 40 | * @param[in,out] when_c Optional, pointer to the previously compiled @p when_p to be reused. Set to NULL |
| 41 | * for the first call. |
| 42 | * @return LY_ERR value. |
| 43 | */ |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame^] | 44 | LY_ERR lys_compile_when(struct lysc_ctx *ctx, const struct lysp_when *when_p, uint16_t inherited_flags, |
| 45 | const struct lysc_node *parent, const struct lysc_node *ctx_node, struct lysc_node *node, struct lysc_when **when_c); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 46 | |
| 47 | /** |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 48 | * @brief Compile information from the must statement |
| 49 | * |
| 50 | * @param[in] ctx Compile context. |
| 51 | * @param[in] must_p The parsed must statement structure. |
| 52 | * @param[in,out] must Prepared (empty) compiled must structure to fill. |
| 53 | * @return LY_ERR value. |
| 54 | */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 55 | LY_ERR lys_compile_must(struct lysc_ctx *ctx, const struct lysp_restr *must_p, struct lysc_must *must); |
| 56 | |
| 57 | /** |
| 58 | * @brief Compile the parsed range restriction. |
| 59 | * |
| 60 | * @param[in] ctx Compile context. |
| 61 | * @param[in] range_p Parsed range structure to compile. |
| 62 | * @param[in] basetype Base YANG built-in type of the node with the range restriction. |
| 63 | * @param[in] length_restr Flag to distinguish between range and length restrictions. Only for logging. |
| 64 | * @param[in] frdigits The fraction-digits value in case of LY_TYPE_DEC64 basetype. |
| 65 | * @param[in] base_range Range restriction of the type from which the current type is derived. The current |
| 66 | * range restriction must be more restrictive than the base_range. |
| 67 | * @param[in,out] range Pointer to the created current range structure. |
| 68 | * @return LY_ERR value. |
| 69 | */ |
| 70 | LY_ERR lys_compile_type_range(struct lysc_ctx *ctx, const struct lysp_restr *range_p, LY_DATA_TYPE basetype, |
| 71 | ly_bool length_restr, uint8_t frdigits, struct lysc_range *base_range, struct lysc_range **range); |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 72 | |
| 73 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 74 | * @brief Checks pattern syntax. |
| 75 | * |
| 76 | * @param[in] ctx Context. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 77 | * @param[in] pattern Pattern to check. |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 78 | * @param[in,out] code Compiled PCRE2 pattern. If NULL, the compiled information used to validate pattern are freed. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 79 | * @return LY_ERR value - LY_SUCCESS, LY_EMEM, LY_EVALID. |
| 80 | */ |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 81 | LY_ERR lys_compile_type_pattern_check(struct ly_ctx *ctx, const char *pattern, pcre2_code **code); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 82 | |
| 83 | /** |
Michal Vasko | 51de7b7 | 2022-04-29 09:50:22 +0200 | [diff] [blame] | 84 | * @brief Compile parsed pattern restriction in conjunction with the patterns from base type. |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 85 | * |
Michal Vasko | 51de7b7 | 2022-04-29 09:50:22 +0200 | [diff] [blame] | 86 | * @param[in] ctx Compile context. |
| 87 | * @param[in] patterns_p Array of parsed patterns from the current type to compile. |
| 88 | * @param[in] base_patterns Compiled patterns from the type from which the current type is derived. |
| 89 | * Patterns from the base type are inherited to have all the patterns that have to match at one place. |
| 90 | * @param[out] patterns Pointer to the storage for the patterns of the current type. |
| 91 | * @return LY_ERR LY_SUCCESS, LY_EMEM, LY_EVALID. |
| 92 | */ |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 93 | LY_ERR lys_compile_type_patterns(struct lysc_ctx *ctx, const struct lysp_restr *patterns_p, |
Michal Vasko | 51de7b7 | 2022-04-29 09:50:22 +0200 | [diff] [blame] | 94 | struct lysc_pattern **base_patterns, struct lysc_pattern ***patterns); |
| 95 | |
| 96 | /** |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 97 | * @brief Compile parsed type's enum structures (for enumeration and bits types). |
| 98 | * |
| 99 | * @param[in] ctx Compile context. |
| 100 | * @param[in] enums_p Array of the parsed enum structures to compile. |
| 101 | * @param[in] basetype Base YANG built-in type from which the current type is derived. Only LY_TYPE_ENUM and LY_TYPE_BITS are expected. |
| 102 | * @param[in] base_enums Array of the compiled enums information from the (latest) base type to check if the current enums are compatible. |
| 103 | * @param[out] bitenums Newly created array of the compiled bitenums information for the current type. |
| 104 | * @return LY_ERR value - LY_SUCCESS or LY_EVALID. |
| 105 | */ |
| 106 | LY_ERR lys_compile_type_enums(struct lysc_ctx *ctx, const struct lysp_type_enum *enums_p, LY_DATA_TYPE basetype, |
| 107 | struct lysc_type_bitenum_item *base_enums, struct lysc_type_bitenum_item **bitenums); |
| 108 | |
| 109 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 110 | * @brief Compile information about the leaf/leaf-list's type. |
| 111 | * |
| 112 | * @param[in] ctx Compile context. |
| 113 | * @param[in] context_pnode Schema node where the type/typedef is placed to correctly find the base types. |
| 114 | * @param[in] context_flags Flags of the context node or the referencing typedef to correctly check status of referencing and referenced objects. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 115 | * @param[in] context_name Name of the context node or referencing typedef for logging. |
| 116 | * @param[in] type_p Parsed type to compile. |
| 117 | * @param[out] type Newly created (or reused with increased refcount) type structure with the filled information about the type. |
| 118 | * @param[out] units Storage for inheriting units value from the typedefs the current type derives from. |
| 119 | * @param[out] dflt Default value for the type. |
| 120 | * @return LY_ERR value. |
| 121 | */ |
| 122 | LY_ERR lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t context_flags, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 123 | const char *context_name, const struct lysp_type *type_p, struct lysc_type **type, const char **units, |
Michal Vasko | a99b357 | 2021-02-01 11:54:58 +0100 | [diff] [blame] | 124 | struct lysp_qname **dflt); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 125 | |
| 126 | /** |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 127 | * @brief Connect the node into the siblings list and check its name uniqueness. Also, |
| 128 | * keep specific order of augments targetting the same node. |
| 129 | * |
| 130 | * @param[in] ctx Compile context |
| 131 | * @param[in] parent Parent node holding the children list, in case of node from a choice's case, |
| 132 | * the choice itself is expected instead of a specific case node. |
| 133 | * @param[in] node Schema node to connect into the list. |
| 134 | * @return LY_ERR value - LY_SUCCESS or LY_EEXIST. |
| 135 | * In case of LY_EEXIST, the node is actually kept in the tree, so do not free it directly. |
| 136 | */ |
| 137 | LY_ERR lys_compile_node_connect(struct lysc_ctx *ctx, struct lysc_node *parent, struct lysc_node *node); |
| 138 | |
| 139 | /** |
| 140 | * @brief Compile parsed action's input/output node information. |
| 141 | * |
| 142 | * @param[in] ctx Compile context |
| 143 | * @param[in] pnode Parsed inout node. |
| 144 | * @param[in,out] node Pre-prepared structure from lys_compile_node_() with filled generic node information |
| 145 | * is enriched with the inout-specific information. |
| 146 | * @return LY_ERR value - LY_SUCCESS or LY_EVALID. |
| 147 | */ |
| 148 | LY_ERR lys_compile_node_action_inout(struct lysc_ctx *ctx, struct lysp_node *pnode, struct lysc_node *node); |
| 149 | |
| 150 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 151 | * @brief Compile choice children. |
| 152 | * |
| 153 | * @param[in] ctx Compile context |
| 154 | * @param[in] child_p Parsed choice children nodes. |
| 155 | * @param[in] node Compiled choice node to compile and add children to. |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 156 | * @param[in,out] child_set Optional set to add all the compiled nodes into (can be more in case of uses). |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 157 | * @return LY_ERR value - LY_SUCCESS or LY_EVALID. |
| 158 | */ |
| 159 | LY_ERR lys_compile_node_choice_child(struct lysc_ctx *ctx, struct lysp_node *child_p, struct lysc_node *node, |
| 160 | struct ly_set *child_set); |
| 161 | |
| 162 | /** |
| 163 | * @brief Set LYS_MAND_TRUE flag for the non-presence container parents. |
| 164 | * |
| 165 | * A non-presence container is mandatory in case it has at least one mandatory children. This function propagate |
| 166 | * the flag to such parents from a mandatory children. |
| 167 | * |
| 168 | * @param[in] parent A schema node to be examined if the mandatory child make it also mandatory. |
| 169 | * @param[in] add Flag to distinguish adding the mandatory flag (new mandatory children appeared) or removing the flag |
| 170 | * (mandatory children was removed). |
| 171 | */ |
| 172 | void lys_compile_mandatory_parents(struct lysc_node *parent, ly_bool add); |
| 173 | |
| 174 | /** |
| 175 | * @brief Validate grouping that was defined but not used in the schema itself. |
| 176 | * |
| 177 | * The grouping does not need to be compiled (and it is compiled here, but the result is forgotten immediately), |
| 178 | * but to have the complete result of the schema validity, even such groupings are supposed to be checked. |
| 179 | * |
| 180 | * @param[in] ctx Compile context. |
| 181 | * @param[in] pnode Parsed parent node of the grouping, NULL for top-level. |
| 182 | * @param[in] grp Parsed grouping node to check. |
| 183 | * @return LY_ERR value. |
| 184 | */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 185 | LY_ERR lys_compile_grouping(struct lysc_ctx *ctx, struct lysp_node *pnode, struct lysp_node_grp *grp); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 186 | |
| 187 | /** |
| 188 | * @brief Compile parsed schema node information. |
| 189 | * |
| 190 | * @param[in] ctx Compile context |
| 191 | * @param[in] pnode Parsed schema node. |
| 192 | * @param[in] parent Compiled parent node where the current node is supposed to be connected. It is |
| 193 | * NULL for top-level nodes, in such a case the module where the node will be connected is taken from |
| 194 | * the compile context. |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame^] | 195 | * @param[in] inherited_flags Inherited flags from a schema-only statement. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 196 | * @param[in,out] child_set Optional set to add all the compiled nodes into (can be more in case of uses). |
| 197 | * @return LY_ERR value - LY_SUCCESS or LY_EVALID. |
| 198 | */ |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame^] | 199 | LY_ERR lys_compile_node(struct lysc_ctx *ctx, struct lysp_node *pnode, struct lysc_node *parent, uint16_t inherited_flags, |
| 200 | struct ly_set *child_set); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 201 | |
| 202 | #endif /* LY_SCHEMA_COMPILE_NODE_H_ */ |