libyang  6.4.13
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
xpath1.0.c
Go to the documentation of this file.
1 
15 #define _GNU_SOURCE
16 
17 #include "plugins_types.h"
18 
19 #include <assert.h>
20 #include <stdint.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include "compat.h"
25 #include "dict.h"
26 #include "ly_common.h"
27 #include "xml.h"
28 #include "xpath.h"
29 
39 LIBYANG_API_DEF LY_ERR
40 lyplg_type_xpath10_print_token(const char *token, uint16_t tok_len, ly_bool is_nametest, const struct lys_module **context_mod,
41  const struct ly_ctx *resolve_ctx, LY_VALUE_FORMAT resolve_format, const void *resolve_prefix_data,
42  LY_VALUE_FORMAT get_format, void *get_prefix_data, char **token_p, struct ly_err_item **err)
43 {
44  LY_ERR ret = LY_SUCCESS;
45  const char *str_begin, *str_next, *prefix;
46  ly_bool is_prefix, has_prefix = 0;
47  char *str = NULL;
48  void *mem;
49  uint32_t len, str_len = 0, pref_len;
50  const struct lys_module *mod;
51 
52  str_begin = token;
53 
54  while (!(ret = ly_value_prefix_next(str_begin, token + tok_len, &len, &is_prefix, &str_next)) && len) {
55  if (!is_prefix) {
56  if (!has_prefix && is_nametest && (get_format == LY_VALUE_XML) && *context_mod) {
57  /* get the prefix */
58  prefix = lyplg_type_get_prefix(*context_mod, get_format, get_prefix_data);
59  assert(prefix);
60 
61  /* append the nametest and prefix */
62  mem = realloc(str, str_len + strlen(prefix) + 1 + len + 1);
63  LY_CHECK_ERR_GOTO(!mem, ret = ly_err_new_no_mem(err), cleanup);
64  str = mem;
65  str_len += sprintf(str + str_len, "%s:%.*s", prefix, (int)len, str_begin);
66  } else {
67  /* just append the string, we may get the first expression node without a prefix but since this
68  * is not strictly forbidden, allow it */
69  mem = realloc(str, str_len + len + 1);
70  LY_CHECK_ERR_GOTO(!mem, ret = ly_err_new_no_mem(err), cleanup);
71  str = mem;
72  str_len += sprintf(str + str_len, "%.*s", (int)len, str_begin);
73  }
74  } else {
75  /* remember there was a prefix found */
76  has_prefix = 1;
77 
78  /* resolve the module in the original format */
79  mod = lys_find_module(resolve_ctx, NULL, str_begin, len, resolve_format, resolve_prefix_data);
80  if (!mod && is_nametest) {
81  ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to resolve prefix \"%.*s\".",
82  (int)len, str_begin);
83  goto cleanup;
84  }
85 
86  if (is_nametest && ((get_format == LY_VALUE_JSON) || (get_format == LY_VALUE_LYB)) && (*context_mod == mod)) {
87  /* inherit the prefix and do not print it again */
88  } else {
89  if (mod) {
90  /* get the prefix in the target format */
91  prefix = lyplg_type_get_prefix(mod, get_format, get_prefix_data);
92  assert(prefix);
93  pref_len = strlen(prefix);
94  } else {
95  /* invalid prefix, just copy it */
96  prefix = str_begin;
97  pref_len = len;
98  }
99 
100  /* append the prefix */
101  mem = realloc(str, str_len + pref_len + 2);
102  LY_CHECK_ERR_GOTO(!mem, ret = ly_err_new_no_mem(err), cleanup);
103  str = mem;
104  str_len += sprintf(str + str_len, "%.*s:", (int)pref_len, prefix);
105  }
106 
107  if (is_nametest) {
108  /* update context module */
109  *context_mod = mod;
110  }
111  }
112 
113  str_begin = str_next;
114  }
115 
116 cleanup:
117  if (ret) {
118  free(str);
119  } else {
120  *token_p = str;
121  }
122  return ret;
123 }
124 
140 static LY_ERR
141 xpath10_print_subexpr_r(uint16_t *cur_idx, enum lyxp_token end_tok, const struct lys_module *context_mod,
142  const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format, void *prefix_data, char **str_value,
143  uint32_t *str_len, struct ly_err_item **err)
144 {
145  enum lyxp_token cur_tok, sub_end_tok;
146  char *str_tok;
147  void *mem;
148  const char *cur_exp_ptr;
149  ly_bool is_nt;
150  const struct lys_module *orig_context_mod = context_mod;
151 
152  while (*cur_idx < xp_val->exp->used) {
153  cur_tok = xp_val->exp->tokens[*cur_idx];
154  cur_exp_ptr = xp_val->exp->expr + xp_val->exp->tok_pos[*cur_idx];
155 
156  if ((cur_tok == LYXP_TOKEN_NAMETEST) || (cur_tok == LYXP_TOKEN_LITERAL)) {
157  /* tokens that may include prefixes, get them in the target format */
158  is_nt = (cur_tok == LYXP_TOKEN_NAMETEST) ? 1 : 0;
159  LY_CHECK_RET(lyplg_type_xpath10_print_token(cur_exp_ptr, xp_val->exp->tok_len[*cur_idx], is_nt, &context_mod,
160  xp_val->ctx, xp_val->format, xp_val->prefix_data, format, prefix_data, &str_tok, err));
161 
162  /* append the converted token */
163  mem = realloc(*str_value, *str_len + strlen(str_tok) + 1);
164  LY_CHECK_ERR_GOTO(!mem, free(str_tok), error_mem);
165  *str_value = mem;
166  *str_len += sprintf(*str_value + *str_len, "%s", str_tok);
167  free(str_tok);
168 
169  /* token processed */
170  ++(*cur_idx);
171  } else {
172  if ((cur_tok == LYXP_TOKEN_OPER_LOG) || (cur_tok == LYXP_TOKEN_OPER_UNI) || (cur_tok == LYXP_TOKEN_OPER_MATH)) {
173  /* copy the token with spaces around */
174  mem = realloc(*str_value, *str_len + 1 + xp_val->exp->tok_len[*cur_idx] + 2);
175  LY_CHECK_GOTO(!mem, error_mem);
176  *str_value = mem;
177  *str_len += sprintf(*str_value + *str_len, " %.*s ", (int)xp_val->exp->tok_len[*cur_idx], cur_exp_ptr);
178 
179  /* reset context mod */
180  context_mod = orig_context_mod;
181  } else {
182  /* just copy the token */
183  mem = realloc(*str_value, *str_len + xp_val->exp->tok_len[*cur_idx] + 1);
184  LY_CHECK_GOTO(!mem, error_mem);
185  *str_value = mem;
186  *str_len += sprintf(*str_value + *str_len, "%.*s", (int)xp_val->exp->tok_len[*cur_idx], cur_exp_ptr);
187  }
188 
189  /* token processed but keep it in cur_tok */
190  ++(*cur_idx);
191 
192  if (end_tok && (cur_tok == end_tok)) {
193  /* end token found */
194  break;
195  } else if ((cur_tok == LYXP_TOKEN_BRACK1) || (cur_tok == LYXP_TOKEN_PAR1)) {
196  sub_end_tok = (cur_tok == LYXP_TOKEN_BRACK1) ? LYXP_TOKEN_BRACK2 : LYXP_TOKEN_PAR2;
197 
198  /* parse the subexpression separately, use the current context mod */
199  LY_CHECK_RET(xpath10_print_subexpr_r(cur_idx, sub_end_tok, context_mod, xp_val, format, prefix_data,
200  str_value, str_len, err));
201  }
202  }
203  }
204 
205  return LY_SUCCESS;
206 
207 error_mem:
208  return ly_err_new_no_mem(err);
209 }
210 
211 LIBYANG_API_DEF LY_ERR
212 lyplg_type_print_xpath10_value(const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format, void *prefix_data,
213  char **str_value, struct ly_err_item **err)
214 {
215  LY_ERR ret = LY_SUCCESS;
216  uint16_t expr_idx = 0;
217  uint32_t str_len = 0;
218  const struct lys_module *local_mod = NULL;
219  struct ly_set *mods;
220 
221  *str_value = NULL;
222  *err = NULL;
223 
224  switch (format) {
225  case LY_VALUE_XML:
226  /* zero the local module so that all the prefixes are printed */
227  mods = prefix_data;
228  local_mod = mods->objs[0];
229  mods->objs[0] = NULL;
230  break;
231  case LY_VALUE_SCHEMA:
233  /* nothing to do */
234  break;
235  case LY_VALUE_CANON:
236  case LY_VALUE_CBOR:
237  case LY_VALUE_JSON:
238  case LY_VALUE_LYB:
239  case LY_VALUE_STR_NS:
240  /* zero the local module so that the first node is always prefixed */
241  prefix_data = NULL;
242  break;
243  }
244 
245  /* recursively print the expression */
246  ret = xpath10_print_subexpr_r(&expr_idx, 0, NULL, xp_val, format, prefix_data, str_value, &str_len, err);
247 
248  if (local_mod) {
249  mods->objs[0] = (void *)local_mod;
250  }
251  if (ret) {
252  free(*str_value);
253  *str_value = NULL;
254  }
255  return ret;
256 }
257 
258 static LY_ERR
259 lyplg_type_store_xpath10(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint64_t value_size_bits,
260  uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node,
261  struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
262 {
263  LY_ERR ret = LY_SUCCESS;
264  const struct ly_err_item *e;
265  uint32_t value_size, *prev_lo, temp_lo = LY_LOSTORE;
266  struct lyd_value_xpath10 *val;
267  char *canon;
268 
269  /* init storage */
270  memset(storage, 0, sizeof *storage);
271  LYPLG_TYPE_VAL_INLINE_PREPARE(storage, val);
272  LY_CHECK_ERR_GOTO(!val, ret = ly_err_new_no_mem(err), cleanup);
273  storage->realtype = type;
274 
275  /* check value length */
276  ret = lyplg_type_check_value_size("xpath1.0", format, value_size_bits, LYPLG_LYB_SIZE_VARIABLE_BYTES, 0,
277  &value_size, err);
278  LY_CHECK_GOTO(ret, cleanup);
279 
280  /* check hints */
281  ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
282  LY_CHECK_GOTO(ret, cleanup);
283 
284  /* parse */
285  prev_lo = ly_temp_log_options(&temp_lo);
286  ret = lyxp_expr_parse(ctx, NULL, value_size ? value : "", value_size, 1, &val->exp);
287  ly_temp_log_options(prev_lo);
288  if (ret) {
289  /* get a copy of the error */
290  e = ly_err_last(ctx);
291  if (e) {
292  ly_err_new(err, e->err, e->vecode, e->data_path, e->apptag, "%s", e->msg);
293  ly_err_clean(ctx, (struct ly_err_item *)e);
294  }
295  goto cleanup;
296  }
297  val->ctx = ctx;
298 
299  if (ctx_node && !strcmp(ctx_node->name, "parent-reference") && !strcmp(ctx_node->module->name, "ietf-yang-schema-mount")) {
300  /* special case, this type uses prefix-namespace mapping provided directly in data, keep empty for now */
301  val->format = format = LY_VALUE_STR_NS;
302  ret = ly_set_new((struct ly_set **)&val->prefix_data);
303  LY_CHECK_GOTO(ret, cleanup);
304  } else {
305  /* store format-specific data and context for later prefix resolution */
306  ret = lyplg_type_prefix_data_new(ctx, value, value_size, format, prefix_data, &val->format, &val->prefix_data);
307  LY_CHECK_GOTO(ret, cleanup);
308  }
309 
310  switch (format) {
311  case LY_VALUE_CANON:
312  case LY_VALUE_CBOR:
313  case LY_VALUE_JSON:
314  case LY_VALUE_LYB:
315  case LY_VALUE_STR_NS:
316  /* store canonical value */
317  if (options & LYPLG_TYPE_STORE_DYNAMIC) {
318  ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
319  options &= ~LYPLG_TYPE_STORE_DYNAMIC;
320  LY_CHECK_GOTO(ret, cleanup);
321  } else {
322  ret = lydict_insert(ctx, value_size ? value : "", value_size, &storage->_canonical);
323  LY_CHECK_GOTO(ret, cleanup);
324  }
325  break;
326  case LY_VALUE_SCHEMA:
328  case LY_VALUE_XML:
329  /* JSON format with prefix is the canonical one */
330  ret = lyplg_type_print_xpath10_value(val, LY_VALUE_JSON, NULL, &canon, err);
331  LY_CHECK_GOTO(ret, cleanup);
332 
333  ret = lydict_insert_zc(ctx, canon, &storage->_canonical);
334  LY_CHECK_GOTO(ret, cleanup);
335  break;
336  }
337 
338 cleanup:
339  if (options & LYPLG_TYPE_STORE_DYNAMIC) {
340  free((void *)value);
341  }
342 
343  if (ret) {
344  lyplg_type_free_xpath10(ctx, storage);
345  } else if (val->format == LY_VALUE_STR_NS) {
346  /* needs validation */
347  return LY_EINCOMPLETE;
348  }
349  return ret;
350 }
351 
360 static LY_ERR
361 xpath10_add_ns(struct ly_set *set, const char *pref, const char *uri)
362 {
363  LY_ERR rc = LY_SUCCESS;
364  struct lyxml_ns *ns = NULL;
365 
366  /* create new ns */
367  ns = calloc(1, sizeof *ns);
368  if (!ns) {
369  rc = LY_EMEM;
370  goto cleanup;
371  }
372  ns->prefix = strdup(pref);
373  ns->uri = strdup(uri);
374  if (!ns->prefix || !ns->uri) {
375  rc = LY_EMEM;
376  goto cleanup;
377  }
378  ns->depth = 1;
379 
380  /* add into the XML namespace set */
381  if ((rc = ly_set_add(set, ns, 1, NULL))) {
382  goto cleanup;
383  }
384  ns = NULL;
385 
386 cleanup:
387  if (ns) {
388  free(ns->prefix);
389  free(ns->uri);
390  free(ns);
391  }
392  return rc;
393 }
394 
398 static LY_ERR
399 lyplg_type_validate_tree_xpath10(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *UNUSED(type),
400  const struct lyd_node *ctx_node, const struct lyd_node *UNUSED(tree), struct lyd_value *storage,
401  struct ly_err_item **err)
402 {
403  LY_ERR ret = LY_SUCCESS;
404  struct lyd_value_xpath10 *val;
405  struct ly_set *set = NULL;
406  uint32_t i;
407  const char *pref, *uri;
408  const struct ly_err_item *eitem;
409 
410  *err = NULL;
411  LYD_VALUE_GET(storage, val);
412 
413  if (val->format != LY_VALUE_STR_NS) {
414  /* nothing to validate */
415  return LY_SUCCESS;
416  }
417 
418  /* the XML namespace set must exist */
419  assert(val->prefix_data);
420 
421  /* special handling of this particular node */
422  assert(!strcmp(LYD_NAME(ctx_node), "parent-reference") &&
423  !strcmp(ctx_node->schema->module->name, "ietf-yang-schema-mount"));
424 
425  /* get all the prefix mappings */
426  if ((ret = lyd_find_xpath(ctx_node, "../../../namespace", &set))) {
427  goto cleanup;
428  }
429 
430  for (i = 0; i < set->count; ++i) {
431  assert(!strcmp(LYD_NAME(lyd_child(set->dnodes[i])), "prefix"));
432  pref = lyd_get_value(lyd_child(set->dnodes[i]));
433 
434  if (!lyd_child(set->dnodes[i])->next) {
435  /* missing URI - invalid mapping, skip */
436  continue;
437  }
438  assert(!strcmp(LYD_NAME(lyd_child(set->dnodes[i])->next), "uri"));
439  uri = lyd_get_value(lyd_child(set->dnodes[i])->next);
440 
441  /* new NS */
442  if ((ret = xpath10_add_ns(val->prefix_data, pref, uri))) {
443  goto cleanup;
444  }
445  }
446 
447 cleanup:
448  ly_set_free(set, NULL);
449  if (ret == LY_EMEM) {
451  } else if (ret) {
452  eitem = ly_err_last(LYD_CTX(ctx_node));
453  ly_err_new(err, ret, LYVE_DATA, eitem->data_path, NULL, "%s", eitem->msg);
454  }
455  return ret;
456 }
457 
458 LIBYANG_API_DEF const void *
459 lyplg_type_print_xpath10(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format,
460  void *prefix_data, ly_bool *dynamic, uint64_t *value_size_bits)
461 {
462  struct lyd_value_xpath10 *val;
463  char *ret;
464  struct ly_err_item *err = NULL;
465 
466  LYD_VALUE_GET(value, val);
467 
468  /* LY_VALUE_STR_NS should never be transformed */
469  if ((val->format == LY_VALUE_STR_NS) || (format == LY_VALUE_CANON) || (format == LY_VALUE_JSON) ||
470  (format == LY_VALUE_LYB) || (format == LY_VALUE_CBOR)) {
471  /* canonical */
472  if (dynamic) {
473  *dynamic = 0;
474  }
475  if (value_size_bits) {
476  *value_size_bits = strlen(value->_canonical) * 8;
477  }
478  return value->_canonical;
479  }
480 
481  /* print in the specific format */
482  if (lyplg_type_print_xpath10_value(val, format, prefix_data, &ret, &err)) {
483  if (err) {
484  ly_err_print(ctx, err, NULL, NULL);
485  ly_err_free(err);
486  }
487  return NULL;
488  }
489 
490  *dynamic = 1;
491  if (value_size_bits) {
492  *value_size_bits = strlen(ret) * 8;
493  }
494  return ret;
495 }
496 
497 LIBYANG_API_DEF LY_ERR
498 lyplg_type_dup_xpath10(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
499 {
500  LY_ERR ret = LY_SUCCESS;
501  struct lyd_value_xpath10 *orig_val, *dup_val;
502 
503  /* init dup value */
504  memset(dup, 0, sizeof *dup);
505  dup->realtype = original->realtype;
506 
507  ret = lydict_insert(ctx, original->_canonical, 0, &dup->_canonical);
508  LY_CHECK_GOTO(ret, cleanup);
509 
510  LYPLG_TYPE_VAL_INLINE_PREPARE(dup, dup_val);
511  LY_CHECK_ERR_GOTO(!dup_val, LOGMEM(ctx); ret = LY_EMEM, cleanup);
512  dup_val->ctx = ctx;
513 
514  LYD_VALUE_GET(original, orig_val);
515  ret = lyxp_expr_dup(ctx, orig_val->exp, 0, 0, &dup_val->exp);
516  LY_CHECK_GOTO(ret, cleanup);
517 
518  ret = lyplg_type_prefix_data_dup(ctx, orig_val->format, orig_val->prefix_data, &dup_val->prefix_data);
519  LY_CHECK_GOTO(ret, cleanup);
520  dup_val->format = orig_val->format;
521 
522 cleanup:
523  if (ret) {
525  }
526  return ret;
527 }
528 
529 LIBYANG_API_DEF void
530 lyplg_type_free_xpath10(const struct ly_ctx *ctx, struct lyd_value *value)
531 {
532  struct lyd_value_xpath10 *val;
533 
534  lydict_remove(ctx, value->_canonical);
535  value->_canonical = NULL;
536  LYD_VALUE_GET(value, val);
537  if (val) {
538  lyxp_expr_free(val->exp);
540 
542  }
543 }
544 
552 const struct lyplg_type_record plugins_xpath10[] = {
553  {
554  .module = "ietf-yang-types",
555  .revision = NULL,
556  .name = "xpath1.0",
557 
558  .plugin.id = "ly2 xpath1.0",
559  .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes,
560  .plugin.store = lyplg_type_store_xpath10,
561  .plugin.validate_value = NULL,
562  .plugin.validate_tree = lyplg_type_validate_tree_xpath10,
563  .plugin.compare = lyplg_type_compare_simple,
564  .plugin.sort = lyplg_type_sort_simple,
565  .plugin.print = lyplg_type_print_xpath10,
566  .plugin.duplicate = lyplg_type_dup_xpath10,
567  .plugin.free = lyplg_type_free_xpath10,
568  },
569  {0}
570 };
libyang dictionary
libyang context handler.
#define LYD_CTX(node)
Macro to get context from a data tree node.
Definition: tree_data.h:580
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...
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_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 err
Definition: log.h:300
LY_VECODE vecode
Definition: log.h:301
char * data_path
Definition: log.h:303
char * apptag
Definition: log.h:306
char * msg
Definition: log.h:302
LIBYANG_API_DECL const struct ly_err_item * ly_err_last(const struct ly_ctx *ctx)
Get the latest (thread, context-specific) generated error structure.
LIBYANG_API_DECL void ly_err_print(const struct ly_ctx *ctx, const struct ly_err_item *eitem, const struct lyd_node *lnode, const struct lysc_node *snode)
Print the error structure as if just generated.
LY_ERR
libyang's error codes returned by the libyang functions.
Definition: log.h:252
LIBYANG_API_DECL void ly_err_clean(const struct ly_ctx *ctx, struct ly_err_item *eitem)
Free error structures from a context.
@ LYVE_DATA
Definition: log.h:290
@ LY_EMEM
Definition: log.h:254
@ LY_EVALID
Definition: log.h:260
@ LY_SUCCESS
Definition: log.h:253
@ LY_EINCOMPLETE
Definition: log.h:262
Libyang full error structure.
Definition: log.h:298
LIBYANG_API_DECL uint32_t * ly_temp_log_options(uint32_t *opts)
Set temporary thread-safe (thread-specific) logger options overwriting those set by ly_log_options().
#define LY_LOSTORE
Definition: log.h:121
uint32_t count
Definition: set.h:49
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,...
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 LY_ERR ly_set_new(struct ly_set **set_p)
Create and initiate new ly_set structure.
Structure to hold a set of (not necessary somehow connected) objects. Usually used for lyd_node,...
Definition: set.h:47
const char * module
#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 void ly_err_free(void *ptr)
Destructor for the error records created with ly_err_new().
LIBYANG_API_DECL LY_ERR lyplg_type_check_hints(uint32_t hints, const char *value, uint32_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_DEF 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.
Definition: xpath1.0.c:212
#define LYPLG_TYPE_VAL_INLINE_DESTROY(type_val)
Destroy a prepared value.
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.
Definition: xpath1.0.c:40
LIBYANG_API_DEF 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.
Definition: xpath1.0.c:498
LIBYANG_API_DECL LY_ERR lyplg_type_prefix_data_new(const struct ly_ctx *ctx, const void *value, uint32_t value_size, 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.
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.
LIBYANG_API_DECL LY_ERR lyplg_type_check_value_size(const char *type_name, LY_VALUE_FORMAT format, uint64_t value_size_bits, enum lyplg_lyb_size_type lyb_size_type, uint64_t lyb_fixed_size_bits, uint32_t *value_size, struct ly_err_item **err)
Check a value type in bits is correct and as expected.
LIBYANG_API_DEF 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, uint64_t *value_size_bits)
Implementation of lyplg_type_print_clb for the ietf-yang-types xpath1.0 type.
Definition: xpath1.0.c:459
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 an error structure.
LIBYANG_API_DEF 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.
Definition: xpath1.0.c:530
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 LY_ERR LIBYANG_API_DECL LY_ERR ly_err_new_no_mem(struct ly_err_item **err)
Create and fill an error structure with a no-memory error.
LIBYANG_API_DECL void lyplg_type_prefix_data_free(LY_VALUE_FORMAT format, void *prefix_data)
Free internal prefix data.
@ LYPLG_LYB_SIZE_VARIABLE_BYTES
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 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.
LIBYANG_API_DECL void lyplg_type_lyb_size_variable_bytes(const struct lysc_type *type, enum lyplg_lyb_size_type *size_type, uint64_t *fixed_size_bits)
Implementation of lyplg_type_lyb_size_clb for a type with variable length rounded to bytes.
#define LYPLG_TYPE_STORE_DYNAMIC
const char * name
Definition: tree_schema.h:2244
LY_DATA_TYPE basetype
Definition: tree_schema.h:1278
struct lys_module * module
Definition: tree_schema.h:1416
const char * name
Definition: tree_schema.h:1423
const char * prefix
Definition: tree_schema.h:2247
LIBYANG_API_DECL const struct lys_module * lys_find_module(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *prefix, uint32_t prefix_len, LY_VALUE_FORMAT format, const void *prefix_data)
Find a module matching a prefix (or a default one).
Available YANG schema tree structures representing YANG module.
Definition: tree_schema.h:2242
Compiled YANG data node.
Definition: tree_schema.h:1412
uint8_t ly_bool
Type to indicate boolean value.
Definition: log.h:29
API for (user) types plugins.
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.
const struct lysc_type * realtype
Definition: tree_data.h:614
const struct lysc_node * schema
Definition: tree_data.h:881
struct lyxp_expr * exp
Definition: tree_data.h:788
#define LYD_NAME(node)
Get the name (associated with) of a data node. Works for opaque nodes as well.
Definition: tree_data.h:992
LY_VALUE_FORMAT format
Definition: tree_data.h:791
const struct ly_ctx * ctx
Definition: tree_data.h:789
#define LYD_VALUE_GET(value, type_val)
Get the value in format specific to the type.
Definition: tree_data.h:653
const char * _canonical
Definition: tree_data.h:611
void * prefix_data
Definition: tree_data.h:790
Generic structure for a data node.
Definition: tree_data.h:875
YANG data representation.
Definition: tree_data.h:610
Special lyd_value structure for ietf-yang-types xpath1.0 values.
Definition: tree_data.h:787
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
Definition: utils.h:93
@ LY_VALUE_JSON
Definition: utils.h:98
@ LY_VALUE_SCHEMA
Definition: utils.h:95
@ LY_VALUE_CBOR
Definition: utils.h:99
@ LY_VALUE_CANON
Definition: utils.h:94
@ LY_VALUE_XML
Definition: utils.h:97
@ LY_VALUE_STR_NS
Definition: utils.h:101
@ LY_VALUE_SCHEMA_RESOLVED
Definition: utils.h:96
@ LY_VALUE_LYB
Definition: utils.h:100
const struct lyplg_type_record plugins_xpath10[]
Plugin information for xpath1.0 type implementation.
Definition: xpath1.0.c:552