parser xml BUGFIX create-subscription filter attrs support
The module is not using filter-attrs extension
so it needs special support.
Fixes #1959
diff --git a/src/parser_xml.c b/src/parser_xml.c
index 5e1f0dc..5a929da 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -73,11 +73,16 @@
*meta = NULL;
/* check for NETCONF filter unqualified attributes */
- LY_ARRAY_FOR(sparent->exts, u) {
- if (!strcmp(sparent->exts[u].def->name, "get-filter-element-attributes") &&
- !strcmp(sparent->exts[u].def->module->name, "ietf-netconf")) {
- filter_attrs = 1;
- break;
+ if (!strcmp(sparent->module->name, "notifications")) {
+ /* ancient module that does not even use the extension */
+ filter_attrs = 1;
+ } else {
+ LY_ARRAY_FOR(sparent->exts, u) {
+ if (!strcmp(sparent->exts[u].def->name, "get-filter-element-attributes") &&
+ !strcmp(sparent->exts[u].def->module->name, "ietf-netconf")) {
+ filter_attrs = 1;
+ break;
+ }
}
}
diff --git a/src/printer_xml.c b/src/printer_xml.c
index e22924c..a7f4c73 100644
--- a/src/printer_xml.c
+++ b/src/printer_xml.c
@@ -192,11 +192,15 @@
}
/* check for NETCONF filter unqualified attributes */
- LY_ARRAY_FOR(node->schema->exts, u) {
- if (!strcmp(node->schema->exts[u].def->name, "get-filter-element-attributes") &&
- !strcmp(node->schema->exts[u].def->module->name, "ietf-netconf")) {
- filter_attrs = 1;
- break;
+ if (!strcmp(node->schema->module->name, "notifications")) {
+ filter_attrs = 1;
+ } else {
+ LY_ARRAY_FOR(node->schema->exts, u) {
+ if (!strcmp(node->schema->exts[u].def->name, "get-filter-element-attributes") &&
+ !strcmp(node->schema->exts[u].def->module->name, "ietf-netconf")) {
+ filter_attrs = 1;
+ break;
+ }
}
}
diff --git a/tests/utests/data/test_parser_xml.c b/tests/utests/data/test_parser_xml.c
index 86b926b..7defd9c 100644
--- a/tests/utests/data/test_parser_xml.c
+++ b/tests/utests/data/test_parser_xml.c
@@ -1,9 +1,10 @@
-/*
+/**
* @file test_parser_xml.c
- * @author: Radek Krejci <rkrejci@cesnet.cz>
+ * @author Radek Krejci <rkrejci@cesnet.cz>
+ * @author Michal Vasko <mvasko@cesnet.cz>
* @brief unit tests for functions from parser_xml.c
*
- * Copyright (c) 2019-2020 CESNET, z.s.p.o.
+ * Copyright (c) 2019 - 2022 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
@@ -749,6 +750,7 @@
const char *feats[] = {"writable-running", NULL};
assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf", "2011-06-01", feats)));
+ assert_non_null((ly_ctx_load_module(UTEST_LYCTX, "notifications", "2008-07-14", NULL)));
data = "<get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
" <filter type=\"xpath\" select=\"/*\"/>\n"
@@ -767,11 +769,20 @@
dsc = "This parameter specifies the portion of the system\nconfiguration and state data to retrieve.";
CHECK_LYSC_NODE(node->schema, dsc, 1, LYS_STATUS_CURR | LYS_IS_INPUT, 1, "filter", 0, LYS_ANYXML, 1, 0, NULL, 0);
- CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS,
- "<get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
- " <filter type=\"xpath\" select=\"/*\"/>\n"
- "</get>\n");
+ CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
+ lyd_free_all(tree);
+ data = "<create-subscription xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n"
+ " <filter type=\"subtree\">\n"
+ " <inner-node xmlns=\"my:urn\"/>\n"
+ " </filter>\n"
+ "</create-subscription>\n";
+ assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
+ assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_XML, LYD_TYPE_RPC_YANG, &tree, NULL));
+ ly_in_free(in, 0);
+ assert_non_null(tree);
+
+ CHECK_LYD_STRING(tree, LYD_PRINT_WITHSIBLINGS, data);
lyd_free_all(tree);
}