|
| 1 | +/** |
| 2 | + * @file schema_comparison.c |
| 3 | + * @author Michal Vasko <[email protected]> |
| 4 | + * @brief libyang extension plugin - backwards-compatible |
| 5 | + * |
| 6 | + * Copyright (c) 2025 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 | +#include <stdint.h> |
| 16 | +#include <stdlib.h> |
| 17 | +#include <string.h> |
| 18 | + |
| 19 | +#include "compat.h" |
| 20 | +#include "libyang.h" |
| 21 | +#include "ly_common.h" |
| 22 | +#include "plugins_exts.h" |
| 23 | +#include "plugins_internal.h" |
| 24 | + |
| 25 | +/** |
| 26 | + * @brief Parse backwards-compatible extension instances. |
| 27 | + * |
| 28 | + * Implementation of ::lyplg_ext_parse_clb callback set as lyext_plugin::parse. |
| 29 | + */ |
| 30 | +static LY_ERR |
| 31 | +bc_parse(struct lysp_ctx *pctx, struct lysp_ext_instance *ext) |
| 32 | +{ |
| 33 | + /* check that the extension is instantiated at an allowed place */ |
| 34 | + if ((ext->parent_stmt != LY_STMT_PATTERN) && (ext->parent_stmt != LY_STMT_WHEN) && |
| 35 | + (ext->parent_stmt != LY_STMT_MUST) && (ext->parent_stmt != LY_STMT_DESCRIPTION) && |
| 36 | + (ext->parent_stmt != LY_STMT_EXTENSION_INSTANCE)) { |
| 37 | + lyplg_ext_parse_log(pctx, ext, LY_LLWRN, 0, "Extension %s is not allowed in \"%s\" statement.", ext->name, |
| 38 | + lyplg_ext_stmt2str(ext->parent_stmt)); |
| 39 | + return LY_ENOT; |
| 40 | + } |
| 41 | + |
| 42 | + return LY_SUCCESS; |
| 43 | +} |
| 44 | + |
| 45 | +/** |
| 46 | + * @brief Plugin descriptions for the schema-comparison backwards-compatible extension |
| 47 | + * |
| 48 | + * Note that external plugins are supposed to use: |
| 49 | + * |
| 50 | + * LYPLG_EXTENSIONS = { |
| 51 | + */ |
| 52 | +const struct lyplg_ext_record plugins_schema_cmp[] = { |
| 53 | + { |
| 54 | + .module = "ietf-schema-comparison", |
| 55 | + .revision = "2025-09-03", |
| 56 | + .name = "backwards-compatible", |
| 57 | + |
| 58 | + .plugin.id = "ly2 schema-comparison", |
| 59 | + .plugin.parse = bc_parse, |
| 60 | + .plugin.compile = NULL, |
| 61 | + .plugin.printer_info = NULL, |
| 62 | + .plugin.printer_ctree = NULL, |
| 63 | + .plugin.printer_ptree = NULL, |
| 64 | + .plugin.node_xpath = NULL, |
| 65 | + .plugin.snode = NULL, |
| 66 | + .plugin.validate = NULL, |
| 67 | + .plugin.pfree = NULL, |
| 68 | + .plugin.cfree = NULL, |
| 69 | + .plugin.compiled_size = NULL, |
| 70 | + .plugin.compiled_print = NULL |
| 71 | + }, |
| 72 | + {0} /* terminating zeroed item */ |
| 73 | +}; |
0 commit comments