schemas FEATURE add schema getters from the context
Also check for the duplicities in the context when parsing a new schema.
diff --git a/src/tree_schema.c b/src/tree_schema.c
index 3960bb3..60bd9b9 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -11,7 +11,8 @@
*
* https://opensource.org/licenses/BSD-3-Clause
*/
-#define _DEFAULT_SOURCE
+
+#include "common.h"
#include <ctype.h>
#include <errno.h>
@@ -24,7 +25,6 @@
#include <unistd.h>
#include "libyang.h"
-#include "common.h"
#include "context.h"
#include "tree_schema_internal.h"
@@ -1076,7 +1076,7 @@
return ret;
}
-const struct lys_module *
+static const struct lys_module *
lys_parse_mem_(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format, const char *revision, int implement)
{
struct lys_module *mod = NULL;
@@ -1103,21 +1103,36 @@
}
if (implement) {
+ if (ly_ctx_get_module_implemented(ctx, mod->parsed->name)) {
+ LOGERR(ctx, LY_EDENIED, "Module \"%s\" is already implemented in the context.", mod->parsed->name);
+ lys_module_free(mod, NULL);
+ return NULL;
+ }
mod->parsed->implemented = 1;
}
if (revision) {
/* check revision of the parsed model */
- if (!mod->parsed->revs || strcmp(revision, mod->parsed->revs[0].rev)) {
+ if (!mod->parsed->revs || strcmp(revision, mod->parsed->revs[0].date)) {
LOGERR(ctx, LY_EINVAL, "Module \"%s\" parsed with the wrong revision (\"%s\" instead \"%s\").",
- mod->parsed->name, mod->parsed->revs[0].rev, revision);
- lysp_module_free(mod->parsed);
- free(mod);
+ mod->parsed->name, mod->parsed->revs[0].date, revision);
+ lys_module_free(mod, NULL);
return NULL;
}
}
/* check for duplicity in the context */
+ if (ly_ctx_get_module(ctx, mod->parsed->name, mod->parsed->revs ? mod->parsed->revs[0].date : NULL)) {
+ if (mod->parsed->revs) {
+ LOGERR(ctx, LY_EEXIST, "Module \"%s\" of revision \"%s\" is already present in the context.",
+ mod->parsed->name, mod->parsed->revs[0].date);
+ } else {
+ LOGERR(ctx, LY_EEXIST, "Module \"%s\" with no revision is already present in the context.",
+ mod->parsed->name);
+ }
+ lys_module_free(mod, NULL);
+ return NULL;
+ }
/* add into context */
ly_set_add(&ctx->list, mod, LY_SET_OPT_USEASLIST);
@@ -1238,9 +1253,9 @@
}
if (rev) {
len = dot - ++rev;
- if (!mod->parsed->revs || len != 10 || strncmp(mod->parsed->revs[0].rev, rev, len)) {
+ if (!mod->parsed->revs || len != 10 || strncmp(mod->parsed->revs[0].date, rev, len)) {
LOGWRN(ctx, "File name \"%s\" does not match module revision \"%s\".", filename,
- mod->parsed->revs ? mod->parsed->revs[0].rev : "none");
+ mod->parsed->revs ? mod->parsed->revs[0].date : "none");
}
}