summaryrefslogtreecommitdiffstats
path: root/src/parser_common.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-17 02:59:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-17 02:59:54 +0000
commit5bc4f4fb5b383ca32b382b6c0d09602346064414 (patch)
treec741e5844c2815679107d648a15841653b9b01a5 /src/parser_common.c
parentAdding upstream version 3.1.0+dfsg. (diff)
downloadlibyang3-5bc4f4fb5b383ca32b382b6c0d09602346064414.tar.xz
libyang3-5bc4f4fb5b383ca32b382b6c0d09602346064414.zip
Adding upstream version 3.4.2+dfsg.upstream/3.4.2+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/parser_common.c')
-rw-r--r--src/parser_common.c74
1 files changed, 44 insertions, 30 deletions
diff --git a/src/parser_common.c b/src/parser_common.c
index 290e3a5..5dadecf 100644
--- a/src/parser_common.c
+++ b/src/parser_common.c
@@ -3,7 +3,7 @@
* @author Michal Vasko <mvasko@cesnet.cz>
* @brief libyang common parser functions.
*
- * Copyright (c) 2015 - 2022 CESNET, z.s.p.o.
+ * Copyright (c) 2015 - 2024 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.
@@ -70,34 +70,48 @@ lyd_parser_notif_eventtime_validate(const struct lyd_node *node)
{
LY_ERR rc = LY_SUCCESS;
struct ly_ctx *ctx = (struct ly_ctx *)LYD_CTX(node);
- struct lysc_ctx cctx;
- const struct lys_module *mod;
+ struct lysc_ctx cctx = {0};
+ const struct lys_module *mod1, *mod2;
+ const struct lysc_node *schema;
LY_ARRAY_COUNT_TYPE u;
struct ly_err_item *err = NULL;
struct lysp_type *type_p = NULL;
struct lysc_pattern **patterns = NULL;
const char *value;
- LYSC_CTX_INIT_CTX(cctx, ctx);
+ /* find the used modules, we will either use a compiled leaf or compile the relevant type ourselves */
+ mod1 = ly_ctx_get_module_implemented(ctx, "notifications");
+ mod2 = ly_ctx_get_module_latest(ctx, "ietf-yang-types");
+ assert(mod2);
- /* get date-and-time parsed type */
- mod = ly_ctx_get_module_latest(ctx, "ietf-yang-types");
- assert(mod);
- LY_ARRAY_FOR(mod->parsed->typedefs, u) {
- if (!strcmp(mod->parsed->typedefs[u].name, "date-and-time")) {
- type_p = &mod->parsed->typedefs[u].type;
- break;
+ if (mod1 || !mod2->parsed) {
+ /* get date-and-time leaf */
+ schema = lys_find_path(LYD_CTX(node), NULL, "/notifications:notification/eventTime", 0);
+ LY_CHECK_RET(!schema, LY_ENOTFOUND);
+
+ /* validate the value */
+ value = lyd_get_value(node);
+ LY_CHECK_RET(lyd_value_validate(LYD_CTX(node), schema, value, strlen(value), NULL, NULL, NULL));
+ } else {
+ LYSC_CTX_INIT_CTX(cctx, ctx);
+
+ /* get date-and-time parsed type */
+ LY_ARRAY_FOR(mod2->parsed->typedefs, u) {
+ if (!strcmp(mod2->parsed->typedefs[u].name, "date-and-time")) {
+ type_p = &mod2->parsed->typedefs[u].type;
+ break;
+ }
}
- }
- assert(type_p);
+ assert(type_p);
- /* compile patterns */
- assert(type_p->patterns);
- LY_CHECK_GOTO(rc = lys_compile_type_patterns(&cctx, type_p->patterns, NULL, &patterns), cleanup);
+ /* compile patterns */
+ assert(type_p->patterns);
+ LY_CHECK_GOTO(rc = lys_compile_type_patterns(&cctx, type_p->patterns, NULL, &patterns), cleanup);
- /* validate */
- value = lyd_get_value(node);
- rc = lyplg_type_validate_patterns(patterns, value, strlen(value), &err);
+ /* validate */
+ value = lyd_get_value(node);
+ rc = lyplg_type_validate_patterns(patterns, value, strlen(value), &err);
+ }
cleanup:
FREE_ARRAY(&cctx.free_ctx, patterns, lysc_pattern_free);
@@ -3559,7 +3573,7 @@ lys_parse_ext_instance_stmt(struct lysp_ctx *pctx, struct lysp_ext_substmt *subs
{
LY_ERR rc = LY_SUCCESS;
- if (!substmt->storage) {
+ if (!substmt->storage_p) {
/* nothing to parse, ignored */
goto cleanup;
}
@@ -3587,7 +3601,7 @@ lys_parse_ext_instance_stmt(struct lysp_ctx *pctx, struct lysp_ext_substmt *subs
LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, (void **)&pnode, NULL), cleanup);
/* usually is a linked-list of all the parsed schema nodes */
- pnodes_p = VOIDPTR_C(substmt->storage);
+ pnodes_p = (struct lysp_node **)substmt->storage_p;
while (*pnodes_p) {
pnodes_p = &(*pnodes_p)->next;
}
@@ -3615,7 +3629,7 @@ lys_parse_ext_instance_stmt(struct lysp_ctx *pctx, struct lysp_ext_substmt *subs
case LY_STMT_TYPEDEF:
case LY_STMT_UNIQUE:
/* parse, sized array */
- LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, VOIDPTR_C(substmt->storage), NULL), cleanup);
+ LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, substmt->storage_p, NULL), cleanup);
break;
case LY_STMT_ARGUMENT:
@@ -3650,50 +3664,50 @@ lys_parse_ext_instance_stmt(struct lysp_ctx *pctx, struct lysp_ext_substmt *subs
case LY_STMT_YANG_VERSION:
case LY_STMT_YIN_ELEMENT:
/* single item */
- if (*VOIDPTR2_C(substmt->storage)) {
+ if (*substmt->storage_p) {
LOGVAL(PARSER_CTX(pctx), LY_VCODE_DUPSTMT, stmt->stmt);
rc = LY_EVALID;
goto cleanup;
}
/* parse */
- LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, VOIDPTR_C(substmt->storage), NULL), cleanup);
+ LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, substmt->storage_p, NULL), cleanup);
break;
case LY_STMT_CONFIG:
/* single item */
- if ((*(uint16_t *)VOIDPTR2_C(substmt->storage)) & LYS_CONFIG_MASK) {
+ if ((*(uint16_t *)substmt->storage_p) & LYS_CONFIG_MASK) {
LOGVAL(PARSER_CTX(pctx), LY_VCODE_DUPSTMT, stmt->stmt);
rc = LY_EVALID;
goto cleanup;
}
/* parse */
- LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, VOIDPTR_C(substmt->storage), NULL), cleanup);
+ LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, substmt->storage_p, NULL), cleanup);
break;
case LY_STMT_ORDERED_BY:
/* single item */
- if ((*(uint16_t *)VOIDPTR2_C(substmt->storage)) & LYS_ORDBY_MASK) {
+ if ((*(uint16_t *)substmt->storage_p) & LYS_ORDBY_MASK) {
LOGVAL(PARSER_CTX(pctx), LY_VCODE_DUPSTMT, stmt->stmt);
rc = LY_EVALID;
goto cleanup;
}
/* parse */
- LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, VOIDPTR_C(substmt->storage), NULL), cleanup);
+ LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, substmt->storage_p, NULL), cleanup);
break;
case LY_STMT_STATUS:
/* single item */
- if ((*(uint16_t *)VOIDPTR2_C(substmt->storage)) & LYS_STATUS_MASK) {
+ if ((*(uint16_t *)substmt->storage_p) & LYS_STATUS_MASK) {
LOGVAL(PARSER_CTX(pctx), LY_VCODE_DUPSTMT, stmt->stmt);
rc = LY_EVALID;
goto cleanup;
}
/* parse */
- LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, VOIDPTR_C(substmt->storage), NULL), cleanup);
+ LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, substmt->storage_p, NULL), cleanup);
break;
default: