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