41 struct lyxp_expr *
exp;
64 xpath10_print_token(
const char *token, uint16_t tok_len,
ly_bool is_nametest,
const struct lys_module **context_mod,
69 const char *str_begin, *str_next, *prefix;
70 ly_bool is_prefix, has_prefix = 0;
73 uint32_t len, str_len = 0, pref_len;
78 while (!(ret = ly_value_prefix_next(str_begin, token + tok_len, &len, &is_prefix, &str_next)) && len) {
80 if (!has_prefix && is_nametest && (get_format ==
LY_VALUE_XML) && *context_mod) {
89 mem = realloc(str, str_len + strlen(prefix) + 1 + len + 1);
92 str_len += sprintf(str + str_len,
"%s:%.*s", prefix, len, str_begin);
96 mem = realloc(str, str_len + len + 1);
99 str_len += sprintf(str + str_len,
"%.*s", len, str_begin);
107 if (!mod && is_nametest) {
122 pref_len = strlen(prefix);
130 mem = realloc(str, str_len + pref_len + 2);
133 str_len += sprintf(str + str_len,
"%.*s:", (
int)pref_len, prefix);
142 str_begin = str_next;
170 xpath10_print_subexpr_r(uint16_t *cur_idx,
enum lyxp_token end_tok,
const struct lys_module *context_mod,
174 enum lyxp_token cur_tok, sub_end_tok;
177 const char *cur_exp_ptr;
179 const struct lys_module *orig_context_mod = context_mod;
181 while (*cur_idx < xp_val->exp->used) {
182 cur_tok = xp_val->
exp->tokens[*cur_idx];
183 cur_exp_ptr = xp_val->
exp->expr + xp_val->
exp->tok_pos[*cur_idx];
185 if ((cur_tok == LYXP_TOKEN_NAMETEST) || (cur_tok == LYXP_TOKEN_LITERAL)) {
187 is_nt = (cur_tok == LYXP_TOKEN_NAMETEST) ? 1 : 0;
188 LY_CHECK_RET(xpath10_print_token(cur_exp_ptr, xp_val->
exp->tok_len[*cur_idx], is_nt, &context_mod,
192 mem = realloc(*str_value, *str_len + strlen(str_tok) + 1);
193 LY_CHECK_ERR_GOTO(!mem, free(str_tok), error_mem);
195 *str_len += sprintf(*str_value + *str_len,
"%s", str_tok);
201 if ((cur_tok == LYXP_TOKEN_OPER_LOG) || (cur_tok == LYXP_TOKEN_OPER_UNI) || (cur_tok == LYXP_TOKEN_OPER_MATH)) {
203 mem = realloc(*str_value, *str_len + 1 + xp_val->
exp->tok_len[*cur_idx] + 2);
204 LY_CHECK_GOTO(!mem, error_mem);
206 *str_len += sprintf(*str_value + *str_len,
" %.*s ", (
int)xp_val->
exp->tok_len[*cur_idx], cur_exp_ptr);
209 context_mod = orig_context_mod;
212 mem = realloc(*str_value, *str_len + xp_val->
exp->tok_len[*cur_idx] + 1);
213 LY_CHECK_GOTO(!mem, error_mem);
215 *str_len += sprintf(*str_value + *str_len,
"%.*s", (
int)xp_val->
exp->tok_len[*cur_idx], cur_exp_ptr);
221 if (end_tok && (cur_tok == end_tok)) {
224 }
else if ((cur_tok == LYXP_TOKEN_BRACK1) || (cur_tok == LYXP_TOKEN_PAR1)) {
225 sub_end_tok = (cur_tok == LYXP_TOKEN_BRACK1) ? LYXP_TOKEN_BRACK2 : LYXP_TOKEN_PAR2;
228 LY_CHECK_RET(xpath10_print_subexpr_r(cur_idx, sub_end_tok, context_mod, xp_val, format, prefix_data,
229 str_value, str_len, err));
255 uint16_t expr_idx = 0;
256 uint32_t str_len = 0;
261 ret = xpath10_print_subexpr_r(&expr_idx, 0, NULL, xp_val, format, prefix_data, str_value, &str_len, err);
271 uint32_t options,
LY_VALUE_FORMAT format,
void *prefix_data, uint32_t hints,
272 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
281 memset(storage, 0,
sizeof *storage);
283 LY_CHECK_ERR_GOTO(!val, ret =
LY_EMEM, cleanup);
288 LY_CHECK_GOTO(ret, cleanup);
294 LY_CHECK_GOTO(ret, cleanup);
299 LY_CHECK_GOTO(ret, cleanup);
303 LY_CHECK_GOTO(ret, cleanup);
307 ret = lyxp_expr_parse(ctx, value, value_len, 1, &val->
exp);
308 LY_CHECK_GOTO(ret, cleanup);
314 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
315 LY_CHECK_GOTO(ret, cleanup);
318 LY_CHECK_GOTO(ret, cleanup);
322 ret = xpath10_print_value(val,
LY_VALUE_JSON, NULL, &canon, err);
323 LY_CHECK_GOTO(ret, cleanup);
326 LY_CHECK_GOTO(ret, cleanup);
342 void *prefix_data,
ly_bool *dynamic,
size_t *value_len)
362 if (xpath10_print_value(val, format, prefix_data, &ret, &err)) {
364 LOGVAL_ERRITEM(ctx, err);
372 *value_len = strlen(ret);
384 memset(dup, 0,
sizeof *dup);
388 LY_CHECK_GOTO(ret, cleanup);
391 LY_CHECK_ERR_GOTO(!dup_val,
LOGMEM(ctx); ret =
LY_EMEM, cleanup);
395 ret = lyxp_expr_dup(ctx, orig_val->
exp, &dup_val->
exp);
396 LY_CHECK_GOTO(ret, cleanup);
399 LY_CHECK_GOTO(ret, cleanup);
418 lyxp_expr_free(ctx, val->
exp);
434 .
module =
"ietf-yang-types",
435 .revision =
"2013-07-15",
438 .plugin.id =
"libyang 2 - xpath1.0, version 1",
440 .plugin.validate = NULL,
446 .plugin.lyb_data_len = -1,
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.
struct lysc_type * realtype
LY_ERR ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *path, char *apptag, const char *err_format,...) _FORMAT_PRINTF(6
Create and fill error structure.
LY_ERR lyplg_type_store_xpath10(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 ietf-yang-types xpath1.0 type.
uint8_t ly_bool
Type to indicate boolean value.
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 ...
#define LYPLG_TYPE_STORE_DYNAMIC
LY_ERR void ly_err_free(void *ptr)
Destructor for the error records created with ly_err_new().
LY_ERR lyplg_type_prefix_data_dup(const struct ly_ctx *ctx, LY_VALUE_FORMAT format, const void *orig, void **dup)
Duplicate prefix data.
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...
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.
struct lysc_pattern ** patterns
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.
struct lysc_range * length
YANG data representation.
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 full error structure.
#define LYD_VALUE_GET(value, type_val)
Get the value in format specific to the type.
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.
struct lyplg_type_record plugins_xpath10[]
Plugin information for xpath1.0 type implementation.
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.
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.
Available YANG schema tree structures representing YANG module.
Stored value structure for xpath1.0.
LY_ERR lyplg_type_compare_simple(const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for a generic simple type.
#define LYPLG_TYPE_VAL_INLINE_DESTROY(type_val)
Destroy a prepared value.
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
void lyplg_type_prefix_data_free(LY_VALUE_FORMAT format, void *prefix_data)
Free internal prefix data.
#define LYPLG_TYPE_VAL_INLINE_PREPARE(storage, type_val)
Prepare value memory for storing a specific type value, may be allocated dynamically.
LY_ERR
libyang's error codes returned by the libyang functions.
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.
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.
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.
API for (user) types plugins.