26 #include "ly_common.h"
28 #include "plugins_internal.h"
49 instanceid_path2str(
const struct ly_path *path,
LY_VALUE_FORMAT format,
void *prefix_data,
char **str)
53 char *result = NULL, quot;
54 const struct lys_module *mod = NULL, *local_mod = NULL;
55 struct ly_set *mods = NULL;
63 local_mod = mods->objs[0];
83 if (!inherit_prefix || (mod != path[u].node->module)) {
84 mod = path[u].node->module;
85 ret = ly_strcat(&result,
"/%s:%s",
lyplg_type_get_prefix(mod, format, prefix_data), path[u].node->name);
87 ret = ly_strcat(&result,
"/%s", path[u].node->name);
89 LY_CHECK_GOTO(ret, cleanup);
93 struct ly_path_predicate *pred = &path[u].predicates[v];
96 case LY_PATH_PREDTYPE_POSITION:
98 ret = ly_strcat(&result,
"[%" PRIu64
"]", pred->position);
100 case LY_PATH_PREDTYPE_LIST:
103 LY_CHECK_GOTO(ret, cleanup);
107 if (strchr(strval, quot)) {
110 if (inherit_prefix) {
112 ret = ly_strcat(&result,
"[%s=%c%s%c]", pred->key->name, quot, strval, quot);
114 ret = ly_strcat(&result,
"[%s:%s=%c%s%c]",
lyplg_type_get_prefix(pred->key->module, format, prefix_data),
115 pred->key->name, quot, strval, quot);
119 case LY_PATH_PREDTYPE_LEAFLIST:
122 LY_CHECK_GOTO(ret, cleanup);
126 if (strchr(strval, quot)) {
129 ret = ly_strcat(&result,
"[.=%c%s%c]", quot, strval, quot);
132 case LY_PATH_PREDTYPE_LIST_VAR:
133 LOGINT(path[u].node->module->ctx);
138 LY_CHECK_GOTO(ret, cleanup);
144 mods->objs[0] = (
void *)local_mod;
155 lyplg_type_store_instanceid(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value, uint32_t value_size_bits,
163 struct ly_path *path;
167 memset(storage, 0,
sizeof *storage);
173 LY_CHECK_GOTO(ret, cleanup);
177 LY_CHECK_GOTO(ret, cleanup);
183 top_ext, unres, &path, err);
186 top_ext, unres, &path, err);
188 LY_CHECK_GOTO(ret, cleanup);
191 storage->target = path;
195 LY_CHECK_GOTO(ret, cleanup);
201 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
202 LY_CHECK_GOTO(ret, cleanup);
205 LY_CHECK_GOTO(ret, cleanup);
209 ret = instanceid_path2str(path,
LY_VALUE_JSON, NULL, &canon);
210 LY_CHECK_GOTO(ret, cleanup);
213 LY_CHECK_GOTO(ret, cleanup);
217 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
233 lyplg_type_validate_tree_instanceid(
const struct ly_ctx *ctx,
const struct lysc_type *UNUSED(type),
250 if ((ret = ly_path_eval(storage->target, tree, NULL, top_ext, NULL))) {
253 return ly_err_new(err, ret,
LYVE_DATA, path, strdup(
"instance-required"), LY_ERRMSG_NOINST, value);
261 void *prefix_data,
ly_bool *dynamic, uint32_t *value_size_bits)
269 if (value_size_bits) {
270 *value_size_bits = strlen(value->
_canonical) * 8;
276 if (instanceid_path2str(value->target, format, prefix_data, &ret)) {
281 if (value_size_bits) {
282 *value_size_bits = strlen(ret) * 8;
293 memset(dup, 0,
sizeof *dup);
297 LY_CHECK_GOTO(ret, error);
300 ret = ly_path_dup(ctx, original->target, &dup->target);
301 LY_CHECK_GOTO(ret, error);
316 ly_path_free(value->target);
330 .name = LY_TYPE_INST_STR,
332 .plugin.id =
"ly2 instance-identifier",
334 .plugin.store = lyplg_type_store_instanceid,
335 .plugin.validate_value = NULL,
336 .plugin.validate_tree = lyplg_type_validate_tree_instanceid,
339 .plugin.print = lyplg_type_print_instanceid,
340 .plugin.duplicate = lyplg_type_dup_instanceid,
struct lysc_type * realtype
LIBYANG_API_DECL LY_ERR lyplg_type_lypath_new(const struct ly_ctx *ctx, const char *value, uint32_t value_len, uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, const struct lysc_node *ctx_node, const struct lysc_ext_instance *top_ext, struct lys_glob_unres *unres, struct ly_path **path, struct ly_err_item **err)
Helper function to create internal schema path representation for instance-identifier value represent...
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
struct lyplg_type_record plugins_instanceid[]
Plugin information for instance-identifier type implementation.
LIBYANG_API_DECL LY_ERR lyplg_type_check_value_size(const char *type_name, LY_VALUE_FORMAT format, uint32_t value_size_bits, enum lyplg_lyb_size_type lyb_size_type, uint32_t lyb_fixed_size_bits, uint32_t *value_size, struct ly_err_item **err)
Check a value type in bits is correct and as expected.
Generic structure for a data node.
YANG extension compiled instance.
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.
LY_ERR
libyang's error codes returned by the libyang functions.
uint8_t ly_bool
Type to indicate boolean value.
LIBYANG_API_DECL LY_ERR lyplg_type_lypath_check_status(const struct lysc_node *ctx_node, const struct ly_path *path, LY_VALUE_FORMAT format, void *prefix_data, struct ly_err_item **err)
Check that the lypath instance-identifier value is allowed based on the status of the nodes...
#define LYPLG_TYPE_STORE_DYNAMIC
LIBYANG_API_DECL char * lyd_path(const struct lyd_node *node, LYD_PATH_TYPE pathtype, char *buffer, size_t buflen)
Generate path of the given node in the requested format.
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 void lyplg_type_free_instanceid(const struct ly_ctx *ctx, struct lyd_value *value)
Implementation of lyplg_type_free_clb for the built-in instance-identifier type.
LIBYANG_API_DECL LY_ERR lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_FORMAT format, void *prefix_data, const char **value)
Convert canonical value into a value in a specific format.
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.
LIBYANG_API_DECL void lyplg_type_lyb_size_variable_bytes(const struct lysc_type *type, enum lyplg_lyb_size_type *size_type, uint32_t *fixed_size_bits)
Implementation of lyplg_type_lyb_size_clb for a type with variable length rounded to bytes...
YANG data representation.
Libyang full error structure.
LIBYANG_API_DECL const char * lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value)
Get the (canonical) value of a lyd_value.
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.
Structure to hold a set of (not necessary somehow connected) objects. Usually used for lyd_node...
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.
#define LY_ARRAY_FOR(ARRAY,...)
Sized-array iterator (for-loop).
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
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.
if((v1->size!=v2->size)||memcmp(v1->data, v2->data, v1->size))
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
LIBYANG_API_DECL LY_ERR lyplg_type_check_hints(uint32_t hints, const char *value, uint32_t value_len, LY_DATA_TYPE type, int *base, struct ly_err_item **err)
Check that the type is suitable for the parser's hints (if any) in the specified format.
API for (user) types plugins.