27 #include "ly_common.h"
28 #include "plugins_internal.h"
42 static size_t integer_lyb_size[] = {
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),
60 memset(storage, 0,
sizeof *storage);
65 if (value_len != integer_lyb_size[type->
basetype]) {
67 value_len, integer_lyb_size[type->
basetype]);
72 memcpy(&num, value, value_len);
77 LY_CHECK_GOTO(ret, cleanup);
82 ret =
lyplg_type_parse_int(
"int8", base, INT64_C(-128), INT64_C(127), value, value_len, &num, err);
85 ret =
lyplg_type_parse_int(
"int16", base, INT64_C(-32768), INT64_C(32767), value, value_len, &num, err);
88 ret =
lyplg_type_parse_int(
"int32", base, INT64_C(-2147483648), INT64_C(2147483647), value, value_len, &num, err);
92 INT64_C(9223372036854775807), value, value_len, &num, err);
98 LY_CHECK_GOTO(ret, cleanup);
108 storage->int16 = num;
109 num = storage->int16;
112 storage->int32 = num;
113 num = storage->int32;
116 storage->int64 = num;
117 num = storage->int64;
127 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
128 LY_CHECK_GOTO(ret, cleanup);
131 LY_CHECK_GOTO(ret, cleanup);
137 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId8, storage->int8) == -1, ret =
LY_EMEM, cleanup);
140 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId16, storage->int16) == -1, ret =
LY_EMEM, cleanup);
143 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId32, storage->int32) == -1, ret =
LY_EMEM, cleanup);
146 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId64, storage->int64) == -1, ret =
LY_EMEM, cleanup);
154 LY_CHECK_GOTO(ret, cleanup);
159 if (type_num->
range) {
162 LY_CHECK_GOTO(ret, cleanup);
186 if (val1->int8 != val2->int8) {
191 if (val1->int16 != val2->int16) {
196 if (val1->int32 != val2->int32) {
201 if (val1->int64 != val2->int64) {
216 if (val1->int8 < val2->int8) {
218 }
else if (val1->int8 > val2->int8) {
225 if (val1->int16 < val2->int16) {
227 }
else if (val1->int16 > val2->int16) {
234 if (val1->int32 < val2->int32) {
236 }
else if (val1->int32 > val2->int32) {
243 if (val1->int64 < val2->int64) {
245 }
else if (val1->int64 > val2->int64) {
257 LIBYANG_API_DEF
const void *
259 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
261 int64_t prev_num = 0, num = 0;
267 prev_num = num = value->int8;
270 prev_num = num = value->int16;
273 prev_num = num = value->int32;
276 prev_num = num = value->int64;
282 if (num == prev_num) {
288 return &value->int64;
292 LY_CHECK_RET(!buf, NULL);
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),
326 memset(storage, 0,
sizeof *storage);
331 if (value_len != integer_lyb_size[type->
basetype]) {
333 value_len, integer_lyb_size[type->
basetype]);
338 memcpy(&num, value, value_len);
343 LY_CHECK_GOTO(ret, cleanup);
357 ret =
lyplg_type_parse_uint(
"uint64", base, UINT64_C(18446744073709551615), value, value_len, &num, err);
363 LY_CHECK_GOTO(ret, cleanup);
369 storage->uint8 = num;
372 storage->uint16 = num;
375 storage->uint32 = num;
378 storage->uint64 = num;
388 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
389 LY_CHECK_GOTO(ret, cleanup);
392 LY_CHECK_GOTO(ret, cleanup);
396 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRIu64, num) == -1, ret =
LY_EMEM, cleanup);
400 LY_CHECK_GOTO(ret, cleanup);
405 if (type_num->
range) {
408 LY_CHECK_GOTO(ret, cleanup);
428 if (val1->uint8 != val2->uint8) {
433 if (val1->uint16 != val2->uint16) {
438 if (val1->uint32 != val2->uint32) {
443 if (val1->uint64 != val2->uint64) {
458 if (val1->uint8 < val2->uint8) {
460 }
else if (val1->uint8 > val2->uint8) {
467 if (val1->uint16 < val2->uint16) {
469 }
else if (val1->uint16 > val2->uint16) {
476 if (val1->uint32 < val2->uint32) {
478 }
else if (val1->uint32 > val2->uint32) {
485 if (val1->uint64 < val2->uint64) {
487 }
else if (val1->uint64 > val2->uint64) {
499 LIBYANG_API_DEF
const void *
501 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
524 if (num == value->uint64) {
530 return &value->uint64;
534 LY_CHECK_RET(!buf, NULL);
566 .name = LY_TYPE_UINT8_STR,
568 .plugin.id =
"libyang 2 - integers, version 1",
570 .plugin.validate = NULL,
576 .plugin.lyb_data_len = 1,
580 .name = LY_TYPE_UINT16_STR,
582 .plugin.id =
"libyang 2 - integers, version 1",
584 .plugin.validate = NULL,
590 .plugin.lyb_data_len = 2,
594 .name = LY_TYPE_UINT32_STR,
596 .plugin.id =
"libyang 2 - integers, version 1",
598 .plugin.validate = NULL,
604 .plugin.lyb_data_len = 4,
608 .name = LY_TYPE_UINT64_STR,
610 .plugin.id =
"libyang 2 - integers, version 1",
612 .plugin.validate = NULL,
618 .plugin.lyb_data_len = 8,
622 .name = LY_TYPE_INT8_STR,
624 .plugin.id =
"libyang 2 - integers, version 1",
626 .plugin.validate = NULL,
632 .plugin.lyb_data_len = 1,
636 .name = LY_TYPE_INT16_STR,
638 .plugin.id =
"libyang 2 - integers, version 1",
640 .plugin.validate = NULL,
646 .plugin.lyb_data_len = 2,
650 .name = LY_TYPE_INT32_STR,
652 .plugin.id =
"libyang 2 - integers, version 1",
654 .plugin.validate = NULL,
660 .plugin.lyb_data_len = 4,
664 .name = LY_TYPE_INT64_STR,
666 .plugin.id =
"libyang 2 - integers, version 1",
668 .plugin.validate = NULL,
674 .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.
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.