libyang  6.4.33
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 "tree_schema_internal.h"
28 #include "xml.h"
29 #include "xpath.h"
30 
40 LIBYANG_API_DEF LY_ERR
41 lyplg_type_xpath10_print_token(const char *token, uint16_t tok_len, ly_bool is_nametest, const struct ly_ctx *resolve_ctx,
42  LY_VALUE_FORMAT resolve_format, const void *resolve_prefix_data, LY_VALUE_FORMAT get_format, void *get_prefix_data,
43  const struct lys_module **ctx_mod, const struct lysc_node **ctx_node, char **token_p, struct ly_err_item **err)
44 {
45  LY_ERR rc = LY_SUCCESS, r;
46  const char *str_begin, *str_next, *str_next2, *prefix;
47  ly_bool is_prefix, is_prefix2, has_prefix = 0;
48  char *str = NULL;
49  uint32_t len, len2, str_size = 0, str_len = 0, pref_len;
50  const struct lysc_node *node = NULL;
51  const struct lys_module *mod;
52 
53  *token_p = NULL;
54 
55  if (*ctx_mod) {
56  /* use context module context in case it is from an extension */
57  resolve_ctx = (*ctx_mod)->ctx;
58  }
59  str_begin = token;
60 
61  while (!(r = ly_value_prefix_next(str_begin, token + tok_len, &len, &is_prefix, &str_next)) && len) {
62  if (!is_prefix) {
63  if (!has_prefix && is_nametest && (get_format == LY_VALUE_XML) && *ctx_mod) {
64  /* get the prefix */
65  prefix = lyplg_type_get_prefix(*ctx_mod, get_format, get_prefix_data);
66  assert(prefix);
67 
68  /* append the nametest and prefix */
69  LY_CHECK_ERR_GOTO(ly_append_str(&str, &str_size, &str_len, "%s:%.*s", prefix, (int)len, str_begin),
70  rc = ly_err_new_no_mem(err), cleanup);
71  } else {
72  /* just append the string, we may get the first expression node without a prefix but since this
73  * is not strictly forbidden, allow it */
74  LY_CHECK_ERR_GOTO(ly_append_str(&str, &str_size, &str_len, "%.*s", (int)len, str_begin),
75  rc = ly_err_new_no_mem(err), cleanup);
76  }
77  } else {
78  /* remember there was a prefix found */
79  has_prefix = 1;
80 
81  if (is_nametest) {
82  /* parse the name as well */
83  r = ly_value_prefix_next(str_next, token + tok_len, &len2, &is_prefix2, &str_next2);
84  if (r) {
85  /* invalid characters in the xpath */
86  break;
87  } else if (!len2) {
88  rc = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Unexpected token end (\"%.*s\").",
89  (int)((token + tok_len) - str_begin), str_begin);
90  goto cleanup;
91  } else if (is_prefix2) {
92  rc = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Unexpected prefix found (\"%.*s\").",
93  (int)((token + tok_len) - str_next), str_next);
94  goto cleanup;
95  }
96 
97  /* find the node */
98  r = lys_find_child_node(resolve_ctx, *ctx_node, *ctx_mod, str_begin, len, resolve_format,
99  (void *)resolve_prefix_data, str_next, len2, 0, &node, NULL);
100  if (r) {
101  /* we were not able to find the node but this function does not strictly require it, only the
102  * module must be found */
103  mod = lys_find_module(resolve_ctx, NULL, str_begin, len, resolve_format, resolve_prefix_data);
104  if (!mod) {
105  rc = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to resolve prefix \"%.*s\".",
106  (int)len, str_begin);
107  goto cleanup;
108  }
109  } else {
110  /* set the current module */
111  mod = node->module;
112  }
113  } else {
114  /* resolve the module in the original format */
115  mod = lys_find_module(resolve_ctx, NULL, str_begin, len, resolve_format, resolve_prefix_data);
116  }
117 
118  if (is_nametest && ((get_format == LY_VALUE_JSON) || (get_format == LY_VALUE_LYB)) && (*ctx_mod == mod)) {
119  /* inherit the prefix and do not print it again */
120  } else {
121  if (mod) {
122  /* get the prefix in the target format */
123  prefix = lyplg_type_get_prefix(mod, get_format, get_prefix_data);
124  assert(prefix);
125  pref_len = strlen(prefix);
126  } else {
127  /* invalid prefix, just copy it */
128  prefix = str_begin;
129  pref_len = len;
130  }
131 
132  /* append the prefix */
133  LY_CHECK_ERR_GOTO(ly_append_str(&str, &str_size, &str_len, "%.*s:", (int)pref_len, prefix),
134  rc = ly_err_new_no_mem(err), cleanup);
135  }
136 
137  if (is_nametest) {
138  /* update context module and node */
139  *ctx_mod = mod;
140  *ctx_node = node;
141  }
142  }
143 
144  str_begin = str_next;
145  }
146  if (r) {
147  /* invalid characters in the xpath */
148  rc = ly_err_new(err, r, LYVE_DATA, NULL, NULL, "Invalid characters found (\"%.*s\").",
149  (int)((token + tok_len) - str_begin), str_begin);
150  }
151 
152 cleanup:
153  if (rc) {
154  free(str);
155  } else {
156  *token_p = str;
157  }
158  return rc;
159 }
160 
178 static LY_ERR
179 xpath10_print_subexpr_r(uint16_t *cur_idx, enum lyxp_token end_tok, const struct lys_module *ctx_mod,
180  const struct lysc_node *ctx_node, const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format,
181  void *prefix_data, char **str_value, uint32_t *str_size, uint32_t *str_len, struct ly_err_item **err)
182 {
183  LY_ERR r;
184  enum lyxp_token cur_tok, sub_end_tok;
185  char *str_tok;
186  const char *cur_exp_ptr;
187  ly_bool is_nt;
188  const struct lys_module *orig_ctx_mod = ctx_mod;
189  const struct lysc_node *orig_ctx_node = ctx_node;
190 
191  while (*cur_idx < xp_val->exp->used) {
192  cur_tok = xp_val->exp->tokens[*cur_idx];
193  cur_exp_ptr = xp_val->exp->expr + xp_val->exp->tok_pos[*cur_idx];
194 
195  if ((cur_tok == LYXP_TOKEN_NAMETEST) || (cur_tok == LYXP_TOKEN_LITERAL)) {
196  /* tokens that may include prefixes, get them in the target format */
197  is_nt = (cur_tok == LYXP_TOKEN_NAMETEST) ? 1 : 0;
198  LY_CHECK_RET(lyplg_type_xpath10_print_token(cur_exp_ptr, xp_val->exp->tok_len[*cur_idx], is_nt, xp_val->ctx,
199  xp_val->format, xp_val->prefix_data, format, prefix_data, &ctx_mod, &ctx_node, &str_tok, err));
200 
201  /* append the converted token */
202  r = ly_append_str(str_value, str_size, str_len, "%s", str_tok);
203  free(str_tok);
204  LY_CHECK_GOTO(r, error_mem);
205 
206  /* token processed */
207  ++(*cur_idx);
208  } else {
209  if ((cur_tok == LYXP_TOKEN_OPER_LOG) || (cur_tok == LYXP_TOKEN_OPER_UNI) || (cur_tok == LYXP_TOKEN_OPER_MATH)) {
210  /* copy the token with spaces around */
211  LY_CHECK_GOTO(ly_append_str(str_value, str_size, str_len, " %.*s ", (int)xp_val->exp->tok_len[*cur_idx],
212  cur_exp_ptr), error_mem);
213 
214  /* reset context module and node */
215  ctx_mod = orig_ctx_mod;
216  ctx_node = orig_ctx_node;
217  } else {
218  /* just copy the token */
219  LY_CHECK_GOTO(ly_append_str(str_value, str_size, str_len, "%.*s", (int)xp_val->exp->tok_len[*cur_idx],
220  cur_exp_ptr), error_mem);
221  }
222 
223  /* token processed but keep it in cur_tok */
224  ++(*cur_idx);
225 
226  if (end_tok && (cur_tok == end_tok)) {
227  /* end token found */
228  break;
229  } else if ((cur_tok == LYXP_TOKEN_BRACK1) || (cur_tok == LYXP_TOKEN_PAR1)) {
230  sub_end_tok = (cur_tok == LYXP_TOKEN_BRACK1) ? LYXP_TOKEN_BRACK2 : LYXP_TOKEN_PAR2;
231 
232  /* parse the subexpression separately, use the current context mod */
233  LY_CHECK_RET(xpath10_print_subexpr_r(cur_idx, sub_end_tok, ctx_mod, ctx_node, xp_val, format,
234  prefix_data, str_value, str_size, str_len, err));
235  }
236  }
237  }
238 
239  return LY_SUCCESS;
240 
241 error_mem:
242  return ly_err_new_no_mem(err);
243 }
244 
245 LIBYANG_API_DEF LY_ERR
246 lyplg_type_print_xpath10_value(const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format, void *prefix_data,
247  char **str_value, struct ly_err_item **err)
248 {
249  LY_ERR ret = LY_SUCCESS;
250  uint16_t expr_idx = 0;
251  uint32_t str_size = 0, str_len = 0;
252  const struct lys_module *local_mod = NULL;
253  struct ly_set *mods;
254 
255  *str_value = NULL;
256  *err = NULL;
257 
258  switch (format) {
259  case LY_VALUE_XML:
260  /* zero the local module so that all the prefixes are printed */
261  mods = prefix_data;
262  local_mod = mods->objs[0];
263  mods->objs[0] = NULL;
264  break;
265  case LY_VALUE_SCHEMA:
267  /* nothing to do */
268  break;
269  case LY_VALUE_CANON:
270  case LY_VALUE_CBOR:
271  case LY_VALUE_JSON:
272  case LY_VALUE_LYB:
273  case LY_VALUE_STR_NS:
274  /* zero the local module so that the first node is always prefixed */
275  prefix_data = NULL;
276  break;
277  }
278 
279  /* recursively print the expression */
280  ret = xpath10_print_subexpr_r(&expr_idx, 0, NULL, NULL, xp_val, format, prefix_data, str_value, &str_size, &str_len,
281  err);
282 
283  if (local_mod) {
284  mods->objs[0] = (void *)local_mod;
285  }
286  if (ret) {
287  free(*str_value);
288  *str_value = NULL;
289  }
290  return ret;
291 }
292 
293 static LY_ERR
294 lyplg_type_store_xpath10(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint64_t value_size_bits,
295  uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node,
296  struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
297 {
298  LY_ERR ret = LY_SUCCESS;
299  const struct ly_err_item *e;
300  uint32_t value_size, *prev_lo, temp_lo = LY_LOSTORE;
301  struct lyd_value_xpath10 *val;
302  char *canon;
303 
304  /* init storage */
305  memset(storage, 0, sizeof *storage);
306  LYPLG_TYPE_VAL_INLINE_PREPARE(storage, val);
307  LY_CHECK_ERR_GOTO(!val, ret = ly_err_new_no_mem(err), cleanup);
308  storage->realtype = type;
309 
310  /* check value length */
311  ret = lyplg_type_check_value_size("xpath1.0", format, value_size_bits, LYPLG_LYB_SIZE_VARIABLE_BYTES, 0,
312  &value_size, err);
313  LY_CHECK_GOTO(ret, cleanup);
314 
315  /* check hints */
316  ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
317  LY_CHECK_GOTO(ret, cleanup);
318 
319  /* parse */
320  prev_lo = ly_temp_log_options(&temp_lo);
321  ret = lyxp_expr_parse(ctx, NULL, value_size ? value : "", value_size, 1, &val->exp);
322  ly_temp_log_options(prev_lo);
323  if (ret) {
324  /* get a copy of the error */
325  e = ly_err_last(ctx);
326  if (e) {
327  ly_err_new(err, e->err, e->vecode, e->data_path, e->apptag, "%s", e->msg);
328  ly_err_clean(ctx, (struct ly_err_item *)e);
329  }
330  goto cleanup;
331  }
332  val->ctx = ctx;
333 
334  if (ctx_node && !strcmp(ctx_node->name, "parent-reference") && !strcmp(ctx_node->module->name, "ietf-yang-schema-mount")) {
335  /* special case, this type uses prefix-namespace mapping provided directly in data, keep empty for now */
336  val->format = format = LY_VALUE_STR_NS;
337  ret = ly_set_new((struct ly_set **)&val->prefix_data);
338  LY_CHECK_GOTO(ret, cleanup);
339  } else {
340  /* store format-specific data and context for later prefix resolution */
341  ret = lyplg_type_prefix_data_new(ctx, value, value_size, format, prefix_data, &val->format, &val->prefix_data);
342  LY_CHECK_GOTO(ret, cleanup);
343  }
344 
345  switch (format) {
346  case LY_VALUE_CANON:
347  case LY_VALUE_CBOR:
348  case LY_VALUE_JSON:
349  case LY_VALUE_LYB:
350  case LY_VALUE_STR_NS:
351  /* store canonical value */
352  if (options & LYPLG_TYPE_STORE_DYNAMIC) {
353  ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
354  options &= ~LYPLG_TYPE_STORE_DYNAMIC;
355  LY_CHECK_GOTO(ret, cleanup);
356  } else {
357  ret = lydict_insert(ctx, value_size ? value : "", value_size, &storage->_canonical);
358  LY_CHECK_GOTO(ret, cleanup);
359  }
360  break;
361  case LY_VALUE_SCHEMA:
363  case LY_VALUE_XML:
364  /* JSON format with prefix is the canonical one */
365  ret = lyplg_type_print_xpath10_value(val, LY_VALUE_JSON, NULL, &canon, err);
366  LY_CHECK_GOTO(ret, cleanup);
367 
368  ret = lydict_insert_zc(ctx, canon, &storage->_canonical);
369  LY_CHECK_GOTO(ret, cleanup);
370  break;
371  }
372 
373 cleanup:
374  if (options & LYPLG_TYPE_STORE_DYNAMIC) {
375  free((void *)value);
376  }
377 
378  if (ret) {
379  lyplg_type_free_xpath10(ctx, storage);
380  } else if (val->format == LY_VALUE_STR_NS) {
381  /* needs validation */
382  return LY_EINCOMPLETE;
383  }
384  return ret;
385 }
386 
395 static LY_ERR
396 xpath10_add_ns(struct ly_set *set, const char *pref, const char *uri)
397 {
398  LY_ERR rc = LY_SUCCESS;
399  struct lyxml_ns *ns = NULL;
400 
401  /* create new ns */
402  ns = calloc(1, sizeof *ns);
403  if (!ns) {
404  rc = LY_EMEM;
405  goto cleanup;
406  }
407  ns->prefix = strdup(pref);
408  ns->uri = strdup(uri);
409  if (!ns->prefix || !ns->uri) {
410  rc = LY_EMEM;
411  goto cleanup;
412  }
413  ns->depth = 1;
414 
415  /* add into the XML namespace set */
416  if ((rc = ly_set_add(set, ns, 1, NULL))) {
417  goto cleanup;
418  }
419  ns = NULL;
420 
421 cleanup:
422  if (ns) {
423  free(ns->prefix);
424  free(ns->uri);
425  free(ns);
426  }
427  return rc;
428 }
429 
433 static LY_ERR
434 lyplg_type_validate_tree_xpath10(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *UNUSED(type),
435  const struct lyd_node *ctx_node, const struct lyd_node *UNUSED(tree), const struct lyd_val_unres *UNUSED(val_unres),
436  struct lyd_value *storage, struct ly_err_item **err)
437 {
438  LY_ERR ret = LY_SUCCESS;
439  struct lyd_value_xpath10 *val;
440  struct ly_set *set = NULL;
441  uint32_t i;
442  const char *pref, *uri;
443  const struct ly_err_item *eitem;
444 
445  *err = NULL;
446  LYD_VALUE_GET(storage, val);
447 
448  if (val->format != LY_VALUE_STR_NS) {
449  /* nothing to validate */
450  return LY_SUCCESS;
451  }
452 
453  /* the XML namespace set must exist */
454  assert(val->prefix_data);
455 
456  /* special handling of this particular node */
457  assert(!strcmp(LYD_NAME(ctx_node), "parent-reference") &&
458  !strcmp(ctx_node->schema->module->name, "ietf-yang-schema-mount"));
459 
460  /* get all the prefix mappings */
461  if ((ret = lyd_find_xpath(ctx_node, "../../../namespace", &set))) {
462  goto cleanup;
463  }
464 
465  for (i = 0; i < set->count; ++i) {
466  assert(!strcmp(LYD_NAME(lyd_child(set->dnodes[i])), "prefix"));
467  pref = lyd_get_value(lyd_child(set->dnodes[i]));
468 
469  if (!lyd_child(set->dnodes[i])->next) {
470  /* missing URI - invalid mapping, skip */
471  continue;
472  }
473  assert(!strcmp(LYD_NAME(lyd_child(set->dnodes[i])->next), "uri"));
474  uri = lyd_get_value(lyd_child(set->dnodes[i])->next);
475 
476  /* new NS */
477  if ((ret = xpath10_add_ns(val->prefix_data, pref, uri))) {
478  goto cleanup;
479  }
480  }
481 
482 cleanup:
483  ly_set_free(set, NULL);
484  if (ret == LY_EMEM) {
486  } else if (ret) {
487  eitem = ly_err_last(LYD_CTX(ctx_node));
488  ly_err_new(err, ret, LYVE_DATA, eitem->data_path, NULL, "%s", eitem->msg);
489  }
490  return ret;
491 }
492 
493 LIBYANG_API_DEF const void *
494 lyplg_type_print_xpath10(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format,
495  void *prefix_data, ly_bool *dynamic, uint64_t *value_size_bits)
496 {
497  struct lyd_value_xpath10 *val;
498  char *ret;
499  struct ly_err_item *err = NULL;
500 
501  LYD_VALUE_GET(value, val);
502 
503  /* LY_VALUE_STR_NS should never be transformed */
504  if ((val->format == LY_VALUE_STR_NS) || (format == LY_VALUE_CANON) || (format == LY_VALUE_JSON) ||
505  (format == LY_VALUE_LYB) || (format == LY_VALUE_CBOR)) {
506  /* canonical */
507  if (dynamic) {
508  *dynamic = 0;
509  }
510  if (value_size_bits) {
511  *value_size_bits = strlen(value->_canonical) * 8;
512  }
513  return value->_canonical;
514  }
515 
516  /* print in the specific format */
517  if (lyplg_type_print_xpath10_value(val, format, prefix_data, &ret, &err)) {
518  if (err) {
519  ly_err_print(ctx, err, NULL, NULL);
520  ly_err_free(err);
521  }
522  return NULL;
523  }
524 
525  *dynamic = 1;
526  if (value_size_bits) {
527  *value_size_bits = strlen(ret) * 8;
528  }
529  return ret;
530 }
531 
532 LIBYANG_API_DEF LY_ERR
533 lyplg_type_dup_xpath10(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
534 {
535  LY_ERR ret = LY_SUCCESS;
536  struct lyd_value_xpath10 *orig_val, *dup_val;
537 
538  /* init dup value */
539  memset(dup, 0, sizeof *dup);
540  dup->realtype = original->realtype;
541 
542  ret = lydict_insert(ctx, original->_canonical, 0, &dup->_canonical);
543  LY_CHECK_GOTO(ret, cleanup);
544 
545  LYPLG_TYPE_VAL_INLINE_PREPARE(dup, dup_val);
546  LY_CHECK_ERR_GOTO(!dup_val, LOGMEM(ctx); ret = LY_EMEM, cleanup);
547  dup_val->ctx = ctx;
548 
549  LYD_VALUE_GET(original, orig_val);
550  ret = lyxp_expr_dup(ctx, orig_val->exp, 0, 0, &dup_val->exp);
551  LY_CHECK_GOTO(ret, cleanup);
552 
553  ret = lyplg_type_prefix_data_dup(ctx, orig_val->format, orig_val->prefix_data, &dup_val->prefix_data);
554  LY_CHECK_GOTO(ret, cleanup);
555  dup_val->format = orig_val->format;
556 
557 cleanup:
558  if (ret) {
560  }
561  return ret;
562 }
563 
564 LIBYANG_API_DEF void
565 lyplg_type_free_xpath10(const struct ly_ctx *ctx, struct lyd_value *value)
566 {
567  struct lyd_value_xpath10 *val;
568 
569  lydict_remove(ctx, value->_canonical);
570  value->_canonical = NULL;
571  LYD_VALUE_GET(value, val);
572  if (val) {
573  lyxp_expr_free(val->exp);
575 
577  }
578 }
579 
587 const struct lyplg_type_record plugins_xpath10[] = {
588  {
589  .module = "ietf-yang-types",
590  .revision = NULL,
591  .name = "xpath1.0",
592 
593  .plugin.id = "ly2 xpath1.0",
594  .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes,
595  .plugin.store = lyplg_type_store_xpath10,
596  .plugin.validate_value = NULL,
597  .plugin.validate_tree = lyplg_type_validate_tree_xpath10,
598  .plugin.compare = lyplg_type_compare_simple,
599  .plugin.sort = lyplg_type_sort_simple,
600  .plugin.print = lyplg_type_print_xpath10,
601  .plugin.duplicate = lyplg_type_dup_xpath10,
602  .plugin.free = lyplg_type_free_xpath10,
603  },
604  {0}
605 };
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:246
#define LYPLG_TYPE_VAL_INLINE_DESTROY(type_val)
Destroy a prepared value.
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:533
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:494
LIBYANG_API_DEF LY_ERR lyplg_type_xpath10_print_token(const char *token, uint16_t tok_len, ly_bool is_nametest, 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, const struct lys_module **ctx_mod, const struct lysc_node **ctx_node, char **token_p, struct ly_err_item **err)
Print xpath1.0 token in the specific format.
Definition: xpath1.0.c:41
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:565
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:587