Skip to content

Commit f66f25d

Browse files
committed
schema cmp UPDATE support for backwards-compatible ext
1 parent d8d2a2b commit f66f25d

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ set(libsrc
160160
src/plugins_exts/yangdata.c
161161
src/plugins_exts/schema_mount.c
162162
src/plugins_exts/structure.c
163+
src/plugins_exts/schema_comparison.c
163164
src/xml.c
164165
src/xpath.c
165166
src/validation.c

src/plugins.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ extern struct lyplg_ext_record plugins_nacm[];
9898
extern struct lyplg_ext_record plugins_yangdata[];
9999
extern struct lyplg_ext_record plugins_schema_mount[];
100100
extern struct lyplg_ext_record plugins_structure[];
101+
extern struct lyplg_ext_record plugins_schema_cmp[];
101102

102103
static pthread_mutex_t plugins_guard = PTHREAD_MUTEX_INITIALIZER;
103104

@@ -619,6 +620,7 @@ lyplg_init(ly_bool builtin_type_plugins_only, ly_bool static_plugins_only)
619620
LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_yangdata), error);
620621
LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_schema_mount), error);
621622
LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_structure), error);
623+
LY_CHECK_GOTO(ret = plugins_insert(NULL, LYPLG_EXTENSION, plugins_schema_cmp), error);
622624

623625
/* the global plugin sets contain only static plugins at this point, so assign to the counters here.
624626
* the counters are used to determine whether a plugin is static or not */
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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

Comments
 (0)