Skip to content

Commit

Permalink
xml printer BUGFIX print namespace of custom attribute in netconf filter
Browse files Browse the repository at this point in the history
  • Loading branch information
fanchanghu authored and michalvasko committed Jan 25, 2021
1 parent dd54b2e commit 6f2b12a
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/printer_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ free_mlist(struct mlist **mlist) {
}
}

inline static int
is_netconf_filter(const struct lyd_node *node)
{
return !strcmp(node->schema->name, "filter")
&& (!strcmp(node->schema->module->name, "ietf-netconf")
|| !strcmp(node->schema->module->name, "notifications"));
}

inline static int
is_type_or_select(const struct lyd_attr *attr)
{
return (!strcmp(attr->name, "type") || !strcmp(attr->name, "select"));
}

static void
xml_print_ns(struct lyout *out, const struct lyd_node *node, struct mlist **mlist, int options)
{
Expand All @@ -86,9 +100,7 @@ xml_print_ns(struct lyout *out, const struct lyd_node *node, struct mlist **mlis

/* add node attribute modules */
for (attr = node->attr; attr; attr = attr->next) {
if (!strcmp(node->schema->name, "filter") &&
(!strcmp(node->schema->module->name, "ietf-netconf") ||
!strcmp(node->schema->module->name, "notifications"))) {
if (is_netconf_filter(node) && is_type_or_select(attr)) {
/* exception for NETCONF's filter attributes */
continue;
} else {
Expand Down Expand Up @@ -127,9 +139,7 @@ xml_print_ns(struct lyout *out, const struct lyd_node *node, struct mlist **mlis
LY_TREE_FOR(node->child, node2) {
LY_TREE_DFS_BEGIN(node2, next, cur) {
for (attr = cur->attr; attr; attr = attr->next) {
if (!strcmp(cur->schema->name, "filter") &&
(!strcmp(cur->schema->module->name, "ietf-netconf") ||
!strcmp(cur->schema->module->name, "notifications"))) {
if (is_netconf_filter(cur) && is_type_or_select(attr)) {
/* exception for NETCONF's filter attributes */
continue;
} else {
Expand Down Expand Up @@ -167,7 +177,7 @@ xml_print_attrs(struct lyout *out, const struct lyd_node *node, int options)
const char *xml_expr = NULL, *mod_name;
char *ident_val;
uint32_t ns_count, i;
int rpc_filter = 0;
int is_nc_filter = 0;
size_t len;
const struct lys_module *wdmod = NULL;

Expand All @@ -187,9 +197,8 @@ xml_print_attrs(struct lyout *out, const struct lyd_node *node, int options)
}
}
/* technically, check for the extension get-filter-element-attributes from ietf-netconf */
if (!strcmp(node->schema->name, "filter")
&& (!strcmp(node->schema->module->name, "ietf-netconf") || !strcmp(node->schema->module->name, "notifications"))) {
rpc_filter = 1;
if (is_netconf_filter(node)) {
is_nc_filter = 1;
}

for (attr = node->attr; attr; attr = attr->next) {
Expand Down Expand Up @@ -225,7 +234,7 @@ xml_print_attrs(struct lyout *out, const struct lyd_node *node, int options)
}

normal_print:
if (rpc_filter) {
if (is_nc_filter && is_type_or_select(attr)) {
/* exception for NETCONF's filter's attributes */
if (!strcmp(attr->name, "select")) {
/* xpath content, we have to convert the JSON format into XML first */
Expand Down

0 comments on commit 6f2b12a

Please sign in to comment.