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