32#include "plugins_internal.h"
44static void lyplg_type_free_date(
const struct ly_ctx *ctx,
struct lyd_value *value);
48 uint32_t *fixed_size_bits)
51 *fixed_size_bits = 64;
58lyplg_type_store_date(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value, uint32_t value_size_bits,
59 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
60 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
72 memset(storage, 0,
sizeof *storage);
73 if (!strcmp(type->
name,
"date")) {
78 LY_CHECK_ERR_GOTO(!val && !val_nz, ret =
LY_EMEM, cleanup);
84 if ((value_size_bits != 64) && (value_size_bits != 65)) {
86 " b (expected 64 or 65 b).", type->
name, value_size_bits);
90 if (value_size_bits != 64) {
92 " b (expected 64 b).", type->
name, value_size_bits);
100 memcpy(&val->
time, value,
sizeof val->
time);
102 memcpy(&val_nz->
time, value,
sizeof val_nz->
time);
106 if (val && (value_size > 8)) {
107 val->
unknown_tz = *(((uint8_t *)value) + 8) ? 1 : 0;
122 LY_CHECK_GOTO(ret, cleanup);
126 LY_CHECK_GOTO(ret, cleanup);
136 if (asprintf(&str,
"%.*sT00:00:00%.*s", 10, (
char *)value, (
int)(value_size - 10), (
char *)value + 10) == -1) {
149 ptr = strptime(value,
"%Y-%m-%d", &tm);
150 if (!ptr || (ptr - (
char *)value != value_size)) {
152 (
int)value_size, (
char *)value);
157 val_nz->
time = timegm(&tm);
160 if (val && (((
char *)value)[value_size - 1] ==
'Z')) {
170 LY_CHECK_GOTO(ret, cleanup);
173 LY_CHECK_GOTO(ret, cleanup);
184 lyplg_type_free_date(ctx, storage);
193lyplg_type_compare_date(
const struct ly_ctx *UNUSED(ctx),
const struct lyd_value *val1,
234 return difftime(v1->
time, v2->
time);
240 return difftime(vn1->
time, vn2->
time);
249 void *UNUSED(prefix_data),
ly_bool *dynamic, uint32_t *value_size_bits)
265 LY_CHECK_ERR_RET(!ret,
LOGMEM(ctx), NULL);
268 if (value_size_bits) {
269 *value_size_bits = 64 + 8;
271 memcpy(ret, &val->
time,
sizeof val->
time);
275 if (value_size_bits) {
276 *value_size_bits = 64;
278 ret = val ? (
char *)&val->
time : (char *)&val_nz->time;
287 if (!gmtime_r(val_nz ? &val_nz->
time : &val->
time, &tm)) {
291 if (asprintf(&ret,
"%04d-%02d-%02d%s", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, val ?
"Z" :
"") == -1) {
300 assert(ret[10] ==
'T');
301 memmove(ret + 10, ret + 19, strlen(ret + 19) + 1);
317 if (value_size_bits) {
318 *value_size_bits = strlen(value->
_canonical) * 8;
333 memset(dup, 0,
sizeof *dup);
337 LY_CHECK_GOTO(ret, error);
342 LY_CHECK_ERR_GOTO(!dup_val, ret =
LY_EMEM, error);
351 LY_CHECK_ERR_GOTO(!dup_val_nz, ret =
LY_EMEM, error);
356 dup_val_nz->
time = orig_val_nz->
time;
363 lyplg_type_free_date(ctx, dup);
400 .module =
"ietf-yang-types",
401 .revision =
"2025-12-22",
404 .plugin.id =
"ly2 date",
406 .plugin.store = lyplg_type_store_date,
408 .plugin.validate_tree = NULL,
409 .plugin.compare = lyplg_type_compare_date,
410 .plugin.sort = lyplg_type_sort_date,
411 .plugin.print = lyplg_type_print_date,
412 .plugin.duplicate = lyplg_type_dup_date,
413 .plugin.free = lyplg_type_free_date,
416 .module =
"ietf-yang-types",
417 .revision =
"2025-12-22",
418 .name =
"date-no-zone",
420 .plugin.id =
"ly2 date",
421 .plugin.lyb_size = lyplg_type_lyb_size_date_nz,
422 .plugin.store = lyplg_type_store_date,
424 .plugin.validate_tree = NULL,
425 .plugin.compare = lyplg_type_compare_date,
426 .plugin.sort = lyplg_type_sort_date,
427 .plugin.print = lyplg_type_print_date,
428 .plugin.duplicate = lyplg_type_dup_date,
429 .plugin.free = lyplg_type_free_date,
const struct lyplg_type_record plugins_date[]
Plugin information for date and date-no-zone type implementation.
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 lydict_remove(const struct ly_ctx *ctx, const char *value)
Remove specified string from the dictionary. It decrement reference counter for the string and if it ...
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,...
LIBYANG_API_DECL const char * ly_last_logmsg(void)
Get the last (thread-specific) full logged error message.
LY_ERR
libyang's error codes returned by the libyang functions.
Libyang full error structure.
#define LYPLG_TYPE_VAL_INLINE_PREPARE(storage, type_val)
Prepare value memory for storing a specific type value, may be allocated dynamically.
LIBYANG_API_DECL LY_ERR lyplg_type_validate_value_string(const struct ly_ctx *ctx, const struct lysc_type *type, struct lyd_value *storage, struct ly_err_item **err)
Implementation of lyplg_type_validate_value_clb for the string type.
lyplg_lyb_size_type
Type of the LYB size of a value of a particular type.
LIBYANG_API_DECL LY_ERR lyplg_type_check_hints(uint32_t hints, const char *value, uint32_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 lyplg_type_validate_patterns(const struct ly_ctx *ctx, struct lysc_pattern **patterns, const char *str, uint32_t str_len, struct ly_err_item **err)
Data type validator for pattern-restricted string values.
#define LYPLG_TYPE_VAL_INLINE_DESTROY(type_val)
Destroy a prepared value.
LIBYANG_API_DECL LY_ERR lyplg_type_check_value_size(const char *type_name, LY_VALUE_FORMAT format, uint32_t value_size_bits, enum lyplg_lyb_size_type lyb_size_type, uint32_t lyb_fixed_size_bits, uint32_t *value_size, struct ly_err_item **err)
Check a value type in bits is correct and as expected.
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.
#define LYPLG_BITS2BYTES(bits)
Convert bits to bytes.
@ LYPLG_LYB_SIZE_VARIABLE_BITS
@ LYPLG_LYB_SIZE_FIXED_BITS
LIBYANG_API_DECL void lyplg_type_lyb_size_variable_bytes(const struct lysc_type *type, enum lyplg_lyb_size_type *size_type, uint32_t *fixed_size_bits)
Implementation of lyplg_type_lyb_size_clb for a type with variable length rounded to bytes.
#define LYPLG_TYPE_STORE_DYNAMIC
#define LYPLG_TYPE_STORE_ONLY
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
The main libyang public header.
uint8_t ly_bool
Type to indicate boolean value.
API for (user) types plugins.
LIBYANG_API_DECL LY_ERR ly_time_str2time(const char *value, time_t *time, char **fractions_s)
Convert date-and-time from string to UNIX timestamp and fractions of a second.
const struct lysc_type * realtype
LIBYANG_API_DECL LY_ERR ly_time_time2str(time_t time, const char *fractions_s, char **str)
Convert UNIX timestamp and fractions of a second into canonical date-and-time string value.
#define LYD_VALUE_GET(value, type_val)
Get the value in format specific to the type.
YANG data representation.
Special lyd_value structure for ietf-yang-types date values.
Special lyd_value structure for ietf-yang-types date-no-zone values.