libyang 6.4.3
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
Loading...
Searching...
No Matches
integer.c
Go to the documentation of this file.
1
16#define _GNU_SOURCE /* asprintf, strdup */
17
18#include "plugins_types.h"
19
20#include <assert.h>
21#include <inttypes.h>
22#include <stdio.h>
23#include <stdlib.h>
24
25#include "compat.h"
26#include "dict.h"
27#include "ly_common.h"
28#include "plugins_internal.h"
29#include "tree_schema_internal.h"
30
40static LY_ERR lyplg_type_validate_value_int(const struct ly_ctx *ctx, const struct lysc_type *type,
41 struct lyd_value *storage, struct ly_err_item **err);
42static LY_ERR lyplg_type_validate_value_uint(const struct ly_ctx *ctx, const struct lysc_type *type,
43 struct lyd_value *storage, struct ly_err_item **err);
44
45static LY_ERR
46lyplg_type_store_int(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint64_t value_size_bits,
47 uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints,
48 const struct lysc_node *UNUSED(ctx_node), struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres),
49 struct ly_err_item **err)
50{
51 LY_ERR ret = LY_SUCCESS;
52 uint32_t value_size;
53 int64_t num = 0;
54 int base = 1;
55 char *canon = NULL;
56
57 /* init storage */
58 memset(storage, 0, sizeof *storage);
59 storage->realtype = type;
60
61 /* check value length */
62 ret = lyplg_type_check_value_size(lys_datatype2str(type->basetype), format, value_size_bits,
63 LYPLG_LYB_SIZE_VARIABLE_BITS, 0, &value_size, err);
64 LY_CHECK_GOTO(ret, cleanup);
65
66 if (format == LY_VALUE_LYB) {
67 /* copy the integer and correct the byte order */
68 if (value_size > sizeof num) {
69 ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid %s LYB value size %u B (max %zu B).",
70 lys_datatype2str(type->basetype), value_size, sizeof num);
71 LY_CHECK_GOTO(ret, cleanup);
72 }
73 memcpy(&num, value, value_size);
74 num = le64toh(num);
75 } else {
76 /* check hints */
77 ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, &base, err);
78 LY_CHECK_GOTO(ret, cleanup);
79
80 /* parse the integer */
81 switch (type->basetype) {
82 case LY_TYPE_INT8:
83 ret = lyplg_type_parse_int("int8", base, INT64_C(-128), INT64_C(127), value, value_size, &num, err);
84 break;
85 case LY_TYPE_INT16:
86 ret = lyplg_type_parse_int("int16", base, INT64_C(-32768), INT64_C(32767), value, value_size, &num, err);
87 break;
88 case LY_TYPE_INT32:
89 ret = lyplg_type_parse_int("int32", base, INT64_C(-2147483648), INT64_C(2147483647), value, value_size, &num, err);
90 break;
91 case LY_TYPE_INT64:
92 ret = lyplg_type_parse_int("int64", base, INT64_C(-9223372036854775807) - INT64_C(1),
93 INT64_C(9223372036854775807), value, value_size, &num, err);
94 break;
95 default:
96 LOGINT(ctx);
97 ret = LY_EINT;
98 }
99 LY_CHECK_GOTO(ret, cleanup);
100 }
101
102 /* set the value (matters for big-endian) and get the correct int64 number */
103 switch (type->basetype) {
104 case LY_TYPE_INT8:
105 storage->int8 = num;
106 num = storage->int8;
107 break;
108 case LY_TYPE_INT16:
109 storage->int16 = num;
110 num = storage->int16;
111 break;
112 case LY_TYPE_INT32:
113 storage->int32 = num;
114 num = storage->int32;
115 break;
116 case LY_TYPE_INT64:
117 storage->int64 = num;
118 num = storage->int64;
119 break;
120 default:
121 break;
122 }
123
124 if (format == LY_VALUE_CANON) {
125 /* store canonical value */
126 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
127 ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
128 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
129 LY_CHECK_GOTO(ret, cleanup);
130 } else {
131 ret = lydict_insert(ctx, value, value_size, &storage->_canonical);
132 LY_CHECK_GOTO(ret, cleanup);
133 }
134 } else {
135 /* generate canonical value */
136 switch (type->basetype) {
137 case LY_TYPE_INT8:
138 LY_CHECK_ERR_GOTO(asprintf(&canon, "%" PRId8, storage->int8) == -1, ret = LY_EMEM, cleanup);
139 break;
140 case LY_TYPE_INT16:
141 LY_CHECK_ERR_GOTO(asprintf(&canon, "%" PRId16, storage->int16) == -1, ret = LY_EMEM, cleanup);
142 break;
143 case LY_TYPE_INT32:
144 LY_CHECK_ERR_GOTO(asprintf(&canon, "%" PRId32, storage->int32) == -1, ret = LY_EMEM, cleanup);
145 break;
146 case LY_TYPE_INT64:
147 LY_CHECK_ERR_GOTO(asprintf(&canon, "%" PRId64, storage->int64) == -1, ret = LY_EMEM, cleanup);
148 break;
149 default:
150 break;
151 }
152
153 /* store it */
154 ret = lydict_insert_zc(ctx, canon, (const char **)&storage->_canonical);
155 LY_CHECK_GOTO(ret, cleanup);
156 }
157
158 if (!(options & LYPLG_TYPE_STORE_ONLY)) {
159 /* validate value */
160 ret = lyplg_type_validate_value_int(ctx, type, storage, err);
161 LY_CHECK_GOTO(ret, cleanup);
162 }
163
164cleanup:
165 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
166 free((void *)value);
167 }
168
169 if (ret) {
170 lyplg_type_free_simple(ctx, storage);
171 }
172 return ret;
173}
174
178static LY_ERR
179lyplg_type_validate_value_int(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, struct lyd_value *storage,
180 struct ly_err_item **err)
181{
182 LY_ERR ret;
183 struct lysc_type_num *type_num = (struct lysc_type_num *)type;
184 int64_t num;
185
186 LY_CHECK_ARG_RET(NULL, type, storage, err, LY_EINVAL);
187 *err = NULL;
188
189 /* set the value (matters for big-endian) and get the correct int64 number */
190 switch (type->basetype) {
191 case LY_TYPE_INT8:
192 num = storage->int8;
193 break;
194 case LY_TYPE_INT16:
195 num = storage->int16;
196 break;
197 case LY_TYPE_INT32:
198 num = storage->int32;
199 break;
200 case LY_TYPE_INT64:
201 num = storage->int64;
202 break;
203 default:
204 return LY_EINVAL;
205 }
206
207 /* validate range of the number */
208 if (type_num->range) {
209 ret = lyplg_type_validate_range(type->basetype, type_num->range, num, storage->_canonical,
210 strlen(storage->_canonical), err);
211 LY_CHECK_RET(ret);
212 }
213
214 return LY_SUCCESS;
215}
216
217static LY_ERR
218lyplg_type_compare_int(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
219{
220 if (val1->realtype != val2->realtype) {
221 return LY_ENOT;
222 }
223
224 switch (val1->realtype->basetype) {
225 case LY_TYPE_INT8:
226 if (val1->int8 != val2->int8) {
227 return LY_ENOT;
228 }
229 break;
230 case LY_TYPE_INT16:
231 if (val1->int16 != val2->int16) {
232 return LY_ENOT;
233 }
234 break;
235 case LY_TYPE_INT32:
236 if (val1->int32 != val2->int32) {
237 return LY_ENOT;
238 }
239 break;
240 case LY_TYPE_INT64:
241 if (val1->int64 != val2->int64) {
242 return LY_ENOT;
243 }
244 break;
245 default:
246 break;
247 }
248 return LY_SUCCESS;
249}
250
251static int
252lyplg_type_sort_int(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
253{
254 switch (val1->realtype->basetype) {
255 case LY_TYPE_INT8:
256 if (val1->int8 < val2->int8) {
257 return -1;
258 } else if (val1->int8 > val2->int8) {
259 return 1;
260 } else {
261 return 0;
262 }
263 break;
264 case LY_TYPE_INT16:
265 if (val1->int16 < val2->int16) {
266 return -1;
267 } else if (val1->int16 > val2->int16) {
268 return 1;
269 } else {
270 return 0;
271 }
272 break;
273 case LY_TYPE_INT32:
274 if (val1->int32 < val2->int32) {
275 return -1;
276 } else if (val1->int32 > val2->int32) {
277 return 1;
278 } else {
279 return 0;
280 }
281 break;
282 case LY_TYPE_INT64:
283 if (val1->int64 < val2->int64) {
284 return -1;
285 } else if (val1->int64 > val2->int64) {
286 return 1;
287 } else {
288 return 0;
289 }
290 break;
291 default:
292 break;
293 }
294 return 0;
295}
296
297static LY_ERR
298lyplg_type_store_uint(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint64_t value_size_bits,
299 uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints,
300 const struct lysc_node *UNUSED(ctx_node), struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres),
301 struct ly_err_item **err)
302{
303 LY_ERR ret = LY_SUCCESS;
304 uint32_t value_size;
305 uint64_t num = 0;
306 int base = 0;
307 char *canon;
308
309 /* init storage */
310 memset(storage, 0, sizeof *storage);
311 storage->realtype = type;
312
313 /* check value length */
314 ret = lyplg_type_check_value_size(lys_datatype2str(type->basetype), format, value_size_bits,
315 LYPLG_LYB_SIZE_VARIABLE_BITS, 0, &value_size, err);
316 LY_CHECK_GOTO(ret, cleanup);
317
318 if (format == LY_VALUE_LYB) {
319 /* copy the integer and correct the byte order */
320 if (value_size > sizeof num) {
321 ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid %s LYB value size %u B (max %zu B).",
322 lys_datatype2str(type->basetype), value_size, sizeof num);
323 LY_CHECK_GOTO(ret, cleanup);
324 }
325 memcpy(&num, value, value_size);
326 num = le64toh(num);
327 } else {
328 /* check hints */
329 ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, &base, err);
330 LY_CHECK_GOTO(ret, cleanup);
331
332 /* parse the integer */
333 switch (type->basetype) {
334 case LY_TYPE_UINT8:
335 ret = lyplg_type_parse_uint("uint8", base, UINT64_C(255), value, value_size, &num, err);
336 break;
337 case LY_TYPE_UINT16:
338 ret = lyplg_type_parse_uint("uint16", base, UINT64_C(65535), value, value_size, &num, err);
339 break;
340 case LY_TYPE_UINT32:
341 ret = lyplg_type_parse_uint("uint32", base, UINT64_C(4294967295), value, value_size, &num, err);
342 break;
343 case LY_TYPE_UINT64:
344 ret = lyplg_type_parse_uint("uint64", base, UINT64_C(18446744073709551615), value, value_size, &num, err);
345 break;
346 default:
347 LOGINT(ctx);
348 ret = LY_EINT;
349 }
350 LY_CHECK_GOTO(ret, cleanup);
351 }
352
353 /* store value, matters for big-endian */
354 switch (type->basetype) {
355 case LY_TYPE_UINT8:
356 storage->uint8 = num;
357 break;
358 case LY_TYPE_UINT16:
359 storage->uint16 = num;
360 break;
361 case LY_TYPE_UINT32:
362 storage->uint32 = num;
363 break;
364 case LY_TYPE_UINT64:
365 storage->uint64 = num;
366 break;
367 default:
368 break;
369 }
370
371 if (format == LY_VALUE_CANON) {
372 /* store canonical value */
373 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
374 ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
375 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
376 LY_CHECK_GOTO(ret, cleanup);
377 } else {
378 ret = lydict_insert(ctx, value, value_size, &storage->_canonical);
379 LY_CHECK_GOTO(ret, cleanup);
380 }
381 } else {
382 /* generate canonical value */
383 LY_CHECK_ERR_GOTO(asprintf(&canon, "%" PRIu64, num) == -1, ret = LY_EMEM, cleanup);
384
385 /* store it */
386 ret = lydict_insert_zc(ctx, canon, (const char **)&storage->_canonical);
387 LY_CHECK_GOTO(ret, cleanup);
388 }
389
390 if (!(options & LYPLG_TYPE_STORE_ONLY)) {
391 /* validate value */
392 ret = lyplg_type_validate_value_uint(ctx, type, storage, err);
393 LY_CHECK_GOTO(ret, cleanup);
394 }
395
396cleanup:
397 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
398 free((void *)value);
399 }
400
401 if (ret) {
402 lyplg_type_free_simple(ctx, storage);
403 }
404 return ret;
405}
406
410static LY_ERR
411lyplg_type_validate_value_uint(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, struct lyd_value *storage,
412 struct ly_err_item **err)
413{
414 LY_ERR ret;
415 struct lysc_type_num *type_num = (struct lysc_type_num *)type;
416 uint64_t num;
417
418 LY_CHECK_ARG_RET(NULL, type, storage, err, LY_EINVAL);
419 *err = NULL;
420
421 /* set the value (matters for big-endian) and get the correct int64 number */
422 switch (type->basetype) {
423 case LY_TYPE_UINT8:
424 num = storage->uint8;
425 break;
426 case LY_TYPE_UINT16:
427 num = storage->uint16;
428 break;
429 case LY_TYPE_UINT32:
430 num = storage->uint32;
431 break;
432 case LY_TYPE_UINT64:
433 num = storage->uint64;
434 break;
435 default:
436 return LY_EINVAL;
437 }
438
439 /* validate range of the number */
440 if (type_num->range) {
441 ret = lyplg_type_validate_range(type->basetype, type_num->range, num, storage->_canonical,
442 strlen(storage->_canonical), err);
443 LY_CHECK_RET(ret);
444 }
445
446 return LY_SUCCESS;
447}
448
449static LY_ERR
450lyplg_type_compare_uint(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
451{
452 switch (val1->realtype->basetype) {
453 case LY_TYPE_UINT8:
454 if (val1->uint8 != val2->uint8) {
455 return LY_ENOT;
456 }
457 break;
458 case LY_TYPE_UINT16:
459 if (val1->uint16 != val2->uint16) {
460 return LY_ENOT;
461 }
462 break;
463 case LY_TYPE_UINT32:
464 if (val1->uint32 != val2->uint32) {
465 return LY_ENOT;
466 }
467 break;
468 case LY_TYPE_UINT64:
469 if (val1->uint64 != val2->uint64) {
470 return LY_ENOT;
471 }
472 break;
473 default:
474 break;
475 }
476 return LY_SUCCESS;
477}
478
479static int
480lyplg_type_sort_uint(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
481{
482 switch (val1->realtype->basetype) {
483 case LY_TYPE_UINT8:
484 if (val1->uint8 < val2->uint8) {
485 return -1;
486 } else if (val1->uint8 > val2->uint8) {
487 return 1;
488 } else {
489 return 0;
490 }
491 break;
492 case LY_TYPE_UINT16:
493 if (val1->uint16 < val2->uint16) {
494 return -1;
495 } else if (val1->uint16 > val2->uint16) {
496 return 1;
497 } else {
498 return 0;
499 }
500 break;
501 case LY_TYPE_UINT32:
502 if (val1->uint32 < val2->uint32) {
503 return -1;
504 } else if (val1->uint32 > val2->uint32) {
505 return 1;
506 } else {
507 return 0;
508 }
509 break;
510 case LY_TYPE_UINT64:
511 if (val1->uint64 < val2->uint64) {
512 return -1;
513 } else if (val1->uint64 > val2->uint64) {
514 return 1;
515 } else {
516 return 0;
517 }
518 break;
519 default:
520 break;
521 }
522 return 0;
523}
524
525static const void *
526lyplg_type_print_u_int(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *value, LY_VALUE_FORMAT format,
527 void *UNUSED(prefix_data), ly_bool *dynamic, uint64_t *value_size_bits)
528{
529 uint64_t num = 0;
530 uint8_t bytes_used;
531 uint16_t bits_used;
532 void *buf;
533
534 if (format == LY_VALUE_LYB) {
535 switch (value->realtype->basetype) {
536 case LY_TYPE_UINT8:
537 case LY_TYPE_INT8:
538 num = value->uint8;
539 break;
540 case LY_TYPE_UINT16:
541 case LY_TYPE_INT16:
542 num = value->uint16;
543 break;
544 case LY_TYPE_UINT32:
545 case LY_TYPE_INT32:
546 num = value->uint32;
547 break;
548 case LY_TYPE_UINT64:
549 case LY_TYPE_INT64:
550 num = value->uint64;
551 break;
552 default:
553 break;
554 }
555
556 if (htole64(num) == value->uint64) {
557 /* values are equal, little-endian or uint8 */
558 *dynamic = 0;
559 if (value_size_bits) {
560 /* the least amount of bits that can hold the number */
561 *value_size_bits = lyplg_type_get_highest_set_bit_pos(num);
562 }
563 return &value->uint64;
564 } else {
565 /* values differ, big-endian */
566 bits_used = lyplg_type_get_highest_set_bit_pos(num);
567 bytes_used = LYPLG_BITS2BYTES(bits_used);
568
569 buf = calloc(1, bytes_used);
570 LY_CHECK_RET(!buf, NULL);
571 num = htole64(num);
572 memcpy(buf, &num, bytes_used);
573
574 *dynamic = 1;
575 if (value_size_bits) {
576 *value_size_bits = bits_used;
577 }
578 return buf;
579 }
580 }
581
582 /* use the cached canonical value */
583 if (dynamic) {
584 *dynamic = 0;
585 }
586 if (value_size_bits) {
587 *value_size_bits = strlen(value->_canonical) * 8;
588 }
589 return value->_canonical;
590}
591
600 {
601 .module = "",
602 .revision = NULL,
603 .name = LY_TYPE_UINT8_STR,
604
605 .plugin.id = "ly2 integers",
606 .plugin.lyb_size = lyplg_type_lyb_size_variable_bits,
607 .plugin.store = lyplg_type_store_uint,
608 .plugin.validate_value = lyplg_type_validate_value_uint,
609 .plugin.validate_tree = NULL,
610 .plugin.compare = lyplg_type_compare_uint,
611 .plugin.sort = lyplg_type_sort_uint,
612 .plugin.print = lyplg_type_print_u_int,
613 .plugin.duplicate = lyplg_type_dup_simple,
614 .plugin.free = lyplg_type_free_simple,
615 }, {
616 .module = "",
617 .revision = NULL,
618 .name = LY_TYPE_UINT16_STR,
619
620 .plugin.id = "ly2 integers",
621 .plugin.lyb_size = lyplg_type_lyb_size_variable_bits,
622 .plugin.store = lyplg_type_store_uint,
623 .plugin.validate_value = lyplg_type_validate_value_uint,
624 .plugin.validate_tree = NULL,
625 .plugin.compare = lyplg_type_compare_uint,
626 .plugin.sort = lyplg_type_sort_uint,
627 .plugin.print = lyplg_type_print_u_int,
628 .plugin.duplicate = lyplg_type_dup_simple,
629 .plugin.free = lyplg_type_free_simple,
630 }, {
631 .module = "",
632 .revision = NULL,
633 .name = LY_TYPE_UINT32_STR,
634
635 .plugin.id = "ly2 integers",
636 .plugin.lyb_size = lyplg_type_lyb_size_variable_bits,
637 .plugin.store = lyplg_type_store_uint,
638 .plugin.validate_value = lyplg_type_validate_value_uint,
639 .plugin.validate_tree = NULL,
640 .plugin.compare = lyplg_type_compare_uint,
641 .plugin.sort = lyplg_type_sort_uint,
642 .plugin.print = lyplg_type_print_u_int,
643 .plugin.duplicate = lyplg_type_dup_simple,
644 .plugin.free = lyplg_type_free_simple,
645 }, {
646 .module = "",
647 .revision = NULL,
648 .name = LY_TYPE_UINT64_STR,
649
650 .plugin.id = "ly2 integers",
651 .plugin.lyb_size = lyplg_type_lyb_size_variable_bits,
652 .plugin.store = lyplg_type_store_uint,
653 .plugin.validate_value = lyplg_type_validate_value_uint,
654 .plugin.validate_tree = NULL,
655 .plugin.compare = lyplg_type_compare_uint,
656 .plugin.sort = lyplg_type_sort_uint,
657 .plugin.print = lyplg_type_print_u_int,
658 .plugin.duplicate = lyplg_type_dup_simple,
659 .plugin.free = lyplg_type_free_simple,
660 }, {
661 .module = "",
662 .revision = NULL,
663 .name = LY_TYPE_INT8_STR,
664
665 .plugin.id = "ly2 integers",
666 .plugin.lyb_size = lyplg_type_lyb_size_variable_bits,
667 .plugin.store = lyplg_type_store_int,
668 .plugin.validate_value = lyplg_type_validate_value_int,
669 .plugin.validate_tree = NULL,
670 .plugin.compare = lyplg_type_compare_int,
671 .plugin.sort = lyplg_type_sort_int,
672 .plugin.print = lyplg_type_print_u_int,
673 .plugin.duplicate = lyplg_type_dup_simple,
674 .plugin.free = lyplg_type_free_simple,
675 }, {
676 .module = "",
677 .revision = NULL,
678 .name = LY_TYPE_INT16_STR,
679
680 .plugin.id = "ly2 integers",
681 .plugin.lyb_size = lyplg_type_lyb_size_variable_bits,
682 .plugin.store = lyplg_type_store_int,
683 .plugin.validate_value = lyplg_type_validate_value_int,
684 .plugin.validate_tree = NULL,
685 .plugin.compare = lyplg_type_compare_int,
686 .plugin.sort = lyplg_type_sort_int,
687 .plugin.print = lyplg_type_print_u_int,
688 .plugin.duplicate = lyplg_type_dup_simple,
689 .plugin.free = lyplg_type_free_simple,
690 }, {
691 .module = "",
692 .revision = NULL,
693 .name = LY_TYPE_INT32_STR,
694
695 .plugin.id = "ly2 integers",
696 .plugin.lyb_size = lyplg_type_lyb_size_variable_bits,
697 .plugin.store = lyplg_type_store_int,
698 .plugin.validate_value = lyplg_type_validate_value_int,
699 .plugin.validate_tree = NULL,
700 .plugin.compare = lyplg_type_compare_int,
701 .plugin.sort = lyplg_type_sort_int,
702 .plugin.print = lyplg_type_print_u_int,
703 .plugin.duplicate = lyplg_type_dup_simple,
704 .plugin.free = lyplg_type_free_simple,
705 }, {
706 .module = "",
707 .revision = NULL,
708 .name = LY_TYPE_INT64_STR,
709
710 .plugin.id = "ly2 integers",
711 .plugin.lyb_size = lyplg_type_lyb_size_variable_bits,
712 .plugin.store = lyplg_type_store_int,
713 .plugin.validate_value = lyplg_type_validate_value_int,
714 .plugin.validate_tree = NULL,
715 .plugin.compare = lyplg_type_compare_int,
716 .plugin.sort = lyplg_type_sort_int,
717 .plugin.print = lyplg_type_print_u_int,
718 .plugin.duplicate = lyplg_type_dup_simple,
719 .plugin.free = lyplg_type_free_simple,
720 },
721 {0}
722};
libyang dictionary
libyang context handler.
LIBYANG_API_DECL LY_ERR lydict_insert(const struct ly_ctx *ctx, const char *value, size_t len, const char **str_p)
Insert string into dictionary. If the string is already present, only a reference counter is incremen...
LIBYANG_API_DECL LY_ERR lydict_insert_zc(const struct ly_ctx *ctx, char *value, const char **str_p)
Insert string into dictionary - zerocopy version. If the string is already present,...
LY_ERR
libyang's error codes returned by the libyang functions.
Definition log.h:252
@ LYVE_DATA
Definition log.h:290
@ LY_EINVAL
Definition log.h:256
@ LY_EMEM
Definition log.h:254
@ LY_ENOT
Definition log.h:266
@ LY_EVALID
Definition log.h:260
@ LY_EINT
Definition log.h:259
@ LY_SUCCESS
Definition log.h:253
Libyang full error structure.
Definition log.h:298
const char *const char * revision
LIBYANG_API_DECL LY_ERR lyplg_type_check_hints(uint32_t hints, const char *value, uint32_t value_len, LY_DATA_TYPE type, int *base, struct ly_err_item **err)
Check that the type is suitable for the parser's hints (if any) in the specified format.
LIBYANG_API_DECL LY_ERR lyplg_type_parse_uint(const char *datatype, int base, uint64_t max, const char *value, uint32_t value_len, uint64_t *ret, struct ly_err_item **err)
Unsigned integer value parser and validator.
LIBYANG_API_DECL LY_ERR lyplg_type_parse_int(const char *datatype, int base, int64_t min, int64_t max, const char *value, uint32_t value_len, int64_t *ret, struct ly_err_item **err)
Unsigned integer value parser and validator.
LIBYANG_API_DECL uint64_t lyplg_type_get_highest_set_bit_pos(uint64_t num)
Learn the position of the highest set bit in a number. Represents also the least amount of bits requi...
LIBYANG_API_DECL LY_ERR lyplg_type_validate_range(LY_DATA_TYPE basetype, struct lysc_range *range, int64_t value, const char *strval, uint32_t strval_len, struct ly_err_item **err)
Data type validator for a range/length-restricted values.
LIBYANG_API_DECL LY_ERR lyplg_type_check_value_size(const char *type_name, LY_VALUE_FORMAT format, uint64_t value_size_bits, enum lyplg_lyb_size_type lyb_size_type, uint64_t lyb_fixed_size_bits, uint32_t *value_size, struct ly_err_item **err)
Check a value type in bits is correct and as expected.
LIBYANG_API_DECL LY_ERR ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *data_path, char *apptag, const char *err_format,...) _FORMAT_PRINTF(6
Create and fill error structure.
#define LYPLG_BITS2BYTES(bits)
Convert bits to bytes.
@ LYPLG_LYB_SIZE_VARIABLE_BITS
LIBYANG_API_DECL void lyplg_type_lyb_size_variable_bits(const struct lysc_type *type, enum lyplg_lyb_size_type *size_type, uint64_t *fixed_size_bits)
Implementation of lyplg_type_lyb_size_clb for a type with variable length in bits.
LIBYANG_API_DECL LY_ERR lyplg_type_dup_simple(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
Implementation of lyplg_type_dup_clb for a generic simple type.
LIBYANG_API_DECL void lyplg_type_free_simple(const struct ly_ctx *ctx, struct lyd_value *value)
Implementation of lyplg_type_free_clb for a generic simple type.
#define LYPLG_TYPE_STORE_DYNAMIC
#define LYPLG_TYPE_STORE_ONLY
struct lysc_range * range
LY_DATA_TYPE basetype
Compiled YANG data node.
const struct lyplg_type_record plugins_integer[]
Plugin information for integer types implementation.
Definition integer.c:599
uint8_t ly_bool
Type to indicate boolean value.
Definition log.h:36
API for (user) types plugins.
const struct lysc_type * realtype
Definition tree_data.h:614
const char * _canonical
Definition tree_data.h:611
YANG data representation.
Definition tree_data.h:610
@ LY_TYPE_UINT16
Definition utils.h:65
@ LY_TYPE_INT16
Definition utils.h:79
@ LY_TYPE_INT32
Definition utils.h:80
@ LY_TYPE_UINT8
Definition utils.h:64
@ LY_TYPE_INT64
Definition utils.h:81
@ LY_TYPE_INT8
Definition utils.h:78
@ LY_TYPE_UINT64
Definition utils.h:67
@ LY_TYPE_UINT32
Definition utils.h:66
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
Definition utils.h:93
@ LY_VALUE_CANON
Definition utils.h:94
@ LY_VALUE_LYB
Definition utils.h:100