27 #include "ly_common.h"
46 const char *str_begin, *str_next, *prefix;
47 ly_bool is_prefix, has_prefix = 0;
50 uint32_t len, str_len = 0, pref_len;
55 while (!(ret = ly_value_prefix_next(str_begin, token + tok_len, &len, &is_prefix, &str_next)) && len) {
57 if (!has_prefix && is_nametest && (get_format ==
LY_VALUE_XML) && *context_mod) {
63 mem = realloc(str, str_len + strlen(prefix) + 1 + len + 1);
66 str_len += sprintf(str + str_len,
"%s:%.*s", prefix, (
int)len, str_begin);
70 mem = realloc(str, str_len + len + 1);
73 str_len += sprintf(str + str_len,
"%.*s", (
int)len, str_begin);
81 if (!mod && is_nametest) {
94 pref_len = strlen(prefix);
102 mem = realloc(str, str_len + pref_len + 2);
105 str_len += sprintf(str + str_len,
"%.*s:", (
int)pref_len, prefix);
114 str_begin = str_next;
142 xpath10_print_subexpr_r(uint16_t *cur_idx,
enum lyxp_token end_tok,
const struct lys_module *context_mod,
146 enum lyxp_token cur_tok, sub_end_tok;
149 const char *cur_exp_ptr;
151 const struct lys_module *orig_context_mod = context_mod;
153 while (*cur_idx < xp_val->exp->used) {
154 cur_tok = xp_val->
exp->tokens[*cur_idx];
155 cur_exp_ptr = xp_val->
exp->expr + xp_val->
exp->tok_pos[*cur_idx];
157 if ((cur_tok == LYXP_TOKEN_NAMETEST) || (cur_tok == LYXP_TOKEN_LITERAL)) {
159 is_nt = (cur_tok == LYXP_TOKEN_NAMETEST) ? 1 : 0;
164 mem = realloc(*str_value, *str_len + strlen(str_tok) + 1);
165 LY_CHECK_ERR_GOTO(!mem, free(str_tok), error_mem);
167 *str_len += sprintf(*str_value + *str_len,
"%s", str_tok);
173 if ((cur_tok == LYXP_TOKEN_OPER_LOG) || (cur_tok == LYXP_TOKEN_OPER_UNI) || (cur_tok == LYXP_TOKEN_OPER_MATH)) {
175 mem = realloc(*str_value, *str_len + 1 + xp_val->
exp->tok_len[*cur_idx] + 2);
176 LY_CHECK_GOTO(!mem, error_mem);
178 *str_len += sprintf(*str_value + *str_len,
" %.*s ", (
int)xp_val->
exp->tok_len[*cur_idx], cur_exp_ptr);
181 context_mod = orig_context_mod;
184 mem = realloc(*str_value, *str_len + xp_val->
exp->tok_len[*cur_idx] + 1);
185 LY_CHECK_GOTO(!mem, error_mem);
187 *str_len += sprintf(*str_value + *str_len,
"%.*s", (
int)xp_val->
exp->tok_len[*cur_idx], cur_exp_ptr);
193 if (end_tok && (cur_tok == end_tok)) {
196 }
else if ((cur_tok == LYXP_TOKEN_BRACK1) || (cur_tok == LYXP_TOKEN_PAR1)) {
197 sub_end_tok = (cur_tok == LYXP_TOKEN_BRACK1) ? LYXP_TOKEN_BRACK2 : LYXP_TOKEN_PAR2;
200 LY_CHECK_RET(xpath10_print_subexpr_r(cur_idx, sub_end_tok, context_mod, xp_val, format, prefix_data,
201 str_value, str_len, err));
217 uint16_t expr_idx = 0;
218 uint32_t str_len = 0;
228 local_mod = mods->objs[0];
229 mods->objs[0] = NULL;
233 ret = xpath10_print_subexpr_r(&expr_idx, 0, NULL, xp_val, format, prefix_data, str_value, &str_len, err);
236 mods->objs[0] = (
void *)local_mod;
255 memset(storage, 0,
sizeof *storage);
257 LY_CHECK_ERR_GOTO(!val, ret =
LY_EMEM, cleanup);
262 LY_CHECK_GOTO(ret, cleanup);
265 ret = lyxp_expr_parse(ctx, value_len ? value :
"", value_len, 1, &val->
exp);
266 LY_CHECK_GOTO(ret, cleanup);
269 if (ctx_node && !strcmp(ctx_node->
name,
"parent-reference") && !strcmp(ctx_node->
module->
name,
"ietf-yang-schema-mount")) {
273 LY_CHECK_GOTO(ret, cleanup);
277 LY_CHECK_GOTO(ret, cleanup);
288 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
289 LY_CHECK_GOTO(ret, cleanup);
292 LY_CHECK_GOTO(ret, cleanup);
300 LY_CHECK_GOTO(ret, cleanup);
303 LY_CHECK_GOTO(ret, cleanup);
330 xpath10_add_ns(
struct ly_set *set,
const char *pref,
const char *uri)
333 struct lyxml_ns *ns = NULL;
336 ns = calloc(1,
sizeof *ns);
341 ns->prefix = strdup(pref);
342 ns->uri = strdup(uri);
343 if (!ns->prefix || !ns->uri) {
368 lyplg_type_validate_xpath10(
const struct ly_ctx *UNUSED(ctx),
const struct lysc_type *UNUSED(type),
374 struct ly_set *set = NULL;
376 const char *pref, *uri;
395 if ((ret =
lyd_find_xpath(ctx_node,
"../../../namespace", &set))) {
399 for (i = 0; i < set->
count; ++i) {
401 pref = lyd_get_value(lyd_child(set->dnodes[i]));
403 if (!lyd_child(set->dnodes[i])->next) {
407 assert(!strcmp(
LYD_NAME(lyd_child(set->dnodes[i])->next),
"uri"));
408 uri = lyd_get_value(lyd_child(set->dnodes[i])->next);
411 if ((ret = xpath10_add_ns(val->
prefix_data, pref, uri))) {
427 LIBYANG_API_DEF
const void *
429 void *prefix_data,
ly_bool *dynamic,
size_t *value_len)
461 *value_len = strlen(ret);
473 memset(dup, 0,
sizeof *dup);
477 LY_CHECK_GOTO(ret, cleanup);
480 LY_CHECK_ERR_GOTO(!dup_val,
LOGMEM(ctx); ret =
LY_EMEM, cleanup);
484 ret = lyxp_expr_dup(ctx, orig_val->
exp, 0, 0, &dup_val->
exp);
485 LY_CHECK_GOTO(ret, cleanup);
488 LY_CHECK_GOTO(ret, cleanup);
507 lyxp_expr_free(ctx, val->
exp);
523 .
module =
"ietf-yang-types",
524 .revision =
"2013-07-15",
527 .plugin.id =
"libyang 2 - xpath1.0, version 1",
529 .plugin.validate = lyplg_type_validate_xpath10,
535 .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 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 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.
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.
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.
LYPLG_TYPE_VAL_INLINE_DESTROY(val)
The main libyang public header.
YANG data representation.
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.
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.
#define LYD_NAME(node)
Get the name (associated with) of a data node. Works for opaque nodes as well.
LIBYANG_API_DECL void ly_err_print(const struct ly_ctx *ctx, const struct ly_err_item *eitem)
Print the error structure as if just generated.
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.
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.
LIBYANG_API_DECL LY_ERR ly_set_new(struct ly_set **set_p)
Create and initiate new ly_set structure.
API for (user) types plugins.
LY_ERR
libyang's error codes returned by the libyang functions.
assert(!value->_canonical)