|
3 | 3 | * @author Michal Vasko <[email protected]> |
4 | 4 | * @brief libyang common parser functions. |
5 | 5 | * |
6 | | - * Copyright (c) 2015 - 2022 CESNET, z.s.p.o. |
| 6 | + * Copyright (c) 2015 - 2024 CESNET, z.s.p.o. |
7 | 7 | * |
8 | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
9 | 9 | * You may not use this file except in compliance with the License. |
@@ -71,33 +71,47 @@ lyd_parser_notif_eventtime_validate(const struct lyd_node *node) |
71 | 71 | LY_ERR rc = LY_SUCCESS; |
72 | 72 | struct ly_ctx *ctx = (struct ly_ctx *)LYD_CTX(node); |
73 | 73 | struct lysc_ctx cctx; |
74 | | - const struct lys_module *mod; |
| 74 | + const struct lys_module *mod1, *mod2; |
| 75 | + const struct lysc_node *schema; |
75 | 76 | LY_ARRAY_COUNT_TYPE u; |
76 | 77 | struct ly_err_item *err = NULL; |
77 | 78 | struct lysp_type *type_p = NULL; |
78 | 79 | struct lysc_pattern **patterns = NULL; |
79 | 80 | const char *value; |
80 | 81 |
|
81 | | - LYSC_CTX_INIT_CTX(cctx, ctx); |
| 82 | + /* find the used modules, we will either use a compiled leaf or compile the relevant type ourselves */ |
| 83 | + mod1 = ly_ctx_get_module_implemented(ctx, "notifications"); |
| 84 | + mod2 = ly_ctx_get_module_latest(ctx, "ietf-yang-types"); |
| 85 | + assert(mod2); |
82 | 86 |
|
83 | | - /* get date-and-time parsed type */ |
84 | | - mod = ly_ctx_get_module_latest(ctx, "ietf-yang-types"); |
85 | | - assert(mod); |
86 | | - LY_ARRAY_FOR(mod->parsed->typedefs, u) { |
87 | | - if (!strcmp(mod->parsed->typedefs[u].name, "date-and-time")) { |
88 | | - type_p = &mod->parsed->typedefs[u].type; |
89 | | - break; |
| 87 | + if (mod1 || !mod2->parsed) { |
| 88 | + /* get date-and-time leaf */ |
| 89 | + schema = lys_find_path(LYD_CTX(node), NULL, "/notifications:notification/eventTime", 0); |
| 90 | + LY_CHECK_RET(!schema, LY_ENOTFOUND); |
| 91 | + |
| 92 | + /* validate the value */ |
| 93 | + value = lyd_get_value(node); |
| 94 | + LY_CHECK_RET(lyd_value_validate(LYD_CTX(node), schema, value, strlen(value), NULL, NULL, NULL)); |
| 95 | + } else { |
| 96 | + LYSC_CTX_INIT_CTX(cctx, ctx); |
| 97 | + |
| 98 | + /* get date-and-time parsed type */ |
| 99 | + LY_ARRAY_FOR(mod2->parsed->typedefs, u) { |
| 100 | + if (!strcmp(mod2->parsed->typedefs[u].name, "date-and-time")) { |
| 101 | + type_p = &mod2->parsed->typedefs[u].type; |
| 102 | + break; |
| 103 | + } |
90 | 104 | } |
91 | | - } |
92 | | - assert(type_p); |
| 105 | + assert(type_p); |
93 | 106 |
|
94 | | - /* compile patterns */ |
95 | | - assert(type_p->patterns); |
96 | | - LY_CHECK_GOTO(rc = lys_compile_type_patterns(&cctx, type_p->patterns, NULL, &patterns), cleanup); |
| 107 | + /* compile patterns */ |
| 108 | + assert(type_p->patterns); |
| 109 | + LY_CHECK_GOTO(rc = lys_compile_type_patterns(&cctx, type_p->patterns, NULL, &patterns), cleanup); |
97 | 110 |
|
98 | | - /* validate */ |
99 | | - value = lyd_get_value(node); |
100 | | - rc = lyplg_type_validate_patterns(patterns, value, strlen(value), &err); |
| 111 | + /* validate */ |
| 112 | + value = lyd_get_value(node); |
| 113 | + rc = lyplg_type_validate_patterns(patterns, value, strlen(value), &err); |
| 114 | + } |
101 | 115 |
|
102 | 116 | cleanup: |
103 | 117 | FREE_ARRAY(&cctx.free_ctx, patterns, lysc_pattern_free); |
|
0 commit comments