![]() |
libyang 6.4.3
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
|
Utilities and generic types of libyang. More...
#include <stdint.h>#include <time.h>Go to the source code of this file.
Macros | |
| #define | LY_DATA_TYPE_COUNT 20 |
| #define | LY_LIST_FOR(START, ELEM) |
| Macro to iterate via all sibling elements without affecting the list itself. | |
| #define | LY_LIST_FOR_SAFE(START, NEXT, ELEM) |
| Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements) | |
Enumerations | |
| enum | LY_DATA_TYPE { LY_TYPE_UNKNOWN = 0 , LY_TYPE_BINARY , LY_TYPE_UINT8 , LY_TYPE_UINT16 , LY_TYPE_UINT32 , LY_TYPE_UINT64 , LY_TYPE_STRING , LY_TYPE_BITS , LY_TYPE_BOOL , LY_TYPE_DEC64 , LY_TYPE_EMPTY , LY_TYPE_ENUM , LY_TYPE_IDENT , LY_TYPE_INST , LY_TYPE_LEAFREF , LY_TYPE_UNION , LY_TYPE_INT8 , LY_TYPE_INT16 , LY_TYPE_INT32 , LY_TYPE_INT64 } |
| YANG built-in types. More... | |
| enum | LY_VALUE_FORMAT { LY_VALUE_CANON , LY_VALUE_SCHEMA , LY_VALUE_SCHEMA_RESOLVED , LY_VALUE_XML , LY_VALUE_JSON , LY_VALUE_CBOR , LY_VALUE_LYB , LY_VALUE_STR_NS } |
| All kinds of supported value formats and prefix mappings to modules. More... | |
Functions | |
| LIBYANG_API_DECL LY_ERR | ly_pattern_compile (const struct ly_ctx *ctx, const char *pattern, void **pat_comp) |
| Compile an XML Schema regex pattern prior to matching. | |
| LIBYANG_API_DECL void | ly_pattern_free (void *pat_comp) |
| Free a compiled XML Schema regex pattern. | |
| LIBYANG_API_DECL LY_ERR | ly_pattern_match (const struct ly_ctx *ctx, const char *pattern, const char *string, uint32_t str_len, void **pat_comp) |
| Check a string matches an XML Schema regex used in YANG. | |
| 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. | |
| LIBYANG_API_DECL LY_ERR | ly_time_str2ts (const char *value, struct timespec *ts) |
| Convert date-and-time from string to timespec. | |
| 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. | |
| LIBYANG_API_DECL LY_ERR | ly_time_ts2str (const struct timespec *ts, char **str) |
| Convert timespec into date-and-time string value. | |
| LIBYANG_API_DECL int | ly_time_tz_offset (void) |
| Get current timezone (including DST setting) UTC (GMT) time offset in seconds. | |
| LIBYANG_API_DECL int | ly_time_tz_offset_at (time_t time) |
| Get UTC (GMT) timezone offset in seconds at a specific timestamp (including DST setting). | |
Variables | |
| const char * | ly_data_type2str [20] |
| Stringfield YANG built-in data types. | |
Utilities and generic types of libyang.
Copyright (c) 2026 CESNET, z.s.p.o.
This source code is licensed under BSD 3-Clause License (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at
https://opensource.org/licenses/BSD-3-Clause
Definition in file utils.h.
| #define LY_LIST_FOR | ( | START, | |
| ELEM | |||
| ) |
Macro to iterate via all sibling elements without affecting the list itself.
Works for all types of nodes despite it is data or schema tree, but all the parameters must be pointers to the same type.
Use with opening curly bracket ({). All parameters must be of the same type.
| START | Pointer to the starting element. |
| ELEM | Iterator. |
| #define LY_LIST_FOR_SAFE | ( | START, | |
| NEXT, | |||
| ELEM | |||
| ) |
Macro to iterate via all sibling elements allowing to modify the list itself (e.g. removing elements)
Use with opening curly bracket ({). All parameters must be of the same type.
| START | Pointer to the starting element. |
| NEXT | Temporary storage to allow removing of the current iterator content. |
| ELEM | Iterator. |
| enum LY_DATA_TYPE |
YANG built-in types.
| Enumerator | |
|---|---|
| LY_TYPE_UNKNOWN | Unknown type |
| LY_TYPE_BINARY | Any binary data (RFC 6020 sec 9.8) |
| LY_TYPE_UINT8 | 8-bit unsigned integer (RFC 6020 sec 9.2) |
| LY_TYPE_UINT16 | 16-bit unsigned integer (RFC 6020 sec 9.2) |
| LY_TYPE_UINT32 | 32-bit unsigned integer (RFC 6020 sec 9.2) |
| LY_TYPE_UINT64 | 64-bit unsigned integer (RFC 6020 sec 9.2) |
| LY_TYPE_STRING | Human-readable string (RFC 6020 sec 9.4) |
| LY_TYPE_BITS | A set of bits or flags (RFC 6020 sec 9.7) |
| LY_TYPE_BOOL | "true" or "false" (RFC 6020 sec 9.5) |
| LY_TYPE_DEC64 | 64-bit signed decimal number (RFC 6020 sec 9.3) |
| LY_TYPE_EMPTY | A leaf that does not have any value (RFC 6020 sec 9.11) |
| LY_TYPE_ENUM | Enumerated strings (RFC 6020 sec 9.6) |
| LY_TYPE_IDENT | A reference to an abstract identity (RFC 6020 sec 9.10) |
| LY_TYPE_INST | References a data tree node (RFC 6020 sec 9.13) |
| LY_TYPE_LEAFREF | A reference to a leaf instance (RFC 6020 sec 9.9) |
| LY_TYPE_UNION | Choice of member types (RFC 6020 sec 9.12) |
| LY_TYPE_INT8 | 8-bit signed integer (RFC 6020 sec 9.2) |
| LY_TYPE_INT16 | 16-bit signed integer (RFC 6020 sec 9.2) |
| LY_TYPE_INT32 | 32-bit signed integer (RFC 6020 sec 9.2) |
| LY_TYPE_INT64 | 64-bit signed integer (RFC 6020 sec 9.2) |
| enum LY_VALUE_FORMAT |
All kinds of supported value formats and prefix mappings to modules.
| LIBYANG_API_DECL LY_ERR ly_pattern_compile | ( | const struct ly_ctx * | ctx, |
| const char * | pattern, | ||
| void ** | pat_comp | ||
| ) |
Compile an XML Schema regex pattern prior to matching.
| [in] | ctx | Optional context for storing errors. |
| [in] | pattern | Regular expression pattern to use. |
| [out] | pat_comp | Compiled pattern to be used by ly_pattern_match(). Free it using ly_pattern_free(). |
| LIBYANG_API_DECL void ly_pattern_free | ( | void * | pat_comp | ) |
Free a compiled XML Schema regex pattern.
| [in] | pat_comp | Compiled pattern to free. |
| LIBYANG_API_DECL LY_ERR ly_pattern_match | ( | const struct ly_ctx * | ctx, |
| const char * | pattern, | ||
| const char * | string, | ||
| uint32_t | str_len, | ||
| void ** | pat_comp | ||
| ) |
Check a string matches an XML Schema regex used in YANG.
| [in] | ctx | Optional context for storing errors. |
| [in] | pattern | Regular expression pattern to use. |
| [in] | string | String to match. |
| [in] | str_len | Length of string, may be 0 if string is 0-terminated. |
| [in,out] | pat_comp | Optional pointer to pattern code. If set and NULL, it is returned. If set and non-NULL, it is used directly for matching instead of compiling pattern. Free it using ly_pattern_free(). |
| 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.
| [in] | value | Valid string date-and-time value, the string may continue after the value (be longer). |
| [out] | time | UNIX timestamp. |
| [out] | fractions_s | Optional fractions of a second, set to NULL if none. |
| LIBYANG_API_DECL LY_ERR ly_time_str2ts | ( | const char * | value, |
| struct timespec * | ts | ||
| ) |
Convert date-and-time from string to timespec.
| [in] | value | Valid string date-and-time value, the string may continue after the value (be longer). |
| [out] | ts | Timespec. |
| 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.
| [in] | time | UNIX timestamp. |
| [in] | fractions_s | Fractions of a second, if any. |
| [out] | str | String date-and-time value in the local timezone. |
| LIBYANG_API_DECL LY_ERR ly_time_ts2str | ( | const struct timespec * | ts, |
| char ** | str | ||
| ) |
Convert timespec into date-and-time string value.
| [in] | ts | Timespec. |
| [out] | str | String date-and-time value in the local timezone. |
| LIBYANG_API_DECL int ly_time_tz_offset | ( | void | ) |
Get current timezone (including DST setting) UTC (GMT) time offset in seconds.
| LIBYANG_API_DECL int ly_time_tz_offset_at | ( | time_t | time | ) |
Get UTC (GMT) timezone offset in seconds at a specific timestamp (including DST setting).
| [in] | time | Timestamp to get the offset at. |
|
extern |
Stringfield YANG built-in data types.