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