44 struct lyxp_expr *
exp;
67 xpath10_print_token(
const char *token, uint16_t tok_len,
ly_bool is_nametest,
const struct ly_ctx *resolve_ctx,
69 void *get_prefix_data,
const char **prev_prefix,
char **token_p,
struct ly_err_item **err)
72 const char *str_begin, *str_next, *prefix;
82 while (!(ret = ly_value_prefix_next(str_begin, token + tok_len, &len, &is_prefix, &str_next)) && len) {
100 mem = realloc(str, str_len + strlen(
prefix) + 2);
103 sprintf(str + str_len,
"%s:",
prefix);
104 str_len += strlen(
prefix) + 1;
110 }
else if (is_nametest && (get_format ==
LY_VALUE_XML) && (len == tok_len) && *prev_prefix) {
112 mem = realloc(str, str_len + strlen(*prev_prefix) + 1 + len + 1);
115 sprintf(str + str_len,
"%s:%.*s", *prev_prefix, len, str_begin);
116 str_len += strlen(*prev_prefix) + 1 + len;
119 mem = realloc(str, str_len + len + 1);
122 sprintf(str + str_len,
"%.*s", len, str_begin);
126 str_begin = str_next;
153 char *str = NULL, *token;
155 const char *str_exp_ptr = xp_val->
exp->expr, *cur_exp_ptr, *prev_prefix = NULL;
156 uint32_t str_len = 0, len;
160 for (idx = 0; idx < xp_val->
exp->used; ++idx) {
161 cur_exp_ptr = xp_val->
exp->expr + xp_val->
exp->tok_pos[idx];
164 if ((xp_val->
exp->tokens[idx] == LYXP_TOKEN_NAMETEST) || (xp_val->
exp->tokens[idx] == LYXP_TOKEN_LITERAL)) {
166 len = cur_exp_ptr - str_exp_ptr;
167 mem = realloc(str, str_len + len + 1);
170 sprintf(str + str_len,
"%.*s", len, str_exp_ptr);
172 str_exp_ptr = cur_exp_ptr;
175 is_nt = (xp_val->
exp->tokens[idx] == LYXP_TOKEN_NAMETEST) ? 1 : 0;
176 ret = xpath10_print_token(cur_exp_ptr, xp_val->
exp->tok_len[idx], is_nt, xp_val->
ctx, xp_val->
format,
177 xp_val->
prefix_data, format, prefix_data, &prev_prefix, &token, err);
178 LY_CHECK_GOTO(ret, cleanup);
181 mem = realloc(str, str_len + strlen(token) + 1);
184 sprintf(str + str_len,
"%s", token);
185 str_len += strlen(token);
186 str_exp_ptr += xp_val->
exp->tok_len[idx];
192 if (str_exp_ptr[0]) {
193 mem = realloc(str, str_len + strlen(str_exp_ptr) + 1);
196 sprintf(str + str_len,
"%s", str_exp_ptr);
210 uint32_t options,
LY_VALUE_FORMAT format,
void *prefix_data, uint32_t hints,
211 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
220 memset(storage, 0,
sizeof *storage);
222 LY_CHECK_ERR_GOTO(!val, ret =
LY_EMEM, cleanup);
227 LY_CHECK_GOTO(ret, cleanup);
233 LY_CHECK_GOTO(ret, cleanup);
238 LY_CHECK_GOTO(ret, cleanup);
242 LY_CHECK_GOTO(ret, cleanup);
246 ret = lyxp_expr_parse(
ctx, value, value_len, 1, &val->
exp);
247 LY_CHECK_GOTO(ret, cleanup);
254 LY_CHECK_GOTO(ret, cleanup);
257 LY_CHECK_GOTO(ret, cleanup);
261 ret = xpath10_print_value(val,
LY_VALUE_JSON, NULL, &canon, err);
262 LY_CHECK_GOTO(ret, cleanup);
265 LY_CHECK_GOTO(ret, cleanup);
301 if (xpath10_print_value(val, format, prefix_data, &ret, &err)) {
303 LOGVAL_ERRITEM(ctx, err);
311 *value_len = strlen(ret);
323 memset(dup, 0,
sizeof *dup);
327 LY_CHECK_GOTO(ret, cleanup);
334 ret = lyxp_expr_dup(
ctx, orig_val->
exp, &dup_val->
exp);
335 LY_CHECK_GOTO(ret, cleanup);
338 LY_CHECK_GOTO(ret, cleanup);
356 lyxp_expr_free(
ctx, val->
exp);
372 .
module =
"ietf-yang-types",
373 .revision =
"2013-07-15",
376 .plugin.id =
"libyang 2 - xpath1.0, version 1",
378 .plugin.validate = NULL,
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 ...
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 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...
LY_ERR
libyang's error codes returned by the libyang functions.
Libyang full error structure.
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.
#define LYPLG_TYPE_VAL_INLINE_PREPARE(storage, type_val)
Prepare value memory for storing a specific type value, may be allocated dynamically.
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.
const 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.
#define LYPLG_TYPE_VAL_INLINE_DESTROY(type_val)
Destroy a prepared value.
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 ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *path, char *apptag, const char *err_msg,...)
Create and fill error structure.
void ly_err_free(void *ptr)
Destructor for the error records created with ly_err_new().
void lyplg_type_prefix_data_free(LY_VALUE_FORMAT format, void *prefix_data)
Free internal prefix data.
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.
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.
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.
API 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.
API 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.
API 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.
#define LYPLG_TYPE_STORE_DYNAMIC
struct lysc_pattern ** patterns
struct lysc_range * length
Available YANG schema tree structures representing YANG module.
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
The main libyang public header.
uint8_t ly_bool
Type to indicate boolean value.
API for (user) types plugins.
const struct lysc_type * realtype
#define LYD_VALUE_GET(value, type_val)
Get the value in format specific to the type.
YANG data representation.
API 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 *UNUSED(ctx_node), struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
const struct ly_ctx * ctx
const struct lyplg_type_record plugins_xpath10[]
Plugin information for xpath1.0 type implementation.
Stored value structure for xpath1.0.