25 #include "ly_common.h"
27 #include "plugins_internal.h"
64 uint32_t cur_idx = 0, str_len = 0;
65 enum lyxp_token cur_tok;
68 const char *cur_exp_ptr;
70 const struct lys_module *context_mod = NULL, *local_mod = NULL;
78 local_mod = mods->objs[0];
82 while (cur_idx < val->keys->used) {
83 cur_tok = val->
keys->tokens[cur_idx];
84 cur_exp_ptr = val->
keys->expr + val->
keys->tok_pos[cur_idx];
86 if ((cur_tok == LYXP_TOKEN_NAMETEST) || (cur_tok == LYXP_TOKEN_LITERAL)) {
88 is_nt = (cur_tok == LYXP_TOKEN_NAMETEST) ? 1 : 0;
93 mem = realloc(*str_value, str_len + strlen(str_tok) + 1);
100 str_len += sprintf(*str_value + str_len,
"%s", str_tok);
107 mem = realloc(*str_value, str_len + val->
keys->tok_len[cur_idx] + 1);
113 str_len += sprintf(*str_value + str_len,
"%.*s", (
int)val->
keys->tok_len[cur_idx], cur_exp_ptr);
122 mods->objs[0] = (
void *)local_mod;
135 lyplg_type_store_instanceid_keys(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value,
size_t value_len,
136 uint32_t options,
LY_VALUE_FORMAT format,
void *prefix_data, uint32_t hints,
const struct lysc_node *UNUSED(ctx_node),
147 memset(storage, 0,
sizeof *storage);
149 LY_CHECK_ERR_GOTO(!val, ret =
LY_EMEM, cleanup);
154 LY_CHECK_GOTO(ret, cleanup);
160 LY_CHECK_GOTO(ret, cleanup);
165 LY_CHECK_GOTO(ret, cleanup);
168 if (value_len && (((
char *)value)[0] !=
'[')) {
176 ret = ly_path_parse_predicate(ctx, NULL, value_len ? value :
"", value_len, LY_PATH_PREFIX_OPTIONAL,
177 LY_PATH_PRED_KEYS, &val->
keys);
189 LY_CHECK_GOTO(ret, cleanup);
199 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
200 LY_CHECK_GOTO(ret, cleanup);
203 LY_CHECK_GOTO(ret, cleanup);
210 ret = instanceid_keys_print_value(val,
LY_VALUE_JSON, NULL, &canon, err);
211 LY_CHECK_GOTO(ret, cleanup);
214 LY_CHECK_GOTO(ret, cleanup);
219 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
240 .name =
"instance-identifier-keys",
242 .plugin.id =
"libyang 2 - instance-identifier-keys, version 1",
243 .plugin.store = lyplg_type_store_instanceid_keys,
244 .plugin.validate = NULL,
250 .plugin.lyb_data_len = -1,
struct lysc_type * realtype
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
LIBYANG_API_DEF LY_ERR lyplg_type_xpath10_print_token(const char *token, uint16_t tok_len, ly_bool is_nametest, const struct lys_module **context_mod, const struct ly_ctx *resolve_ctx, LY_VALUE_FORMAT resolve_format, const void *resolve_prefix_data, LY_VALUE_FORMAT get_format, void *get_prefix_data, char **token_p, struct ly_err_item **err)
Print xpath1.0 token in the specific format.
LIBYANG_API_DECL uint32_t * ly_temp_log_options(uint32_t *opts)
Set temporary thread-safe logger options overwriting those set by ly_log_options().
LIBYANG_API_DECL LY_ERR lyplg_type_compare_simple(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for a generic simple type.
uint8_t ly_bool
Type to indicate boolean value.
#define LYPLG_TYPE_STORE_DYNAMIC
LIBYANG_API_DEF int lyplg_type_sort_simple(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_sort_clb for a generic simple type.
The main libyang public header.
struct lysc_pattern ** patterns
struct lysc_range * length
YANG data representation.
LIBYANG_API_DECL LY_ERR lyplg_type_validate_patterns(struct lysc_pattern **patterns, const char *str, size_t str_len, struct ly_err_item **err)
Data type validator for pattern-restricted string values.
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 LY_ERR lyplg_type_prefix_data_new(const struct ly_ctx *ctx, const void *value, size_t value_len, LY_VALUE_FORMAT format, const void *prefix_data, LY_VALUE_FORMAT *format_p, void **prefix_data_p)
Store used prefixes in a string into an internal libyang structure used in lyd_value.
Structure to hold a set of (not necessary somehow connected) objects. Usually used for lyd_node...
LIBYANG_API_DECL LY_ERR lyplg_type_dup_xpath10(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
Implementation of lyplg_type_dup_clb for the ietf-yang-types xpath1.0 type.
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_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.
LIBYANG_API_DECL const void * lyplg_type_print_xpath10(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 ietf-yang-types xpath1.0 type.
LIBYANG_API_DECL void ly_err_clean(struct ly_ctx *ctx, struct ly_err_item *eitem)
Free error structures from a context.
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.
LIBYANG_API_DECL void lyplg_type_free_xpath10(const struct ly_ctx *ctx, struct lyd_value *value)
Implementation of lyplg_type_free_clb for the ietf-yang-types xpath1.0 type.
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
LIBYANG_API_DECL struct ly_err_item * ly_err_last(const struct ly_ctx *ctx)
Get the latest (thread, context-specific) generated error structure.
#define LYPLG_TYPE_VAL_INLINE_PREPARE(storage, type_val)
Prepare value memory for storing a specific type value, may be allocated dynamically.
struct lyplg_type_record plugins_instanceid_keys[]
Plugin information for instance-identifier type implementation.
API for (user) types plugins.
Special lyd_value structure for yang instance-identifier-keys values.
LY_ERR
libyang's error codes returned by the libyang functions.
LIBYANG_API_DECL LY_ERR lyplg_type_validate_range(LY_DATA_TYPE basetype, struct lysc_range *range, int64_t value, const char *strval, size_t strval_len, struct ly_err_item **err)
Data type validator for a range/length-restricted values.