28#include "plugins_internal.h"
50identityref_ident2str(
const struct lysc_ident *ident,
LY_VALUE_FORMAT format,
void *prefix_data,
char **str, uint32_t *str_len)
59 len = asprintf(str,
"%s:%s", prefix, ident->
name);
61 len = asprintf(str,
"%s", ident->
name);
68 *str_len = (uint32_t)len;
87identityref_str2ident(
const char *value, uint32_t value_size,
LY_VALUE_FORMAT format,
void *prefix_data,
90 const char *id_name, *prefix = value;
91 uint32_t id_len, prefix_len;
97 for (prefix_len = 0; (prefix_len < value_size) && (value[prefix_len] !=
':'); ++prefix_len) {}
98 if (prefix_len < value_size) {
99 id_name = &value[prefix_len + 1];
100 id_len = value_size - (prefix_len + 1);
111 mod =
lys_find_module(ctx, ctx_node, prefix, prefix_len, format, prefix_data);
114 "Invalid identityref \"%.*s\" value - unable to map prefix to YANG schema.", (
int)value_size, value);
120 if (!ly_strncmp(identities[u].
name, id_name, id_len)) {
129 "Invalid identityref \"%.*s\" value - identity not found in module \"%s\".",
130 (
int)value_size, value, mod->
name);
169 base = type->
bases[u];
170 str_len += (u ? 2 : 0) + 1 + strlen(base->module->
name) + 1 + strlen(base->
name) + 1;
171 str = ly_realloc(str, str_len);
172 sprintf(str + (u ? strlen(str) : 0),
"%s\"%s:%s\"", u ?
", " :
"", base->module->
name, base->
name);
178 "Invalid identityref \"%.*s\" value - identity not derived from the base %s.",
179 (
int)value_size, value, str);
182 "Invalid identityref \"%.*s\" value - identity not derived from all the bases %s.",
183 (
int)value_size, value, str);
208identityref_check_ident(
const struct lysc_ident *ident,
const char *value, uint32_t value_size, uint32_t options,
209 struct lys_glob_unres *unres,
struct ly_err_item **err)
213 if (!ident->module->implemented) {
218 "Invalid identityref \"%.*s\" value - identity found in non-implemented module \"%s\".",
219 (
int)value_size, (
char *)value, ident->module->
name);
223 "Invalid identityref \"%.*s\" value - identity is disabled by if-feature.",
224 (
int)value_size, value);
231lyplg_type_store_identityref(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value, uint64_t value_size_bits,
242 memset(storage, 0,
sizeof *storage);
248 LY_CHECK_GOTO(ret, cleanup);
252 LY_CHECK_GOTO(ret, cleanup);
255 ret = identityref_str2ident(value, value_size, format, prefix_data, ctx, ctx_node, &ident, err);
256 LY_CHECK_GOTO(ret, cleanup);
259 ret = identityref_check_ident(ident, value, value_size, options, unres, err);
260 LY_CHECK_GOTO(ret, cleanup);
263 ret = identityref_check_base(ident, type_ident, value, value_size, err);
264 LY_CHECK_GOTO(ret, cleanup);
269 LY_CHECK_GOTO(ret, cleanup);
273 storage->ident = ident;
279 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
280 LY_CHECK_GOTO(ret, cleanup);
283 LY_CHECK_GOTO(ret, cleanup);
287 if (asprintf(&canon,
"%s:%s", ident->module->
name, ident->
name) == -1) {
294 LY_CHECK_GOTO(ret, cleanup);
309lyplg_type_compare_identityref(
const struct ly_ctx *UNUSED(ctx),
const struct lyd_value *val1,
312 if (val1->ident == val2->ident) {
319lyplg_type_sort_identityref(
const struct ly_ctx *UNUSED(ctx),
const struct lyd_value *val1,
322 return strcmp(val1->ident->name, val2->ident->name);
327 void *prefix_data,
ly_bool *dynamic, uint64_t *value_size_bits)
336 if (value_size_bits) {
337 *value_size_bits = strlen(value->
_canonical) * 8;
343 if (identityref_ident2str(value->ident, format, prefix_data, &ret, &value_size)) {
347 if (value_size_bits) {
348 *value_size_bits = value_size * 8;
365 .name = LY_TYPE_IDENT_STR,
367 .plugin.id =
"ly2 identityref",
369 .plugin.store = lyplg_type_store_identityref,
370 .plugin.validate_value = NULL,
371 .plugin.validate_tree = NULL,
372 .plugin.compare = lyplg_type_compare_identityref,
373 .plugin.sort = lyplg_type_sort_identityref,
374 .plugin.print = lyplg_type_print_identityref,
#define LYA_COUNT(ARRAY)
Get the number of records in the ARRAY.
#define LYA_FOR(ARRAY, INDEX)
Helper macro to go through sized-arrays with a numeric iterator.
#define LYA_COUNT_T
Type (i.e. size) of the sized array's size counter.
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_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,...
LY_ERR
libyang's error codes returned by the libyang functions.
Libyang full error structure.
const char *const char * revision
LIBYANG_API_DECL LY_ERR lyplg_type_make_implemented(struct lys_module *mod, const char **features, struct lys_glob_unres *unres)
Implement a module (just like lys_set_implemented()), but keep maintaining unresolved items.
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_check_status(const struct lysc_node *ctx_node, uint16_t val_flags, LY_VALUE_FORMAT format, void *prefix_data, const char *val_name, struct ly_err_item **err)
Check that the value of a type is allowed based on its status.
LIBYANG_API_DECL LY_ERR lyplg_type_identity_isderived(const struct lysc_ident *base, const struct lysc_ident *derived)
Decide if the derived identity is derived from (based on) the base identity.
LIBYANG_API_DECL const char * lyplg_type_get_prefix(const struct lys_module *mod, LY_VALUE_FORMAT format, void *prefix_data)
Get format-specific prefix for a module.
LIBYANG_API_DECL LY_ERR lyplg_type_check_value_size(const char *type_name, LY_VALUE_FORMAT format, uint64_t value_size_bits, enum lyplg_lyb_size_type lyb_size_type, uint64_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.
@ LYPLG_LYB_SIZE_VARIABLE_BYTES
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 void lyplg_type_lyb_size_variable_bytes(const struct lysc_type *type, enum lyplg_lyb_size_type *size_type, uint64_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_IMPLEMENT
struct lysc_ident * identities
struct lysc_ident ** bases
LIBYANG_API_DECL const struct lys_module * lys_find_module(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *prefix, uint32_t prefix_len, LY_VALUE_FORMAT format, const void *prefix_data)
Find a module matching a prefix (or a default one).
LIBYANG_API_DECL LY_ERR lys_identity_iffeature_value(const struct lysc_ident *ident)
Get how the if-feature statement is evaluated for certain identity.
Available YANG schema tree structures representing YANG module.
const struct lyplg_type_record plugins_identityref[]
Plugin information for identityref type implementation.
uint8_t ly_bool
Type to indicate boolean value.
API for (user) types plugins.
const struct lysc_type * realtype
YANG data representation.
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.