data parsers CHANGE simplify API of data parser functions
Adds some checks regarding data set type and prepares code for support
of RPCs/actions and Notifications.
diff --git a/tools/lint/commands.c b/tools/lint/commands.c
index 4b65a76..a8030ed 100644
--- a/tools/lint/commands.c
+++ b/tools/lint/commands.c
@@ -543,7 +543,7 @@
}
static int
-parse_data(char *filepath, int *options, struct lyd_node *val_tree, const char *rpc_act_file,
+parse_data(char *filepath, int *options, const struct lyd_node **trees, const char *rpc_act_file,
struct lyd_node **result)
{
LYD_FORMAT informat = LYD_UNKNOWN;
@@ -641,26 +641,41 @@
fprintf(stderr, "RPC/action reply data require additional argument (file with the RPC/action).\n");
return EXIT_FAILURE;
}
- rpc_act = lyd_parse_path(ctx, rpc_act_file, informat, LYD_OPT_RPC, val_tree);
+ rpc_act = lyd_parse_path(ctx, rpc_act_file, informat, LYD_OPT_RPC, trees);
if (!rpc_act) {
fprintf(stderr, "Failed to parse RPC/action.\n");
return EXIT_FAILURE;
}
- data = lyd_parse_path(ctx, filepath, informat, opts, rpc_act, val_tree);
+ if (trees) {
+ const struct lyd_node **trees_new;
+ unsigned int u;
+ trees_new = lyd_trees_new(1, rpc_act);
+
+ LY_ARRAY_FOR(trees, u) {
+ trees_new = lyd_trees_add(trees_new, trees[u]);
+ }
+ lyd_trees_free(trees, 0);
+ trees = trees_new;
+ } else {
+ trees = lyd_trees_new(1, rpc_act);
+ }
+ data = lyd_parse_path(ctx, filepath, informat, opts, trees);
} else if (opts & (LYD_OPT_RPC | LYD_OPT_NOTIF)) {
- data = lyd_parse_path(ctx, filepath, informat, opts, val_tree);
+ data = lyd_parse_path(ctx, filepath, informat, opts, trees);
+#if 0
} else if (opts & LYD_OPT_DATA_TEMPLATE) {
if (!rpc_act_file) {
fprintf(stderr, "YANG-DATA require additional argument (name instance of yang-data extension).\n");
return EXIT_FAILURE;
}
data = lyd_parse_path(ctx, filepath, informat, opts, rpc_act_file);
+#endif
} else {
if (!(opts & LYD_OPT_TYPEMASK)) {
/* automatically add yang-library data */
opts |= LYD_OPT_DATA_ADD_YANGLIB;
}
- data = lyd_parse_path(ctx, filepath, informat, opts);
+ data = lyd_parse_path(ctx, filepath, informat, opts, NULL);
}
#if 0
}
@@ -686,6 +701,7 @@
char **argv = NULL, *ptr;
const char *out_path = NULL;
struct lyd_node *data = NULL, *val_tree = NULL;
+ const struct lyd_node **trees = NULL;
LYD_FORMAT outformat = LYD_UNKNOWN;
FILE *output = stdout;
static struct option long_options[] = {
@@ -763,20 +779,21 @@
out_path = optarg;
break;
case 'r':
- if (val_tree || (options & LYD_OPT_NOEXTDEPS)) {
- fprintf(stderr, "The running datastore (-r) cannot be set multiple times.\n");
- goto cleanup;
- }
if (optarg[0] == '!') {
/* ignore extenral dependencies to the running datastore */
options |= LYD_OPT_NOEXTDEPS;
} else {
/* external file with the running datastore */
- val_tree = lyd_parse_path(ctx, optarg, LYD_XML, LYD_OPT_DATA_NO_YANGLIB);
+ val_tree = lyd_parse_path(ctx, optarg, LYD_XML, LYD_OPT_DATA_NO_YANGLIB, trees);
if (!val_tree) {
fprintf(stderr, "Failed to parse the additional data tree for validation.\n");
goto cleanup;
}
+ if (!trees) {
+ trees = lyd_trees_new(1, val_tree);
+ } else {
+ trees = lyd_trees_add(trees, val_tree);
+ }
}
break;
case 's':
@@ -822,7 +839,7 @@
goto cleanup;
}
- if (parse_data(argv[optind], &options, val_tree, argv[optind + 1], &data)) {
+ if (parse_data(argv[optind], &options, trees, argv[optind + 1], &data)) {
goto cleanup;
}
@@ -852,7 +869,7 @@
fclose(output);
}
- lyd_free_all(val_tree);
+ lyd_trees_free(trees, 1);
lyd_free_all(data);
return ret;
diff --git a/tools/lint/main_ni.c b/tools/lint/main_ni.c
index 8b72e15..9b19ee1 100644
--- a/tools/lint/main_ni.c
+++ b/tools/lint/main_ni.c
@@ -322,6 +322,7 @@
struct *subroot, *next, *node;
#endif
struct lyd_node *oper = NULL;
+ const struct lyd_node **trees = NULL;
struct dataitem {
const char *filename;
struct lyd_node *tree;
@@ -803,11 +804,12 @@
fprintf(stderr, "yanglint error: The operational data are expected in XML or JSON format.\n");
goto cleanup;
}
- oper = lyd_parse_path(ctx, oper_file, informat_d, LYD_OPT_DATA_NO_YANGLIB | LYD_OPT_TRUSTED);
+ oper = lyd_parse_path(ctx, oper_file, informat_d, LYD_OPT_DATA_NO_YANGLIB | LYD_OPT_TRUSTED, NULL);
if (!oper) {
fprintf(stderr, "yanglint error: Failed to parse the operational datastore file for RPC/Notification validation.\n");
goto cleanup;
}
+ trees = lyd_trees_new(1, oper);
}
for (data_item = data, data_prev = NULL; data_item; data_prev = data_item, data_item = data_item->next) {
@@ -973,7 +975,7 @@
#else
{
#endif
- data_item->tree = lyd_parse_path(ctx, data_item->filename, data_item->format, options_parser, oper);
+ data_item->tree = lyd_parse_path(ctx, data_item->filename, data_item->format, options_parser, trees);
}
if (ly_err_first(ctx)) {
goto cleanup;
@@ -1107,7 +1109,7 @@
lyd_free_all(data->tree);
free(data);
}
- lyd_free_all(oper);
+ lyd_trees_free(trees, 1);
ly_ctx_destroy(ctx, NULL);
return ret;