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