48 const char *str_begin, *str_next, *prefix;
49 ly_bool is_prefix, has_prefix = 0;
52 uint32_t len, str_len = 0, pref_len;
57 while (!(ret = ly_value_prefix_next(str_begin, token + tok_len, &len, &is_prefix, &str_next)) && len) {
59 if (!has_prefix && is_nametest && (get_format ==
LY_VALUE_XML) && *context_mod) {
65 mem = realloc(str, str_len + strlen(prefix) + 1 + len + 1);
68 str_len += sprintf(str + str_len,
"%s:%.*s", prefix, len, str_begin);
72 mem = realloc(str, str_len + len + 1);
75 str_len += sprintf(str + str_len,
"%.*s", len, str_begin);
83 if (!mod && is_nametest) {
95 pref_len = strlen(prefix);
103 mem = realloc(str, str_len + pref_len + 2);
106 str_len += sprintf(str + str_len,
"%.*s:", (
int)pref_len, prefix);
115 str_begin = str_next;
143 xpath10_print_subexpr_r(uint16_t *cur_idx,
enum lyxp_token end_tok,
const struct lys_module *context_mod,
147 enum lyxp_token cur_tok, sub_end_tok;
150 const char *cur_exp_ptr;
152 const struct lys_module *orig_context_mod = context_mod;
154 while (*cur_idx < xp_val->exp->used) {
155 cur_tok = xp_val->
exp->tokens[*cur_idx];
156 cur_exp_ptr = xp_val->
exp->expr + xp_val->
exp->tok_pos[*cur_idx];
158 if ((cur_tok == LYXP_TOKEN_NAMETEST) || (cur_tok == LYXP_TOKEN_LITERAL)) {
160 is_nt = (cur_tok == LYXP_TOKEN_NAMETEST) ? 1 : 0;
165 mem = realloc(*str_value, *str_len + strlen(str_tok) + 1);
166 LY_CHECK_ERR_GOTO(!mem, free(str_tok), error_mem);
168 *str_len += sprintf(*str_value + *str_len,
"%s", str_tok);
174 if ((cur_tok == LYXP_TOKEN_OPER_LOG) || (cur_tok == LYXP_TOKEN_OPER_UNI) || (cur_tok == LYXP_TOKEN_OPER_MATH)) {
176 mem = realloc(*str_value, *str_len + 1 + xp_val->
exp->tok_len[*cur_idx] + 2);
177 LY_CHECK_GOTO(!mem, error_mem);
179 *str_len += sprintf(*str_value + *str_len,
" %.*s ", (
int)xp_val->
exp->tok_len[*cur_idx], cur_exp_ptr);
182 context_mod = orig_context_mod;
185 mem = realloc(*str_value, *str_len + xp_val->
exp->tok_len[*cur_idx] + 1);
186 LY_CHECK_GOTO(!mem, error_mem);
188 *str_len += sprintf(*str_value + *str_len,
"%.*s", (
int)xp_val->
exp->tok_len[*cur_idx], cur_exp_ptr);
194 if (end_tok && (cur_tok == end_tok)) {
197 }
else if ((cur_tok == LYXP_TOKEN_BRACK1) || (cur_tok == LYXP_TOKEN_PAR1)) {
198 sub_end_tok = (cur_tok == LYXP_TOKEN_BRACK1) ? LYXP_TOKEN_BRACK2 : LYXP_TOKEN_PAR2;
201 LY_CHECK_RET(xpath10_print_subexpr_r(cur_idx, sub_end_tok, context_mod, xp_val, format, prefix_data,
202 str_value, str_len, err));
218 uint16_t expr_idx = 0;
219 uint32_t str_len = 0;
229 local_mod = mods->objs[0];
230 mods->objs[0] = NULL;
234 ret = xpath10_print_subexpr_r(&expr_idx, 0, NULL, xp_val, format, prefix_data, str_value, &str_len, err);
237 mods->objs[0] = (
void *)local_mod;
257 memset(storage, 0,
sizeof *storage);
259 LY_CHECK_ERR_GOTO(!val, ret =
LY_EMEM, cleanup);
264 LY_CHECK_GOTO(ret, cleanup);
270 LY_CHECK_GOTO(ret, cleanup);
275 LY_CHECK_GOTO(ret, cleanup);
278 ret = lyxp_expr_parse(ctx, value_len ? value :
"", value_len, 1, &val->
exp);
279 LY_CHECK_GOTO(ret, cleanup);
282 if (ctx_node && !strcmp(ctx_node->
name,
"parent-reference") && !strcmp(ctx_node->
module->
name,
"ietf-yang-schema-mount")) {
286 LY_CHECK_GOTO(ret, cleanup);
290 LY_CHECK_GOTO(ret, cleanup);
301 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
302 LY_CHECK_GOTO(ret, cleanup);
305 LY_CHECK_GOTO(ret, cleanup);
313 LY_CHECK_GOTO(ret, cleanup);
316 LY_CHECK_GOTO(ret, cleanup);
343 xpath10_add_ns(
struct ly_set *set,
const char *pref,
const char *uri)
346 struct lyxml_ns *ns = NULL;
349 ns = calloc(1,
sizeof *ns);
354 ns->prefix = strdup(pref);
355 ns->uri = strdup(uri);
356 if (!ns->prefix || !ns->uri) {
381 lyplg_type_validate_xpath10(
const struct ly_ctx *UNUSED(ctx),
const struct lysc_type *UNUSED(type),
387 struct ly_set *set = NULL;
389 const char *pref, *uri;
403 assert(!strcmp(
LYD_NAME(ctx_node),
"parent-reference") &&
407 if ((ret =
lyd_find_xpath(ctx_node,
"../../../namespace", &set))) {
411 for (i = 0; i < set->
count; ++i) {
412 assert(!strcmp(
LYD_NAME(lyd_child(set->dnodes[i])),
"prefix"));
413 pref = lyd_get_value(lyd_child(set->dnodes[i]));
415 if (!lyd_child(set->dnodes[i])->next) {
419 assert(!strcmp(
LYD_NAME(lyd_child(set->dnodes[i])->next),
"uri"));
420 uri = lyd_get_value(lyd_child(set->dnodes[i])->next);
423 if ((ret = xpath10_add_ns(val->
prefix_data, pref, uri))) {
438 LIBYANG_API_DEF
const void *
440 void *prefix_data,
ly_bool *dynamic,
size_t *value_len)
464 LOGVAL_ERRITEM(ctx, err);
472 *value_len = strlen(ret);
484 memset(dup, 0,
sizeof *dup);
488 LY_CHECK_GOTO(ret, cleanup);
491 LY_CHECK_ERR_GOTO(!dup_val,
LOGMEM(ctx); ret =
LY_EMEM, cleanup);
495 ret = lyxp_expr_dup(ctx, orig_val->
exp, 0, 0, &dup_val->
exp);
496 LY_CHECK_GOTO(ret, cleanup);
499 LY_CHECK_GOTO(ret, cleanup);
518 lyxp_expr_free(ctx, val->
exp);
534 .
module =
"ietf-yang-types",
535 .revision =
"2013-07-15",
538 .plugin.id =
"libyang 2 - xpath1.0, version 1",
540 .plugin.validate = lyplg_type_validate_xpath10,
546 .plugin.lyb_data_len = -1,
struct lysc_type * realtype
LIBYANG_API_DECL 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.
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 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.
Generic structure for a data node.
LIBYANG_API_DECL LY_ERR lyd_find_xpath(const struct lyd_node *ctx_node, const char *xpath, struct ly_set **set)
Search in the given data for instances of nodes matching the provided XPath.
LIBYANG_API_DECL 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.
LIBYANG_API_DECL 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.
LIBYANG_API_DECL const char * ly_errmsg(const struct ly_ctx *ctx)
Get the last (thread, context-specific) error message. If the coresponding module defined a specific ...
#define LYPLG_TYPE_STORE_DYNAMIC
LIBYANG_API_DECL LY_ERR ly_set_add(struct ly_set *set, const void *object, ly_bool list, uint32_t *index_p)
Add an object into the set.
LIBYANG_API_DECL void ly_set_free(struct ly_set *set, void(*destructor)(void *obj))
Free the ly_set data. If the destructor is not provided, it frees only the set structure content...
struct lysc_node * schema
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.
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.
#define LYD_VALUE_GET(value, type_val)
Get the value in format specific to the type.
LIBYANG_API_DECL LY_ERR LIBYANG_API_DECL void ly_err_free(void *ptr)
Destructor for the error records created with ly_err_new().
struct lyplg_type_record plugins_xpath10[]
Plugin information for xpath1.0 type implementation.
#define LYD_NAME(node)
Get the name (associated with) of a data node. Works for opaque nodes as well.
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_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 ...
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 LY_ERR lyplg_type_prefix_data_dup(const struct ly_ctx *ctx, LY_VALUE_FORMAT format, const void *orig, void **dup)
Duplicate prefix data.
LIBYANG_API_DECL void lyplg_type_prefix_data_free(LY_VALUE_FORMAT format, void *prefix_data)
Free internal prefix data.
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.
struct lys_module * module
Special lyd_value structure for ietf-yang-types xpath1.0 values.
#define LYD_CTX(node)
Macro to get context from a data tree node.
LIBYANG_API_DECL LY_ERR lyplg_type_print_xpath10_value(const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format, void *prefix_data, char **str_value, struct ly_err_item **err)
Print xpath1.0 value in the specific format.
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.
#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.
#define LYPLG_TYPE_VAL_INLINE_PREPARE(storage, type_val)
Prepare value memory for storing a specific type value, may be allocated dynamically.
LIBYANG_API_DECL LY_ERR ly_set_new(struct ly_set **set_p)
Create and initiate new ly_set structure.
LY_ERR
libyang's error codes returned by the libyang functions.
API for (user) types plugins.
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.