27 #include "ly_common.h"
28 #include "plugins_internal.h"
45 static size_t integer_lyb_size[] = {
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),
62 memset(storage, 0,
sizeof *storage);
67 if (value_len != integer_lyb_size[type->
basetype]) {
69 value_len, integer_lyb_size[type->
basetype]);
74 memcpy(&num, value, value_len);
79 LY_CHECK_GOTO(ret, cleanup);
84 ret =
lyplg_type_parse_int(
"int8", base, INT64_C(-128), INT64_C(127), value, value_len, &num, err);
87 ret =
lyplg_type_parse_int(
"int16", base, INT64_C(-32768), INT64_C(32767), value, value_len, &num, err);
90 ret =
lyplg_type_parse_int(
"int32", base, INT64_C(-2147483648), INT64_C(2147483647), value, value_len, &num, err);
94 INT64_C(9223372036854775807), value, value_len, &num, err);
100 LY_CHECK_GOTO(ret, cleanup);
110 storage->int16 = num;
111 num = storage->int16;
114 storage->int32 = num;
115 num = storage->int32;
118 storage->int64 = num;
119 num = storage->int64;
129 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
130 LY_CHECK_GOTO(ret, cleanup);
133 LY_CHECK_GOTO(ret, cleanup);
139 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId8, storage->int8) == -1, ret =
LY_EMEM, cleanup);
142 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId16, storage->int16) == -1, ret =
LY_EMEM, cleanup);
145 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId32, storage->int32) == -1, ret =
LY_EMEM, cleanup);
148 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId64, storage->int64) == -1, ret =
LY_EMEM, cleanup);
156 LY_CHECK_GOTO(ret, cleanup);
161 ret = lyplg_type_validate_int(ctx, type, NULL, NULL, storage, err);
162 LY_CHECK_GOTO(ret, cleanup);
180 lyplg_type_validate_int(
const struct ly_ctx *UNUSED(ctx),
const struct lysc_type *type,
const struct lyd_node *UNUSED(ctx_node),
187 LY_CHECK_ARG_RET(NULL, type, storage, err,
LY_EINVAL);
196 num = storage->int16;
199 num = storage->int32;
202 num = storage->int64;
209 if (type_num->
range) {
227 if (val1->int8 != val2->int8) {
232 if (val1->int16 != val2->int16) {
237 if (val1->int32 != val2->int32) {
242 if (val1->int64 != val2->int64) {
257 if (val1->int8 < val2->int8) {
259 }
else if (val1->int8 > val2->int8) {
266 if (val1->int16 < val2->int16) {
268 }
else if (val1->int16 > val2->int16) {
275 if (val1->int32 < val2->int32) {
277 }
else if (val1->int32 > val2->int32) {
284 if (val1->int64 < val2->int64) {
286 }
else if (val1->int64 > val2->int64) {
298 LIBYANG_API_DEF
const void *
300 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
302 int64_t prev_num = 0, num = 0;
308 prev_num = num = value->int8;
311 prev_num = num = value->int16;
314 prev_num = num = value->int32;
317 prev_num = num = value->int64;
323 if (num == prev_num) {
329 return &value->int64;
333 LY_CHECK_RET(!buf, NULL);
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),
366 memset(storage, 0,
sizeof *storage);
371 if (value_len != integer_lyb_size[type->
basetype]) {
373 value_len, integer_lyb_size[type->
basetype]);
378 memcpy(&num, value, value_len);
383 LY_CHECK_GOTO(ret, cleanup);
397 ret =
lyplg_type_parse_uint(
"uint64", base, UINT64_C(18446744073709551615), value, value_len, &num, err);
403 LY_CHECK_GOTO(ret, cleanup);
409 storage->uint8 = num;
412 storage->uint16 = num;
415 storage->uint32 = num;
418 storage->uint64 = num;
428 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
429 LY_CHECK_GOTO(ret, cleanup);
432 LY_CHECK_GOTO(ret, cleanup);
436 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRIu64, num) == -1, ret =
LY_EMEM, cleanup);
440 LY_CHECK_GOTO(ret, cleanup);
445 ret = lyplg_type_validate_uint(ctx, type, NULL, NULL, storage, err);
446 LY_CHECK_GOTO(ret, cleanup);
464 lyplg_type_validate_uint(
const struct ly_ctx *UNUSED(ctx),
const struct lysc_type *type,
const struct lyd_node *UNUSED(ctx_node),
471 LY_CHECK_ARG_RET(NULL, type, storage, err,
LY_EINVAL);
477 num = storage->uint8;
480 num = storage->uint16;
483 num = storage->uint32;
486 num = storage->uint64;
493 if (type_num->
range) {
507 if (val1->uint8 != val2->uint8) {
512 if (val1->uint16 != val2->uint16) {
517 if (val1->uint32 != val2->uint32) {
522 if (val1->uint64 != val2->uint64) {
537 if (val1->uint8 < val2->uint8) {
539 }
else if (val1->uint8 > val2->uint8) {
546 if (val1->uint16 < val2->uint16) {
548 }
else if (val1->uint16 > val2->uint16) {
555 if (val1->uint32 < val2->uint32) {
557 }
else if (val1->uint32 > val2->uint32) {
564 if (val1->uint64 < val2->uint64) {
566 }
else if (val1->uint64 > val2->uint64) {
578 LIBYANG_API_DEF
const void *
580 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
603 if (num == value->uint64) {
609 return &value->uint64;
613 LY_CHECK_RET(!buf, NULL);
645 .name = LY_TYPE_UINT8_STR,
647 .plugin.id =
"libyang 2 - integers, version 1",
649 .plugin.validate = lyplg_type_validate_uint,
655 .plugin.lyb_data_len = 1,
659 .name = LY_TYPE_UINT16_STR,
661 .plugin.id =
"libyang 2 - integers, version 1",
663 .plugin.validate = lyplg_type_validate_uint,
669 .plugin.lyb_data_len = 2,
673 .name = LY_TYPE_UINT32_STR,
675 .plugin.id =
"libyang 2 - integers, version 1",
677 .plugin.validate = lyplg_type_validate_uint,
683 .plugin.lyb_data_len = 4,
687 .name = LY_TYPE_UINT64_STR,
689 .plugin.id =
"libyang 2 - integers, version 1",
691 .plugin.validate = lyplg_type_validate_uint,
697 .plugin.lyb_data_len = 8,
701 .name = LY_TYPE_INT8_STR,
703 .plugin.id =
"libyang 2 - integers, version 1",
705 .plugin.validate = lyplg_type_validate_int,
711 .plugin.lyb_data_len = 1,
715 .name = LY_TYPE_INT16_STR,
717 .plugin.id =
"libyang 2 - integers, version 1",
719 .plugin.validate = lyplg_type_validate_int,
725 .plugin.lyb_data_len = 2,
729 .name = LY_TYPE_INT32_STR,
731 .plugin.id =
"libyang 2 - integers, version 1",
733 .plugin.validate = lyplg_type_validate_int,
739 .plugin.lyb_data_len = 4,
743 .name = LY_TYPE_INT64_STR,
745 .plugin.id =
"libyang 2 - integers, version 1",
747 .plugin.validate = lyplg_type_validate_int,
753 .plugin.lyb_data_len = 8,
struct lysc_type * realtype
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. ...
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.
Generic structure for a data node.
struct lyplg_type_record plugins_integer[]
Plugin information for integer types implementation.
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.
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.
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.
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
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's hints (if any) in the specified format.
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.
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's error codes returned by the libyang functions.
#define LYPLG_TYPE_STORE_ONLY
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.