16 #include <sys/cdefs.h>
30 #include "plugins_internal.h"
68 value = ((
char *)subvalue->
original) + 4;
124 ret = union_store_type(ctx, types[u], subvalue, resolve, ctx_node, tree, unres, err);
156 memset(storage, 0,
sizeof *storage);
158 LY_CHECK_ERR_GOTO(!subvalue, ret =
LY_EMEM, cleanup);
168 type_idx = *(uint32_t *)
value;
180 }
else if (value_len) {
181 subvalue->
original = calloc(1, value_len);
193 LY_CHECK_GOTO(ret, cleanup);
199 ret = union_store_type(ctx, type_u->
types[type_idx], subvalue, 0, NULL, NULL, unres, err);
203 ret = union_find_type(ctx, type_u->
types, subvalue, 0, NULL, NULL, unres, err);
209 LY_CHECK_GOTO(ret, cleanup);
232 if (!val->value.realtype->plugin->validate) {
238 if (!val->value.realtype->plugin->validate(ctx, type, ctx_node, tree, &val->value, err)) {
252 uint32_t type_idx = *(uint32_t *)val->original;
253 ret = union_store_type(ctx, type_u->
types[type_idx], val, 1, ctx_node, tree, NULL, err);
257 ret = union_find_type(ctx, type_u->
types, val, 1, ctx_node, tree, NULL, err);
262 ret = union_find_type(ctx, type_u->
types, val, 1, ctx_node, tree, NULL, err);
281 return val1->subvalue->value.
realtype->
plugin->
compare(&val1->subvalue->value, &val2->subvalue->value);
286 void *prefix_data,
ly_bool *dynamic,
size_t *value_len)
290 ret = value->subvalue->value.
realtype->
plugin->
print(ctx, &value->subvalue->value, format, prefix_data, dynamic, value_len);
306 memset(dup, 0,
sizeof *dup);
310 LY_CHECK_GOTO(ret, cleanup);
312 dup_val = calloc(1,
sizeof *dup_val);
313 LY_CHECK_ERR_GOTO(!dup_val,
LOGMEM(ctx); ret =
LY_EMEM, cleanup);
314 dup->subvalue = dup_val;
317 LY_CHECK_GOTO(ret, cleanup);
320 dup_val->original = calloc(1, orig_val->
orig_len);
321 LY_CHECK_ERR_GOTO(!dup_val->original,
LOGMEM(ctx); ret =
LY_EMEM, cleanup);
324 dup_val->original = strdup(
"");
325 LY_CHECK_ERR_GOTO(!dup_val->original,
LOGMEM(ctx); ret =
LY_EMEM, cleanup);
327 dup_val->orig_len = orig_val->
orig_len;
329 dup_val->format = orig_val->
format;
331 LY_CHECK_GOTO(ret, cleanup);
369 .name = LY_TYPE_UNION_STR,
371 .plugin.id =
"libyang 2 - union,version 1",
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 ...
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...
LY_ERR
libyang's error codes returned by the libyang functions.
Libyang full error structure.
uint32_t ly_log_options(uint32_t opts)
Set logger options. Default is LY_LOLOG | LY_LOSTORE_LAST.
lyplg_type_print_clb print
lyplg_type_store_clb store
lyplg_type_compare_clb compare
lyplg_type_validate_clb validate
lyplg_type_dup_clb duplicate
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.
#define LYPLG_TYPE_VAL_INLINE_PREPARE(storage, type_val)
Prepare value memory for storing a specific type value, may be allocated dynamically.
#define LYPLG_TYPE_VAL_INLINE_DESTROY(type_val)
Destroy a prepared value.
LY_ERR lyplg_type_prefix_data_dup(const struct ly_ctx *ctx, LY_VALUE_FORMAT format, const void *orig, void **dup)
Duplicate prefix data.
LY_ERR ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *path, char *apptag, const char *err_msg,...)
Create and fill error structure.
void ly_err_free(void *ptr)
Destructor for the error records created with ly_err_new().
void lyplg_type_prefix_data_free(LY_VALUE_FORMAT format, void *prefix_data)
Free internal prefix data.
API void lyplg_type_free_union(const struct ly_ctx *ctx, struct lyd_value *value)
Implementation of lyplg_type_free_clb for the built-in union type.
API LY_ERR lyplg_type_dup_union(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
Implementation of lyplg_type_dup_clb for the built-in union type.
API LY_ERR lyplg_type_compare_union(const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for the built-in union type.
API const void * lyplg_type_print_union(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 built-in union type.
API LY_ERR lyplg_type_store_union(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 union type.
API LY_ERR lyplg_type_validate_union(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err)
Implementation of lyplg_type_validate_clb for the built-in union type.
#define LYPLG_TYPE_STORE_DYNAMIC
struct lyplg_type * plugin
struct lysc_type ** types
#define LY_ARRAY_COUNT(ARRAY)
Get the number of records in the ARRAY.
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
#define LY_PRI_ARRAY_COUNT_TYPE
Printing format specifier macro for LY_ARRAY_SIZE_TYPE values.
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
The main libyang public header.
uint8_t ly_bool
Type to indicate boolean value.
API for (user) types plugins.
const struct lysc_type * realtype
#define LYD_VALUE_GET(value, type_val)
Get the value in format specific to the type.
const struct lysc_node * ctx_node
Generic structure for a data node.
YANG data representation.
Special lyd_value structure for built-in union values.
const struct lyplg_type_record plugins_union[]
Plugin information for union type implementation.