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);
158 if (type_num->
range) {
161 LY_CHECK_GOTO(ret, cleanup);
184 if (val1->int8 != val2->int8) {
189 if (val1->int16 != val2->int16) {
194 if (val1->int32 != val2->int32) {
199 if (val1->int64 != val2->int64) {
209 LIBYANG_API_DEF
const void *
211 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
213 int64_t prev_num = 0, num = 0;
219 prev_num = num = value->int8;
222 prev_num = num = value->int16;
225 prev_num = num = value->int32;
228 prev_num = num = value->int64;
234 if (num == prev_num) {
240 return &value->int64;
244 LY_CHECK_RET(!buf, NULL);
267 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
268 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
278 memset(storage, 0,
sizeof *storage);
283 if (value_len != integer_lyb_size[type->
basetype]) {
285 value_len, integer_lyb_size[type->
basetype]);
290 memcpy(&num, value, value_len);
295 LY_CHECK_GOTO(ret, cleanup);
309 ret =
lyplg_type_parse_uint(
"uint64", base, UINT64_C(18446744073709551615), value, value_len, &num, err);
315 LY_CHECK_GOTO(ret, cleanup);
321 storage->uint8 = num;
324 storage->uint16 = num;
327 storage->uint32 = num;
330 storage->uint64 = num;
340 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
341 LY_CHECK_GOTO(ret, cleanup);
344 LY_CHECK_GOTO(ret, cleanup);
348 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRIu64, num) == -1, ret =
LY_EMEM, cleanup);
352 LY_CHECK_GOTO(ret, cleanup);
356 if (type_num->
range) {
359 LY_CHECK_GOTO(ret, cleanup);
382 if (val1->uint8 != val2->uint8) {
387 if (val1->uint16 != val2->uint16) {
392 if (val1->uint32 != val2->uint32) {
397 if (val1->uint64 != val2->uint64) {
407 LIBYANG_API_DEF
const void *
409 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
432 if (num == value->uint64) {
438 return &value->uint64;
442 LY_CHECK_RET(!buf, NULL);
474 .name = LY_TYPE_UINT8_STR,
476 .plugin.id =
"libyang 2 - integers, version 1",
478 .plugin.validate = NULL,
484 .plugin.lyb_data_len = 1,
488 .name = LY_TYPE_UINT16_STR,
490 .plugin.id =
"libyang 2 - integers, version 1",
492 .plugin.validate = NULL,
498 .plugin.lyb_data_len = 2,
502 .name = LY_TYPE_UINT32_STR,
504 .plugin.id =
"libyang 2 - integers, version 1",
506 .plugin.validate = NULL,
512 .plugin.lyb_data_len = 4,
516 .name = LY_TYPE_UINT64_STR,
518 .plugin.id =
"libyang 2 - integers, version 1",
520 .plugin.validate = NULL,
526 .plugin.lyb_data_len = 8,
530 .name = LY_TYPE_INT8_STR,
532 .plugin.id =
"libyang 2 - integers, version 1",
534 .plugin.validate = NULL,
540 .plugin.lyb_data_len = 1,
544 .name = LY_TYPE_INT16_STR,
546 .plugin.id =
"libyang 2 - integers, version 1",
548 .plugin.validate = NULL,
554 .plugin.lyb_data_len = 2,
558 .name = LY_TYPE_INT32_STR,
560 .plugin.id =
"libyang 2 - integers, version 1",
562 .plugin.validate = NULL,
568 .plugin.lyb_data_len = 4,
572 .name = LY_TYPE_INT64_STR,
574 .plugin.id =
"libyang 2 - integers, version 1",
576 .plugin.validate = NULL,
582 .plugin.lyb_data_len = 8,
struct lysc_type * realtype
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.
struct lyplg_type_record plugins_integer[]
Plugin information for integer types implementation.
LIBYANG_API_DECL LY_ERR ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *path, char *apptag, const char *err_format,...) _FORMAT_PRINTF(6
Create and fill error structure.
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.
#define LYPLG_TYPE_STORE_DYNAMIC
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 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...
LIBYANG_API_DECL LY_ERR lyplg_type_compare_int(const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for the built-in signed integer types.
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.
LY_ERR
libyang's error codes returned by the libyang functions.
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.
LIBYANG_API_DECL LY_ERR lyplg_type_compare_uint(const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for the built-in unsigned integer types. ...
API for (user) types plugins.
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.