28 #include "ly_common.h"
29 #include "plugins_internal.h"
51 identityref_ident2str(
const struct lysc_ident *ident,
LY_VALUE_FORMAT format,
void *prefix_data,
char **str,
size_t *str_len)
60 len = asprintf(str,
"%s:%s", prefix, ident->
name);
62 len = asprintf(str,
"%s", ident->
name);
69 *str_len = (size_t)len;
88 identityref_str2ident(
const char *value,
size_t value_len,
LY_VALUE_FORMAT format,
void *prefix_data,
91 const char *id_name, *prefix = value;
92 size_t id_len, prefix_len;
98 for (prefix_len = 0; (prefix_len < value_len) && (value[prefix_len] !=
':'); ++prefix_len) {}
99 if (prefix_len < value_len) {
100 id_name = &value[prefix_len + 1];
101 id_len = value_len - (prefix_len + 1);
115 "Invalid identityref \"%.*s\" value - unable to map prefix to YANG schema.", (
int)value_len, value);
121 if (!ly_strncmp(identities[u].
name, id_name, id_len)) {
130 "Invalid identityref \"%.*s\" value - identity not found in module \"%s\".",
131 (
int)value_len, value, mod->
name);
170 base = type->
bases[u];
171 str_len += (u ? 2 : 0) + 1 + strlen(base->
module->
name) + 1 + strlen(base->
name) + 1;
173 sprintf(str + (u ? strlen(str) : 0),
"%s\"%s:%s\"", u ?
", " :
"", base->
module->
name, base->
name);
179 "Invalid identityref \"%.*s\" value - identity not derived from the base %s.",
180 (
int)value_len, value, str);
183 "Invalid identityref \"%.*s\" value - identity not derived from all the bases %s.",
184 (
int)value_len, value, str);
209 identityref_check_ident(
const struct lysc_ident *ident,
const char *value,
210 size_t value_len, uint32_t options,
struct lys_glob_unres *unres,
struct ly_err_item **err)
219 "Invalid identityref \"%.*s\" value - identity found in non-implemented module \"%s\".",
220 (
int)value_len, (
char *)value, ident->
module->
name);
224 "Invalid identityref \"%.*s\" value - identity is disabled by if-feature.",
225 (
int)value_len, value);
242 memset(storage, 0,
sizeof *storage);
247 LY_CHECK_GOTO(ret, cleanup);
250 ret = identityref_str2ident(value, value_len, format, prefix_data, ctx, ctx_node, &ident, err);
251 LY_CHECK_GOTO(ret, cleanup);
254 ret = identityref_check_ident(ident, value, value_len, options, unres, err);
255 LY_CHECK_GOTO(ret, cleanup);
258 ret = identityref_check_base(ident, type_ident, value, value_len, err);
259 LY_CHECK_GOTO(ret, cleanup);
264 LY_CHECK_GOTO(ret, cleanup);
268 storage->ident = ident;
274 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
275 LY_CHECK_GOTO(ret, cleanup);
278 LY_CHECK_GOTO(ret, cleanup);
282 if (asprintf(&canon,
"%s:%s", ident->
module->
name, ident->
name) == -1) {
289 LY_CHECK_GOTO(ret, cleanup);
307 if (val1->ident == val2->ident) {
317 return strcmp(val1->ident->name, val2->ident->name);
320 LIBYANG_API_DEF
const void *
322 void *prefix_data,
ly_bool *dynamic,
size_t *value_len)
337 if (identityref_ident2str(value->ident, format, prefix_data, &ret, value_len)) {
355 .name = LY_TYPE_IDENT_STR,
357 .plugin.id =
"libyang 2 - identityref, version 1",
359 .plugin.validate = NULL,
365 .plugin.lyb_data_len = -1,
struct lysc_type * realtype
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
LIBYANG_API_DECL struct lys_module * lyplg_type_identity_module(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *prefix, size_t prefix_len, LY_VALUE_FORMAT format, const void *prefix_data)
Get the corresponding module for the identity value.
uint8_t ly_bool
Type to indicate boolean value.
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...
struct lys_module * module
struct lysc_ident * identities
LIBYANG_API_DEF int lyplg_type_sort_identityref(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_sort_clb for the built-in identityref type.
#define LYPLG_TYPE_STORE_DYNAMIC
struct lyplg_type_record plugins_identityref[]
Plugin information for identityref type implementation.
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 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.
The main libyang public header.
YANG data representation.
Libyang full error structure.
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.
LIBYANG_API_DECL const void * lyplg_type_print_identityref(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 identityref type.
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.
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...
Available YANG schema tree structures representing YANG module.
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 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.
#define LY_ARRAY_COUNT(ARRAY)
Get the number of records in the ARRAY.
void * ly_realloc(void *ptr, size_t size)
Wrapper for realloc() call. The only difference is that if it fails to allocate the requested memory...
#define LY_ARRAY_FOR(ARRAY,...)
Sized-array iterator (for-loop).
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
LIBYANG_API_DECL LY_ERR lyplg_type_store_identityref(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 identityref type.
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.
#define LYPLG_TYPE_STORE_IMPLEMENT
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
struct lysc_ident ** bases
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.
API for (user) types plugins.
LY_ERR
libyang's error codes returned by the libyang functions.
LIBYANG_API_DECL LY_ERR lyplg_type_compare_identityref(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for the built-in identityref type.