libyang  2.2.8
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "compat.h"
27 #include "ly_common.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 lys_module **context_mod,
42  const struct ly_ctx *resolve_ctx, LY_VALUE_FORMAT resolve_format, const void *resolve_prefix_data,
43  LY_VALUE_FORMAT get_format, void *get_prefix_data, char **token_p, struct ly_err_item **err)
44 {
45  LY_ERR ret = LY_SUCCESS;
46  const char *str_begin, *str_next, *prefix;
47  ly_bool is_prefix, has_prefix = 0;
48  char *str = NULL;
49  void *mem;
50  uint32_t len, str_len = 0, pref_len;
51  const struct lys_module *mod;
52 
53  str_begin = token;
54 
55  while (!(ret = ly_value_prefix_next(str_begin, token + tok_len, &len, &is_prefix, &str_next)) && len) {
56  if (!is_prefix) {
57  if (!has_prefix && is_nametest && (get_format == LY_VALUE_XML) && *context_mod) {
58  /* get the prefix */
59  prefix = lyplg_type_get_prefix(*context_mod, get_format, get_prefix_data);
60  assert(prefix);
61 
62  /* append the nametest and prefix */
63  mem = realloc(str, str_len + strlen(prefix) + 1 + len + 1);
64  LY_CHECK_ERR_GOTO(!mem, ret = ly_err_new(err, LY_EMEM, LYVE_DATA, NULL, NULL, "No memory."), cleanup);
65  str = mem;
66  str_len += sprintf(str + str_len, "%s:%.*s", prefix, (int)len, str_begin);
67  } else {
68  /* just append the string, we may get the first expression node without a prefix but since this
69  * is not strictly forbidden, allow it */
70  mem = realloc(str, str_len + len + 1);
71  LY_CHECK_ERR_GOTO(!mem, ret = ly_err_new(err, LY_EMEM, LYVE_DATA, NULL, NULL, "No memory."), cleanup);
72  str = mem;
73  str_len += sprintf(str + str_len, "%.*s", (int)len, str_begin);
74  }
75  } else {
76  /* remember there was a prefix found */
77  has_prefix = 1;
78 
79  /* resolve the module in the original format */
80  mod = lyplg_type_identity_module(resolve_ctx, NULL, str_begin, len, resolve_format, resolve_prefix_data);
81  if (!mod && is_nametest) {
82  ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to resolve prefix \"%.*s\".",
83  (int)len, str_begin);
84  goto cleanup;
85  }
86 
87  if (is_nametest && ((get_format == LY_VALUE_JSON) || (get_format == LY_VALUE_LYB)) && (*context_mod == mod)) {
88  /* inherit the prefix and do not print it again */
89  } else {
90  if (mod) {
91  /* get the prefix in the target format */
92  prefix = lyplg_type_get_prefix(mod, get_format, get_prefix_data);
93  assert(prefix);
94  pref_len = strlen(prefix);
95  } else {
96  /* invalid prefix, just copy it */
97  prefix = str_begin;
98  pref_len = len;
99  }
100 
101  /* append the prefix */
102  mem = realloc(str, str_len + pref_len + 2);
103  LY_CHECK_ERR_GOTO(!mem, ret = ly_err_new(err, LY_EMEM, LYVE_DATA, NULL, NULL, "No memory."), cleanup);
104  str = mem;
105  str_len += sprintf(str + str_len, "%.*s:", (int)pref_len, prefix);
106  }
107 
108  if (is_nametest) {
109  /* update context module */
110  *context_mod = mod;
111  }
112  }
113 
114  str_begin = str_next;
115  }
116 
117 cleanup:
118  if (ret) {
119  free(str);
120  } else {
121  *token_p = str;
122  }
123  return ret;
124 }
125 
141 static LY_ERR
142 xpath10_print_subexpr_r(uint16_t *cur_idx, enum lyxp_token end_tok, const struct lys_module *context_mod,
143  const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format, void *prefix_data, char **str_value,
144  uint32_t *str_len, struct ly_err_item **err)
145 {
146  enum lyxp_token cur_tok, sub_end_tok;
147  char *str_tok;
148  void *mem;
149  const char *cur_exp_ptr;
150  ly_bool is_nt;
151  const struct lys_module *orig_context_mod = context_mod;
152 
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];
156 
157  if ((cur_tok == LYXP_TOKEN_NAMETEST) || (cur_tok == LYXP_TOKEN_LITERAL)) {
158  /* tokens that may include prefixes, get them in the target format */
159  is_nt = (cur_tok == LYXP_TOKEN_NAMETEST) ? 1 : 0;
160  LY_CHECK_RET(lyplg_type_xpath10_print_token(cur_exp_ptr, xp_val->exp->tok_len[*cur_idx], is_nt, &context_mod,
161  xp_val->ctx, xp_val->format, xp_val->prefix_data, format, prefix_data, &str_tok, err));
162 
163  /* append the converted token */
164  mem = realloc(*str_value, *str_len + strlen(str_tok) + 1);
165  LY_CHECK_ERR_GOTO(!mem, free(str_tok), error_mem);
166  *str_value = mem;
167  *str_len += sprintf(*str_value + *str_len, "%s", str_tok);
168  free(str_tok);
169 
170  /* token processed */
171  ++(*cur_idx);
172  } else {
173  if ((cur_tok == LYXP_TOKEN_OPER_LOG) || (cur_tok == LYXP_TOKEN_OPER_UNI) || (cur_tok == LYXP_TOKEN_OPER_MATH)) {
174  /* copy the token with spaces around */
175  mem = realloc(*str_value, *str_len + 1 + xp_val->exp->tok_len[*cur_idx] + 2);
176  LY_CHECK_GOTO(!mem, error_mem);
177  *str_value = mem;
178  *str_len += sprintf(*str_value + *str_len, " %.*s ", (int)xp_val->exp->tok_len[*cur_idx], cur_exp_ptr);
179 
180  /* reset context mod */
181  context_mod = orig_context_mod;
182  } else {
183  /* just copy the token */
184  mem = realloc(*str_value, *str_len + xp_val->exp->tok_len[*cur_idx] + 1);
185  LY_CHECK_GOTO(!mem, error_mem);
186  *str_value = mem;
187  *str_len += sprintf(*str_value + *str_len, "%.*s", (int)xp_val->exp->tok_len[*cur_idx], cur_exp_ptr);
188  }
189 
190  /* token processed but keep it in cur_tok */
191  ++(*cur_idx);
192 
193  if (end_tok && (cur_tok == end_tok)) {
194  /* end token found */
195  break;
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;
198 
199  /* parse the subexpression separately, use the current context mod */
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));
202  }
203  }
204  }
205 
206  return LY_SUCCESS;
207 
208 error_mem:
209  return ly_err_new(err, LY_EMEM, LYVE_DATA, NULL, NULL, "No memory.");
210 }
211 
212 LIBYANG_API_DEF LY_ERR
213 lyplg_type_print_xpath10_value(const struct lyd_value_xpath10 *xp_val, LY_VALUE_FORMAT format, void *prefix_data,
214  char **str_value, struct ly_err_item **err)
215 {
216  LY_ERR ret = LY_SUCCESS;
217  uint16_t expr_idx = 0;
218  uint32_t str_len = 0;
219  const struct lys_module *local_mod = NULL;
220  struct ly_set *mods;
221 
222  *str_value = NULL;
223  *err = NULL;
224 
225  if (format == LY_VALUE_XML) {
226  /* null 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  }
231 
232  /* recursively print the expression */
233  ret = xpath10_print_subexpr_r(&expr_idx, 0, NULL, xp_val, format, prefix_data, str_value, &str_len, err);
234 
235  if (local_mod) {
236  mods->objs[0] = (void *)local_mod;
237  }
238  if (ret) {
239  free(*str_value);
240  *str_value = NULL;
241  }
242  return ret;
243 }
244 
245 LIBYANG_API_DEF LY_ERR
246 lyplg_type_store_xpath10(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, size_t value_len,
247  uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node,
248  struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
249 {
250  LY_ERR ret = LY_SUCCESS;
251  struct lysc_type_str *type_str = (struct lysc_type_str *)type;
252  struct lyd_value_xpath10 *val;
253  char *canon;
254 
255  /* init storage */
256  memset(storage, 0, sizeof *storage);
257  LYPLG_TYPE_VAL_INLINE_PREPARE(storage, val);
258  LY_CHECK_ERR_GOTO(!val, ret = LY_EMEM, cleanup);
259  storage->realtype = type;
260 
261  /* check hints */
262  ret = lyplg_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
263  LY_CHECK_GOTO(ret, cleanup);
264 
265  /* length restriction of the string */
266  if (type_str->length) {
267  /* value_len is in bytes, but we need number of characters here */
268  ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
269  LY_CHECK_GOTO(ret, cleanup);
270  }
271 
272  /* pattern restrictions */
273  ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
274  LY_CHECK_GOTO(ret, cleanup);
275 
276  /* parse */
277  ret = lyxp_expr_parse(ctx, value_len ? value : "", value_len, 1, &val->exp);
278  LY_CHECK_GOTO(ret, cleanup);
279  val->ctx = ctx;
280 
281  if (ctx_node && !strcmp(ctx_node->name, "parent-reference") && !strcmp(ctx_node->module->name, "ietf-yang-schema-mount")) {
282  /* special case, this type uses prefix-namespace mapping provided directly in data, keep empty for now */
283  val->format = format = LY_VALUE_STR_NS;
284  ret = ly_set_new((struct ly_set **)&val->prefix_data);
285  LY_CHECK_GOTO(ret, cleanup);
286  } else {
287  /* store format-specific data and context for later prefix resolution */
288  ret = lyplg_type_prefix_data_new(ctx, value, value_len, format, prefix_data, &val->format, &val->prefix_data);
289  LY_CHECK_GOTO(ret, cleanup);
290  }
291 
292  switch (format) {
293  case LY_VALUE_CANON:
294  case LY_VALUE_JSON:
295  case LY_VALUE_LYB:
296  case LY_VALUE_STR_NS:
297  /* store canonical value */
298  if (options & LYPLG_TYPE_STORE_DYNAMIC) {
299  ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
300  options &= ~LYPLG_TYPE_STORE_DYNAMIC;
301  LY_CHECK_GOTO(ret, cleanup);
302  } else {
303  ret = lydict_insert(ctx, value_len ? value : "", value_len, &storage->_canonical);
304  LY_CHECK_GOTO(ret, cleanup);
305  }
306  break;
307  case LY_VALUE_SCHEMA:
309  case LY_VALUE_XML:
310  /* JSON format with prefix is the canonical one */
311  ret = lyplg_type_print_xpath10_value(val, LY_VALUE_JSON, NULL, &canon, err);
312  LY_CHECK_GOTO(ret, cleanup);
313 
314  ret = lydict_insert_zc(ctx, canon, &storage->_canonical);
315  LY_CHECK_GOTO(ret, cleanup);
316  break;
317  }
318 
319 cleanup:
320  if (options & LYPLG_TYPE_STORE_DYNAMIC) {
321  free((void *)value);
322  }
323 
324  if (ret) {
325  lyplg_type_free_xpath10(ctx, storage);
326  } else if (val->format == LY_VALUE_STR_NS) {
327  /* needs validation */
328  return LY_EINCOMPLETE;
329  }
330  return ret;
331 }
332 
341 static LY_ERR
342 xpath10_add_ns(struct ly_set *set, const char *pref, const char *uri)
343 {
344  LY_ERR rc = LY_SUCCESS;
345  struct lyxml_ns *ns = NULL;
346 
347  /* create new ns */
348  ns = calloc(1, sizeof *ns);
349  if (!ns) {
350  rc = LY_EMEM;
351  goto cleanup;
352  }
353  ns->prefix = strdup(pref);
354  ns->uri = strdup(uri);
355  if (!ns->prefix || !ns->uri) {
356  rc = LY_EMEM;
357  goto cleanup;
358  }
359  ns->depth = 1;
360 
361  /* add into the XML namespace set */
362  if ((rc = ly_set_add(set, ns, 1, NULL))) {
363  goto cleanup;
364  }
365  ns = NULL;
366 
367 cleanup:
368  if (ns) {
369  free(ns->prefix);
370  free(ns->uri);
371  free(ns);
372  }
373  return rc;
374 }
375 
379 static LY_ERR
380 lyplg_type_validate_xpath10(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *UNUSED(type),
381  const struct lyd_node *ctx_node, const struct lyd_node *UNUSED(tree), struct lyd_value *storage,
382  struct ly_err_item **err)
383 {
384  LY_ERR ret = LY_SUCCESS;
385  struct lyd_value_xpath10 *val;
386  struct ly_set *set = NULL;
387  uint32_t i;
388  const char *pref, *uri;
389  const struct ly_err_item *eitem;
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  eitem = ly_err_last(LYD_CTX(ctx_node));
434  ly_err_new(err, ret, LYVE_DATA, eitem->data_path, NULL, "%s", eitem->msg);
435  }
436  return ret;
437 }
438 
439 LIBYANG_API_DEF const void *
440 lyplg_type_print_xpath10(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format,
441  void *prefix_data, ly_bool *dynamic, size_t *value_len)
442 {
443  struct lyd_value_xpath10 *val;
444  char *ret;
445  struct ly_err_item *err = NULL;
446 
447  LYD_VALUE_GET(value, val);
448 
449  /* LY_VALUE_STR_NS should never be transformed */
450  if ((val->format == LY_VALUE_STR_NS) || (format == LY_VALUE_CANON) || (format == LY_VALUE_JSON) ||
451  (format == LY_VALUE_LYB)) {
452  /* canonical */
453  if (dynamic) {
454  *dynamic = 0;
455  }
456  if (value_len) {
457  *value_len = strlen(value->_canonical);
458  }
459  return value->_canonical;
460  }
461 
462  /* print in the specific format */
463  if (lyplg_type_print_xpath10_value(val, format, prefix_data, &ret, &err)) {
464  if (err) {
465  ly_err_print(ctx, err);
466  ly_err_free(err);
467  }
468  return NULL;
469  }
470 
471  *dynamic = 1;
472  if (value_len) {
473  *value_len = strlen(ret);
474  }
475  return ret;
476 }
477 
478 LIBYANG_API_DEF LY_ERR
479 lyplg_type_dup_xpath10(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
480 {
481  LY_ERR ret = LY_SUCCESS;
482  struct lyd_value_xpath10 *orig_val, *dup_val;
483 
484  /* init dup value */
485  memset(dup, 0, sizeof *dup);
486  dup->realtype = original->realtype;
487 
488  ret = lydict_insert(ctx, original->_canonical, 0, &dup->_canonical);
489  LY_CHECK_GOTO(ret, cleanup);
490 
491  LYPLG_TYPE_VAL_INLINE_PREPARE(dup, dup_val);
492  LY_CHECK_ERR_GOTO(!dup_val, LOGMEM(ctx); ret = LY_EMEM, cleanup);
493  dup_val->ctx = ctx;
494 
495  LYD_VALUE_GET(original, orig_val);
496  ret = lyxp_expr_dup(ctx, orig_val->exp, 0, 0, &dup_val->exp);
497  LY_CHECK_GOTO(ret, cleanup);
498 
499  ret = lyplg_type_prefix_data_dup(ctx, orig_val->format, orig_val->prefix_data, &dup_val->prefix_data);
500  LY_CHECK_GOTO(ret, cleanup);
501  dup_val->format = orig_val->format;
502 
503 cleanup:
504  if (ret) {
505  lyplg_type_free_xpath10(ctx, dup);
506  }
507  return ret;
508 }
509 
510 LIBYANG_API_DEF void
511 lyplg_type_free_xpath10(const struct ly_ctx *ctx, struct lyd_value *value)
512 {
513  struct lyd_value_xpath10 *val;
514 
515  lydict_remove(ctx, value->_canonical);
516  value->_canonical = NULL;
517  LYD_VALUE_GET(value, val);
518  if (val) {
519  lyxp_expr_free(ctx, val->exp);
521 
523  }
524 }
525 
534  {
535  .module = "ietf-yang-types",
536  .revision = "2013-07-15",
537  .name = "xpath1.0",
538 
539  .plugin.id = "libyang 2 - xpath1.0, version 1",
540  .plugin.store = lyplg_type_store_xpath10,
541  .plugin.validate = lyplg_type_validate_xpath10,
542  .plugin.compare = lyplg_type_compare_simple,
543  .plugin.sort = lyplg_type_sort_simple,
544  .plugin.print = lyplg_type_print_xpath10,
545  .plugin.duplicate = lyplg_type_dup_xpath10,
546  .plugin.free = lyplg_type_free_xpath10,
547  .plugin.lyb_data_len = -1,
548  },
549  {0}
550 };
struct lysc_type * realtype
Definition: tree_data.h:575
Compiled YANG data node.
Definition: tree_schema.h:1439
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.
Definition: xpath1.0.c:41
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.
Definition: tree_data.h:799
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.
Definition: log.h:28
Definition: log.h:242
const char * name
Definition: tree_schema.h:1450
#define LYPLG_TYPE_STORE_DYNAMIC
#define LOGMEM(CTX)
Definition: tree_edit.h:22
char * msg
Definition: log.h:289
void * prefix_data
Definition: tree_data.h:719
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
Definition: tree_data.h:805
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.
struct lysc_pattern ** patterns
Definition: tree_schema.h:1339
struct lysc_range * length
Definition: tree_schema.h:1338
YANG data representation.
Definition: tree_data.h:571
const char * _canonical
Definition: tree_data.h:572
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.
uint32_t count
Definition: set.h:49
Libyang full error structure.
Definition: log.h:285
struct ly_ctx * ctx
Definition: tree_data.h:718
Definition: log.h:277
#define LYD_VALUE_GET(value, type_val)
Get the value in format specific to the type.
Definition: tree_data.h:614
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.
Definition: xpath1.0.c:533
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.
Definition: tree_data.h:925
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...
Definition: set.h:47
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.
Definition: xpath1.0.c:479
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.
Definition: tree_schema.h:2131
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&#39;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.
Definition: xpath1.0.c:440
const char * module
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
Definition: tree_schema.h:1443
Special lyd_value structure for ietf-yang-types xpath1.0 values.
Definition: tree_data.h:716
#define LYD_CTX(node)
Macro to get context from a data tree node.
Definition: tree_data.h:527
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.
Definition: xpath1.0.c:213
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.
Definition: xpath1.0.c:511
LY_VALUE_FORMAT format
Definition: tree_data.h:720
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
Definition: tree.h:234
LIBYANG_API_DECL struct ly_err_item * ly_err_last(const struct ly_ctx *ctx)
Get the latest (thread, context-specific) generated error structure.
Definition: log.h:248
#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_DATA_TYPE basetype
Definition: tree_schema.h:1305
struct lyxp_expr * exp
Definition: tree_data.h:717
API for (user) types plugins.
LY_ERR
libyang&#39;s error codes returned by the libyang functions.
Definition: log.h:240
libyang context handler.
const char * name
Definition: tree_schema.h:2133
char * data_path
Definition: log.h:290
assert(!value->_canonical)
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.