Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file tree_schema_helpers.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 4 | * @brief Parsing and validation helper functions for schema trees |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 5 | * |
| 6 | * Copyright (c) 2015 - 2018 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 14 | #include "common.h" |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 15 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 16 | #include <assert.h> |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 17 | #include <ctype.h> |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 18 | #include <errno.h> |
| 19 | #include <fcntl.h> |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 20 | #include <limits.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 21 | #include <stdint.h> |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 22 | #include <stdlib.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 23 | #include <string.h> |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 24 | #include <unistd.h> |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 25 | #include <time.h> |
| 26 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 27 | #include "context.h" |
| 28 | #include "dict.h" |
| 29 | #include "extensions.h" |
| 30 | #include "hash_table.h" |
| 31 | #include "log.h" |
| 32 | #include "set.h" |
| 33 | #include "tree.h" |
| 34 | #include "tree_schema.h" |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 35 | #include "tree_schema_internal.h" |
| 36 | |
| 37 | LY_ERR |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 38 | lys_resolve_schema_nodeid(struct lysc_ctx *ctx, const char *nodeid, size_t nodeid_len, const struct lysc_node *context_node, |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 39 | const struct lys_module *context_module, int nodetype, int implement, |
| 40 | const struct lysc_node **target, uint16_t *result_flag) |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 41 | { |
| 42 | LY_ERR ret = LY_EVALID; |
| 43 | const char *name, *prefix, *id; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 44 | size_t name_len, prefix_len; |
Radek Krejci | 7af6424 | 2019-02-18 13:07:53 +0100 | [diff] [blame] | 45 | const struct lys_module *mod; |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 46 | const char *nodeid_type; |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 47 | int getnext_extra_flag = 0; |
Radek Krejci | 05b774b | 2019-02-25 13:26:18 +0100 | [diff] [blame] | 48 | int current_nodetype = 0; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 49 | |
| 50 | assert(nodeid); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 51 | assert(target); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 52 | assert(result_flag); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 53 | *target = NULL; |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 54 | *result_flag = 0; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 55 | |
| 56 | id = nodeid; |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 57 | |
| 58 | if (context_node) { |
| 59 | /* descendant-schema-nodeid */ |
| 60 | nodeid_type = "descendant"; |
Radek Krejci | 3641f56 | 2019-02-13 15:38:40 +0100 | [diff] [blame] | 61 | |
| 62 | if (*id == '/') { |
| 63 | LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_REFERENCE, |
| 64 | "Invalid descendant-schema-nodeid value \"%.*s\" - absolute-schema-nodeid used.", |
| 65 | nodeid_len ? nodeid_len : strlen(nodeid), nodeid); |
| 66 | return LY_EVALID; |
| 67 | } |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 68 | } else { |
| 69 | /* absolute-schema-nodeid */ |
| 70 | nodeid_type = "absolute"; |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 71 | |
| 72 | if (*id != '/') { |
| 73 | LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_REFERENCE, |
| 74 | "Invalid absolute-schema-nodeid value \"%.*s\" - missing starting \"/\".", |
Radek Krejci | 3641f56 | 2019-02-13 15:38:40 +0100 | [diff] [blame] | 75 | nodeid_len ? nodeid_len : strlen(nodeid), nodeid); |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 76 | return LY_EVALID; |
| 77 | } |
| 78 | ++id; |
| 79 | } |
| 80 | |
Radek Krejci | b4a4a27 | 2019-06-10 12:44:52 +0200 | [diff] [blame] | 81 | while (*id && (ret = ly_parse_nodeid(&id, &prefix, &prefix_len, &name, &name_len)) == LY_SUCCESS) { |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 82 | if (prefix) { |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 83 | mod = lys_module_find_prefix(context_module, prefix, prefix_len); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 84 | if (!mod) { |
| 85 | LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_REFERENCE, |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 86 | "Invalid %s-schema-nodeid value \"%.*s\" - prefix \"%.*s\" not defined in module \"%s\".", |
| 87 | nodeid_type, id - nodeid, nodeid, prefix_len, prefix, context_module->name); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 88 | return LY_ENOTFOUND; |
| 89 | } |
| 90 | } else { |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 91 | mod = context_module; |
| 92 | } |
| 93 | if (implement && !mod->implemented) { |
| 94 | /* make the module implemented */ |
| 95 | ly_ctx_module_implement_internal(ctx->ctx, (struct lys_module*)mod, 2); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 96 | } |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 97 | if (context_node && context_node->nodetype == LYS_ACTION) { |
| 98 | /* move through input/output manually */ |
| 99 | if (!strncmp("input", name, name_len)) { |
| 100 | (*result_flag) |= LYSC_OPT_RPC_INPUT; |
Radek Krejci | 05b774b | 2019-02-25 13:26:18 +0100 | [diff] [blame] | 101 | } else if (!strncmp("output", name, name_len)) { |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 102 | (*result_flag) |= LYSC_OPT_RPC_OUTPUT; |
| 103 | getnext_extra_flag = LYS_GETNEXT_OUTPUT; |
Radek Krejci | 05b774b | 2019-02-25 13:26:18 +0100 | [diff] [blame] | 104 | } else { |
| 105 | goto getnext; |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 106 | } |
Radek Krejci | 05b774b | 2019-02-25 13:26:18 +0100 | [diff] [blame] | 107 | current_nodetype = LYS_INOUT; |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 108 | } else { |
Radek Krejci | 05b774b | 2019-02-25 13:26:18 +0100 | [diff] [blame] | 109 | getnext: |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 110 | context_node = lys_child(context_node, mod, name, name_len, 0, |
| 111 | getnext_extra_flag | LYS_GETNEXT_NOSTATECHECK | LYS_GETNEXT_WITHCHOICE | LYS_GETNEXT_WITHCASE); |
| 112 | if (!context_node) { |
| 113 | LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_REFERENCE, |
| 114 | "Invalid %s-schema-nodeid value \"%.*s\" - target node not found.", nodeid_type, id - nodeid, nodeid); |
| 115 | return LY_ENOTFOUND; |
| 116 | } |
| 117 | getnext_extra_flag = 0; |
Radek Krejci | 05b774b | 2019-02-25 13:26:18 +0100 | [diff] [blame] | 118 | current_nodetype = context_node->nodetype; |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 119 | |
Radek Krejci | 05b774b | 2019-02-25 13:26:18 +0100 | [diff] [blame] | 120 | if (current_nodetype == LYS_NOTIF) { |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 121 | (*result_flag) |= LYSC_OPT_NOTIFICATION; |
| 122 | } |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 123 | } |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 124 | if (!*id || (nodeid_len && ((size_t)(id - nodeid) >= nodeid_len))) { |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 125 | break; |
| 126 | } |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 127 | if (*id != '/') { |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 128 | LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_REFERENCE, |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 129 | "Invalid %s-schema-nodeid value \"%.*s\" - missing \"/\" as node-identifier separator.", |
| 130 | nodeid_type, id - nodeid + 1, nodeid); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 131 | return LY_EVALID; |
| 132 | } |
| 133 | ++id; |
| 134 | } |
| 135 | |
| 136 | if (ret == LY_SUCCESS) { |
Radek Krejci | 7af6424 | 2019-02-18 13:07:53 +0100 | [diff] [blame] | 137 | *target = context_node; |
Radek Krejci | 05b774b | 2019-02-25 13:26:18 +0100 | [diff] [blame] | 138 | if (nodetype & LYS_INOUT) { |
| 139 | /* instead of input/output nodes, the RPC/action node is actually returned */ |
| 140 | } |
| 141 | if (nodetype && !(current_nodetype & nodetype)) { |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 142 | return LY_EDENIED; |
| 143 | } |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 144 | } else { |
| 145 | LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_REFERENCE, |
| 146 | "Invalid %s-schema-nodeid value \"%.*s\" - unexpected end of expression.", |
Radek Krejci | 3641f56 | 2019-02-13 15:38:40 +0100 | [diff] [blame] | 147 | nodeid_type, nodeid_len ? nodeid_len : strlen(nodeid), nodeid); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | return ret; |
| 151 | } |
| 152 | |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 153 | LY_ERR |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 154 | lysp_check_prefix(struct lys_parser_ctx *ctx, struct lysp_import *imports, const char *module_prefix, const char **value) |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 155 | { |
| 156 | struct lysp_import *i; |
| 157 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 158 | if (module_prefix && &module_prefix != value && !strcmp(module_prefix, *value)) { |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 159 | LOGVAL(ctx->ctx, LY_VLOG_LINE, &ctx->line, LYVE_REFERENCE, |
| 160 | "Prefix \"%s\" already used as module prefix.", *value); |
| 161 | return LY_EEXIST; |
| 162 | } |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 163 | LY_ARRAY_FOR(imports, struct lysp_import, i) { |
| 164 | if (i->prefix && &i->prefix != value && !strcmp(i->prefix, *value)) { |
| 165 | LOGVAL(ctx->ctx, LY_VLOG_LINE, &ctx->line, LYVE_REFERENCE, "Prefix \"%s\" already used to import \"%s\" module.", |
| 166 | *value, i->name); |
| 167 | return LY_EEXIST; |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | return LY_SUCCESS; |
| 171 | } |
| 172 | |
| 173 | LY_ERR |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 174 | lysc_check_status(struct lysc_ctx *ctx, |
| 175 | uint16_t flags1, void *mod1, const char *name1, |
| 176 | uint16_t flags2, void *mod2, const char *name2) |
| 177 | { |
| 178 | uint16_t flg1, flg2; |
| 179 | |
| 180 | flg1 = (flags1 & LYS_STATUS_MASK) ? (flags1 & LYS_STATUS_MASK) : LYS_STATUS_CURR; |
| 181 | flg2 = (flags2 & LYS_STATUS_MASK) ? (flags2 & LYS_STATUS_MASK) : LYS_STATUS_CURR; |
| 182 | |
| 183 | if ((flg1 < flg2) && (mod1 == mod2)) { |
| 184 | if (ctx) { |
| 185 | LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_REFERENCE, |
| 186 | "A %s definition \"%s\" is not allowed to reference %s definition \"%s\".", |
| 187 | flg1 == LYS_STATUS_CURR ? "current" : "deprecated", name1, |
| 188 | flg2 == LYS_STATUS_OBSLT ? "obsolete" : "deprecated", name2); |
| 189 | } |
| 190 | return LY_EVALID; |
| 191 | } |
| 192 | |
| 193 | return LY_SUCCESS; |
| 194 | } |
| 195 | |
| 196 | LY_ERR |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 197 | lysp_check_date(struct lys_parser_ctx *ctx, const char *date, int date_len, const char *stmt) |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 198 | { |
| 199 | int i; |
| 200 | struct tm tm, tm_; |
| 201 | char *r; |
| 202 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 203 | LY_CHECK_ARG_RET(ctx ? ctx->ctx : NULL, date, LY_EINVAL); |
| 204 | LY_CHECK_ERR_RET(date_len != LY_REV_SIZE - 1, LOGARG(ctx ? ctx->ctx : NULL, date_len), LY_EINVAL); |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 205 | |
| 206 | /* check format */ |
| 207 | for (i = 0; i < date_len; i++) { |
| 208 | if (i == 4 || i == 7) { |
| 209 | if (date[i] != '-') { |
| 210 | goto error; |
| 211 | } |
| 212 | } else if (!isdigit(date[i])) { |
| 213 | goto error; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /* check content, e.g. 2018-02-31 */ |
| 218 | memset(&tm, 0, sizeof tm); |
| 219 | r = strptime(date, "%Y-%m-%d", &tm); |
| 220 | if (!r || r != &date[LY_REV_SIZE - 1]) { |
| 221 | goto error; |
| 222 | } |
| 223 | memcpy(&tm_, &tm, sizeof tm); |
| 224 | mktime(&tm_); /* mktime modifies tm_ if it refers invalid date */ |
| 225 | if (tm.tm_mday != tm_.tm_mday) { /* e.g 2018-02-29 -> 2018-03-01 */ |
| 226 | /* checking days is enough, since other errors |
| 227 | * have been checked by strptime() */ |
| 228 | goto error; |
| 229 | } |
| 230 | |
| 231 | return LY_SUCCESS; |
| 232 | |
| 233 | error: |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 234 | if (stmt) { |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 235 | if (ctx) { |
| 236 | LOGVAL(ctx->ctx, LY_VLOG_LINE, &ctx->line, LY_VCODE_INVAL, date_len, date, stmt); |
| 237 | } else { |
| 238 | LOGVAL(NULL, LY_VLOG_NONE, NULL, LY_VCODE_INVAL, date_len, date, stmt); |
| 239 | } |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 240 | } |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 241 | return LY_EINVAL; |
| 242 | } |
| 243 | |
| 244 | void |
| 245 | lysp_sort_revisions(struct lysp_revision *revs) |
| 246 | { |
| 247 | uint8_t i, r; |
| 248 | struct lysp_revision rev; |
| 249 | |
| 250 | for (i = 1, r = 0; revs && i < LY_ARRAY_SIZE(revs); i++) { |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 251 | if (strcmp(revs[i].date, revs[r].date) > 0) { |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 252 | r = i; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | if (r) { |
| 257 | /* the newest revision is not on position 0, switch them */ |
Radek Krejci | 2c4e717 | 2018-10-19 15:56:26 +0200 | [diff] [blame] | 258 | memcpy(&rev, &revs[0], sizeof rev); |
| 259 | memcpy(&revs[0], &revs[r], sizeof rev); |
| 260 | memcpy(&revs[r], &rev, sizeof rev); |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 261 | } |
| 262 | } |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 263 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 264 | static const struct lysp_tpdf * |
| 265 | lysp_type_match(const char *name, struct lysp_node *node) |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 266 | { |
Radek Krejci | 0fb2856 | 2018-12-13 15:17:37 +0100 | [diff] [blame] | 267 | const struct lysp_tpdf *typedefs; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 268 | unsigned int u; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 269 | |
Radek Krejci | 0fb2856 | 2018-12-13 15:17:37 +0100 | [diff] [blame] | 270 | typedefs = lysp_node_typedefs(node); |
| 271 | LY_ARRAY_FOR(typedefs, u) { |
| 272 | if (!strcmp(name, typedefs[u].name)) { |
| 273 | /* match */ |
| 274 | return &typedefs[u]; |
Radek Krejci | 151a5b7 | 2018-10-19 14:21:44 +0200 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
| 278 | return NULL; |
| 279 | } |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 280 | |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 281 | static LY_DATA_TYPE |
| 282 | lysp_type_str2builtin(const char *name, size_t len) |
| 283 | { |
| 284 | if (len >= 4) { /* otherwise it does not match any built-in type */ |
| 285 | if (name[0] == 'b') { |
| 286 | if (name[1] == 'i') { |
| 287 | if (len == 6 && !strncmp(&name[2], "nary", 4)) { |
| 288 | return LY_TYPE_BINARY; |
| 289 | } else if (len == 4 && !strncmp(&name[2], "ts", 2)) { |
| 290 | return LY_TYPE_BITS; |
| 291 | } |
| 292 | } else if (len == 7 && !strncmp(&name[1], "oolean", 6)) { |
| 293 | return LY_TYPE_BOOL; |
| 294 | } |
| 295 | } else if (name[0] == 'd') { |
| 296 | if (len == 9 && !strncmp(&name[1], "ecimal64", 8)) { |
| 297 | return LY_TYPE_DEC64; |
| 298 | } |
| 299 | } else if (name[0] == 'e') { |
| 300 | if (len == 5 && !strncmp(&name[1], "mpty", 4)) { |
| 301 | return LY_TYPE_EMPTY; |
| 302 | } else if (len == 11 && !strncmp(&name[1], "numeration", 10)) { |
| 303 | return LY_TYPE_ENUM; |
| 304 | } |
| 305 | } else if (name[0] == 'i') { |
| 306 | if (name[1] == 'n') { |
| 307 | if (len == 4 && !strncmp(&name[2], "t8", 2)) { |
| 308 | return LY_TYPE_INT8; |
| 309 | } else if (len == 5) { |
| 310 | if (!strncmp(&name[2], "t16", 3)) { |
| 311 | return LY_TYPE_INT16; |
| 312 | } else if (!strncmp(&name[2], "t32", 3)) { |
| 313 | return LY_TYPE_INT32; |
| 314 | } else if (!strncmp(&name[2], "t64", 3)) { |
| 315 | return LY_TYPE_INT64; |
| 316 | } |
| 317 | } else if (len == 19 && !strncmp(&name[2], "stance-identifier", 17)) { |
| 318 | return LY_TYPE_INST; |
| 319 | } |
| 320 | } else if (len == 11 && !strncmp(&name[1], "dentityref", 10)) { |
| 321 | return LY_TYPE_IDENT; |
| 322 | } |
| 323 | } else if (name[0] == 'l') { |
| 324 | if (len == 7 && !strncmp(&name[1], "eafref", 6)) { |
| 325 | return LY_TYPE_LEAFREF; |
| 326 | } |
| 327 | } else if (name[0] == 's') { |
| 328 | if (len == 6 && !strncmp(&name[1], "tring", 5)) { |
| 329 | return LY_TYPE_STRING; |
| 330 | } |
| 331 | } else if (name[0] == 'u') { |
| 332 | if (name[1] == 'n') { |
| 333 | if (len == 5 && !strncmp(&name[2], "ion", 3)) { |
| 334 | return LY_TYPE_UNION; |
| 335 | } |
| 336 | } else if (name[1] == 'i' && name[2] == 'n' && name[3] == 't') { |
| 337 | if (len == 5 && name[4] == '8') { |
| 338 | return LY_TYPE_UINT8; |
| 339 | } else if (len == 6) { |
| 340 | if (!strncmp(&name[4], "16", 2)) { |
| 341 | return LY_TYPE_UINT16; |
| 342 | } else if (!strncmp(&name[4], "32", 2)) { |
| 343 | return LY_TYPE_UINT32; |
| 344 | } else if (!strncmp(&name[4], "64", 2)) { |
| 345 | return LY_TYPE_UINT64; |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | return LY_TYPE_UNKNOWN; |
| 353 | } |
| 354 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 355 | LY_ERR |
| 356 | lysp_type_find(const char *id, struct lysp_node *start_node, struct lysp_module *start_module, |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 357 | LY_DATA_TYPE *type, const struct lysp_tpdf **tpdf, struct lysp_node **node, struct lysp_module **module) |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 358 | { |
| 359 | const char *str, *name; |
| 360 | struct lysp_tpdf *typedefs; |
| 361 | unsigned int u, v; |
| 362 | |
| 363 | assert(id); |
| 364 | assert(start_module); |
| 365 | assert(tpdf); |
| 366 | assert(node); |
| 367 | assert(module); |
| 368 | |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 369 | *node = NULL; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 370 | str = strchr(id, ':'); |
| 371 | if (str) { |
| 372 | *module = lysp_module_find_prefix(start_module, id, str - id); |
| 373 | name = str + 1; |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 374 | *type = LY_TYPE_UNKNOWN; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 375 | } else { |
| 376 | *module = start_module; |
| 377 | name = id; |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 378 | |
| 379 | /* check for built-in types */ |
| 380 | *type = lysp_type_str2builtin(name, strlen(name)); |
| 381 | if (*type) { |
| 382 | *tpdf = NULL; |
| 383 | return LY_SUCCESS; |
| 384 | } |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 385 | } |
| 386 | LY_CHECK_RET(!(*module), LY_ENOTFOUND); |
| 387 | |
| 388 | if (start_node && *module == start_module) { |
| 389 | /* search typedefs in parent's nodes */ |
| 390 | *node = start_node; |
| 391 | while (*node) { |
| 392 | *tpdf = lysp_type_match(name, *node); |
| 393 | if (*tpdf) { |
| 394 | /* match */ |
| 395 | return LY_SUCCESS; |
| 396 | } |
| 397 | *node = (*node)->parent; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | /* search in top-level typedefs */ |
| 402 | if ((*module)->typedefs) { |
| 403 | LY_ARRAY_FOR((*module)->typedefs, u) { |
| 404 | if (!strcmp(name, (*module)->typedefs[u].name)) { |
| 405 | /* match */ |
| 406 | *tpdf = &(*module)->typedefs[u]; |
| 407 | return LY_SUCCESS; |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | /* search in submodules' typedefs */ |
| 413 | LY_ARRAY_FOR((*module)->includes, u) { |
| 414 | typedefs = (*module)->includes[u].submodule->typedefs; |
Radek Krejci | 76b3e96 | 2018-12-14 17:01:25 +0100 | [diff] [blame] | 415 | LY_ARRAY_FOR(typedefs, v) { |
| 416 | if (!strcmp(name, typedefs[v].name)) { |
| 417 | /* match */ |
| 418 | *tpdf = &typedefs[v]; |
| 419 | return LY_SUCCESS; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | return LY_ENOTFOUND; |
| 425 | } |
| 426 | |
David Sedlák | 6544c18 | 2019-07-12 13:17:33 +0200 | [diff] [blame] | 427 | LY_ERR |
David Sedlák | 07869a5 | 2019-07-12 14:28:19 +0200 | [diff] [blame] | 428 | lysp_check_enum_name(struct lys_parser_ctx *ctx, const char *name, size_t name_len) |
David Sedlák | 6544c18 | 2019-07-12 13:17:33 +0200 | [diff] [blame] | 429 | { |
| 430 | if (!name_len) { |
| 431 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Enum name must not be zero-length."); |
| 432 | return LY_EVALID; |
| 433 | } else if (isspace(name[0]) || isspace(name[name_len - 1])) { |
| 434 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Enum name must not have any leading or trailing whitespaces (\"%.*s\").", |
| 435 | name_len, name); |
| 436 | return LY_EVALID; |
| 437 | } else { |
| 438 | for (size_t u = 0; u < name_len; ++u) { |
| 439 | if (iscntrl(name[u])) { |
| 440 | LOGWRN(ctx->ctx, "Control characters in enum name should be avoided (\"%.*s\", character number %d).", |
| 441 | name_len, name, u + 1); |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | return LY_SUCCESS; |
| 448 | } |
| 449 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 450 | /* |
| 451 | * @brief Check name of a new type to avoid name collisions. |
| 452 | * |
| 453 | * @param[in] ctx Parser context, module where the type is being defined is taken from here. |
| 454 | * @param[in] node Schema node where the type is being defined, NULL in case of a top-level typedef. |
| 455 | * @param[in] tpdf Typedef definition to check. |
| 456 | * @param[in,out] tpdfs_global Initialized hash table to store temporary data between calls. When the module's |
| 457 | * typedefs are checked, caller is supposed to free the table. |
| 458 | * @param[in,out] tpdfs_global Initialized hash table to store temporary data between calls. When the module's |
| 459 | * typedefs are checked, caller is supposed to free the table. |
| 460 | * @return LY_EEXIST in case of collision, LY_SUCCESS otherwise. |
| 461 | */ |
| 462 | static LY_ERR |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 463 | lysp_check_typedef(struct lys_parser_ctx *ctx, struct lysp_node *node, const struct lysp_tpdf *tpdf, |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 464 | struct hash_table *tpdfs_global, struct hash_table *tpdfs_scoped) |
| 465 | { |
| 466 | struct lysp_node *parent; |
| 467 | uint32_t hash; |
| 468 | size_t name_len; |
| 469 | const char *name; |
| 470 | unsigned int u; |
Radek Krejci | 0fb2856 | 2018-12-13 15:17:37 +0100 | [diff] [blame] | 471 | const struct lysp_tpdf *typedefs; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 472 | |
| 473 | assert(ctx); |
| 474 | assert(tpdf); |
| 475 | |
| 476 | name = tpdf->name; |
| 477 | name_len = strlen(name); |
| 478 | |
Radek Krejci | 4f28eda | 2018-11-12 11:46:16 +0100 | [diff] [blame] | 479 | if (lysp_type_str2builtin(name, name_len)) { |
| 480 | LOGVAL(ctx->ctx, LY_VLOG_LINE, &ctx->line, LYVE_SYNTAX_YANG, |
| 481 | "Invalid name \"%s\" of typedef - name collision with a built-in type.", name); |
| 482 | return LY_EEXIST; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /* check locally scoped typedefs (avoid name shadowing) */ |
| 486 | if (node) { |
Radek Krejci | 0fb2856 | 2018-12-13 15:17:37 +0100 | [diff] [blame] | 487 | typedefs = lysp_node_typedefs(node); |
| 488 | LY_ARRAY_FOR(typedefs, u) { |
| 489 | if (&typedefs[u] == tpdf) { |
| 490 | break; |
| 491 | } |
| 492 | if (!strcmp(name, typedefs[u].name)) { |
| 493 | LOGVAL(ctx->ctx, LY_VLOG_LINE, &ctx->line, LYVE_SYNTAX_YANG, |
| 494 | "Invalid name \"%s\" of typedef - name collision with sibling type.", name); |
| 495 | return LY_EEXIST; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 496 | } |
| 497 | } |
| 498 | /* search typedefs in parent's nodes */ |
Radek Krejci | 87e78ca | 2019-05-02 09:51:29 +0200 | [diff] [blame] | 499 | for (parent = node->parent; parent; parent = parent->parent) { |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 500 | if (lysp_type_match(name, parent)) { |
| 501 | LOGVAL(ctx->ctx, LY_VLOG_LINE, &ctx->line, LYVE_SYNTAX_YANG, |
| 502 | "Invalid name \"%s\" of typedef - name collision with another scoped type.", name); |
| 503 | return LY_EEXIST; |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | /* check collision with the top-level typedefs */ |
| 509 | hash = dict_hash(name, name_len); |
| 510 | if (node) { |
| 511 | lyht_insert(tpdfs_scoped, &name, hash, NULL); |
| 512 | if (!lyht_find(tpdfs_global, &name, hash, NULL)) { |
| 513 | LOGVAL(ctx->ctx, LY_VLOG_LINE, &ctx->line, LYVE_SYNTAX_YANG, |
| 514 | "Invalid name \"%s\" of typedef - scoped type collide with a top-level type.", name); |
| 515 | return LY_EEXIST; |
| 516 | } |
| 517 | } else { |
| 518 | if (lyht_insert(tpdfs_global, &name, hash, NULL)) { |
| 519 | LOGVAL(ctx->ctx, LY_VLOG_LINE, &ctx->line, LYVE_SYNTAX_YANG, |
| 520 | "Invalid name \"%s\" of typedef - name collision with another top-level type.", name); |
| 521 | return LY_EEXIST; |
| 522 | } |
Radek Krejci | 3b1f929 | 2018-11-08 10:58:35 +0100 | [diff] [blame] | 523 | /* it is not necessary to test collision with the scoped types - in lysp_check_typedefs, all the |
| 524 | * top-level typedefs are inserted into the tables before the scoped typedefs, so the collision |
| 525 | * is detected in the first branch few lines above */ |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | return LY_SUCCESS; |
| 529 | } |
| 530 | |
| 531 | static int |
| 532 | lysp_id_cmp(void *val1, void *val2, int UNUSED(mod), void *UNUSED(cb_data)) |
| 533 | { |
| 534 | return !strcmp(val1, val2); |
| 535 | } |
| 536 | |
| 537 | LY_ERR |
David Sedlák | d2ebe57 | 2019-07-22 12:53:14 +0200 | [diff] [blame] | 538 | lysp_parse_finalize_reallocated(struct lys_parser_ctx *ctx, struct lysp_grp *groupings, struct lysp_augment *augments, |
| 539 | struct lysp_action *actions, struct lysp_notif *notifs) |
| 540 | { |
| 541 | unsigned int u, v; |
| 542 | struct lysp_node *child; |
| 543 | |
| 544 | /* finalize parent pointers to the reallocated items */ |
| 545 | |
| 546 | /* gropings */ |
| 547 | LY_ARRAY_FOR(groupings, u) { |
| 548 | LY_LIST_FOR(groupings[u].data, child) { |
| 549 | child->parent = (struct lysp_node*)&groupings[u]; |
| 550 | } |
| 551 | LY_ARRAY_FOR(groupings[u].actions, v) { |
| 552 | groupings[u].actions[v].parent = (struct lysp_node*)&groupings[u]; |
| 553 | } |
| 554 | LY_ARRAY_FOR(groupings[u].notifs, v) { |
| 555 | groupings[u].notifs[v].parent = (struct lysp_node*)&groupings[u]; |
| 556 | } |
| 557 | LY_ARRAY_FOR(groupings[u].groupings, v) { |
| 558 | groupings[u].groupings[v].parent = (struct lysp_node*)&groupings[u]; |
| 559 | } |
| 560 | if (groupings[u].typedefs) { |
| 561 | ly_set_add(&ctx->tpdfs_nodes, &groupings[u], 0); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | /* augments */ |
| 566 | LY_ARRAY_FOR(augments, u) { |
| 567 | LY_LIST_FOR(augments[u].child, child) { |
| 568 | child->parent = (struct lysp_node*)&augments[u]; |
| 569 | } |
| 570 | LY_ARRAY_FOR(augments[u].actions, v) { |
| 571 | augments[u].actions[v].parent = (struct lysp_node*)&augments[u]; |
| 572 | } |
| 573 | LY_ARRAY_FOR(augments[u].notifs, v) { |
| 574 | augments[u].notifs[v].parent = (struct lysp_node*)&augments[u]; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | /* actions */ |
| 579 | LY_ARRAY_FOR(actions, u) { |
| 580 | if (actions[u].input.parent) { |
| 581 | actions[u].input.parent = (struct lysp_node*)&actions[u]; |
| 582 | LY_LIST_FOR(actions[u].input.data, child) { |
| 583 | child->parent = (struct lysp_node*)&actions[u].input; |
| 584 | } |
| 585 | LY_ARRAY_FOR(actions[u].input.groupings, v) { |
| 586 | actions[u].input.groupings[v].parent = (struct lysp_node*)&actions[u].input; |
| 587 | } |
| 588 | if (actions[u].input.typedefs) { |
| 589 | ly_set_add(&ctx->tpdfs_nodes, &actions[u].input, 0); |
| 590 | } |
| 591 | } |
| 592 | if (actions[u].output.parent) { |
| 593 | actions[u].output.parent = (struct lysp_node*)&actions[u]; |
| 594 | LY_LIST_FOR(actions[u].output.data, child) { |
| 595 | child->parent = (struct lysp_node*)&actions[u].output; |
| 596 | } |
| 597 | LY_ARRAY_FOR(actions[u].output.groupings, v) { |
| 598 | actions[u].output.groupings[v].parent = (struct lysp_node*)&actions[u].output; |
| 599 | } |
| 600 | if (actions[u].output.typedefs) { |
| 601 | ly_set_add(&ctx->tpdfs_nodes, &actions[u].output, 0); |
| 602 | } |
| 603 | } |
| 604 | LY_ARRAY_FOR(actions[u].groupings, v) { |
| 605 | actions[u].groupings[v].parent = (struct lysp_node*)&actions[u]; |
| 606 | } |
| 607 | if (actions[u].typedefs) { |
| 608 | ly_set_add(&ctx->tpdfs_nodes, &actions[u], 0); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | /* notifications */ |
| 613 | LY_ARRAY_FOR(notifs, u) { |
| 614 | LY_LIST_FOR(notifs[u].data, child) { |
| 615 | child->parent = (struct lysp_node*)¬ifs[u]; |
| 616 | } |
| 617 | LY_ARRAY_FOR(notifs[u].groupings, v) { |
| 618 | notifs[u].groupings[v].parent = (struct lysp_node*)¬ifs[u]; |
| 619 | } |
| 620 | if (notifs[u].typedefs) { |
| 621 | ly_set_add(&ctx->tpdfs_nodes, ¬ifs[u], 0); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | return LY_SUCCESS; |
| 626 | } |
| 627 | |
| 628 | LY_ERR |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 629 | lysp_check_typedefs(struct lys_parser_ctx *ctx, struct lysp_module *mod) |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 630 | { |
| 631 | struct hash_table *ids_global; |
| 632 | struct hash_table *ids_scoped; |
Radek Krejci | 0fb2856 | 2018-12-13 15:17:37 +0100 | [diff] [blame] | 633 | const struct lysp_tpdf *typedefs; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 634 | unsigned int i, u; |
| 635 | LY_ERR ret = LY_EVALID; |
| 636 | |
| 637 | /* check name collisions - typedefs and groupings */ |
| 638 | ids_global = lyht_new(8, sizeof(char*), lysp_id_cmp, NULL, 1); |
| 639 | ids_scoped = lyht_new(8, sizeof(char*), lysp_id_cmp, NULL, 1); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 640 | LY_ARRAY_FOR(mod->typedefs, i) { |
| 641 | if (lysp_check_typedef(ctx, NULL, &mod->typedefs[i], ids_global, ids_scoped)) { |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 642 | goto cleanup; |
| 643 | } |
| 644 | } |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 645 | LY_ARRAY_FOR(mod->includes, i) { |
| 646 | LY_ARRAY_FOR(mod->includes[i].submodule->typedefs, u) { |
| 647 | if (lysp_check_typedef(ctx, NULL, &mod->includes[i].submodule->typedefs[u], ids_global, ids_scoped)) { |
Radek Krejci | 3b1f929 | 2018-11-08 10:58:35 +0100 | [diff] [blame] | 648 | goto cleanup; |
| 649 | } |
| 650 | } |
| 651 | } |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 652 | for (u = 0; u < ctx->tpdfs_nodes.count; ++u) { |
Radek Krejci | 0fb2856 | 2018-12-13 15:17:37 +0100 | [diff] [blame] | 653 | typedefs = lysp_node_typedefs((struct lysp_node *)ctx->tpdfs_nodes.objs[u]); |
| 654 | LY_ARRAY_FOR(typedefs, i) { |
| 655 | if (lysp_check_typedef(ctx, (struct lysp_node *)ctx->tpdfs_nodes.objs[u], &typedefs[i], ids_global, ids_scoped)) { |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 656 | goto cleanup; |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | ret = LY_SUCCESS; |
| 661 | cleanup: |
| 662 | lyht_free(ids_global); |
| 663 | lyht_free(ids_scoped); |
| 664 | ly_set_erase(&ctx->tpdfs_nodes, NULL); |
| 665 | |
| 666 | return ret; |
| 667 | } |
| 668 | |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 669 | struct lysp_load_module_check_data { |
| 670 | const char *name; |
| 671 | const char *revision; |
| 672 | const char *path; |
| 673 | const char* submoduleof; |
| 674 | }; |
| 675 | |
| 676 | static LY_ERR |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 677 | lysp_load_module_check(struct ly_ctx *ctx, struct lysp_module *mod, struct lysp_submodule *submod, void *data) |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 678 | { |
| 679 | struct lysp_load_module_check_data *info = data; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 680 | const char *filename, *dot, *rev, *name; |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 681 | size_t len; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 682 | struct lysp_revision *revs; |
| 683 | |
| 684 | name = mod ? mod->mod->name : submod->name; |
| 685 | revs = mod ? mod->revs : submod->revs; |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 686 | |
| 687 | if (info->name) { |
| 688 | /* check name of the parsed model */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 689 | if (strcmp(info->name, name)) { |
| 690 | LOGERR(ctx, LY_EINVAL, "Unexpected module \"%s\" parsed instead of \"%s\").", name, info->name); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 691 | return LY_EINVAL; |
| 692 | } |
| 693 | } |
| 694 | if (info->revision) { |
| 695 | /* check revision of the parsed model */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 696 | if (!revs || strcmp(info->revision, revs[0].date)) { |
| 697 | LOGERR(ctx, LY_EINVAL, "Module \"%s\" parsed with the wrong revision (\"%s\" instead \"%s\").", name, |
Radek Krejci | b07b5c9 | 2019-04-08 10:56:37 +0200 | [diff] [blame] | 698 | revs ? revs[0].date : "none", info->revision); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 699 | return LY_EINVAL; |
| 700 | } |
| 701 | } |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 702 | if (submod) { |
| 703 | assert(info->submoduleof); |
| 704 | |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 705 | /* check that the submodule belongs-to our module */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 706 | if (strcmp(info->submoduleof, submod->belongsto)) { |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 707 | LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_REFERENCE, "Included \"%s\" submodule from \"%s\" belongs-to a different module \"%s\".", |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 708 | submod->name, info->submoduleof, submod->belongsto); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 709 | return LY_EVALID; |
| 710 | } |
| 711 | /* check circular dependency */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 712 | if (submod->parsing) { |
| 713 | LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_REFERENCE, "A circular dependency (include) for module \"%s\".", submod->name); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 714 | return LY_EVALID; |
| 715 | } |
| 716 | } |
| 717 | if (info->path) { |
| 718 | /* check that name and revision match filename */ |
| 719 | filename = strrchr(info->path, '/'); |
| 720 | if (!filename) { |
| 721 | filename = info->path; |
| 722 | } else { |
| 723 | filename++; |
| 724 | } |
| 725 | /* name */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 726 | len = strlen(name); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 727 | rev = strchr(filename, '@'); |
| 728 | dot = strrchr(info->path, '.'); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 729 | if (strncmp(filename, name, len) || |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 730 | ((rev && rev != &filename[len]) || (!rev && dot != &filename[len]))) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 731 | LOGWRN(ctx, "File name \"%s\" does not match module name \"%s\".", filename, name); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 732 | } |
| 733 | /* revision */ |
| 734 | if (rev) { |
| 735 | len = dot - ++rev; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 736 | if (!revs || len != 10 || strncmp(revs[0].date, rev, len)) { |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 737 | LOGWRN(ctx, "File name \"%s\" does not match module revision \"%s\".", filename, |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 738 | revs ? revs[0].date : "none"); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | } |
| 742 | return LY_SUCCESS; |
| 743 | } |
| 744 | |
| 745 | LY_ERR |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 746 | lys_module_localfile(struct ly_ctx *ctx, const char *name, const char *revision, int implement, struct lys_parser_ctx *main_ctx, |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 747 | void **result) |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 748 | { |
| 749 | int fd; |
| 750 | char *filepath = NULL; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 751 | const char **fp; |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 752 | LYS_INFORMAT format; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 753 | void *mod = NULL; |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 754 | LY_ERR ret = LY_SUCCESS; |
| 755 | struct lysp_load_module_check_data check_data = {0}; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 756 | char rpath[PATH_MAX]; |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 757 | |
| 758 | LY_CHECK_RET(lys_search_localfile(ly_ctx_get_searchdirs(ctx), !(ctx->flags & LY_CTX_DISABLE_SEARCHDIR_CWD), name, revision, |
| 759 | &filepath, &format)); |
| 760 | LY_CHECK_ERR_RET(!filepath, LOGERR(ctx, LY_ENOTFOUND, "Data model \"%s%s%s\" not found in local searchdirs.", |
| 761 | name, revision ? "@" : "", revision ? revision : ""), LY_ENOTFOUND); |
| 762 | |
| 763 | |
| 764 | LOGVRB("Loading schema from \"%s\" file.", filepath); |
| 765 | |
| 766 | /* open the file */ |
| 767 | fd = open(filepath, O_RDONLY); |
| 768 | LY_CHECK_ERR_GOTO(fd < 0, LOGERR(ctx, LY_ESYS, "Unable to open data model file \"%s\" (%s).", |
| 769 | filepath, strerror(errno)); ret = LY_ESYS, cleanup); |
| 770 | |
| 771 | check_data.name = name; |
| 772 | check_data.revision = revision; |
| 773 | check_data.path = filepath; |
Radek Krejci | 3b1f929 | 2018-11-08 10:58:35 +0100 | [diff] [blame] | 774 | mod = lys_parse_fd_(ctx, fd, format, implement, main_ctx, |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 775 | lysp_load_module_check, &check_data); |
| 776 | close(fd); |
| 777 | LY_CHECK_ERR_GOTO(!mod, ly_errcode(ctx), cleanup); |
| 778 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 779 | if (main_ctx) { |
| 780 | fp = &((struct lysp_submodule*)mod)->filepath; |
| 781 | } else { |
| 782 | fp = &((struct lys_module*)mod)->filepath; |
| 783 | } |
| 784 | if (!(*fp)) { |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 785 | if (realpath(filepath, rpath) != NULL) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 786 | (*fp) = lydict_insert(ctx, rpath, 0); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 787 | } else { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 788 | (*fp) = lydict_insert(ctx, filepath, 0); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 789 | } |
| 790 | } |
| 791 | |
| 792 | *result = mod; |
| 793 | |
| 794 | /* success */ |
| 795 | cleanup: |
| 796 | free(filepath); |
| 797 | return ret; |
| 798 | } |
| 799 | |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 800 | LY_ERR |
Radek Krejci | 6d6e4e4 | 2018-10-29 13:28:19 +0100 | [diff] [blame] | 801 | lysp_load_module(struct ly_ctx *ctx, const char *name, const char *revision, int implement, int require_parsed, struct lys_module **mod) |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 802 | { |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 803 | const char *module_data = NULL; |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 804 | LYS_INFORMAT format = LYS_IN_UNKNOWN; |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 805 | void (*module_data_free)(void *module_data, void *user_data) = NULL; |
| 806 | struct lysp_load_module_check_data check_data = {0}; |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 807 | struct lys_module *m; |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 808 | |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 809 | assert(mod); |
| 810 | |
| 811 | if (!*mod) { |
| 812 | /* try to get the module from the context */ |
| 813 | if (revision) { |
Radek Krejci | ed5acc5 | 2019-04-25 15:57:04 +0200 | [diff] [blame] | 814 | /* get the specific revision */ |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 815 | *mod = (struct lys_module*)ly_ctx_get_module(ctx, name, revision); |
Radek Krejci | ed5acc5 | 2019-04-25 15:57:04 +0200 | [diff] [blame] | 816 | } else if (implement) { |
| 817 | /* prefer the implemented module instead of the latest one */ |
| 818 | *mod = (struct lys_module*)ly_ctx_get_module_implemented(ctx, name); |
| 819 | if (!*mod) { |
| 820 | /* there is no implemented module in the context, try to get the latest revision module */ |
| 821 | goto latest_in_the_context; |
| 822 | } |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 823 | } else { |
Radek Krejci | ed5acc5 | 2019-04-25 15:57:04 +0200 | [diff] [blame] | 824 | /* get the requested module of the latest revision in the context */ |
| 825 | latest_in_the_context: |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 826 | *mod = (struct lys_module*)ly_ctx_get_module_latest(ctx, name); |
| 827 | } |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 828 | } |
| 829 | |
Radek Krejci | 6d6e4e4 | 2018-10-29 13:28:19 +0100 | [diff] [blame] | 830 | if (!(*mod) || (require_parsed && !(*mod)->parsed)) { |
| 831 | (*mod) = NULL; |
| 832 | |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 833 | /* check collision with other implemented revision */ |
| 834 | if (implement && ly_ctx_get_module_implemented(ctx, name)) { |
| 835 | LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_REFERENCE, |
| 836 | "Module \"%s\" is already present in other implemented revision.", name); |
| 837 | return LY_EDENIED; |
| 838 | } |
| 839 | |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 840 | /* module not present in the context, get the input data and parse it */ |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 841 | if (!(ctx->flags & LY_CTX_PREFER_SEARCHDIRS)) { |
| 842 | search_clb: |
| 843 | if (ctx->imp_clb) { |
| 844 | if (ctx->imp_clb(name, revision, NULL, NULL, ctx->imp_clb_data, |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 845 | &format, &module_data, &module_data_free) == LY_SUCCESS) { |
| 846 | check_data.name = name; |
| 847 | check_data.revision = revision; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 848 | *mod = lys_parse_mem_module(ctx, module_data, format, implement, |
| 849 | lysp_load_module_check, &check_data); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 850 | if (module_data_free) { |
| 851 | module_data_free((void*)module_data, ctx->imp_clb_data); |
| 852 | } |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 853 | if (*mod && implement && lys_compile(*mod, 0)) { |
| 854 | ly_set_rm(&ctx->list, *mod, NULL); |
| 855 | lys_module_free(*mod, NULL); |
| 856 | *mod = NULL; |
| 857 | } |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 858 | } |
| 859 | } |
| 860 | if (!(*mod) && !(ctx->flags & LY_CTX_PREFER_SEARCHDIRS)) { |
| 861 | goto search_file; |
| 862 | } |
| 863 | } else { |
| 864 | search_file: |
| 865 | if (!(ctx->flags & LY_CTX_DISABLE_SEARCHDIRS)) { |
| 866 | /* module was not received from the callback or there is no callback set */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 867 | lys_module_localfile(ctx, name, revision, implement, NULL, (void **)mod); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 868 | } |
| 869 | if (!(*mod) && (ctx->flags & LY_CTX_PREFER_SEARCHDIRS)) { |
| 870 | goto search_clb; |
| 871 | } |
| 872 | } |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 873 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 874 | if ((*mod) && !revision && ((*mod)->latest_revision == 1)) { |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 875 | /* update the latest_revision flag - here we have selected the latest available schema, |
| 876 | * consider that even the callback provides correct latest revision */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 877 | (*mod)->latest_revision = 2; |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 878 | } |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 879 | } else { |
| 880 | /* we have module from the current context */ |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 881 | if (implement) { |
| 882 | m = ly_ctx_get_module_implemented(ctx, name); |
| 883 | if (m && m != *mod) { |
| 884 | /* check collision with other implemented revision */ |
| 885 | LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_REFERENCE, |
| 886 | "Module \"%s\" is already present in other implemented revision.", name); |
| 887 | *mod = NULL; |
| 888 | return LY_EDENIED; |
| 889 | } |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | /* circular check */ |
Radek Krejci | f8f882a | 2018-10-31 14:51:15 +0100 | [diff] [blame] | 893 | if ((*mod)->parsed && (*mod)->parsed->parsing) { |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 894 | LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_REFERENCE, "A circular dependency (import) for module \"%s\".", name); |
| 895 | *mod = NULL; |
| 896 | return LY_EVALID; |
| 897 | } |
| 898 | } |
| 899 | if (!(*mod)) { |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 900 | LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_REFERENCE, "%s \"%s\" module failed.", implement ? "Loading" : "Importing", name); |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 901 | return LY_EVALID; |
| 902 | } |
| 903 | |
| 904 | if (implement) { |
| 905 | /* mark the module implemented, check for collision was already done */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 906 | (*mod)->implemented = 1; |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 907 | } |
Radek Krejci | 086c713 | 2018-10-26 15:29:04 +0200 | [diff] [blame] | 908 | |
| 909 | return LY_SUCCESS; |
| 910 | } |
| 911 | |
| 912 | LY_ERR |
David Sedlák | 4a65053 | 2019-07-10 11:55:18 +0200 | [diff] [blame] | 913 | lysp_check_stringchar(struct lys_parser_ctx *ctx, unsigned int c) |
| 914 | { |
| 915 | if (!is_yangutf8char(c)) { |
| 916 | LOGVAL_PARSER(ctx, LY_VCODE_INCHAR, c); |
| 917 | return LY_EVALID; |
| 918 | } |
| 919 | return LY_SUCCESS; |
| 920 | } |
| 921 | |
| 922 | LY_ERR |
| 923 | lysp_check_identifierchar(struct lys_parser_ctx *ctx, unsigned int c, int first, int *prefix) |
| 924 | { |
| 925 | if (first || (prefix && (*prefix) == 1)) { |
| 926 | if (!is_yangidentstartchar(c)) { |
| 927 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Invalid identifier first character '%c'.", c); |
| 928 | return LY_EVALID; |
| 929 | } |
| 930 | if (prefix) { |
| 931 | if (first) { |
| 932 | (*prefix) = 0; |
| 933 | } else { |
| 934 | (*prefix) = 2; |
| 935 | } |
| 936 | } |
| 937 | } else if (c == ':' && prefix && (*prefix) == 0) { |
| 938 | (*prefix) = 1; |
| 939 | } else if (!is_yangidentchar(c)) { |
| 940 | LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Invalid identifier character '%c'.", c); |
| 941 | return LY_EVALID; |
| 942 | } |
| 943 | |
| 944 | return LY_SUCCESS; |
| 945 | } |
| 946 | |
| 947 | LY_ERR |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 948 | lysp_load_submodule(struct lys_parser_ctx *ctx, struct lysp_module *mod, struct lysp_include *inc) |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 949 | { |
Radek Krejci | 3eb299d | 2019-04-08 15:07:44 +0200 | [diff] [blame] | 950 | struct lysp_submodule *submod = NULL; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 951 | const char *submodule_data = NULL; |
| 952 | LYS_INFORMAT format = LYS_IN_UNKNOWN; |
| 953 | void (*submodule_data_free)(void *module_data, void *user_data) = NULL; |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 954 | struct lysp_load_module_check_data check_data = {0}; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 955 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 956 | /* submodule not present in the context, get the input data and parse it */ |
Radek Krejci | 3b1f929 | 2018-11-08 10:58:35 +0100 | [diff] [blame] | 957 | if (!(ctx->ctx->flags & LY_CTX_PREFER_SEARCHDIRS)) { |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 958 | search_clb: |
Radek Krejci | 3b1f929 | 2018-11-08 10:58:35 +0100 | [diff] [blame] | 959 | if (ctx->ctx->imp_clb) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 960 | if (ctx->ctx->imp_clb(mod->mod->name, NULL, inc->name, inc->rev[0] ? inc->rev : NULL, ctx->ctx->imp_clb_data, |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 961 | &format, &submodule_data, &submodule_data_free) == LY_SUCCESS) { |
| 962 | check_data.name = inc->name; |
| 963 | check_data.revision = inc->rev[0] ? inc->rev : NULL; |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 964 | check_data.submoduleof = mod->mod->name; |
| 965 | submod = lys_parse_mem_submodule(ctx->ctx, submodule_data, format, ctx, |
| 966 | lysp_load_module_check, &check_data); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 967 | if (submodule_data_free) { |
Radek Krejci | 3b1f929 | 2018-11-08 10:58:35 +0100 | [diff] [blame] | 968 | submodule_data_free((void*)submodule_data, ctx->ctx->imp_clb_data); |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 969 | } |
| 970 | } |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 971 | } |
Radek Krejci | 3b1f929 | 2018-11-08 10:58:35 +0100 | [diff] [blame] | 972 | if (!submod && !(ctx->ctx->flags & LY_CTX_PREFER_SEARCHDIRS)) { |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 973 | goto search_file; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 974 | } |
Radek Krejci | 2d31ea7 | 2018-10-25 15:46:42 +0200 | [diff] [blame] | 975 | } else { |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 976 | search_file: |
Radek Krejci | 3b1f929 | 2018-11-08 10:58:35 +0100 | [diff] [blame] | 977 | if (!(ctx->ctx->flags & LY_CTX_DISABLE_SEARCHDIRS)) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 978 | /* submodule was not received from the callback or there is no callback set */ |
| 979 | lys_module_localfile(ctx->ctx, inc->name, inc->rev[0] ? inc->rev : NULL, 0, ctx, (void**)&submod); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 980 | } |
Radek Krejci | 3b1f929 | 2018-11-08 10:58:35 +0100 | [diff] [blame] | 981 | if (!submod && (ctx->ctx->flags & LY_CTX_PREFER_SEARCHDIRS)) { |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 982 | goto search_clb; |
| 983 | } |
| 984 | } |
| 985 | if (submod) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 986 | if (!inc->rev[0] && (submod->latest_revision == 1)) { |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 987 | /* update the latest_revision flag - here we have selected the latest available schema, |
| 988 | * consider that even the callback provides correct latest revision */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 989 | submod->latest_revision = 2; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 990 | } |
| 991 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 992 | inc->submodule = submod; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 993 | } |
| 994 | if (!inc->submodule) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 995 | LOGVAL(ctx->ctx, LY_VLOG_NONE, NULL, LYVE_REFERENCE, "Including \"%s\" submodule into \"%s\" failed.", |
| 996 | inc->name, mod->mod->name); |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 997 | return LY_EVALID; |
| 998 | } |
| 999 | |
| 1000 | return LY_SUCCESS; |
| 1001 | } |
| 1002 | |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 1003 | #define FIND_MODULE(TYPE, MOD) \ |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1004 | TYPE *imp; \ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1005 | if (!strncmp((MOD)->mod->prefix, prefix, len) && (MOD)->mod->prefix[len] == '\0') { \ |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1006 | /* it is the prefix of the module itself */ \ |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 1007 | m = ly_ctx_get_module((MOD)->mod->ctx, (MOD)->mod->name, (MOD)->mod->revision); \ |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1008 | } \ |
| 1009 | /* search in imports */ \ |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1010 | if (!m) { \ |
| 1011 | LY_ARRAY_FOR((MOD)->imports, TYPE, imp) { \ |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 1012 | if (!strncmp(imp->prefix, prefix, len) && imp->prefix[len] == '\0') { \ |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1013 | m = imp->module; \ |
| 1014 | break; \ |
| 1015 | } \ |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1016 | } \ |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1017 | } |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1018 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1019 | struct lysc_module * |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1020 | lysc_module_find_prefix(const struct lysc_module *mod, const char *prefix, size_t len) |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 1021 | { |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1022 | const struct lys_module *m = NULL; |
| 1023 | |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 1024 | FIND_MODULE(struct lysc_import, mod); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1025 | return m ? m->compiled : NULL; |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1026 | } |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 1027 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1028 | struct lysp_module * |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1029 | lysp_module_find_prefix(const struct lysp_module *mod, const char *prefix, size_t len) |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1030 | { |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1031 | const struct lys_module *m = NULL; |
| 1032 | |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 1033 | FIND_MODULE(struct lysp_import, mod); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1034 | return m ? m->parsed : NULL; |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1035 | } |
Radek Krejci | 86d106e | 2018-10-18 09:53:19 +0200 | [diff] [blame] | 1036 | |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1037 | struct lys_module * |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1038 | lys_module_find_prefix(const struct lys_module *mod, const char *prefix, size_t len) |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1039 | { |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1040 | const struct lys_module *m = NULL; |
| 1041 | |
Radek Krejci | 73dead2 | 2019-07-11 16:46:16 +0200 | [diff] [blame] | 1042 | if (!prefix) { |
| 1043 | return (struct lys_module*)mod; |
| 1044 | } |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1045 | if (mod->compiled) { |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 1046 | FIND_MODULE(struct lysc_import, mod->compiled); |
Radek Krejci | ce8c159 | 2018-10-29 15:35:51 +0100 | [diff] [blame] | 1047 | } else { |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 1048 | FIND_MODULE(struct lysp_import, mod->parsed); |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1049 | } |
| 1050 | return (struct lys_module*)m; |
| 1051 | } |
| 1052 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1053 | const char * |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1054 | lys_prefix_find_module(const struct lys_module *mod, const struct lys_module *import) |
| 1055 | { |
| 1056 | unsigned int u; |
| 1057 | |
| 1058 | if (import == mod) { |
| 1059 | return mod->prefix; |
| 1060 | } |
| 1061 | |
| 1062 | if (mod->parsed) { |
| 1063 | LY_ARRAY_FOR(mod->parsed->imports, u) { |
| 1064 | if (mod->parsed->imports[u].module == import) { |
| 1065 | return mod->parsed->imports[u].prefix; |
| 1066 | } |
| 1067 | } |
| 1068 | } else { |
| 1069 | /* we don't have original information about the import's prefix, |
| 1070 | * so the prefix of the import module itself is returned instead */ |
| 1071 | return import->prefix; |
| 1072 | } |
| 1073 | |
| 1074 | return NULL; |
| 1075 | } |
| 1076 | |
| 1077 | const char * |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1078 | lys_nodetype2str(uint16_t nodetype) |
| 1079 | { |
| 1080 | switch(nodetype) { |
| 1081 | case LYS_CONTAINER: |
| 1082 | return "container"; |
| 1083 | case LYS_CHOICE: |
| 1084 | return "choice"; |
| 1085 | case LYS_LEAF: |
| 1086 | return "leaf"; |
| 1087 | case LYS_LEAFLIST: |
| 1088 | return "leaf-list"; |
| 1089 | case LYS_LIST: |
| 1090 | return "list"; |
| 1091 | case LYS_ANYXML: |
| 1092 | return "anyxml"; |
| 1093 | case LYS_ANYDATA: |
| 1094 | return "anydata"; |
Radek Krejci | f12a1f0 | 2019-02-11 16:42:08 +0100 | [diff] [blame] | 1095 | case LYS_CASE: |
| 1096 | return "case"; |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 1097 | case LYS_ACTION: |
| 1098 | return "RPC/action"; |
| 1099 | case LYS_NOTIF: |
| 1100 | return "Notification"; |
Radek Krejci | fc81ea8 | 2019-04-18 13:27:22 +0200 | [diff] [blame] | 1101 | case LYS_USES: |
| 1102 | return "uses"; |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1103 | default: |
| 1104 | return "unknown"; |
| 1105 | } |
| 1106 | } |
| 1107 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1108 | const char * |
| 1109 | lys_datatype2str(LY_DATA_TYPE basetype) |
| 1110 | { |
| 1111 | switch(basetype) { |
| 1112 | case LY_TYPE_BINARY: |
| 1113 | return "binary"; |
| 1114 | case LY_TYPE_UINT8: |
| 1115 | return "uint8"; |
| 1116 | case LY_TYPE_UINT16: |
| 1117 | return "uint16"; |
| 1118 | case LY_TYPE_UINT32: |
| 1119 | return "uint32"; |
| 1120 | case LY_TYPE_UINT64: |
| 1121 | return "uint64"; |
| 1122 | case LY_TYPE_STRING: |
| 1123 | return "string"; |
| 1124 | case LY_TYPE_BITS: |
| 1125 | return "bits"; |
| 1126 | case LY_TYPE_BOOL: |
| 1127 | return "boolean"; |
| 1128 | case LY_TYPE_DEC64: |
| 1129 | return "decimal64"; |
| 1130 | case LY_TYPE_EMPTY: |
| 1131 | return "empty"; |
| 1132 | case LY_TYPE_ENUM: |
| 1133 | return "enumeration"; |
| 1134 | case LY_TYPE_IDENT: |
| 1135 | return "identityref"; |
| 1136 | case LY_TYPE_INST: |
| 1137 | return "instance-identifier"; |
| 1138 | case LY_TYPE_LEAFREF: |
| 1139 | return "leafref"; |
| 1140 | case LY_TYPE_UNION: |
| 1141 | return "union"; |
| 1142 | case LY_TYPE_INT8: |
| 1143 | return "int8"; |
| 1144 | case LY_TYPE_INT16: |
| 1145 | return "int16"; |
| 1146 | case LY_TYPE_INT32: |
| 1147 | return "int32"; |
| 1148 | case LY_TYPE_INT64: |
| 1149 | return "int64"; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1150 | default: |
| 1151 | return "unknown"; |
| 1152 | } |
| 1153 | } |
| 1154 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1155 | API const struct lysp_tpdf * |
| 1156 | lysp_node_typedefs(const struct lysp_node *node) |
| 1157 | { |
Radek Krejci | 0fb2856 | 2018-12-13 15:17:37 +0100 | [diff] [blame] | 1158 | switch (node->nodetype) { |
| 1159 | case LYS_CONTAINER: |
| 1160 | return ((struct lysp_node_container*)node)->typedefs; |
| 1161 | case LYS_LIST: |
| 1162 | return ((struct lysp_node_list*)node)->typedefs; |
| 1163 | case LYS_GROUPING: |
| 1164 | return ((struct lysp_grp*)node)->typedefs; |
| 1165 | case LYS_ACTION: |
| 1166 | return ((struct lysp_action*)node)->typedefs; |
| 1167 | case LYS_INOUT: |
| 1168 | return ((struct lysp_action_inout*)node)->typedefs; |
| 1169 | case LYS_NOTIF: |
| 1170 | return ((struct lysp_notif*)node)->typedefs; |
| 1171 | default: |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1172 | return NULL; |
| 1173 | } |
| 1174 | } |
| 1175 | |
Radek Krejci | 53ea615 | 2018-12-13 15:21:15 +0100 | [diff] [blame] | 1176 | API const struct lysp_grp * |
| 1177 | lysp_node_groupings(const struct lysp_node *node) |
| 1178 | { |
| 1179 | switch (node->nodetype) { |
| 1180 | case LYS_CONTAINER: |
| 1181 | return ((struct lysp_node_container*)node)->groupings; |
| 1182 | case LYS_LIST: |
| 1183 | return ((struct lysp_node_list*)node)->groupings; |
| 1184 | case LYS_GROUPING: |
| 1185 | return ((struct lysp_grp*)node)->groupings; |
| 1186 | case LYS_ACTION: |
| 1187 | return ((struct lysp_action*)node)->groupings; |
| 1188 | case LYS_INOUT: |
| 1189 | return ((struct lysp_action_inout*)node)->groupings; |
| 1190 | case LYS_NOTIF: |
| 1191 | return ((struct lysp_notif*)node)->groupings; |
| 1192 | default: |
| 1193 | return NULL; |
| 1194 | } |
| 1195 | } |
| 1196 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1197 | struct lysp_action ** |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1198 | lysp_node_actions_p(struct lysp_node *node) |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1199 | { |
| 1200 | assert(node); |
| 1201 | switch (node->nodetype) { |
| 1202 | case LYS_CONTAINER: |
| 1203 | return &((struct lysp_node_container*)node)->actions; |
| 1204 | case LYS_LIST: |
| 1205 | return &((struct lysp_node_list*)node)->actions; |
| 1206 | case LYS_GROUPING: |
| 1207 | return &((struct lysp_grp*)node)->actions; |
| 1208 | case LYS_AUGMENT: |
| 1209 | return &((struct lysp_augment*)node)->actions; |
| 1210 | default: |
| 1211 | return NULL; |
| 1212 | } |
| 1213 | } |
| 1214 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1215 | API const struct lysp_action * |
| 1216 | lysp_node_actions(const struct lysp_node *node) |
| 1217 | { |
| 1218 | struct lysp_action **actions; |
| 1219 | actions = lysp_node_actions_p((struct lysp_node*)node); |
| 1220 | if (actions) { |
| 1221 | return *actions; |
| 1222 | } else { |
| 1223 | return NULL; |
| 1224 | } |
| 1225 | } |
| 1226 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1227 | struct lysp_notif ** |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1228 | lysp_node_notifs_p(struct lysp_node *node) |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1229 | { |
| 1230 | assert(node); |
| 1231 | switch (node->nodetype) { |
| 1232 | case LYS_CONTAINER: |
| 1233 | return &((struct lysp_node_container*)node)->notifs; |
| 1234 | case LYS_LIST: |
| 1235 | return &((struct lysp_node_list*)node)->notifs; |
| 1236 | case LYS_GROUPING: |
| 1237 | return &((struct lysp_grp*)node)->notifs; |
| 1238 | case LYS_AUGMENT: |
| 1239 | return &((struct lysp_augment*)node)->notifs; |
| 1240 | default: |
| 1241 | return NULL; |
| 1242 | } |
| 1243 | } |
| 1244 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1245 | API const struct lysp_notif * |
| 1246 | lysp_node_notifs(const struct lysp_node *node) |
| 1247 | { |
| 1248 | struct lysp_notif **notifs; |
| 1249 | notifs = lysp_node_notifs_p((struct lysp_node*)node); |
| 1250 | if (notifs) { |
| 1251 | return *notifs; |
| 1252 | } else { |
| 1253 | return NULL; |
| 1254 | } |
| 1255 | } |
| 1256 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1257 | struct lysp_node ** |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1258 | lysp_node_children_p(struct lysp_node *node) |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1259 | { |
| 1260 | assert(node); |
| 1261 | switch (node->nodetype) { |
| 1262 | case LYS_CONTAINER: |
| 1263 | return &((struct lysp_node_container*)node)->child; |
| 1264 | case LYS_CHOICE: |
| 1265 | return &((struct lysp_node_choice*)node)->child; |
| 1266 | case LYS_LIST: |
| 1267 | return &((struct lysp_node_list*)node)->child; |
| 1268 | case LYS_CASE: |
| 1269 | return &((struct lysp_node_case*)node)->child; |
| 1270 | case LYS_GROUPING: |
| 1271 | return &((struct lysp_grp*)node)->data; |
| 1272 | case LYS_AUGMENT: |
| 1273 | return &((struct lysp_augment*)node)->child; |
| 1274 | case LYS_INOUT: |
| 1275 | return &((struct lysp_action_inout*)node)->data; |
| 1276 | case LYS_NOTIF: |
| 1277 | return &((struct lysp_notif*)node)->data; |
| 1278 | default: |
| 1279 | return NULL; |
| 1280 | } |
| 1281 | } |
| 1282 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1283 | API const struct lysp_node * |
| 1284 | lysp_node_children(const struct lysp_node *node) |
| 1285 | { |
| 1286 | struct lysp_node **children; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 1287 | |
| 1288 | if (!node) { |
| 1289 | return NULL; |
| 1290 | } |
| 1291 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1292 | children = lysp_node_children_p((struct lysp_node*)node); |
| 1293 | if (children) { |
| 1294 | return *children; |
| 1295 | } else { |
| 1296 | return NULL; |
| 1297 | } |
| 1298 | } |
| 1299 | |
| 1300 | struct lysc_action ** |
| 1301 | lysc_node_actions_p(struct lysc_node *node) |
| 1302 | { |
| 1303 | assert(node); |
| 1304 | switch (node->nodetype) { |
| 1305 | case LYS_CONTAINER: |
| 1306 | return &((struct lysc_node_container*)node)->actions; |
| 1307 | case LYS_LIST: |
| 1308 | return &((struct lysc_node_list*)node)->actions; |
| 1309 | default: |
| 1310 | return NULL; |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | API const struct lysc_action * |
| 1315 | lysc_node_actions(const struct lysc_node *node) |
| 1316 | { |
| 1317 | struct lysc_action **actions; |
| 1318 | actions = lysc_node_actions_p((struct lysc_node*)node); |
| 1319 | if (actions) { |
| 1320 | return *actions; |
| 1321 | } else { |
| 1322 | return NULL; |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | struct lysc_notif ** |
| 1327 | lysc_node_notifs_p(struct lysc_node *node) |
| 1328 | { |
| 1329 | assert(node); |
| 1330 | switch (node->nodetype) { |
| 1331 | case LYS_CONTAINER: |
| 1332 | return &((struct lysc_node_container*)node)->notifs; |
| 1333 | case LYS_LIST: |
| 1334 | return &((struct lysc_node_list*)node)->notifs; |
| 1335 | default: |
| 1336 | return NULL; |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | API const struct lysc_notif * |
| 1341 | lysc_node_notifs(const struct lysc_node *node) |
| 1342 | { |
| 1343 | struct lysc_notif **notifs; |
| 1344 | notifs = lysc_node_notifs_p((struct lysc_node*)node); |
| 1345 | if (notifs) { |
| 1346 | return *notifs; |
| 1347 | } else { |
| 1348 | return NULL; |
| 1349 | } |
| 1350 | } |
| 1351 | |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1352 | struct lysc_node ** |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 1353 | lysc_node_children_p(const struct lysc_node *node, uint16_t flags) |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1354 | { |
| 1355 | assert(node); |
| 1356 | switch (node->nodetype) { |
| 1357 | case LYS_CONTAINER: |
| 1358 | return &((struct lysc_node_container*)node)->child; |
| 1359 | case LYS_CHOICE: |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1360 | if (((struct lysc_node_choice*)node)->cases) { |
Radek Krejci | 95710c9 | 2019-02-11 15:49:55 +0100 | [diff] [blame] | 1361 | return &((struct lysc_node_choice*)node)->cases->child; |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1362 | } else { |
| 1363 | return NULL; |
| 1364 | } |
Radek Krejci | 01342af | 2019-01-03 15:18:08 +0100 | [diff] [blame] | 1365 | case LYS_CASE: |
| 1366 | return &((struct lysc_node_case*)node)->child; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1367 | case LYS_LIST: |
| 1368 | return &((struct lysc_node_list*)node)->child; |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 1369 | case LYS_ACTION: |
| 1370 | if (flags & LYS_CONFIG_R) { |
| 1371 | return &((struct lysc_action*)node)->output.data; |
| 1372 | } else { |
| 1373 | /* LYS_CONFIG_W, but also the default case */ |
| 1374 | return &((struct lysc_action*)node)->input.data; |
| 1375 | } |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 1376 | case LYS_NOTIF: |
| 1377 | return &((struct lysc_notif*)node)->data; |
Radek Krejci | bbe09a9 | 2018-11-08 09:36:54 +0100 | [diff] [blame] | 1378 | default: |
| 1379 | return NULL; |
| 1380 | } |
| 1381 | } |
| 1382 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1383 | API const struct lysc_node * |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 1384 | lysc_node_children(const struct lysc_node *node, uint16_t flags) |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1385 | { |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1386 | struct lysc_node **children; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 1387 | |
| 1388 | if (!node) { |
| 1389 | return NULL; |
| 1390 | } |
| 1391 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 1392 | children = lysc_node_children_p((struct lysc_node*)node, flags); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1393 | if (children) { |
| 1394 | return *children; |
| 1395 | } else { |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 1396 | return NULL; |
| 1397 | } |
| 1398 | } |
| 1399 | |
Radek Krejci | 96a0bfd | 2018-11-22 15:25:06 +0100 | [diff] [blame] | 1400 | struct lys_module * |
| 1401 | lysp_find_module(struct ly_ctx *ctx, const struct lysp_module *mod) |
| 1402 | { |
| 1403 | unsigned int u; |
| 1404 | |
| 1405 | for (u = 0; u < ctx->list.count; ++u) { |
| 1406 | if (((struct lys_module*)ctx->list.objs[u])->parsed == mod) { |
| 1407 | return ((struct lys_module*)ctx->list.objs[u]); |
| 1408 | } |
| 1409 | } |
| 1410 | return NULL; |
| 1411 | } |
| 1412 | |
David Sedlák | c10e790 | 2018-12-17 02:17:59 +0100 | [diff] [blame] | 1413 | enum yang_keyword |
David Sedlák | 5f8f033 | 2019-06-18 16:34:30 +0200 | [diff] [blame] | 1414 | lysp_match_kw(struct lys_parser_ctx *ctx, const char **data) |
David Sedlák | c10e790 | 2018-12-17 02:17:59 +0100 | [diff] [blame] | 1415 | { |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1416 | /** |
| 1417 | * @brief Move the DATA pointer by COUNT items. Also updates the indent value in yang parser context |
| 1418 | * @param[in] CTX yang parser context to update its indent value. |
| 1419 | * @param[in,out] DATA pointer to move |
| 1420 | * @param[in] COUNT number of items for which the DATA pointer is supposed to move on. |
| 1421 | */ |
| 1422 | #define MOVE_IN(CTX, DATA, COUNT) (*(DATA))+=COUNT;if(CTX){(CTX)->indent+=COUNT;} |
| 1423 | #define IF_KW(STR, LEN, STMT) if (!strncmp(*(data), STR, LEN)) {MOVE_IN(ctx, data, LEN);*kw=STMT;} |
| 1424 | #define IF_KW_PREFIX(STR, LEN) if (!strncmp(*(data), STR, LEN)) {MOVE_IN(ctx, data, LEN); |
| 1425 | #define IF_KW_PREFIX_END } |
David Sedlák | 572e7ab | 2019-06-04 16:01:58 +0200 | [diff] [blame] | 1426 | |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1427 | enum yang_keyword result = YANG_NONE; |
| 1428 | enum yang_keyword *kw = &result; |
| 1429 | /* read the keyword itself */ |
| 1430 | switch (**data) { |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1431 | case 'a': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1432 | MOVE_IN(ctx, data, 1); |
| 1433 | IF_KW("rgument", 7, YANG_ARGUMENT) |
| 1434 | else IF_KW("ugment", 6, YANG_AUGMENT) |
| 1435 | else IF_KW("ction", 5, YANG_ACTION) |
| 1436 | else IF_KW_PREFIX("ny", 2) |
| 1437 | IF_KW("data", 4, YANG_ANYDATA) |
| 1438 | else IF_KW("xml", 3, YANG_ANYXML) |
| 1439 | IF_KW_PREFIX_END |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1440 | break; |
| 1441 | case 'b': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1442 | MOVE_IN(ctx, data, 1); |
| 1443 | IF_KW("ase", 3, YANG_BASE) |
| 1444 | else IF_KW("elongs-to", 9, YANG_BELONGS_TO) |
| 1445 | else IF_KW("it", 2, YANG_BIT) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1446 | break; |
| 1447 | case 'c': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1448 | MOVE_IN(ctx, data, 1); |
| 1449 | IF_KW("ase", 3, YANG_CASE) |
| 1450 | else IF_KW("hoice", 5, YANG_CHOICE) |
| 1451 | else IF_KW_PREFIX("on", 2) |
| 1452 | IF_KW("fig", 3, YANG_CONFIG) |
| 1453 | else IF_KW_PREFIX("ta", 2) |
| 1454 | IF_KW("ct", 2, YANG_CONTACT) |
| 1455 | else IF_KW("iner", 4, YANG_CONTAINER) |
| 1456 | IF_KW_PREFIX_END |
| 1457 | IF_KW_PREFIX_END |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1458 | break; |
| 1459 | case 'd': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1460 | MOVE_IN(ctx, data, 1); |
| 1461 | IF_KW_PREFIX("e", 1) |
| 1462 | IF_KW("fault", 5, YANG_DEFAULT) |
| 1463 | else IF_KW("scription", 9, YANG_DESCRIPTION) |
| 1464 | else IF_KW_PREFIX("viat", 4) |
| 1465 | IF_KW("e", 1, YANG_DEVIATE) |
| 1466 | else IF_KW("ion", 3, YANG_DEVIATION) |
| 1467 | IF_KW_PREFIX_END |
| 1468 | IF_KW_PREFIX_END |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1469 | break; |
| 1470 | case 'e': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1471 | MOVE_IN(ctx, data, 1); |
| 1472 | IF_KW("num", 3, YANG_ENUM) |
| 1473 | else IF_KW_PREFIX("rror-", 5) |
| 1474 | IF_KW("app-tag", 7, YANG_ERROR_APP_TAG) |
| 1475 | else IF_KW("message", 7, YANG_ERROR_MESSAGE) |
| 1476 | IF_KW_PREFIX_END |
| 1477 | else IF_KW("xtension", 8, YANG_EXTENSION) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1478 | break; |
| 1479 | case 'f': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1480 | MOVE_IN(ctx, data, 1); |
| 1481 | IF_KW("eature", 6, YANG_FEATURE) |
| 1482 | else IF_KW("raction-digits", 14, YANG_FRACTION_DIGITS) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1483 | break; |
| 1484 | case 'g': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1485 | MOVE_IN(ctx, data, 1); |
| 1486 | IF_KW("rouping", 7, YANG_GROUPING) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1487 | break; |
| 1488 | case 'i': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1489 | MOVE_IN(ctx, data, 1); |
| 1490 | IF_KW("dentity", 7, YANG_IDENTITY) |
| 1491 | else IF_KW("f-feature", 9, YANG_IF_FEATURE) |
| 1492 | else IF_KW("mport", 5, YANG_IMPORT) |
| 1493 | else IF_KW_PREFIX("n", 1) |
| 1494 | IF_KW("clude", 5, YANG_INCLUDE) |
| 1495 | else IF_KW("put", 3, YANG_INPUT) |
| 1496 | IF_KW_PREFIX_END |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1497 | break; |
| 1498 | case 'k': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1499 | MOVE_IN(ctx, data, 1); |
| 1500 | IF_KW("ey", 2, YANG_KEY) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1501 | break; |
| 1502 | case 'l': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1503 | MOVE_IN(ctx, data, 1); |
| 1504 | IF_KW_PREFIX("e", 1) |
| 1505 | IF_KW("af-list", 7, YANG_LEAF_LIST) |
| 1506 | else IF_KW("af", 2, YANG_LEAF) |
| 1507 | else IF_KW("ngth", 4, YANG_LENGTH) |
| 1508 | IF_KW_PREFIX_END |
| 1509 | else IF_KW("ist", 3, YANG_LIST) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1510 | break; |
| 1511 | case 'm': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1512 | MOVE_IN(ctx, data, 1); |
| 1513 | IF_KW_PREFIX("a", 1) |
| 1514 | IF_KW("ndatory", 7, YANG_MANDATORY) |
| 1515 | else IF_KW("x-elements", 10, YANG_MAX_ELEMENTS) |
| 1516 | IF_KW_PREFIX_END |
| 1517 | else IF_KW("in-elements", 11, YANG_MIN_ELEMENTS) |
| 1518 | else IF_KW("ust", 3, YANG_MUST) |
| 1519 | else IF_KW_PREFIX("od", 2) |
| 1520 | IF_KW("ule", 3, YANG_MODULE) |
| 1521 | else IF_KW("ifier", 5, YANG_MODIFIER) |
| 1522 | IF_KW_PREFIX_END |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1523 | break; |
| 1524 | case 'n': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1525 | MOVE_IN(ctx, data, 1); |
| 1526 | IF_KW("amespace", 8, YANG_NAMESPACE) |
| 1527 | else IF_KW("otification", 11, YANG_NOTIFICATION) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1528 | break; |
| 1529 | case 'o': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1530 | MOVE_IN(ctx, data, 1); |
| 1531 | IF_KW_PREFIX("r", 1) |
| 1532 | IF_KW("dered-by", 8, YANG_ORDERED_BY) |
| 1533 | else IF_KW("ganization", 10, YANG_ORGANIZATION) |
| 1534 | IF_KW_PREFIX_END |
| 1535 | else IF_KW("utput", 5, YANG_OUTPUT) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1536 | break; |
| 1537 | case 'p': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1538 | MOVE_IN(ctx, data, 1); |
| 1539 | IF_KW("ath", 3, YANG_PATH) |
| 1540 | else IF_KW("attern", 6, YANG_PATTERN) |
| 1541 | else IF_KW("osition", 7, YANG_POSITION) |
| 1542 | else IF_KW_PREFIX("re", 2) |
| 1543 | IF_KW("fix", 3, YANG_PREFIX) |
| 1544 | else IF_KW("sence", 5, YANG_PRESENCE) |
| 1545 | IF_KW_PREFIX_END |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1546 | break; |
| 1547 | case 'r': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1548 | MOVE_IN(ctx, data, 1); |
| 1549 | IF_KW("ange", 4, YANG_RANGE) |
| 1550 | else IF_KW_PREFIX("e", 1) |
| 1551 | IF_KW_PREFIX("f", 1) |
| 1552 | IF_KW("erence", 6, YANG_REFERENCE) |
| 1553 | else IF_KW("ine", 3, YANG_REFINE) |
| 1554 | IF_KW_PREFIX_END |
| 1555 | else IF_KW("quire-instance", 14, YANG_REQUIRE_INSTANCE) |
| 1556 | else IF_KW("vision-date", 11, YANG_REVISION_DATE) |
| 1557 | else IF_KW("vision", 6, YANG_REVISION) |
| 1558 | IF_KW_PREFIX_END |
| 1559 | else IF_KW("pc", 2, YANG_RPC) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1560 | break; |
| 1561 | case 's': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1562 | MOVE_IN(ctx, data, 1); |
| 1563 | IF_KW("tatus", 5, YANG_STATUS) |
| 1564 | else IF_KW("ubmodule", 8, YANG_SUBMODULE) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1565 | break; |
| 1566 | case 't': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1567 | MOVE_IN(ctx, data, 1); |
| 1568 | IF_KW("ypedef", 6, YANG_TYPEDEF) |
| 1569 | else IF_KW("ype", 3, YANG_TYPE) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1570 | break; |
| 1571 | case 'u': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1572 | MOVE_IN(ctx, data, 1); |
| 1573 | IF_KW_PREFIX("ni", 2) |
| 1574 | IF_KW("que", 3, YANG_UNIQUE) |
| 1575 | else IF_KW("ts", 2, YANG_UNITS) |
| 1576 | IF_KW_PREFIX_END |
| 1577 | else IF_KW("ses", 3, YANG_USES) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1578 | break; |
| 1579 | case 'v': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1580 | MOVE_IN(ctx, data, 1); |
| 1581 | IF_KW("alue", 4, YANG_VALUE) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1582 | break; |
| 1583 | case 'w': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1584 | MOVE_IN(ctx, data, 1); |
| 1585 | IF_KW("hen", 3, YANG_WHEN) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1586 | break; |
| 1587 | case 'y': |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1588 | MOVE_IN(ctx, data, 1); |
| 1589 | IF_KW("ang-version", 11, YANG_YANG_VERSION) |
| 1590 | else IF_KW("in-element", 10, YANG_YIN_ELEMENT) |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1591 | break; |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1592 | default: |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1593 | /* if context is not NULL we are matching keyword from YANG data*/ |
| 1594 | if (ctx) { |
| 1595 | if (**data == ';') { |
| 1596 | MOVE_IN(ctx, data, 1); |
| 1597 | *kw = YANG_SEMICOLON; |
| 1598 | } else if (**data == '{') { |
| 1599 | MOVE_IN(ctx, data, 1); |
| 1600 | *kw = YANG_LEFT_BRACE; |
| 1601 | } else if (**data == '}') { |
| 1602 | MOVE_IN(ctx, data, 1); |
| 1603 | *kw = YANG_RIGHT_BRACE; |
| 1604 | } |
| 1605 | } |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1606 | break; |
| 1607 | } |
| 1608 | |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1609 | #undef IF_KW |
| 1610 | #undef IF_KW_PREFIX |
| 1611 | #undef IF_KW_PREFIX_END |
David Sedlák | 1873013 | 2019-03-15 15:51:34 +0100 | [diff] [blame] | 1612 | #undef MOVE_IN |
David Sedlák | 1873013 | 2019-03-15 15:51:34 +0100 | [diff] [blame] | 1613 | |
David Sedlák | 1bccdfa | 2019-06-17 15:55:27 +0200 | [diff] [blame] | 1614 | return result; |
David Sedlák | 23a59a6 | 2018-10-26 13:08:02 +0200 | [diff] [blame] | 1615 | } |
David Sedlák | ecf5eb8 | 2019-06-03 14:12:44 +0200 | [diff] [blame] | 1616 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1617 | unsigned int |
| 1618 | lysp_ext_instance_iter(struct lysp_ext_instance *ext, unsigned int index, LYEXT_SUBSTMT substmt) |
| 1619 | { |
| 1620 | LY_CHECK_ARG_RET(NULL, ext, LY_EINVAL); |
| 1621 | |
| 1622 | for (; index < LY_ARRAY_SIZE(ext); index++) { |
| 1623 | if (ext[index].insubstmt == substmt) { |
| 1624 | return index; |
| 1625 | } |
| 1626 | } |
| 1627 | |
| 1628 | return LY_ARRAY_SIZE(ext); |
| 1629 | } |
| 1630 | |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1631 | /** |
| 1632 | * @brief Schema mapping of YANG modules to prefixes in values. |
| 1633 | * |
| 1634 | * Implementation of ly_clb_get_prefix. Inverse function to lys_resolve_prefix. |
| 1635 | * |
| 1636 | * In this case the @p mod is searched in the list of imports and the import's prefix |
| 1637 | * (not the module's itself) prefix is returned. |
| 1638 | */ |
| 1639 | const char * |
| 1640 | lys_get_prefix(const struct lys_module *mod, void *private) |
| 1641 | { |
| 1642 | struct lys_module *context_mod = (struct lys_module*)private; |
| 1643 | unsigned int u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1644 | |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1645 | LY_ARRAY_FOR(context_mod->compiled->imports, u) { |
| 1646 | if (context_mod->compiled->imports[u].module == mod) { |
| 1647 | /* match */ |
| 1648 | return mod->compiled->imports[u].prefix; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | return NULL; |
| 1653 | } |
| 1654 | |
| 1655 | /** |
| 1656 | * @brief Schema mapping of prefix in values to YANG modules (imports). |
| 1657 | * |
| 1658 | * Implementation of ly_clb_resolve_prefix. Inverse function to lys_get_prefix(). |
| 1659 | * |
| 1660 | * In this case the @p prefix is searched in the list of imports' prefixes (not the prefixes of the imported modules themselves). |
| 1661 | */ |
| 1662 | const struct lys_module * |
| 1663 | lys_resolve_prefix(struct ly_ctx *UNUSED(ctx), const char *prefix, size_t prefix_len, void *private) |
| 1664 | { |
| 1665 | return lys_module_find_prefix((const struct lys_module*)private, prefix, prefix_len); |
| 1666 | } |