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