|
39 | 39 | * | variable | yes | pointer to the specific integer type | little-endian integer value | |
40 | 40 | */ |
41 | 41 |
|
| 42 | +static LY_ERR lyplg_type_validate_int(const struct ly_ctx *ctx, const struct lysc_type *type, |
| 43 | + const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err); |
| 44 | +static LY_ERR lyplg_type_validate_uint(const struct ly_ctx *ctx, const struct lysc_type *type, |
| 45 | + const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err); |
| 46 | + |
42 | 47 | static LY_ERR |
43 | 48 | lyplg_type_store_int(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits, |
44 | 49 | uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints, |
@@ -165,6 +170,48 @@ lyplg_type_store_int(const struct ly_ctx *ctx, const struct lysc_type *type, con |
165 | 170 | return ret; |
166 | 171 | } |
167 | 172 |
|
| 173 | +/** |
| 174 | + * @brief Implementation of ::lyplg_type_validate_clb for the signed interger types. |
| 175 | + */ |
| 176 | +static LY_ERR |
| 177 | +lyplg_type_validate_int(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), |
| 178 | + const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err) |
| 179 | +{ |
| 180 | + LY_ERR ret; |
| 181 | + struct lysc_type_num *type_num = (struct lysc_type_num *)type; |
| 182 | + int64_t num; |
| 183 | + |
| 184 | + LY_CHECK_ARG_RET(NULL, type, storage, err, LY_EINVAL); |
| 185 | + *err = NULL; |
| 186 | + |
| 187 | + /* set the value (matters for big-endian) and get the correct int64 number */ |
| 188 | + switch (type->basetype) { |
| 189 | + case LY_TYPE_INT8: |
| 190 | + num = storage->int8; |
| 191 | + break; |
| 192 | + case LY_TYPE_INT16: |
| 193 | + num = storage->int16; |
| 194 | + break; |
| 195 | + case LY_TYPE_INT32: |
| 196 | + num = storage->int32; |
| 197 | + break; |
| 198 | + case LY_TYPE_INT64: |
| 199 | + num = storage->int64; |
| 200 | + break; |
| 201 | + default: |
| 202 | + return LY_EINVAL; |
| 203 | + } |
| 204 | + |
| 205 | + /* validate range of the number */ |
| 206 | + if (type_num->range) { |
| 207 | + ret = lyplg_type_validate_range(type->basetype, type_num->range, num, storage->_canonical, |
| 208 | + strlen(storage->_canonical), err); |
| 209 | + LY_CHECK_RET(ret); |
| 210 | + } |
| 211 | + |
| 212 | + return LY_SUCCESS; |
| 213 | +} |
| 214 | + |
168 | 215 | static LY_ERR |
169 | 216 | lyplg_type_compare_int(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2) |
170 | 217 | { |
@@ -409,6 +456,48 @@ lyplg_type_store_uint(const struct ly_ctx *ctx, const struct lysc_type *type, co |
409 | 456 | return ret; |
410 | 457 | } |
411 | 458 |
|
| 459 | +/** |
| 460 | + * @brief Implementation of ::lyplg_type_validate_clb for the unsigned interger types. |
| 461 | + */ |
| 462 | +static LY_ERR |
| 463 | +lyplg_type_validate_uint(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), |
| 464 | + const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err) |
| 465 | +{ |
| 466 | + LY_ERR ret; |
| 467 | + struct lysc_type_num *type_num = (struct lysc_type_num *)type; |
| 468 | + uint64_t num; |
| 469 | + |
| 470 | + LY_CHECK_ARG_RET(NULL, type, storage, err, LY_EINVAL); |
| 471 | + *err = NULL; |
| 472 | + |
| 473 | + /* set the value (matters for big-endian) and get the correct int64 number */ |
| 474 | + switch (type->basetype) { |
| 475 | + case LY_TYPE_UINT8: |
| 476 | + num = storage->uint8; |
| 477 | + break; |
| 478 | + case LY_TYPE_UINT16: |
| 479 | + num = storage->uint16; |
| 480 | + break; |
| 481 | + case LY_TYPE_UINT32: |
| 482 | + num = storage->uint32; |
| 483 | + break; |
| 484 | + case LY_TYPE_UINT64: |
| 485 | + num = storage->uint64; |
| 486 | + break; |
| 487 | + default: |
| 488 | + return LY_EINVAL; |
| 489 | + } |
| 490 | + |
| 491 | + /* validate range of the number */ |
| 492 | + if (type_num->range) { |
| 493 | + ret = lyplg_type_validate_range(type->basetype, type_num->range, num, storage->_canonical, |
| 494 | + strlen(storage->_canonical), err); |
| 495 | + LY_CHECK_RET(ret); |
| 496 | + } |
| 497 | + |
| 498 | + return LY_SUCCESS; |
| 499 | +} |
| 500 | + |
412 | 501 | static LY_ERR |
413 | 502 | lyplg_type_compare_uint(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2) |
414 | 503 | { |
|
0 commit comments