libyang  2.1.30
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
empty.c
Go to the documentation of this file.
1 
15 #include "plugins_types.h"
16 
17 #include <stdint.h>
18 #include <stdlib.h>
19 
20 #include "libyang.h"
21 
22 /* additional internal headers for some useful simple macros */
23 #include "common.h"
24 #include "compat.h"
25 #include "plugins_internal.h" /* LY_TYPE_*_STR */
26 
36 LIBYANG_API_DEF LY_ERR
37 lyplg_type_store_empty(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, size_t value_len,
38  uint32_t options, LY_VALUE_FORMAT UNUSED(format), void *UNUSED(prefix_data), uint32_t hints,
39  const struct lysc_node *UNUSED(ctx_node), struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres),
40  struct ly_err_item **err)
41 {
42  LY_ERR ret = LY_SUCCESS;
43 
44  /* init storage */
45  memset(storage, 0, sizeof *storage);
46  storage->realtype = type;
47 
48  /* check hints */
49  ret = lyplg_type_check_hints(hints, value, value_len, type->basetype, NULL, err);
50  LY_CHECK_GOTO(ret, cleanup);
51 
52  /* validation */
53  if (value_len) {
54  ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid empty value length %zu.", value_len);
55  goto cleanup;
56  }
57 
58  /* store canonical value, it always is */
59  if (options & LYPLG_TYPE_STORE_DYNAMIC) {
60  ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
61  options &= ~LYPLG_TYPE_STORE_DYNAMIC;
62  LY_CHECK_GOTO(ret, cleanup);
63  } else {
64  ret = lydict_insert(ctx, "", value_len, &storage->_canonical);
65  LY_CHECK_GOTO(ret, cleanup);
66  }
67 
68 cleanup:
69  if (options & LYPLG_TYPE_STORE_DYNAMIC) {
70  free((void *)value);
71  }
72 
73  if (ret) {
74  lyplg_type_free_simple(ctx, storage);
75  }
76  return ret;
77 }
78 
86 const struct lyplg_type_record plugins_empty[] = {
87  {
88  .module = "",
89  .revision = NULL,
90  .name = LY_TYPE_EMPTY_STR,
91 
92  .plugin.id = "libyang 2 - empty, version 1",
93  .plugin.store = lyplg_type_store_empty,
94  .plugin.validate = NULL,
95  .plugin.compare = lyplg_type_compare_simple,
96  .plugin.sort = NULL,
97  .plugin.print = lyplg_type_print_simple,
98  .plugin.duplicate = lyplg_type_dup_simple,
99  .plugin.free = lyplg_type_free_simple,
100  .plugin.lyb_data_len = 0,
101  },
102  {0}
103 };
struct lysc_type * realtype
Definition: tree_data.h:564
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
LIBYANG_API_DECL LY_ERR lyplg_type_store_empty(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 built-in empty type.
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 const void * lyplg_type_print_simple(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 a generic simple type.
#define LYPLG_TYPE_STORE_DYNAMIC
The main libyang public header.
YANG data representation.
Definition: tree_data.h:560
const char * _canonical
Definition: tree_data.h:561
Libyang full error structure.
Definition: log.h:299
Definition: log.h:291
Definition: log.h:262
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 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.
const char * module
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.
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
Definition: tree.h:234
struct lyplg_type_record plugins_empty[]
Plugin information for empty type implementation.
Definition: empty.c:86
LY_DATA_TYPE basetype
Definition: tree_schema.h:1299
LIBYANG_API_DECL LY_ERR lyplg_type_dup_simple(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
Implementation of lyplg_type_dup_clb for a generic simple type.
LY_ERR
libyang&#39;s error codes returned by the libyang functions.
Definition: log.h:254
LIBYANG_API_DECL void lyplg_type_free_simple(const struct ly_ctx *ctx, struct lyd_value *value)
Implementation of lyplg_type_free_clb for a generic simple type.
API for (user) types plugins.
libyang context handler.