libyang  2.1.148
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 "libyang.h"
25 
26 #include "common.h"
27 #include "compat.h"
28 
29 /* internal headers */
30 #include "xml.h"
31 #include "xpath.h"
32 
42 LIBYANG_API_DEF LY_ERR
43 lyplg_type_xpath10_print_token(const char *token, uint16_t tok_len, ly_bool is_nametest, const struct lys_module **context_mod,
44  const struct ly_ctx *resolve_ctx, LY_VALUE_FORMAT resolve_format, const void *resolve_prefix_data,
45  LY_VALUE_FORMAT get_format, void *get_prefix_data, char **token_p, struct ly_err_item **err)
46 {
47  LY_ERR ret = LY_SUCCESS;
48  const char *str_begin, *str_next, *prefix;
49  ly_bool is_prefix, has_prefix = 0;
50  char *str = NULL;
51  void *mem;
52  uint32_t len, str_len = 0, pref_len;
53  const struct lys_module *mod;
54 
55  str_begin = token;
56 
57  while (!(ret = ly_value_prefix_next(str_begin, token + tok_len, &len, &is_prefix, &str_next)) && len) {
58  if (!is_prefix) {
59  if (!has_prefix && is_nametest && (get_format == LY_VALUE_XML) && *context_mod) {
60  /* get the prefix */
61  prefix = lyplg_type_get_prefix(*context_mod, get_format, get_prefix_data);
62  assert(prefix);
63 
64  /* append the nametest and prefix */
65  mem = realloc(str, str_len + strlen(prefix) + 1 + len + 1);
66  LY_CHECK_ERR_GOTO(!mem, ret = ly_err_new(err, LY_EMEM, LYVE_DATA, NULL, NULL, "No memory."), cleanup);
67  str = mem;
68  str_len += sprintf(str + str_len, "%s:%.*s", prefix, len, str_begin);
69  } else {
70  /* just append the string, we may get the first expression node without a prefix but since this
71  * is not strictly forbidden, allow it */
72  mem = realloc(str, str_len + len + 1);
73  LY_CHECK_ERR_GOTO(!mem, ret = ly_err_new(err, LY_EMEM, LYVE_DATA, NULL, NULL, "No memory."), cleanup);
74  str = mem;
75  str_len += sprintf(str + str_len, "%.*s", len, str_begin);
76  }
77  } else {
78  /* remember there was a prefix found */
79  has_prefix = 1;
80 
81  /* resolve the module in the original format */
82  mod = lyplg_type_identity_module(resolve_ctx, NULL, str_begin, len, resolve_format, resolve_prefix_data);
83  if (!mod && is_nametest) {
84  ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to resolve prefix \"%.*s\".", len, str_begin);
85  goto cleanup;
86  }
87 
88  if (is_nametest && ((get_format == LY_VALUE_JSON) || (get_format == LY_VALUE_LYB)) && (*context_mod == mod)) {
89  /* inherit the prefix and do not print it again */
90  } else {
91  if (mod) {
92  /* get the prefix in the target format */
93  prefix = lyplg_type_get_prefix(mod, get_format, get_prefix_data);
94  assert(prefix);
95  pref_len = strlen(prefix);
96  } else {
97  /* invalid prefix, just copy it */
98  prefix = str_begin;
99  pref_len = len;
100  }
101 
102  /* append the prefix */
103  mem = realloc(str, str_len + pref_len + 2);
104  LY_CHECK_ERR_GOTO(!mem, ret = ly_err_new(err, LY_EMEM, LYVE_DATA, NULL, NULL, "No memory."), cleanup);
105  str = mem;
106  str_len += sprintf(str + str_len, "%.*s:", (int)pref_len, prefix);
107  }
108 
109  if (is_nametest) {
110  /* update context module */
111  *context_mod = mod;
112  }
113  }
114 
115  str_begin = str_next;
116  }
117 
118 cleanup:
119  if (ret) {
120  free(str);
121  } else {
122  *token_p = str;
123  }
124  return ret;
125 }
126 
142 static LY_ERR
143 xpath10_print_subexpr_r(uint16_t *cur_idx, enum lyxp_token end_tok, const struct lys_module *context_mod,
144  const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format, void *prefix_data, char **str_value,
145  uint32_t *str_len, struct ly_err_item **err)
146 {
147  enum lyxp_token cur_tok, sub_end_tok;
148  char *str_tok;
149  void *mem;
150  const char *cur_exp_ptr;
151  ly_bool is_nt;
152  const struct lys_module *orig_context_mod = context_mod;
153 
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];
157 
158  if ((cur_tok == LYXP_TOKEN_NAMETEST) || (cur_tok == LYXP_TOKEN_LITERAL)) {
159  /* tokens that may include prefixes, get them in the target format */
160  is_nt = (cur_tok == LYXP_TOKEN_NAMETEST) ? 1 : 0;
161  LY_CHECK_RET(lyplg_type_xpath10_print_token(cur_exp_ptr, xp_val->exp->tok_len[*cur_idx], is_nt, &context_mod,
162  xp_val->ctx, xp_val->format, xp_val->prefix_data, format, prefix_data, &str_tok, err));
163 
164  /* append the converted token */
165  mem = realloc(*str_value, *str_len + strlen(str_tok) + 1);
166  LY_CHECK_ERR_GOTO(!mem, free(str_tok), error_mem);
167  *str_value = mem;
168  *str_len += sprintf(*str_value + *str_len, "%s", str_tok);
169  free(str_tok);
170 
171  /* token processed */
172  ++(*cur_idx);
173  } else {
174  if ((cur_tok == LYXP_TOKEN_OPER_LOG) || (cur_tok == LYXP_TOKEN_OPER_UNI) || (cur_tok == LYXP_TOKEN_OPER_MATH)) {
175  /* copy the token with spaces around */
176  mem = realloc(*str_value, *str_len + 1 + xp_val->exp->tok_len[*cur_idx] + 2);
177  LY_CHECK_GOTO(!mem, error_mem);
178  *str_value = mem;
179  *str_len += sprintf(*str_value + *str_len, " %.*s ", (int)xp_val->exp->tok_len[*cur_idx], cur_exp_ptr);
180 
181  /* reset context mod */
182  context_mod = orig_context_mod;
183  } else {
184  /* just copy the token */
185  mem = realloc(*str_value, *str_len + xp_val->exp->tok_len[*cur_idx] + 1);
186  LY_CHECK_GOTO(!mem, error_mem);
187  *str_value = mem;
188  *str_len += sprintf(*str_value + *str_len, "%.*s", (int)xp_val->exp->tok_len[*cur_idx], cur_exp_ptr);
189  }
190 
191  /* token processed but keep it in cur_tok */
192  ++(*cur_idx);
193 
194  if (end_tok && (cur_tok == end_tok)) {
195  /* end token found */
196  break;
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;
199 
200  /* parse the subexpression separately, use the current context mod */
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));
203  }
204  }
205  }
206 
207  return LY_SUCCESS;
208 
209 error_mem:
210  return ly_err_new(err, LY_EMEM, LYVE_DATA, NULL, NULL, "No memory.");
211 }
212 
213 LIBYANG_API_DEF LY_ERR
214 lyplg_type_print_xpath10_value(const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format, void *prefix_data,
215  char **str_value, struct ly_err_item **err)
216 {
217  LY_ERR ret = LY_SUCCESS;
218  uint16_t expr_idx = 0;
219  uint32_t str_len = 0;
220  const struct lys_module *local_mod = NULL;
221  struct ly_set *mods;
222 
223  *str_value = NULL;
224  *err = NULL;
225 
226  if (format == LY_VALUE_XML) {
227  /* null the local module so that all the prefixes are printed */
228  mods = prefix_data;
229  local_mod = mods->objs[0];
230  mods->objs[0] = NULL;
231  }
232 
233  /* recursively print the expression */
234  ret = xpath10_print_subexpr_r(&expr_idx, 0, NULL, xp_val, format, prefix_data, str_value, &str_len, err);
235 
236  if (local_mod) {
237  mods->objs[0] = (void *)local_mod;
238  }
239  if (ret) {
240  free(*str_value);
241  *str_value = NULL;
242  }
243  return ret;
244 }
245 
246 LIBYANG_API_DEF LY_ERR
247 lyplg_type_store_xpath10(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, size_t value_len,
248  uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node,
249  struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
250 {
251  LY_ERR ret = LY_SUCCESS;
252  struct lysc_type_str *type_str = (struct lysc_type_str *)type;
253  struct lyd_value_xpath10 *val;
254  char *canon;
255 
256  /* init storage */
257  memset(storage, 0, sizeof *storage);
258  LYPLG_TYPE_VAL_INLINE_PREPARE(storage, val);
259  LY_CHECK_ERR_GOTO(!val, ret = LY_EMEM, cleanup);
260  storage->realtype = type;
261 
262  /* check hints */
263  ret = lyplg_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
264  LY_CHECK_GOTO(ret, cleanup);
265 
266  /* length restriction of the string */
267  if (type_str->length) {
268  /* value_len is in bytes, but we need number of characters here */
269  ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
270  LY_CHECK_GOTO(ret, cleanup);
271  }
272 
273  /* pattern restrictions */
274  ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
275  LY_CHECK_GOTO(ret, cleanup);
276 
277  /* parse */
278  ret = lyxp_expr_parse(ctx, value_len ? value : "", value_len, 1, &val->exp);
279  LY_CHECK_GOTO(ret, cleanup);
280  val->ctx = ctx;
281 
282  if (ctx_node && !strcmp(ctx_node->name, "parent-reference") && !strcmp(ctx_node->module->name, "ietf-yang-schema-mount")) {
283  /* special case, this type uses prefix-namespace mapping provided directly in data, keep empty for now */
284  val->format = format = LY_VALUE_STR_NS;
285  ret = ly_set_new((struct ly_set **)&val->prefix_data);
286  LY_CHECK_GOTO(ret, cleanup);
287  } else {
288  /* store format-specific data and context for later prefix resolution */
289  ret = lyplg_type_prefix_data_new(ctx, value, value_len, format, prefix_data, &val->format, &val->prefix_data);
290  LY_CHECK_GOTO(ret, cleanup);
291  }
292 
293  switch (format) {
294  case LY_VALUE_CANON:
295  case LY_VALUE_JSON:
296  case LY_VALUE_LYB:
297  case LY_VALUE_STR_NS:
298  /* store canonical value */
299  if (options & LYPLG_TYPE_STORE_DYNAMIC) {
300  ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
301  options &= ~LYPLG_TYPE_STORE_DYNAMIC;
302  LY_CHECK_GOTO(ret, cleanup);
303  } else {
304  ret = lydict_insert(ctx, value_len ? value : "", value_len, &storage->_canonical);
305  LY_CHECK_GOTO(ret, cleanup);
306  }
307  break;
308  case LY_VALUE_SCHEMA:
310  case LY_VALUE_XML:
311  /* JSON format with prefix is the canonical one */
312  ret = lyplg_type_print_xpath10_value(val, LY_VALUE_JSON, NULL, &canon, err);
313  LY_CHECK_GOTO(ret, cleanup);
314 
315  ret = lydict_insert_zc(ctx, canon, &storage->_canonical);
316  LY_CHECK_GOTO(ret, cleanup);
317  break;
318  }
319 
320 cleanup:
321  if (options & LYPLG_TYPE_STORE_DYNAMIC) {
322  free((void *)value);
323  }
324 
325  if (ret) {
326  lyplg_type_free_xpath10(ctx, storage);
327  } else if (val->format == LY_VALUE_STR_NS) {
328  /* needs validation */
329  return LY_EINCOMPLETE;
330  }
331  return ret;
332 }
333 
342 static LY_ERR
343 xpath10_add_ns(struct ly_set *set, const char *pref, const char *uri)
344 {
345  LY_ERR rc = LY_SUCCESS;
346  struct lyxml_ns *ns = NULL;
347 
348  /* create new ns */
349  ns = calloc(1, sizeof *ns);
350  if (!ns) {
351  rc = LY_EMEM;
352  goto cleanup;
353  }
354  ns->prefix = strdup(pref);
355  ns->uri = strdup(uri);
356  if (!ns->prefix || !ns->uri) {
357  rc = LY_EMEM;
358  goto cleanup;
359  }
360  ns->depth = 1;
361 
362  /* add into the XML namespace set */
363  if ((rc = ly_set_add(set, ns, 1, NULL))) {
364  goto cleanup;
365  }
366  ns = NULL;
367 
368 cleanup:
369  if (ns) {
370  free(ns->prefix);
371  free(ns->uri);
372  free(ns);
373  }
374  return rc;
375 }
376 
380 static LY_ERR
381 lyplg_type_validate_xpath10(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *UNUSED(type),
382  const struct lyd_node *ctx_node, const struct lyd_node *UNUSED(tree), struct lyd_value *storage,
383  struct ly_err_item **err)
384 {
385  LY_ERR ret = LY_SUCCESS;
386  struct lyd_value_xpath10 *val;
387  struct ly_set *set = NULL;
388  uint32_t i;
389  const char *pref, *uri;
390 
391  *err = NULL;
392  LYD_VALUE_GET(storage, val);
393 
394  if (val->format != LY_VALUE_STR_NS) {
395  /* nothing to validate */
396  return LY_SUCCESS;
397  }
398 
399  /* the XML namespace set must exist */
400  assert(val->prefix_data);
401 
402  /* special handling of this particular node */
403  assert(!strcmp(LYD_NAME(ctx_node), "parent-reference") &&
404  !strcmp(ctx_node->schema->module->name, "ietf-yang-schema-mount"));
405 
406  /* get all the prefix mappings */
407  if ((ret = lyd_find_xpath(ctx_node, "../../../namespace", &set))) {
408  goto cleanup;
409  }
410 
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]));
414 
415  if (!lyd_child(set->dnodes[i])->next) {
416  /* missing URI - invalid mapping, skip */
417  continue;
418  }
419  assert(!strcmp(LYD_NAME(lyd_child(set->dnodes[i])->next), "uri"));
420  uri = lyd_get_value(lyd_child(set->dnodes[i])->next);
421 
422  /* new NS */
423  if ((ret = xpath10_add_ns(val->prefix_data, pref, uri))) {
424  goto cleanup;
425  }
426  }
427 
428 cleanup:
429  ly_set_free(set, NULL);
430  if (ret == LY_EMEM) {
431  ly_err_new(err, LY_EMEM, LYVE_DATA, NULL, NULL, LY_EMEM_MSG);
432  } else if (ret) {
433  ly_err_new(err, ret, LYVE_DATA, NULL, NULL, "%s", ly_errmsg(LYD_CTX(ctx_node)));
434  }
435  return ret;
436 }
437 
438 LIBYANG_API_DEF const void *
439 lyplg_type_print_xpath10(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format,
440  void *prefix_data, ly_bool *dynamic, size_t *value_len)
441 {
442  struct lyd_value_xpath10 *val;
443  char *ret;
444  struct ly_err_item *err = NULL;
445 
446  LYD_VALUE_GET(value, val);
447 
448  /* LY_VALUE_STR_NS should never be transformed */
449  if ((val->format == LY_VALUE_STR_NS) || (format == LY_VALUE_CANON) || (format == LY_VALUE_JSON) ||
450  (format == LY_VALUE_LYB)) {
451  /* canonical */
452  if (dynamic) {
453  *dynamic = 0;
454  }
455  if (value_len) {
456  *value_len = strlen(value->_canonical);
457  }
458  return value->_canonical;
459  }
460 
461  /* print in the specific format */
462  if (lyplg_type_print_xpath10_value(val, format, prefix_data, &ret, &err)) {
463  if (err) {
464  LOGVAL_ERRITEM(ctx, err);
465  ly_err_free(err);
466  }
467  return NULL;
468  }
469 
470  *dynamic = 1;
471  if (value_len) {
472  *value_len = strlen(ret);
473  }
474  return ret;
475 }
476 
477 LIBYANG_API_DEF LY_ERR
478 lyplg_type_dup_xpath10(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
479 {
480  LY_ERR ret = LY_SUCCESS;
481  struct lyd_value_xpath10 *orig_val, *dup_val;
482 
483  /* init dup value */
484  memset(dup, 0, sizeof *dup);
485  dup->realtype = original->realtype;
486 
487  ret = lydict_insert(ctx, original->_canonical, 0, &dup->_canonical);
488  LY_CHECK_GOTO(ret, cleanup);
489 
490  LYPLG_TYPE_VAL_INLINE_PREPARE(dup, dup_val);
491  LY_CHECK_ERR_GOTO(!dup_val, LOGMEM(ctx); ret = LY_EMEM, cleanup);
492  dup_val->ctx = ctx;
493 
494  LYD_VALUE_GET(original, orig_val);
495  ret = lyxp_expr_dup(ctx, orig_val->exp, 0, 0, &dup_val->exp);
496  LY_CHECK_GOTO(ret, cleanup);
497 
498  ret = lyplg_type_prefix_data_dup(ctx, orig_val->format, orig_val->prefix_data, &dup_val->prefix_data);
499  LY_CHECK_GOTO(ret, cleanup);
500  dup_val->format = orig_val->format;
501 
502 cleanup:
503  if (ret) {
505  }
506  return ret;
507 }
508 
509 LIBYANG_API_DEF void
510 lyplg_type_free_xpath10(const struct ly_ctx *ctx, struct lyd_value *value)
511 {
512  struct lyd_value_xpath10 *val;
513 
514  lydict_remove(ctx, value->_canonical);
515  value->_canonical = NULL;
516  LYD_VALUE_GET(value, val);
517  if (val) {
518  lyxp_expr_free(ctx, val->exp);
520 
522  }
523 }
524 
532 const struct lyplg_type_record plugins_xpath10[] = {
533  {
534  .module = "ietf-yang-types",
535  .revision = "2013-07-15",
536  .name = "xpath1.0",
537 
538  .plugin.id = "libyang 2 - xpath1.0, version 1",
539  .plugin.store = lyplg_type_store_xpath10,
540  .plugin.validate = lyplg_type_validate_xpath10,
541  .plugin.compare = lyplg_type_compare_simple,
542  .plugin.sort = NULL,
543  .plugin.print = lyplg_type_print_xpath10,
544  .plugin.duplicate = lyplg_type_dup_xpath10,
545  .plugin.free = lyplg_type_free_xpath10,
546  .plugin.lyb_data_len = -1,
547  },
548  {0}
549 };
libyang context handler.
#define LYD_CTX(node)
Macro to get context from a data tree node.
Definition: tree_data.h:527
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,...
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 ...
LY_ERR
libyang's error codes returned by the libyang functions.
Definition: log.h:248
@ LYVE_DATA
Definition: log.h:285
@ LY_EMEM
Definition: log.h:250
@ LY_EVALID
Definition: log.h:256
@ LY_SUCCESS
Definition: log.h:249
@ LY_EINCOMPLETE
Definition: log.h:258
Libyang full error structure.
Definition: log.h:293
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 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_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:43
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_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:214
LIBYANG_API_DECL LY_ERR LIBYANG_API_DECL void ly_err_free(void *ptr)
Destructor for the error records created with ly_err_new().
#define LYPLG_TYPE_VAL_INLINE_DESTROY(type_val)
Destroy a prepared value.
LIBYANG_API_DECL 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.
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.
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_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 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.
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 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_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:478
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:510
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, size_t *value_len)
Implementation of lyplg_type_print_clb for the ietf-yang-types xpath1.0 type.
Definition: xpath1.0.c:439
#define LYPLG_TYPE_STORE_DYNAMIC
const char * name
Definition: tree_schema.h:2090
LY_DATA_TYPE basetype
Definition: tree_schema.h:1283
struct lys_module * module
Definition: tree_schema.h:1402
struct lysc_pattern ** patterns
Definition: tree_schema.h:1311
const char * name
Definition: tree_schema.h:1409
struct lysc_range * length
Definition: tree_schema.h:1310
const char * prefix
Definition: tree_schema.h:2093
Available YANG schema tree structures representing YANG module.
Definition: tree_schema.h:2088
Compiled YANG data node.
Definition: tree_schema.h:1398
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
Definition: tree.h:234
@ LY_TYPE_STRING
Definition: tree.h:209
@ LY_VALUE_JSON
Definition: tree.h:239
@ LY_VALUE_SCHEMA
Definition: tree.h:236
@ LY_VALUE_CANON
Definition: tree.h:235
@ LY_VALUE_XML
Definition: tree.h:238
@ LY_VALUE_STR_NS
Definition: tree.h:241
@ LY_VALUE_SCHEMA_RESOLVED
Definition: tree.h:237
@ LY_VALUE_LYB
Definition: tree.h:240
The main libyang public header.
uint8_t ly_bool
Type to indicate boolean value.
Definition: log.h:28
API for (user) types plugins.
struct lyd_node * next
Definition: tree_data.h:789
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:564
LIBYANG_API_DECL struct lyd_node * lyd_child(const struct lyd_node *node)
Get the child pointer of a generic data node.
LIBYANG_API_DECL const char * lyd_get_value(const struct lyd_node *node)
Get the (canonical) value of a data node.
const struct lysc_node * schema
Definition: tree_data.h:787
struct lyxp_expr * exp
Definition: tree_data.h:706
#define LYD_NAME(node)
Get the name (associated with) of a data node. Works for opaque nodes as well.
Definition: tree_data.h:907
LY_VALUE_FORMAT format
Definition: tree_data.h:709
const struct ly_ctx * ctx
Definition: tree_data.h:707
#define LYD_VALUE_GET(value, type_val)
Get the value in format specific to the type.
Definition: tree_data.h:603
const char * _canonical
Definition: tree_data.h:561
void * prefix_data
Definition: tree_data.h:708
Generic structure for a data node.
Definition: tree_data.h:781
YANG data representation.
Definition: tree_data.h:560
Special lyd_value structure for ietf-yang-types xpath1.0 values.
Definition: tree_data.h:705
#define LOGMEM(CTX)
Definition: tree_edit.h:22
LIBYANG_API_DEF 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 *UNUSED(unres), struct ly_err_item **err)
Definition: xpath1.0.c:247
const struct lyplg_type_record plugins_xpath10[]
Plugin information for xpath1.0 type implementation.
Definition: xpath1.0.c:532