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