Skip to content

Commit 7f4b97f

Browse files
committed
node instanceid BUGFIX special path '/' handling
Refs CESNET/netopeer2#1674
1 parent b90865b commit 7f4b97f

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/plugins_types/node_instanceid.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ lyplg_type_store_node_instanceid(const struct ly_ctx *ctx, const struct lysc_typ
190190

191191
if ((((char *)value)[0] == '/') && (value_len == 1)) {
192192
/* special path */
193+
format = LY_VALUE_CANON;
193194
goto store;
194195
}
195196

@@ -296,6 +297,34 @@ lyplg_type_print_node_instanceid(const struct ly_ctx *UNUSED(ctx), const struct
296297
return ret;
297298
}
298299

300+
/**
301+
* @brief Implementation of ::lyplg_type_dup_clb for the node-instance-identifier ietf-netconf-acm type.
302+
*/
303+
static LY_ERR
304+
lyplg_type_dup_node_instanceid(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
305+
{
306+
LY_ERR ret;
307+
308+
memset(dup, 0, sizeof *dup);
309+
310+
/* canonical value */
311+
ret = lydict_insert(ctx, original->_canonical, 0, &dup->_canonical);
312+
LY_CHECK_GOTO(ret, error);
313+
314+
if (original->target) {
315+
/* copy path */
316+
ret = ly_path_dup(ctx, original->target, &dup->target);
317+
LY_CHECK_GOTO(ret, error);
318+
} /* else is the special path "/" that has no target stored */
319+
320+
dup->realtype = original->realtype;
321+
return LY_SUCCESS;
322+
323+
error:
324+
lyplg_type_free_instanceid(ctx, dup);
325+
return ret;
326+
}
327+
299328
/**
300329
* @brief Plugin information for instance-identifier type implementation.
301330
*
@@ -315,7 +344,7 @@ const struct lyplg_type_record plugins_node_instanceid[] = {
315344
.plugin.compare = lyplg_type_compare_simple,
316345
.plugin.sort = lyplg_type_sort_simple,
317346
.plugin.print = lyplg_type_print_node_instanceid,
318-
.plugin.duplicate = lyplg_type_dup_instanceid,
347+
.plugin.duplicate = lyplg_type_dup_node_instanceid,
319348
.plugin.free = lyplg_type_free_instanceid,
320349
.plugin.lyb_data_len = -1,
321350
},
@@ -330,7 +359,7 @@ const struct lyplg_type_record plugins_node_instanceid[] = {
330359
.plugin.compare = lyplg_type_compare_simple,
331360
.plugin.sort = lyplg_type_sort_simple,
332361
.plugin.print = lyplg_type_print_node_instanceid,
333-
.plugin.duplicate = lyplg_type_dup_instanceid,
362+
.plugin.duplicate = lyplg_type_dup_node_instanceid,
334363
.plugin.free = lyplg_type_free_instanceid,
335364
.plugin.lyb_data_len = -1,
336365
},

0 commit comments

Comments
 (0)