Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file context.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief context implementation for libyang |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 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 |
Michal Vasko | 8de098c | 2016-02-26 10:00:25 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #define _GNU_SOURCE |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 16 | #include <stddef.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | #include <sys/types.h> |
| 20 | #include <sys/stat.h> |
| 21 | #include <unistd.h> |
| 22 | #include <errno.h> |
| 23 | #include <fcntl.h> |
| 24 | |
| 25 | #include "common.h" |
| 26 | #include "context.h" |
Radek Krejci | 41912fe | 2015-10-22 10:22:12 +0200 | [diff] [blame] | 27 | #include "dict_private.h" |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 28 | #include "parser.h" |
Radek Krejci | bc9cf93 | 2015-07-30 11:09:39 +0200 | [diff] [blame] | 29 | #include "tree_internal.h" |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 30 | |
Radek Krejci | d9f7ec5 | 2016-02-11 16:27:01 +0100 | [diff] [blame] | 31 | #define YANG_FAKEMODULE_PATH "../models/yang@2016-02-11.h" |
Michal Vasko | 8d054e4 | 2015-08-03 12:42:06 +0200 | [diff] [blame] | 32 | #define IETF_INET_TYPES_PATH "../models/ietf-inet-types@2013-07-15.h" |
Michal Vasko | 21181c4 | 2015-08-03 13:46:45 +0200 | [diff] [blame] | 33 | #define IETF_YANG_TYPES_PATH "../models/ietf-yang-types@2013-07-15.h" |
Radek Krejci | d972391 | 2016-09-16 17:06:06 +0200 | [diff] [blame^] | 34 | #define IETF_YANG_LIB_PATH "../models/ietf-yang-library@2016-06-21.h" |
| 35 | #define IETF_YANG_LIB_REV "2016-06-21" |
Michal Vasko | 8d054e4 | 2015-08-03 12:42:06 +0200 | [diff] [blame] | 36 | |
Radek Krejci | d9f7ec5 | 2016-02-11 16:27:01 +0100 | [diff] [blame] | 37 | #include YANG_FAKEMODULE_PATH |
Michal Vasko | 8d054e4 | 2015-08-03 12:42:06 +0200 | [diff] [blame] | 38 | #include IETF_INET_TYPES_PATH |
Michal Vasko | 21181c4 | 2015-08-03 13:46:45 +0200 | [diff] [blame] | 39 | #include IETF_YANG_TYPES_PATH |
Michal Vasko | 8d054e4 | 2015-08-03 12:42:06 +0200 | [diff] [blame] | 40 | #include IETF_YANG_LIB_PATH |
| 41 | |
Radek Krejci | 0320341 | 2016-06-23 15:20:53 +0200 | [diff] [blame] | 42 | #define INTERNAL_MODULES_COUNT 4 |
| 43 | static struct internal_modules_s { |
| 44 | const char *name; |
| 45 | const char *revision; |
| 46 | const char *data; |
| 47 | uint8_t implemented; |
| 48 | LYS_INFORMAT format; |
| 49 | } internal_modules[INTERNAL_MODULES_COUNT] = { |
| 50 | {"yang", "2016-02-11", (const char*)yang_2016_02_11_yin, 1, LYS_IN_YIN}, |
| 51 | {"ietf-inet-types", "2013-07-15", (const char*)ietf_inet_types_2013_07_15_yin, 0, LYS_IN_YIN}, |
| 52 | {"ietf-yang-types", "2013-07-15", (const char*)ietf_yang_types_2013_07_15_yin, 0, LYS_IN_YIN}, |
Radek Krejci | d972391 | 2016-09-16 17:06:06 +0200 | [diff] [blame^] | 53 | {"ietf-yang-library", "2016-06-21", (const char*)ietf_yang_library_2016_06_21_yin, 1, LYS_IN_YIN} |
Radek Krejci | 0320341 | 2016-06-23 15:20:53 +0200 | [diff] [blame] | 54 | }; |
| 55 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 56 | API struct ly_ctx * |
| 57 | ly_ctx_new(const char *search_dir) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 58 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 59 | struct ly_ctx *ctx; |
Michal Vasko | 7d7de95 | 2016-05-02 17:13:14 +0200 | [diff] [blame] | 60 | struct lys_module *module; |
Michal Vasko | 70b6d69 | 2015-08-03 14:05:59 +0200 | [diff] [blame] | 61 | char *cwd; |
Radek Krejci | 0320341 | 2016-06-23 15:20:53 +0200 | [diff] [blame] | 62 | int i; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 63 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 64 | ctx = calloc(1, sizeof *ctx); |
| 65 | if (!ctx) { |
| 66 | LOGMEM; |
| 67 | return NULL; |
| 68 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 69 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 70 | /* dictionary */ |
| 71 | lydict_init(&ctx->dict); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 72 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 73 | /* models list */ |
| 74 | ctx->models.list = calloc(16, sizeof *ctx->models.list); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 75 | if (!ctx->models.list) { |
| 76 | LOGMEM; |
| 77 | free(ctx); |
| 78 | return NULL; |
| 79 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 80 | ctx->models.used = 0; |
| 81 | ctx->models.size = 16; |
| 82 | if (search_dir) { |
| 83 | cwd = get_current_dir_name(); |
| 84 | if (chdir(search_dir)) { |
| 85 | LOGERR(LY_ESYS, "Unable to use search directory \"%s\" (%s)", |
| 86 | search_dir, strerror(errno)); |
| 87 | free(cwd); |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 88 | ly_ctx_destroy(ctx, NULL); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 89 | return NULL; |
| 90 | } |
| 91 | ctx->models.search_path = get_current_dir_name(); |
Radek Krejci | 15412ca | 2016-03-03 11:16:52 +0100 | [diff] [blame] | 92 | if (chdir(cwd)) { |
| 93 | LOGWRN("Unable to return back to working directory \"%s\" (%s)", |
| 94 | cwd, strerror(errno)); |
| 95 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 96 | free(cwd); |
| 97 | } |
Michal Vasko | 14719b2 | 2015-08-03 12:47:55 +0200 | [diff] [blame] | 98 | ctx->models.module_set_id = 1; |
| 99 | |
Radek Krejci | 0320341 | 2016-06-23 15:20:53 +0200 | [diff] [blame] | 100 | /* load internal modules */ |
| 101 | for (i = 0; i < INTERNAL_MODULES_COUNT; i++) { |
| 102 | module = (struct lys_module *)lys_parse_mem(ctx, internal_modules[i].data, internal_modules[i].format); |
| 103 | if (!module) { |
| 104 | ly_ctx_destroy(ctx, NULL); |
| 105 | return NULL; |
| 106 | } |
| 107 | module->implemented = internal_modules[i].implemented; |
Michal Vasko | 8d054e4 | 2015-08-03 12:42:06 +0200 | [diff] [blame] | 108 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 109 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 110 | return ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 111 | } |
| 112 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 113 | API void |
Michal Vasko | 60ba9a6 | 2015-07-03 14:42:31 +0200 | [diff] [blame] | 114 | ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir) |
| 115 | { |
| 116 | char *cwd; |
| 117 | |
| 118 | if (!ctx) { |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | if (search_dir) { |
| 123 | cwd = get_current_dir_name(); |
| 124 | if (chdir(search_dir)) { |
| 125 | LOGERR(LY_ESYS, "Unable to use search directory \"%s\" (%s)", |
| 126 | search_dir, strerror(errno)); |
| 127 | free(cwd); |
| 128 | return; |
| 129 | } |
Michal Vasko | 3eff932 | 2015-11-10 11:02:30 +0100 | [diff] [blame] | 130 | free(ctx->models.search_path); |
Michal Vasko | 60ba9a6 | 2015-07-03 14:42:31 +0200 | [diff] [blame] | 131 | ctx->models.search_path = get_current_dir_name(); |
Michal Vasko | 3eff932 | 2015-11-10 11:02:30 +0100 | [diff] [blame] | 132 | |
Radek Krejci | 15412ca | 2016-03-03 11:16:52 +0100 | [diff] [blame] | 133 | if (chdir(cwd)) { |
| 134 | LOGWRN("Unable to return back to working directory \"%s\" (%s)", |
| 135 | cwd, strerror(errno)); |
| 136 | } |
Michal Vasko | 60ba9a6 | 2015-07-03 14:42:31 +0200 | [diff] [blame] | 137 | free(cwd); |
| 138 | } else { |
| 139 | free(ctx->models.search_path); |
| 140 | ctx->models.search_path = NULL; |
| 141 | } |
| 142 | } |
| 143 | |
Radek Krejci | b081d8d | 2015-10-21 16:29:07 +0200 | [diff] [blame] | 144 | API const char * |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 145 | ly_ctx_get_searchdir(const struct ly_ctx *ctx) |
Radek Krejci | 5a79757 | 2015-10-21 15:45:45 +0200 | [diff] [blame] | 146 | { |
| 147 | return ctx->models.search_path; |
| 148 | } |
| 149 | |
Michal Vasko | 60ba9a6 | 2015-07-03 14:42:31 +0200 | [diff] [blame] | 150 | API void |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 151 | ly_ctx_destroy(struct ly_ctx *ctx, void (*private_destructor)(const struct lys_node *node, void *priv)) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 152 | { |
Michal Vasko | 627975a | 2016-02-11 11:39:03 +0100 | [diff] [blame] | 153 | int i; |
| 154 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 155 | if (!ctx) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 156 | return; |
| 157 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 158 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 159 | /* models list */ |
Michal Vasko | 627975a | 2016-02-11 11:39:03 +0100 | [diff] [blame] | 160 | for (i = 0; i < ctx->models.used; ++i) { |
| 161 | lys_free(ctx->models.list[i], private_destructor, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 162 | } |
| 163 | free(ctx->models.search_path); |
| 164 | free(ctx->models.list); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 165 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 166 | /* dictionary */ |
| 167 | lydict_clean(&ctx->dict); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 168 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 169 | free(ctx); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 170 | } |
| 171 | |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 172 | API const struct lys_submodule * |
Radek Krejci | 62f0da7 | 2016-03-07 11:35:43 +0100 | [diff] [blame] | 173 | ly_ctx_get_submodule2(const struct lys_module *main_module, const char *submodule) |
| 174 | { |
| 175 | struct lys_submodule *result; |
| 176 | int i; |
| 177 | |
| 178 | if (!main_module || !submodule) { |
| 179 | ly_errno = LY_EINVAL; |
| 180 | return NULL; |
| 181 | } |
| 182 | |
| 183 | /* search in submodules list */ |
| 184 | for (i = 0; i < main_module->inc_size; i++) { |
| 185 | result = main_module->inc[i].submodule; |
| 186 | if (result && ly_strequal(submodule, result->name, 0)) { |
| 187 | return result; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | return NULL; |
| 192 | } |
| 193 | |
| 194 | API const struct lys_submodule * |
Michal Vasko | f6d94c6 | 2016-04-05 11:21:54 +0200 | [diff] [blame] | 195 | ly_ctx_get_submodule(const struct ly_ctx *ctx, const char *module, const char *revision, const char *submodule, |
| 196 | const char *sub_revision) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 197 | { |
Radek Krejci | e797355 | 2016-03-07 08:12:01 +0100 | [diff] [blame] | 198 | const struct lys_module *mainmod; |
Michal Vasko | f6d94c6 | 2016-04-05 11:21:54 +0200 | [diff] [blame] | 199 | const struct lys_submodule *ret = NULL, *submod; |
| 200 | uint32_t idx = 0; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 201 | |
Michal Vasko | f6d94c6 | 2016-04-05 11:21:54 +0200 | [diff] [blame] | 202 | if (!ctx || !submodule || (revision && !module)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 203 | ly_errno = LY_EINVAL; |
| 204 | return NULL; |
| 205 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 206 | |
Michal Vasko | f6d94c6 | 2016-04-05 11:21:54 +0200 | [diff] [blame] | 207 | while ((mainmod = ly_ctx_get_module_iter(ctx, &idx))) { |
| 208 | if (module && strcmp(mainmod->name, module)) { |
| 209 | /* main module name does not match */ |
| 210 | continue; |
| 211 | } |
| 212 | |
| 213 | if (revision && (!mainmod->rev || strcmp(revision, mainmod->rev[0].date))) { |
| 214 | /* main module revision does not match */ |
| 215 | continue; |
| 216 | } |
| 217 | |
| 218 | submod = ly_ctx_get_submodule2(mainmod, submodule); |
| 219 | if (!submod) { |
| 220 | continue; |
| 221 | } |
| 222 | |
| 223 | if (!sub_revision) { |
| 224 | /* store only if newer */ |
| 225 | if (ret) { |
| 226 | if (submod->rev && (!ret->rev || (strcmp(submod->rev[0].date, ret->rev[0].date) > 0))) { |
| 227 | ret = submod; |
| 228 | } |
| 229 | } else { |
| 230 | ret = submod; |
| 231 | } |
| 232 | } else { |
| 233 | /* store only if revision matches, we are done if it does */ |
| 234 | if (!submod->rev) { |
| 235 | continue; |
| 236 | } else if (!strcmp(sub_revision, submod->rev[0].date)) { |
| 237 | ret = submod; |
| 238 | break; |
| 239 | } |
| 240 | } |
Radek Krejci | a7533f2 | 2016-03-07 07:37:45 +0100 | [diff] [blame] | 241 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 242 | |
Michal Vasko | f6d94c6 | 2016-04-05 11:21:54 +0200 | [diff] [blame] | 243 | return ret; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 246 | static const struct lys_module * |
| 247 | ly_ctx_get_module_by(const struct ly_ctx *ctx, const char *key, int offset, const char *revision) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 248 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 249 | int i; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 250 | struct lys_module *result = NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 251 | |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 252 | if (!ctx || !key) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 253 | ly_errno = LY_EINVAL; |
| 254 | return NULL; |
| 255 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 256 | |
Radek Krejci | dce5145 | 2015-06-16 15:20:08 +0200 | [diff] [blame] | 257 | for (i = 0; i < ctx->models.used; i++) { |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 258 | /* use offset to get address of the pointer to string (char**), remember that offset is in |
| 259 | * bytes, so we have to cast the pointer to the module to (char*), finally, we want to have |
| 260 | * string not the pointer to string |
| 261 | */ |
| 262 | if (!ctx->models.list[i] || strcmp(key, *(char**)(((char*)ctx->models.list[i]) + offset))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 263 | continue; |
| 264 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 265 | |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 266 | if (!revision) { |
| 267 | /* compare revisons and remember the newest one */ |
| 268 | if (result) { |
| 269 | if (!ctx->models.list[i]->rev_size) { |
| 270 | /* the current have no revision, keep the previous with some revision */ |
| 271 | continue; |
| 272 | } |
| 273 | if (result->rev_size && strcmp(ctx->models.list[i]->rev[0].date, result->rev[0].date) < 0) { |
| 274 | /* the previous found matching module has a newer revision */ |
| 275 | continue; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | /* remember the current match and search for newer version */ |
| 280 | result = ctx->models.list[i]; |
| 281 | } else { |
| 282 | if (ctx->models.list[i]->rev_size && !strcmp(revision, ctx->models.list[i]->rev[0].date)) { |
| 283 | /* matching revision */ |
Michal Vasko | 9758650 | 2015-08-12 14:32:18 +0200 | [diff] [blame] | 284 | result = ctx->models.list[i]; |
| 285 | break; |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 286 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 287 | } |
| 288 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 289 | |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 290 | return result; |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 291 | |
| 292 | } |
| 293 | |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 294 | API const struct lys_module * |
| 295 | ly_ctx_get_module_by_ns(const struct ly_ctx *ctx, const char *ns, const char *revision) |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 296 | { |
| 297 | return ly_ctx_get_module_by(ctx, ns, offsetof(struct lys_module, ns), revision); |
| 298 | } |
| 299 | |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 300 | API const struct lys_module * |
| 301 | ly_ctx_get_module(const struct ly_ctx *ctx, const char *name, const char *revision) |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 302 | { |
| 303 | return ly_ctx_get_module_by(ctx, name, offsetof(struct lys_module, name), revision); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 304 | } |
Michal Vasko | 3ec07dc | 2015-06-30 15:51:30 +0200 | [diff] [blame] | 305 | |
Radek Krejci | 21601a3 | 2016-03-07 11:39:27 +0100 | [diff] [blame] | 306 | API const struct lys_module * |
| 307 | ly_ctx_get_module_older(const struct ly_ctx *ctx, const struct lys_module *module) |
| 308 | { |
| 309 | int i; |
| 310 | const struct lys_module *result = NULL, *iter; |
| 311 | |
| 312 | if (!ctx || !module || !module->rev_size) { |
| 313 | ly_errno = LY_EINVAL; |
| 314 | return NULL; |
| 315 | } |
| 316 | |
| 317 | |
| 318 | for (i = 0; i < ctx->models.used; i++) { |
| 319 | iter = ctx->models.list[i]; |
| 320 | if (iter == module || !iter->rev_size) { |
| 321 | /* iter is the module itself or iter has no revision */ |
| 322 | continue; |
| 323 | } |
| 324 | if (!ly_strequal(module->name, iter->name, 0)) { |
| 325 | /* different module */ |
| 326 | continue; |
| 327 | } |
| 328 | if (strcmp(iter->rev[0].date, module->rev[0].date) < 0) { |
| 329 | /* iter is older than module */ |
| 330 | if (result) { |
| 331 | if (strcmp(iter->rev[0].date, result->rev[0].date) > 0) { |
| 332 | /* iter is newer than current result */ |
| 333 | result = iter; |
| 334 | } |
| 335 | } else { |
| 336 | result = iter; |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | return result; |
| 342 | } |
| 343 | |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 344 | API void |
| 345 | ly_ctx_set_module_clb(struct ly_ctx *ctx, ly_module_clb clb, void *user_data) |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 346 | { |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 347 | ctx->module_clb = clb; |
| 348 | ctx->module_clb_data = user_data; |
| 349 | } |
| 350 | |
| 351 | API ly_module_clb |
| 352 | ly_ctx_get_module_clb(const struct ly_ctx *ctx, void **user_data) |
| 353 | { |
| 354 | if (user_data) { |
| 355 | *user_data = ctx->module_clb_data; |
| 356 | } |
| 357 | return ctx->module_clb; |
| 358 | } |
| 359 | |
Michal Vasko | 8447515 | 2016-07-25 16:16:25 +0200 | [diff] [blame] | 360 | struct lys_module * |
| 361 | ly_ctx_load_sub_module(struct ly_ctx *ctx, struct lys_module *module, const char *name, const char *revision, |
Michal Vasko | 58e5f3e | 2016-07-28 11:06:34 +0200 | [diff] [blame] | 362 | int implement, struct unres_schema *unres) |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 363 | { |
Michal Vasko | 8447515 | 2016-07-25 16:16:25 +0200 | [diff] [blame] | 364 | struct lys_module *mod; |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 365 | char *module_data; |
Radek Krejci | 0320341 | 2016-06-23 15:20:53 +0200 | [diff] [blame] | 366 | int i; |
Michal Vasko | d3e975b | 2016-03-03 15:40:21 +0100 | [diff] [blame] | 367 | void (*module_data_free)(void *module_data) = NULL; |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 368 | LYS_INFORMAT format = LYS_IN_UNKNOWN; |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 369 | |
Radek Krejci | 0320341 | 2016-06-23 15:20:53 +0200 | [diff] [blame] | 370 | /* exception for internal modules */ |
Michal Vasko | 8447515 | 2016-07-25 16:16:25 +0200 | [diff] [blame] | 371 | if (!module) { |
| 372 | for (i = 0; i < INTERNAL_MODULES_COUNT; i++) { |
| 373 | if (ly_strequal(name, internal_modules[i].name, 0)) { |
| 374 | if (!revision || ly_strequal(revision, internal_modules[i].revision, 0)) { |
| 375 | /* return internal module */ |
| 376 | return (struct lys_module *)ly_ctx_get_module(ctx, name, revision); |
| 377 | } |
Radek Krejci | 0320341 | 2016-06-23 15:20:53 +0200 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 382 | if (ctx->module_clb) { |
Michal Vasko | 8447515 | 2016-07-25 16:16:25 +0200 | [diff] [blame] | 383 | if (module) { |
| 384 | mod = lys_main_module(module); |
| 385 | module_data = ctx->module_clb(mod->name, (mod->rev_size ? mod->rev[0].date : NULL), name, revision, ctx->module_clb_data, &format, &module_data_free); |
| 386 | } else { |
| 387 | module_data = ctx->module_clb(name, revision, NULL, NULL, ctx->module_clb_data, &format, &module_data_free); |
| 388 | } |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 389 | if (!module_data) { |
Radek Krejci | 0fd4974 | 2016-06-22 10:04:46 +0200 | [diff] [blame] | 390 | LOGERR(0, "User module retrieval callback failed!"); |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 391 | return NULL; |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 392 | } |
Michal Vasko | 8447515 | 2016-07-25 16:16:25 +0200 | [diff] [blame] | 393 | |
| 394 | if (module) { |
| 395 | mod = (struct lys_module *)lys_submodule_parse(module, module_data, format, unres); |
| 396 | } else { |
| 397 | mod = (struct lys_module *)lys_parse_mem(ctx, module_data, format); |
| 398 | } |
| 399 | |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 400 | if (module_data_free) { |
| 401 | module_data_free(module_data); |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 402 | } |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 403 | } else { |
Michal Vasko | 58e5f3e | 2016-07-28 11:06:34 +0200 | [diff] [blame] | 404 | mod = lyp_search_file(ctx, module, name, revision, implement, unres); |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Michal Vasko | 8447515 | 2016-07-25 16:16:25 +0200 | [diff] [blame] | 407 | return mod; |
| 408 | } |
| 409 | |
| 410 | API const struct lys_module * |
| 411 | ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision) |
| 412 | { |
| 413 | if (!ctx || !name) { |
| 414 | ly_errno = LY_EINVAL; |
| 415 | return NULL; |
| 416 | } |
| 417 | |
Michal Vasko | 58e5f3e | 2016-07-28 11:06:34 +0200 | [diff] [blame] | 418 | return ly_ctx_load_sub_module(ctx, NULL, name, revision, 1, NULL); |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 419 | } |
| 420 | |
Michal Vasko | d7957c0 | 2016-04-01 10:27:26 +0200 | [diff] [blame] | 421 | API const struct lys_module * |
| 422 | ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *idx) |
| 423 | { |
| 424 | if (!ctx || !idx) { |
| 425 | ly_errno = LY_EINVAL; |
| 426 | return NULL; |
| 427 | } |
| 428 | |
| 429 | if (*idx >= (unsigned)ctx->models.used) { |
| 430 | return NULL; |
| 431 | } |
| 432 | |
| 433 | return ctx->models.list[(*idx)++]; |
| 434 | } |
| 435 | |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 436 | static int |
| 437 | ylib_feature(struct lyd_node *parent, struct lys_module *cur_mod) |
| 438 | { |
| 439 | int i, j; |
| 440 | |
| 441 | /* module features */ |
| 442 | for (i = 0; i < cur_mod->features_size; ++i) { |
| 443 | if (!(cur_mod->features[i].flags & LYS_FENABLED)) { |
| 444 | continue; |
| 445 | } |
| 446 | |
Michal Vasko | 3e671b5 | 2015-10-23 16:23:15 +0200 | [diff] [blame] | 447 | if (!lyd_new_leaf(parent, NULL, "feature", cur_mod->features[i].name)) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 448 | return EXIT_FAILURE; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /* submodule features */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 453 | for (i = 0; i < cur_mod->inc_size && cur_mod->inc[i].submodule; ++i) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 454 | for (j = 0; j < cur_mod->inc[i].submodule->features_size; ++j) { |
| 455 | if (!(cur_mod->inc[i].submodule->features[j].flags & LYS_FENABLED)) { |
| 456 | continue; |
| 457 | } |
| 458 | |
Michal Vasko | 3e671b5 | 2015-10-23 16:23:15 +0200 | [diff] [blame] | 459 | if (!lyd_new_leaf(parent, NULL, "feature", cur_mod->inc[i].submodule->features[j].name)) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 460 | return EXIT_FAILURE; |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | return EXIT_SUCCESS; |
| 466 | } |
| 467 | |
| 468 | static int |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 469 | ylib_deviation(struct lyd_node *parent, struct lys_module *cur_mod) |
Michal Vasko | 97d8c6d | 2016-02-12 11:05:48 +0100 | [diff] [blame] | 470 | { |
Michal Vasko | 89563fc | 2016-07-28 16:19:35 +0200 | [diff] [blame] | 471 | uint32_t i = 0, j; |
| 472 | const struct lys_module *mod; |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 473 | struct lyd_node *cont; |
Michal Vasko | 89563fc | 2016-07-28 16:19:35 +0200 | [diff] [blame] | 474 | const char *ptr; |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 475 | |
Michal Vasko | 89563fc | 2016-07-28 16:19:35 +0200 | [diff] [blame] | 476 | if (cur_mod->deviated) { |
| 477 | while ((mod = ly_ctx_get_module_iter(cur_mod->ctx, &i))) { |
| 478 | if (mod == cur_mod) { |
| 479 | continue; |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 480 | } |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 481 | |
Michal Vasko | 89563fc | 2016-07-28 16:19:35 +0200 | [diff] [blame] | 482 | for (j = 0; j < mod->deviation_size; ++j) { |
| 483 | ptr = strstr(mod->deviation[j].target_name, cur_mod->name); |
| 484 | if (ptr && ptr[strlen(cur_mod->name)] == ':') { |
| 485 | cont = lyd_new(parent, NULL, "deviation"); |
| 486 | if (!cont) { |
| 487 | return EXIT_FAILURE; |
| 488 | } |
| 489 | |
| 490 | if (!lyd_new_leaf(cont, NULL, "name", mod->name)) { |
| 491 | return EXIT_FAILURE; |
| 492 | } |
| 493 | if (!lyd_new_leaf(cont, NULL, "revision", (mod->rev_size ? mod->rev[0].date : ""))) { |
| 494 | return EXIT_FAILURE; |
| 495 | } |
Michal Vasko | 0c2215b | 2016-08-25 14:18:43 +0200 | [diff] [blame] | 496 | |
| 497 | break; |
Michal Vasko | 89563fc | 2016-07-28 16:19:35 +0200 | [diff] [blame] | 498 | } |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | return EXIT_SUCCESS; |
| 504 | } |
| 505 | |
| 506 | static int |
| 507 | ylib_submodules(struct lyd_node *parent, struct lys_module *cur_mod) |
| 508 | { |
| 509 | int i; |
Radek Krejci | a77904e | 2016-02-25 16:23:45 +0100 | [diff] [blame] | 510 | char *str; |
Radek Krejci | d972391 | 2016-09-16 17:06:06 +0200 | [diff] [blame^] | 511 | struct lyd_node *item; |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 512 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 513 | for (i = 0; i < cur_mod->inc_size && cur_mod->inc[i].submodule; ++i) { |
Radek Krejci | d972391 | 2016-09-16 17:06:06 +0200 | [diff] [blame^] | 514 | item = lyd_new(parent, NULL, "submodule"); |
Radek Krejci | 6e05cea | 2015-12-10 16:34:37 +0100 | [diff] [blame] | 515 | if (!item) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 516 | return EXIT_FAILURE; |
| 517 | } |
| 518 | |
Radek Krejci | 6e05cea | 2015-12-10 16:34:37 +0100 | [diff] [blame] | 519 | if (!lyd_new_leaf(item, NULL, "name", cur_mod->inc[i].submodule->name)) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 520 | return EXIT_FAILURE; |
| 521 | } |
Radek Krejci | 6e05cea | 2015-12-10 16:34:37 +0100 | [diff] [blame] | 522 | if (!lyd_new_leaf(item, NULL, "revision", (cur_mod->inc[i].submodule->rev_size ? |
Michal Vasko | 3e671b5 | 2015-10-23 16:23:15 +0200 | [diff] [blame] | 523 | cur_mod->inc[i].submodule->rev[0].date : ""))) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 524 | return EXIT_FAILURE; |
| 525 | } |
Radek Krejci | a77904e | 2016-02-25 16:23:45 +0100 | [diff] [blame] | 526 | if (cur_mod->inc[i].submodule->filepath) { |
Radek Krejci | 95aa201 | 2016-03-03 11:21:09 +0100 | [diff] [blame] | 527 | if (asprintf(&str, "file://%s", cur_mod->inc[i].submodule->filepath) == -1) { |
Radek Krejci | a77904e | 2016-02-25 16:23:45 +0100 | [diff] [blame] | 528 | LOGMEM; |
| 529 | return EXIT_FAILURE; |
Radek Krejci | 6e65af9 | 2016-03-07 12:48:19 +0100 | [diff] [blame] | 530 | } else if (!lyd_new_leaf(item, NULL, "schema", str)) { |
Radek Krejci | 19f9ede | 2016-02-25 16:29:21 +0100 | [diff] [blame] | 531 | free(str); |
Radek Krejci | a77904e | 2016-02-25 16:23:45 +0100 | [diff] [blame] | 532 | return EXIT_FAILURE; |
| 533 | } |
Radek Krejci | 19f9ede | 2016-02-25 16:29:21 +0100 | [diff] [blame] | 534 | free(str); |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
| 538 | return EXIT_SUCCESS; |
| 539 | } |
| 540 | |
| 541 | API struct lyd_node * |
| 542 | ly_ctx_info(struct ly_ctx *ctx) |
| 543 | { |
| 544 | int i; |
| 545 | char id[8]; |
Radek Krejci | a77904e | 2016-02-25 16:23:45 +0100 | [diff] [blame] | 546 | char *str; |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 547 | const struct lys_module *mod; |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 548 | struct lyd_node *root, *cont; |
| 549 | |
Michal Vasko | 7eccc6c | 2016-03-24 14:56:33 +0100 | [diff] [blame] | 550 | if (!ctx) { |
| 551 | ly_errno = LY_EINVAL; |
| 552 | return NULL; |
| 553 | } |
| 554 | |
Radek Krejci | bd9e8d2 | 2016-02-03 14:11:48 +0100 | [diff] [blame] | 555 | mod = ly_ctx_get_module(ctx, "ietf-yang-library", IETF_YANG_LIB_REV); |
| 556 | if (!mod || !mod->data) { |
| 557 | LOGINT; |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 558 | return NULL; |
| 559 | } |
| 560 | |
Radek Krejci | bd9e8d2 | 2016-02-03 14:11:48 +0100 | [diff] [blame] | 561 | root = lyd_new(NULL, mod, "modules-state"); |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 562 | if (!root) { |
| 563 | return NULL; |
| 564 | } |
| 565 | |
| 566 | for (i = 0; i < ctx->models.used; ++i) { |
| 567 | cont = lyd_new(root, NULL, "module"); |
| 568 | if (!cont) { |
| 569 | lyd_free(root); |
| 570 | return NULL; |
| 571 | } |
| 572 | |
Michal Vasko | 3e671b5 | 2015-10-23 16:23:15 +0200 | [diff] [blame] | 573 | if (!lyd_new_leaf(cont, NULL, "name", ctx->models.list[i]->name)) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 574 | lyd_free(root); |
| 575 | return NULL; |
| 576 | } |
Michal Vasko | 3e671b5 | 2015-10-23 16:23:15 +0200 | [diff] [blame] | 577 | if (!lyd_new_leaf(cont, NULL, "revision", (ctx->models.list[i]->rev_size ? |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 578 | ctx->models.list[i]->rev[0].date : ""))) { |
| 579 | lyd_free(root); |
| 580 | return NULL; |
| 581 | } |
Radek Krejci | a77904e | 2016-02-25 16:23:45 +0100 | [diff] [blame] | 582 | if (ctx->models.list[i]->filepath) { |
Radek Krejci | 15412ca | 2016-03-03 11:16:52 +0100 | [diff] [blame] | 583 | if (asprintf(&str, "file://%s", ctx->models.list[i]->filepath) == -1) { |
Radek Krejci | a77904e | 2016-02-25 16:23:45 +0100 | [diff] [blame] | 584 | LOGMEM; |
| 585 | lyd_free(root); |
| 586 | return NULL; |
| 587 | } else if (!lyd_new_leaf(cont, NULL, "schema", str)) { |
Radek Krejci | 19f9ede | 2016-02-25 16:29:21 +0100 | [diff] [blame] | 588 | free(str); |
Radek Krejci | a77904e | 2016-02-25 16:23:45 +0100 | [diff] [blame] | 589 | lyd_free(root); |
| 590 | return NULL; |
| 591 | } |
Radek Krejci | 19f9ede | 2016-02-25 16:29:21 +0100 | [diff] [blame] | 592 | free(str); |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 593 | } |
Michal Vasko | 3e671b5 | 2015-10-23 16:23:15 +0200 | [diff] [blame] | 594 | if (!lyd_new_leaf(cont, NULL, "namespace", ctx->models.list[i]->ns)) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 595 | lyd_free(root); |
| 596 | return NULL; |
| 597 | } |
| 598 | if (ylib_feature(cont, ctx->models.list[i])) { |
| 599 | lyd_free(root); |
| 600 | return NULL; |
| 601 | } |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 602 | if (ylib_deviation(cont, ctx->models.list[i])) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 603 | lyd_free(root); |
| 604 | return NULL; |
| 605 | } |
| 606 | if (ctx->models.list[i]->implemented |
Radek Krejci | bd9e8d2 | 2016-02-03 14:11:48 +0100 | [diff] [blame] | 607 | && !lyd_new_leaf(cont, NULL, "conformance-type", "implement")) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 608 | lyd_free(root); |
| 609 | return NULL; |
| 610 | } |
| 611 | if (!ctx->models.list[i]->implemented |
Radek Krejci | bd9e8d2 | 2016-02-03 14:11:48 +0100 | [diff] [blame] | 612 | && !lyd_new_leaf(cont, NULL, "conformance-type", "import")) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 613 | lyd_free(root); |
| 614 | return NULL; |
| 615 | } |
| 616 | if (ylib_submodules(cont, ctx->models.list[i])) { |
| 617 | lyd_free(root); |
| 618 | return NULL; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | sprintf(id, "%u", ctx->models.module_set_id); |
Michal Vasko | 3e671b5 | 2015-10-23 16:23:15 +0200 | [diff] [blame] | 623 | if (!lyd_new_leaf(root, mod, "module-set-id", id)) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 624 | lyd_free(root); |
| 625 | return NULL; |
| 626 | } |
| 627 | |
Michal Vasko | cdb9017 | 2016-09-13 09:34:36 +0200 | [diff] [blame] | 628 | if (lyd_validate(&root, LYD_OPT_NOSIBLINGS, NULL)) { |
Michal Vasko | 209a622 | 2015-10-16 09:51:07 +0200 | [diff] [blame] | 629 | lyd_free(root); |
| 630 | return NULL; |
| 631 | } |
| 632 | |
| 633 | return root; |
| 634 | } |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 635 | |
| 636 | API const struct lys_node * |
Michal Vasko | 3547c53 | 2016-03-14 09:40:50 +0100 | [diff] [blame] | 637 | ly_ctx_get_node(struct ly_ctx *ctx, const struct lys_node *start, const char *nodeid) |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 638 | { |
Michal Vasko | e733d68 | 2016-03-14 09:08:27 +0100 | [diff] [blame] | 639 | const struct lys_node *node; |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 640 | |
Michal Vasko | 3547c53 | 2016-03-14 09:40:50 +0100 | [diff] [blame] | 641 | if (!ctx || !nodeid || ((nodeid[0] != '/') && !start)) { |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 642 | ly_errno = LY_EINVAL; |
| 643 | return NULL; |
| 644 | } |
| 645 | |
Michal Vasko | e733d68 | 2016-03-14 09:08:27 +0100 | [diff] [blame] | 646 | /* sets error and everything */ |
Michal Vasko | 8d26e5c | 2016-09-08 10:03:49 +0200 | [diff] [blame] | 647 | node = resolve_json_nodeid(nodeid, ctx, start); |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 648 | |
Michal Vasko | e733d68 | 2016-03-14 09:08:27 +0100 | [diff] [blame] | 649 | return node; |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 650 | } |