Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 1 | /** |
| 2 | * @file plugins_exts_compile.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief libyang support for YANG extensions implementation - schema compilation related items. |
| 5 | * |
| 6 | * Copyright (c) 2015 - 2021 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_PLUGINS_EXTS_COMPILE_H_ |
| 16 | #define LY_PLUGINS_EXTS_COMPILE_H_ |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | |
| 20 | #include "log.h" |
| 21 | #include "tree_schema.h" |
| 22 | |
| 23 | struct ly_ctx; |
| 24 | struct lyd_node; |
| 25 | struct lysc_ctx; |
| 26 | |
| 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
| 31 | /** |
Radek Krejci | 7510412 | 2021-04-01 15:37:45 +0200 | [diff] [blame] | 32 | * @defgroup pluginsExtensionsCompile Plugins: Extensions compilation support |
| 33 | * @ingroup pluginsExtensions |
| 34 | * |
| 35 | * Helper functions to implement extension plugin's compile callback. |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 36 | * |
| 37 | * @{ |
| 38 | */ |
| 39 | |
| 40 | /** |
| 41 | * @defgroup scflags Schema compile flags |
| 42 | * |
| 43 | * Flags to modify schema compilation process and change the way how the particular statements are being compiled. * |
| 44 | * @{ |
| 45 | */ |
| 46 | #define LYS_COMPILE_GROUPING 0x01 /**< Compiling (validation) of a non-instantiated grouping. |
| 47 | In this case not all the restrictions are checked since they can |
Radek Krejci | 4e39123 | 2021-04-15 14:41:26 +0200 | [diff] [blame] | 48 | be valid only in the real placement of the grouping. This is |
| 49 | the case of any restriction that needs to look out of the statements |
| 50 | themselves, since the context is not known. */ |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 51 | #define LYS_COMPILE_DISABLED 0x02 /**< Compiling a disabled subtree (by its if-features). Meaning |
| 52 | it will be removed at the end of compilation and should not be |
| 53 | added to any unres sets. */ |
| 54 | #define LYS_COMPILE_NO_CONFIG 0x04 /**< ignore config statements, neither inherit config value */ |
| 55 | #define LYS_COMPILE_NO_DISABLED 0x08 /**< ignore if-feature statements */ |
| 56 | |
| 57 | #define LYS_COMPILE_RPC_INPUT (LYS_IS_INPUT | LYS_COMPILE_NO_CONFIG) /**< Internal option when compiling schema tree of RPC/action input */ |
| 58 | #define LYS_COMPILE_RPC_OUTPUT (LYS_IS_OUTPUT | LYS_COMPILE_NO_CONFIG) /**< Internal option when compiling schema tree of RPC/action output */ |
| 59 | #define LYS_COMPILE_NOTIFICATION (LYS_IS_NOTIF | LYS_COMPILE_NO_CONFIG) /**< Internal option when compiling schema tree of Notification */ |
| 60 | |
| 61 | /** @} scflags */ |
| 62 | |
| 63 | /** |
Radek Krejci | 0b01330 | 2021-03-29 15:22:32 +0200 | [diff] [blame] | 64 | * @brief YANG schema compilation context for use in ::lyplg_ext_compile_clb callback implementation. |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 65 | * |
| 66 | * The structure stores complex information connected with the schema compilation process. In the most simple case, |
| 67 | * the callback is just supposed to pass the provided callback to ::lys_compile_extension_instance() functions. |
| 68 | * |
| 69 | * To access various items from the context, use some of the following lysc_ctx_get_* getters. |
| 70 | */ |
| 71 | struct lysc_ctx; |
| 72 | |
| 73 | /** |
| 74 | * @brief YANG schema compilation context getter for libyang context. |
| 75 | * @param[in] ctx YANG schema compilation context. |
| 76 | * @return libyang context connected with the compilation context. |
| 77 | */ |
| 78 | struct ly_ctx *lysc_ctx_get_ctx(const struct lysc_ctx *ctx); |
| 79 | |
| 80 | /** |
| 81 | * @brief YANG schema compilation context getter for compilation options. |
| 82 | * @param[in] ctx YANG schema compilation context. |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 83 | * @return pointer to the compilation options to allow modifying them with @ref scflags values. |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 84 | */ |
| 85 | uint32_t *lysc_ctx_get_options(const struct lysc_ctx *ctx); |
| 86 | |
| 87 | /** |
| 88 | * @brief YANG schema compilation context getter for path being currently processed. |
| 89 | * @param[in] ctx YANG schema compilation context. |
| 90 | * @return path identifying the place in schema being currently processed by the schema compiler. |
| 91 | */ |
| 92 | const char *lysc_ctx_get_path(const struct lysc_ctx *ctx); |
| 93 | |
| 94 | /** |
| 95 | * @brief Compile substatements of an extension instance. |
| 96 | * |
| 97 | * Uses standard libyang schema compiler to transform YANG statements into the compiled schema structures. The plugins are |
| 98 | * supposed to use this function when the extension instance's substatements are supposed to be compiled in a standard way |
| 99 | * (or if just the @ref scflags are enough to modify the compilation process). |
| 100 | * |
| 101 | * @param[in] ctx YANG schema compile context to track the compilation state. |
| 102 | * @param[in] ext_p Parsed representation of the extension instance being processed. |
| 103 | * @param[in,out] ext Compiled extension instance with the prepared ::lysc_ext_instance.substmts array, which will be updated |
| 104 | * by storing the compiled data. |
| 105 | * @return LY_SUCCESS on success. |
| 106 | * @return LY_EVALID if compilation of the substatements fails. |
| 107 | * @return LY_ENOT if the extension is disabled (by if-feature) and should be ignored. |
| 108 | */ |
| 109 | LY_ERR lys_compile_extension_instance(struct lysc_ctx *ctx, const struct lysp_ext_instance *ext_p, struct lysc_ext_instance *ext); |
| 110 | |
| 111 | /** |
| 112 | * @brief Update path in the compile context, which is used for logging where the compilation failed. |
| 113 | * |
| 114 | * @param[in] ctx Compile context with the path. |
| 115 | * @param[in] parent_module Module of the current node's parent to check difference with the currently processed module (taken from @p ctx). |
| 116 | * @param[in] name Name of the node to update path with. If NULL, the last segment is removed. If the format is `{keyword}`, the following |
| 117 | * call updates the segment to the form `{keyword='name'}` (to remove this compound segment, 2 calls with NULL @p name must be used). |
| 118 | */ |
| 119 | void lysc_update_path(struct lysc_ctx *ctx, struct lys_module *parent_module, const char *name); |
| 120 | |
| 121 | /** |
| 122 | * @brief Duplicate the compiled extension (definition) structure. |
Radek Krejci | 5f9a367 | 2021-03-05 21:35:22 +0100 | [diff] [blame] | 123 | * |
| 124 | * @param[in] orig The extension structure to duplicate. |
| 125 | * @return The duplicated structure to use. |
| 126 | */ |
| 127 | struct lysc_ext *lysc_ext_dup(struct lysc_ext *orig); |
| 128 | |
| 129 | /** @} extensions */ |
| 130 | |
| 131 | #ifdef __cplusplus |
| 132 | } |
| 133 | #endif |
| 134 | |
| 135 | #endif /* LY_PLUGINS_EXTS_COMPILE_H_ */ |