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> |
| 4 | * @brief Header for schema compilation of common nodes. |
| 5 | * |
| 6 | * Copyright (c) 2015 - 2020 CESNET, z.s.p.o. |
| 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 | |
| 15 | #ifndef LY_SCHEMA_COMPILE_NODE_H_ |
| 16 | #define LY_SCHEMA_COMPILE_NODE_H_ |
| 17 | |
| 18 | #include <stddef.h> |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 19 | #include <stdint.h> |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 20 | |
| 21 | #include "log.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 22 | #include "tree.h" |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 23 | #include "tree_schema.h" |
| 24 | |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 25 | struct ly_ctx; |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 26 | struct ly_set; |
| 27 | struct lysc_ctx; |
| 28 | |
| 29 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 30 | * @brief Compile information from the when statement by either standard compilation or by reusing |
| 31 | * another compiled when structure. |
| 32 | * |
| 33 | * @param[in] ctx Compile context. |
| 34 | * @param[in] when_p Parsed when structure. |
Michal Vasko | dfd254d | 2021-06-24 09:24:59 +0200 | [diff] [blame] | 35 | * @param[in] parent_flags Flags of the parsed node with the when statement. |
| 36 | * @param[in] compiled_parent Closest compiled parent of the when statement. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 37 | * @param[in] ctx_node Context node for the when statement. |
| 38 | * @param[in] node Compiled node to which add the compiled when. |
| 39 | * @param[in,out] when_c Optional, pointer to the previously compiled @p when_p to be reused. Set to NULL |
| 40 | * for the first call. |
| 41 | * @return LY_ERR value. |
| 42 | */ |
Michal Vasko | dfd254d | 2021-06-24 09:24:59 +0200 | [diff] [blame] | 43 | LY_ERR lys_compile_when(struct lysc_ctx *ctx, struct lysp_when *when_p, uint16_t parent_flags, |
| 44 | const struct lysc_node *compiled_parent, const struct lysc_node *ctx_node, struct lysc_node *node, |
| 45 | struct lysc_when **when_c); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * @brief Checks pattern syntax. |
| 49 | * |
| 50 | * @param[in] ctx Context. |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 51 | * @param[in] pattern Pattern to check. |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 52 | * @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] | 53 | * @return LY_ERR value - LY_SUCCESS, LY_EMEM, LY_EVALID. |
| 54 | */ |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 55 | 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] | 56 | |
| 57 | /** |
Michal Vasko | 51de7b7 | 2022-04-29 09:50:22 +0200 | [diff] [blame] | 58 | * @brief Compile parsed pattern restriction in conjunction with the patterns from base type. |
| 59 | * @param[in] ctx Compile context. |
| 60 | * @param[in] patterns_p Array of parsed patterns from the current type to compile. |
| 61 | * @param[in] base_patterns Compiled patterns from the type from which the current type is derived. |
| 62 | * Patterns from the base type are inherited to have all the patterns that have to match at one place. |
| 63 | * @param[out] patterns Pointer to the storage for the patterns of the current type. |
| 64 | * @return LY_ERR LY_SUCCESS, LY_EMEM, LY_EVALID. |
| 65 | */ |
| 66 | LY_ERR lys_compile_type_patterns(struct lysc_ctx *ctx, struct lysp_restr *patterns_p, |
| 67 | struct lysc_pattern **base_patterns, struct lysc_pattern ***patterns); |
| 68 | |
| 69 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 70 | * @brief Compile information about the leaf/leaf-list's type. |
| 71 | * |
| 72 | * @param[in] ctx Compile context. |
| 73 | * @param[in] context_pnode Schema node where the type/typedef is placed to correctly find the base types. |
| 74 | * @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] | 75 | * @param[in] context_name Name of the context node or referencing typedef for logging. |
| 76 | * @param[in] type_p Parsed type to compile. |
| 77 | * @param[out] type Newly created (or reused with increased refcount) type structure with the filled information about the type. |
| 78 | * @param[out] units Storage for inheriting units value from the typedefs the current type derives from. |
| 79 | * @param[out] dflt Default value for the type. |
| 80 | * @return LY_ERR value. |
| 81 | */ |
| 82 | LY_ERR lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t context_flags, |
Michal Vasko | a99b357 | 2021-02-01 11:54:58 +0100 | [diff] [blame] | 83 | const char *context_name, struct lysp_type *type_p, struct lysc_type **type, const char **units, |
| 84 | struct lysp_qname **dflt); |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 85 | |
| 86 | /** |
Michal Vasko | 1a7a7bd | 2020-10-16 14:39:15 +0200 | [diff] [blame] | 87 | * @brief Compile choice children. |
| 88 | * |
| 89 | * @param[in] ctx Compile context |
| 90 | * @param[in] child_p Parsed choice children nodes. |
| 91 | * @param[in] node Compiled choice node to compile and add children to. |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 92 | * @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] | 93 | * @return LY_ERR value - LY_SUCCESS or LY_EVALID. |
| 94 | */ |
| 95 | LY_ERR lys_compile_node_choice_child(struct lysc_ctx *ctx, struct lysp_node *child_p, struct lysc_node *node, |
| 96 | struct ly_set *child_set); |
| 97 | |
| 98 | /** |
| 99 | * @brief Set LYS_MAND_TRUE flag for the non-presence container parents. |
| 100 | * |
| 101 | * A non-presence container is mandatory in case it has at least one mandatory children. This function propagate |
| 102 | * the flag to such parents from a mandatory children. |
| 103 | * |
| 104 | * @param[in] parent A schema node to be examined if the mandatory child make it also mandatory. |
| 105 | * @param[in] add Flag to distinguish adding the mandatory flag (new mandatory children appeared) or removing the flag |
| 106 | * (mandatory children was removed). |
| 107 | */ |
| 108 | void lys_compile_mandatory_parents(struct lysc_node *parent, ly_bool add); |
| 109 | |
| 110 | /** |
| 111 | * @brief Validate grouping that was defined but not used in the schema itself. |
| 112 | * |
| 113 | * The grouping does not need to be compiled (and it is compiled here, but the result is forgotten immediately), |
| 114 | * but to have the complete result of the schema validity, even such groupings are supposed to be checked. |
| 115 | * |
| 116 | * @param[in] ctx Compile context. |
| 117 | * @param[in] pnode Parsed parent node of the grouping, NULL for top-level. |
| 118 | * @param[in] grp Parsed grouping node to check. |
| 119 | * @return LY_ERR value. |
| 120 | */ |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 121 | 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] | 122 | |
| 123 | /** |
| 124 | * @brief Compile parsed schema node information. |
| 125 | * |
| 126 | * @param[in] ctx Compile context |
| 127 | * @param[in] pnode Parsed schema node. |
| 128 | * @param[in] parent Compiled parent node where the current node is supposed to be connected. It is |
| 129 | * NULL for top-level nodes, in such a case the module where the node will be connected is taken from |
| 130 | * the compile context. |
| 131 | * @param[in] uses_status If the node is being placed instead of uses, here we have the uses's status value (as node's flags). |
| 132 | * Zero means no uses, non-zero value with no status bit set mean the default status. |
| 133 | * @param[in,out] child_set Optional set to add all the compiled nodes into (can be more in case of uses). |
| 134 | * @return LY_ERR value - LY_SUCCESS or LY_EVALID. |
| 135 | */ |
| 136 | LY_ERR lys_compile_node(struct lysc_ctx *ctx, struct lysp_node *pnode, struct lysc_node *parent, uint16_t uses_status, |
| 137 | struct ly_set *child_set); |
| 138 | |
| 139 | #endif /* LY_SCHEMA_COMPILE_NODE_H_ */ |