blob: 20fcb0f3a90143df9a9f0978d4d83efb96de7237 [file] [log] [blame]
Michal Vasko1324b6c2018-09-07 11:16:23 +02001/**
2 * @file common.c
3 * @author Michal Vasko <mvasko@cesnet.cz>
4 * @brief common internal definitions for libyang
5 *
6 * Copyright (c) 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 Krejcib7db73a2018-10-24 14:18:40 +020014
15#include "common.h"
Michal Vasko1324b6c2018-09-07 11:16:23 +020016
Radek Krejci86d106e2018-10-18 09:53:19 +020017#include <assert.h>
18#include <errno.h>
Michal Vasko1324b6c2018-09-07 11:16:23 +020019#include <stdlib.h>
Michal Vasko841d1a92018-09-07 15:40:31 +020020#include <ctype.h>
21#include <string.h>
Radek Krejci86d106e2018-10-18 09:53:19 +020022#include <sys/mman.h>
23#include <sys/stat.h>
Radek Krejci86d106e2018-10-18 09:53:19 +020024#include <unistd.h>
Michal Vasko841d1a92018-09-07 15:40:31 +020025
Radek Krejcie7b95092019-05-15 11:03:07 +020026#include "extensions.h"
Michal Vasko841d1a92018-09-07 15:40:31 +020027#include "tree_schema.h"
Radek Krejcib4a4a272019-06-10 12:44:52 +020028#include "tree_schema_internal.h"
Michal Vasko1324b6c2018-09-07 11:16:23 +020029
Radek Krejcic59bc972018-09-17 16:13:06 +020030const char *const ly_stmt_list[] = {
31 [YANG_ACTION] = "action",
32 [YANG_ANYDATA] = "anydata",
33 [YANG_ANYXML] = "anyxml",
34 [YANG_ARGUMENT] = "argument",
35 [YANG_AUGMENT] = "augment",
36 [YANG_BASE] = "base",
37 [YANG_BELONGS_TO] = "belongs-to",
38 [YANG_BIT] = "bit",
39 [YANG_CASE] = "case",
40 [YANG_CHOICE] = "choice",
41 [YANG_CONFIG] = "config",
42 [YANG_CONTACT] = "contact",
43 [YANG_CONTAINER] = "container",
44 [YANG_CUSTOM] = "<extension-instance>",
45 [YANG_DEFAULT] = "default",
46 [YANG_DESCRIPTION] = "description",
47 [YANG_DEVIATE] = "deviate",
48 [YANG_DEVIATION] = "deviation",
49 [YANG_ENUM] = "enum",
50 [YANG_ERROR_APP_TAG] = "error-app-tag",
51 [YANG_ERROR_MESSAGE] = "error-message",
52 [YANG_EXTENSION] = "extension",
53 [YANG_FEATURE] = "feature",
54 [YANG_FRACTION_DIGITS] = "fraction-digits",
55 [YANG_GROUPING] = "grouping",
56 [YANG_IDENTITY] = "identitiy",
57 [YANG_IF_FEATURE] = "if-feature",
58 [YANG_IMPORT] = "import",
59 [YANG_INCLUDE] = "include",
60 [YANG_INPUT] = "input",
61 [YANG_KEY] = "key",
62 [YANG_LEAF] = "leaf",
63 [YANG_LEAF_LIST] = "leaf-list",
64 [YANG_LENGTH] = "length",
65 [YANG_LIST] = "list",
66 [YANG_MANDATORY] = "mandatory",
67 [YANG_MAX_ELEMENTS] = "max-elements",
68 [YANG_MIN_ELEMENTS] = "min-elements",
69 [YANG_MODIFIER] = "modifier",
70 [YANG_MODULE] = "module",
71 [YANG_MUST] = "must",
72 [YANG_NAMESPACE] = "namespace",
73 [YANG_NOTIFICATION] = "notification",
74 [YANG_ORDERED_BY] = "ordered-by",
75 [YANG_ORGANIZATION] = "organization",
76 [YANG_OUTPUT] = "output",
77 [YANG_PATH] = "path",
78 [YANG_PATTERN] = "pattern",
79 [YANG_POSITION] = "position",
80 [YANG_PREFIX] = "prefix",
81 [YANG_PRESENCE] = "presence",
82 [YANG_RANGE] = "range",
83 [YANG_REFERENCE] = "reference",
84 [YANG_REFINE] = "refine",
85 [YANG_REQUIRE_INSTANCE] = "require-instance",
86 [YANG_REVISION] = "revision",
87 [YANG_REVISION_DATE] = "revision-date",
88 [YANG_RPC] = "rpc",
89 [YANG_STATUS] = "status",
90 [YANG_SUBMODULE] = "submodule",
91 [YANG_TYPE] = "type",
92 [YANG_TYPEDEF] = "typedef",
93 [YANG_UNIQUE] = "unique",
94 [YANG_UNITS] = "units",
95 [YANG_USES] = "uses",
96 [YANG_VALUE] = "value",
97 [YANG_WHEN] = "when",
98 [YANG_YANG_VERSION] = "yang-version",
99 [YANG_YIN_ELEMENT] = "yin-element",
100 [YANG_SEMICOLON] = ";",
101 [YANG_LEFT_BRACE] = "{",
102 [YANG_RIGHT_BRACE] = "}",
David Sedlák21f87cd2019-07-03 16:53:23 +0200103 [YIN_TEXT] = "text",
104 [YIN_VALUE] = "value",
Radek Krejcic59bc972018-09-17 16:13:06 +0200105};
106
107const char *const lyext_substmt_list[] = {
108 [LYEXT_SUBSTMT_ARGUMENT] = "argument",
109 [LYEXT_SUBSTMT_BASE] = "base",
110 [LYEXT_SUBSTMT_BELONGSTO] = "belongs-to",
111 [LYEXT_SUBSTMT_CONTACT] = "contact",
112 [LYEXT_SUBSTMT_DEFAULT] = "default",
113 [LYEXT_SUBSTMT_DESCRIPTION] = "description",
114 [LYEXT_SUBSTMT_ERRTAG] = "error-app-tag",
115 [LYEXT_SUBSTMT_ERRMSG] = "error-message",
116 [LYEXT_SUBSTMT_KEY] = "key",
117 [LYEXT_SUBSTMT_NAMESPACE] = "namespace",
118 [LYEXT_SUBSTMT_ORGANIZATION] = "organization",
119 [LYEXT_SUBSTMT_PATH] = "path",
120 [LYEXT_SUBSTMT_PREFIX] = "prefix",
121 [LYEXT_SUBSTMT_PRESENCE] = "presence",
122 [LYEXT_SUBSTMT_REFERENCE] = "reference",
123 [LYEXT_SUBSTMT_REVISIONDATE] = "revision-date",
124 [LYEXT_SUBSTMT_UNITS] = "units",
125 [LYEXT_SUBSTMT_VALUE] = "value",
126 [LYEXT_SUBSTMT_VERSION] = "yang-version",
127 [LYEXT_SUBSTMT_MODIFIER] = "modifier",
128 [LYEXT_SUBSTMT_REQINSTANCE] = "require-instance",
129 [LYEXT_SUBSTMT_YINELEM] = "yin-element",
130 [LYEXT_SUBSTMT_CONFIG] = "config",
131 [LYEXT_SUBSTMT_MANDATORY] = "mandatory",
132 [LYEXT_SUBSTMT_ORDEREDBY] = "ordered-by",
133 [LYEXT_SUBSTMT_STATUS] = "status",
134 [LYEXT_SUBSTMT_FRACDIGITS] = "fraction-digits",
135 [LYEXT_SUBSTMT_MAX] = "max-elements",
136 [LYEXT_SUBSTMT_MIN] = "min-elements",
137 [LYEXT_SUBSTMT_POSITION] = "position",
138 [LYEXT_SUBSTMT_UNIQUE] = "unique",
139 [LYEXT_SUBSTMT_IFFEATURE] = "if-feature",
140};
141
142const char *const ly_devmod_list[] = {
143 [LYS_DEV_NOT_SUPPORTED] = "not-supported",
144 [LYS_DEV_ADD] = "add",
145 [LYS_DEV_DELETE] = "delete",
146 [LYS_DEV_REPLACE] = "replace",
147};
148
Michal Vasko1324b6c2018-09-07 11:16:23 +0200149void *
150ly_realloc(void *ptr, size_t size)
151{
152 void *new_mem;
153
154 new_mem = realloc(ptr, size);
155 if (!new_mem) {
156 free(ptr);
157 }
158
159 return new_mem;
160}
Michal Vasko841d1a92018-09-07 15:40:31 +0200161
Radek Krejcib416be62018-10-01 14:51:45 +0200162LY_ERR
163ly_getutf8(const char **input, unsigned int *utf8_char, size_t *bytes_read)
164{
165 unsigned int c, len;
166 int aux;
167 int i;
168
Radek Krejcicc6a45c2019-05-13 10:16:14 +0200169 if (bytes_read) {
170 (*bytes_read) = 0;
171 }
172
Radek Krejcib416be62018-10-01 14:51:45 +0200173 c = (*input)[0];
174 LY_CHECK_RET(!c, LY_EINVAL);
175
176 if (!(c & 0x80)) {
177 /* one byte character */
178 len = 1;
179
180 if (c < 0x20 && c != 0x9 && c != 0xa && c != 0xd) {
181 return LY_EINVAL;
182 }
183 } else if ((c & 0xe0) == 0xc0) {
184 /* two bytes character */
185 len = 2;
186
187 aux = (*input)[1];
188 if ((aux & 0xc0) != 0x80) {
189 return LY_EINVAL;
190 }
191 c = ((c & 0x1f) << 6) | (aux & 0x3f);
192
193 if (c < 0x80) {
194 return LY_EINVAL;
195 }
196 } else if ((c & 0xf0) == 0xe0) {
197 /* three bytes character */
198 len = 3;
199
200 c &= 0x0f;
201 for (i = 1; i <= 2; i++) {
202 aux = (*input)[i];
203 if ((aux & 0xc0) != 0x80) {
204 return LY_EINVAL;
205 }
206
207 c = (c << 6) | (aux & 0x3f);
208 }
209
210 if (c < 0x800 || (c > 0xd7ff && c < 0xe000) || c > 0xfffd) {
211 return LY_EINVAL;
212 }
213 } else if ((c & 0xf8) == 0xf0) {
214 /* four bytes character */
215 len = 4;
216
217 c &= 0x07;
218 for (i = 1; i <= 3; i++) {
219 aux = (*input)[i];
220 if ((aux & 0xc0) != 0x80) {
221 return LY_EINVAL;
222 }
223
224 c = (c << 6) | (aux & 0x3f);
225 }
226
227 if (c < 0x1000 || c > 0x10ffff) {
228 return LY_EINVAL;
229 }
230 } else {
231 return LY_EINVAL;
232 }
233
234 (*utf8_char) = c;
235 (*input) += len;
236 if (bytes_read) {
237 (*bytes_read) = len;
238 }
239 return LY_SUCCESS;
240}
241
Radek Krejcid972c252018-09-25 13:23:39 +0200242size_t
243LY_VCODE_INSTREXP_len(const char *str)
244{
245 size_t len = 0;
246 if (!str) {
247 return len;
248 } else if (!str[0]) {
249 return 1;
250 }
251 for (len = 1; len < LY_VCODE_INSTREXP_MAXLEN && str[len]; ++len);
252 return len;
253}
254
Radek Krejcif345c012018-09-19 11:12:59 +0200255LY_ERR
Radek Krejci86d106e2018-10-18 09:53:19 +0200256ly_mmap(struct ly_ctx *ctx, int fd, size_t *length, void **addr)
Michal Vasko841d1a92018-09-07 15:40:31 +0200257{
Radek Krejci86d106e2018-10-18 09:53:19 +0200258 struct stat sb;
259 long pagesize;
260 size_t m;
Michal Vasko841d1a92018-09-07 15:40:31 +0200261
Radek Krejci86d106e2018-10-18 09:53:19 +0200262 assert(length);
263 assert(addr);
264 assert(fd >= 0);
Michal Vasko841d1a92018-09-07 15:40:31 +0200265
Radek Krejci86d106e2018-10-18 09:53:19 +0200266 if (fstat(fd, &sb) == -1) {
267 LOGERR(ctx, LY_ESYS, "Failed to stat the file descriptor (%s) for the mmap().", strerror(errno));
268 return LY_ESYS;
Michal Vasko841d1a92018-09-07 15:40:31 +0200269 }
Radek Krejci86d106e2018-10-18 09:53:19 +0200270 if (!S_ISREG(sb.st_mode)) {
271 LOGERR(ctx, LY_EINVAL, "File to mmap() is not a regular file.");
272 return LY_ESYS;
Michal Vasko841d1a92018-09-07 15:40:31 +0200273 }
Radek Krejci86d106e2018-10-18 09:53:19 +0200274 if (!sb.st_size) {
275 *addr = NULL;
276 return LY_SUCCESS;
277 }
278 pagesize = sysconf(_SC_PAGESIZE);
279
280 m = sb.st_size % pagesize;
281 if (m && pagesize - m >= 1) {
282 /* there will be enough space (at least 1 byte) after the file content mapping to provide zeroed NULL-termination byte */
283 *length = sb.st_size + 1;
284 *addr = mmap(NULL, *length, PROT_READ, MAP_PRIVATE, fd, 0);
285 } else {
286 /* there will not be enough bytes after the file content mapping for the additional bytes and some of them
287 * would overflow into another page that would not be zerroed and any access into it would generate SIGBUS.
288 * Therefore we have to do the following hack with double mapping. First, the required number of bytes
289 * (including the additinal bytes) is required as anonymous and thus they will be really provided (actually more
290 * because of using whole pages) and also initialized by zeros. Then, the file is mapped to the same address
291 * where the anonymous mapping starts. */
292 *length = sb.st_size + pagesize;
293 *addr = mmap(NULL, *length, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
294 *addr = mmap(*addr, sb.st_size, PROT_READ, MAP_PRIVATE | MAP_FIXED, fd, 0);
295 }
296 if (*addr == MAP_FAILED) {
297 LOGERR(ctx, LY_ESYS, "mmap() failed (%s).", strerror(errno));
298 return LY_ESYS;
Michal Vasko841d1a92018-09-07 15:40:31 +0200299 }
300
Radek Krejcif345c012018-09-19 11:12:59 +0200301 return LY_SUCCESS;
Radek Krejci86d106e2018-10-18 09:53:19 +0200302}
Michal Vasko841d1a92018-09-07 15:40:31 +0200303
Radek Krejci86d106e2018-10-18 09:53:19 +0200304LY_ERR
305ly_munmap(void *addr, size_t length)
306{
307 if (munmap(addr, length)) {
308 return LY_ESYS;
309 }
310 return LY_SUCCESS;
Michal Vasko841d1a92018-09-07 15:40:31 +0200311}
Radek Krejci4f28eda2018-11-12 11:46:16 +0100312
313LY_ERR
Radek Krejci249973a2019-06-10 10:50:54 +0200314ly_parse_int(const char *val_str, size_t val_len, int64_t min, int64_t max, int base, int64_t *ret)
Radek Krejci4f28eda2018-11-12 11:46:16 +0100315{
316 char *strptr;
Radek Krejci9ea8ca12019-06-10 13:11:55 +0200317 int64_t i;
Radek Krejci4f28eda2018-11-12 11:46:16 +0100318
Radek Krejci249973a2019-06-10 10:50:54 +0200319 LY_CHECK_ARG_RET(NULL, val_str, val_str[0], val_len, LY_EINVAL);
Radek Krejci4f28eda2018-11-12 11:46:16 +0100320
321 /* convert to 64-bit integer, all the redundant characters are handled */
322 errno = 0;
323 strptr = NULL;
324
325 /* parse the value */
Radek Krejci9ea8ca12019-06-10 13:11:55 +0200326 i = strtoll(val_str, &strptr, base);
Radek Krejci249973a2019-06-10 10:50:54 +0200327 if (errno || strptr == val_str) {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100328 return LY_EVALID;
Radek Krejci9ea8ca12019-06-10 13:11:55 +0200329 } else if ((i < min) || (i > max)) {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100330 return LY_EDENIED;
331 } else if (strptr && *strptr) {
332 while (isspace(*strptr)) {
333 ++strptr;
334 }
Radek Krejci249973a2019-06-10 10:50:54 +0200335 if (*strptr && strptr < val_str + val_len) {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100336 return LY_EVALID;
337 }
338 }
Radek Krejci9ea8ca12019-06-10 13:11:55 +0200339
340 *ret = i;
Radek Krejci4f28eda2018-11-12 11:46:16 +0100341 return LY_SUCCESS;
342}
343
344LY_ERR
Radek Krejci249973a2019-06-10 10:50:54 +0200345ly_parse_uint(const char *val_str, size_t val_len, uint64_t max, int base, uint64_t *ret)
Radek Krejci4f28eda2018-11-12 11:46:16 +0100346{
347 char *strptr;
348 uint64_t u;
349
350 LY_CHECK_ARG_RET(NULL, val_str, val_str[0], LY_EINVAL);
351
352 errno = 0;
353 strptr = NULL;
354 u = strtoull(val_str, &strptr, base);
Radek Krejci249973a2019-06-10 10:50:54 +0200355 if (errno || strptr == val_str) {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100356 return LY_EVALID;
357 } else if ((u > max) || (u && val_str[0] == '-')) {
358 return LY_EDENIED;
359 } else if (strptr && *strptr) {
360 while (isspace(*strptr)) {
361 ++strptr;
362 }
Radek Krejci249973a2019-06-10 10:50:54 +0200363 if (*strptr && strptr < val_str + val_len) {
Radek Krejci4f28eda2018-11-12 11:46:16 +0100364 return LY_EVALID;
365 }
366 }
367
368 *ret = u;
369 return LY_SUCCESS;
370}
Radek Krejcib4a4a272019-06-10 12:44:52 +0200371
372/**
373 * @brief Parse an identifier.
374 *
375 * ;; An identifier MUST NOT start with (('X'|'x') ('M'|'m') ('L'|'l'))
376 * identifier = (ALPHA / "_")
377 * *(ALPHA / DIGIT / "_" / "-" / ".")
378 *
379 * @param[in,out] id Identifier to parse. When returned, it points to the first character which is not part of the identifier.
380 * @return LY_ERR value: LY_SUCCESS or LY_EINVAL in case of invalid starting character.
381 */
382static LY_ERR
383lys_parse_id(const char **id)
384{
385 assert(id && *id);
386
387 if (!is_yangidentstartchar(**id)) {
388 return LY_EINVAL;
389 }
390 ++(*id);
391
392 while (is_yangidentchar(**id)) {
393 ++(*id);
394 }
395 return LY_SUCCESS;
396}
397
398LY_ERR
399ly_parse_nodeid(const char **id, const char **prefix, size_t *prefix_len, const char **name, size_t *name_len)
400{
401 assert(id && *id);
402 assert(prefix && prefix_len);
403 assert(name && name_len);
404
405 *prefix = *id;
406 *prefix_len = 0;
407 *name = NULL;
408 *name_len = 0;
409
410 LY_CHECK_RET(lys_parse_id(id));
411 if (**id == ':') {
412 /* there is prefix */
413 *prefix_len = *id - *prefix;
414 ++(*id);
415 *name = *id;
416
417 LY_CHECK_RET(lys_parse_id(id));
418 *name_len = *id - *name;
419 } else {
420 /* there is no prefix, so what we have as prefix now is actually the name */
421 *name = *prefix;
422 *name_len = *id - *name;
423 *prefix = NULL;
424 }
425
426 return LY_SUCCESS;
427}
428
429LY_ERR
430ly_parse_instance_predicate(const char **pred, size_t limit,
431 const char **prefix, size_t *prefix_len, const char **id, size_t *id_len, const char **value, size_t *value_len,
432 const char **errmsg)
433{
434 LY_ERR ret = LY_EVALID;
435 const char *in = *pred;
436 size_t offset = 1;
437 int expr = 0;
438 char quot;
439
440 assert(in[0] == '\[');
441
442 *prefix = *id = *value = NULL;
443 *prefix_len = *id_len = *value_len = 0;
444
445 /* leading *WSP */
446 for (; isspace(in[offset]); offset++);
447
448 if (isdigit(in[offset])) {
449 /* pos: "[" *WSP positive-integer-value *WSP "]" */
450 if (in[offset] == '0') {
451 /* zero */
452 *errmsg = "The position predicate cannot be zero.";
453 goto error;
454 }
455
456 /* positive-integer-value */
Radek Krejci10bfdf82019-06-10 14:08:13 +0200457 *value = &in[offset++];
Radek Krejcib4a4a272019-06-10 12:44:52 +0200458 for (; isdigit(in[offset]); offset++);
Radek Krejci10bfdf82019-06-10 14:08:13 +0200459 *value_len = &in[offset] - *value;
Radek Krejcib4a4a272019-06-10 12:44:52 +0200460
461 } else if (in[offset] == '.') {
462 /* leaf-list-predicate: "[" *WSP "." *WSP "=" *WSP quoted-string *WSP "]" */
463 *id = &in[offset];
464 *id_len = 1;
465 offset++;
466 expr = 1;
Radek Krejci10bfdf82019-06-10 14:08:13 +0200467 } else if (in[offset] == '-') {
468 /* typically negative value */
469 *errmsg = "Invalid instance predicate format (negative position or invalid node-identifier).";
470 goto error;
Radek Krejcib4a4a272019-06-10 12:44:52 +0200471 } else {
472 /* key-predicate: "[" *WSP node-identifier *WSP "=" *WSP quoted-string *WSP "]" */
473 in = &in[offset];
474 if (ly_parse_nodeid(&in, prefix, prefix_len, id, id_len)) {
475 *errmsg = "Invalid node-identifier.";
476 goto error;
477 }
478 offset = in - *pred;
479 in = *pred;
Radek Krejci10bfdf82019-06-10 14:08:13 +0200480 expr = 2;
Radek Krejcib4a4a272019-06-10 12:44:52 +0200481 }
482
483 if (expr) {
484 /* *WSP "=" *WSP quoted-string *WSP "]" */
485 for (; isspace(in[offset]); offset++);
486
487 if (in[offset] != '=') {
Radek Krejci10bfdf82019-06-10 14:08:13 +0200488 if (expr == 1) {
489 *errmsg = "Unexpected character instead of \'=\' in leaf-list-predicate.";
490 } else { /* 2 */
491 *errmsg = "Unexpected character instead of \'=\' in key-predicate.";
492 }
Radek Krejcib4a4a272019-06-10 12:44:52 +0200493 goto error;
494 }
495 offset++;
496 for (; isspace(in[offset]); offset++);
497
498 /* quoted-string */
499 quot = in[offset++];
500 if (quot != '\'' && quot != '\"') {
501 *errmsg = "String value is not quoted.";
502 goto error;
503 }
504 *value = &in[offset];
505 for (;offset < limit && in[offset] != quot; offset++);
Radek Krejci10bfdf82019-06-10 14:08:13 +0200506 if (in[offset] == quot) {
507 *value_len = &in[offset] - *value;
508 offset++;
509 } else {
510 *errmsg = "Value is not terminated quoted-string.";
511 goto error;
512 }
Radek Krejcib4a4a272019-06-10 12:44:52 +0200513 }
514
515 /* *WSP "]" */
516 for(; isspace(in[offset]); offset++);
517 if (in[offset] != ']') {
Radek Krejci10bfdf82019-06-10 14:08:13 +0200518 if (expr == 0) {
519 *errmsg = "Predicate (pos) is not terminated by \']\' character.";
520 } else if (expr == 1) {
521 *errmsg = "Predicate (leaf-list-predicate) is not terminated by \']\' character.";
522 } else { /* 2 */
523 *errmsg = "Predicate (key-predicate) is not terminated by \']\' character.";
524 }
Radek Krejcib4a4a272019-06-10 12:44:52 +0200525 goto error;
526 }
Radek Krejci10bfdf82019-06-10 14:08:13 +0200527 offset++;
Radek Krejcib4a4a272019-06-10 12:44:52 +0200528
Radek Krejci10bfdf82019-06-10 14:08:13 +0200529 if (offset <= limit) {
530 *pred = &in[offset];
Radek Krejcib4a4a272019-06-10 12:44:52 +0200531 return LY_SUCCESS;
532 }
533
534 /* we read after the limit */
535 *errmsg = "Predicate is incomplete.";
536 *prefix = *id = *value = NULL;
537 *prefix_len = *id_len = *value_len = 0;
538 offset = limit;
539 ret = LY_EINVAL;
540
541error:
542 *pred = &in[offset];
543 return ret;
544}