27#include "plugins_internal.h"
48instanceid_path2str(
const struct ly_path *path,
LY_VALUE_FORMAT format,
void *prefix_data,
char **str)
52 char *result = NULL, quot;
53 const struct lys_module *mod = NULL, *local_mod = NULL;
54 struct ly_set *mods = NULL;
62 local_mod = mods->objs[0];
82 if (!inherit_prefix || (mod != path[u].node->module)) {
83 mod = path[u].node->module;
84 ret = ly_strcat(&result,
"/%s:%s",
lyplg_type_get_prefix(mod, format, prefix_data), path[u].node->name);
86 ret = ly_strcat(&result,
"/%s", path[u].node->name);
88 LY_CHECK_GOTO(ret, cleanup);
92 struct ly_path_predicate *pred = &path[u].predicates[v];
95 case LY_PATH_PREDTYPE_POSITION:
97 ret = ly_strcat(&result,
"[%" PRIu64
"]", pred->position);
99 case LY_PATH_PREDTYPE_LIST:
101 strval = pred->value.realtype->plugin->print(path[u].node->module->ctx, &pred->value, format, prefix_data,
106 if (strchr(strval, quot)) {
109 if (inherit_prefix) {
111 ret = ly_strcat(&result,
"[%s=%c%s%c]", pred->key->name, quot, strval, quot);
113 ret = ly_strcat(&result,
"[%s:%s=%c%s%c]",
lyplg_type_get_prefix(pred->key->module, format, prefix_data),
114 pred->key->name, quot, strval, quot);
117 free((
char *)strval);
120 case LY_PATH_PREDTYPE_LEAFLIST:
122 strval = pred->value.realtype->plugin->print(path[u].node->module->ctx, &pred->value, format, prefix_data,
127 if (strchr(strval, quot)) {
130 ret = ly_strcat(&result,
"[.=%c%s%c]", quot, strval, quot);
132 free((
char *)strval);
135 case LY_PATH_PREDTYPE_LIST_VAR:
136 LOGINT(path[u].node->module->ctx);
141 LY_CHECK_GOTO(ret, cleanup);
147 mods->objs[0] = (
void *)local_mod;
164 struct ly_path *path;
168 memset(storage, 0,
sizeof *storage);
173 LY_CHECK_GOTO(ret, cleanup);
184 LY_CHECK_GOTO(ret, cleanup);
187 storage->target = path;
191 LY_CHECK_GOTO(ret, cleanup);
197 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
198 LY_CHECK_GOTO(ret, cleanup);
201 LY_CHECK_GOTO(ret, cleanup);
205 ret = instanceid_path2str(path,
LY_VALUE_JSON, NULL, &canon);
206 LY_CHECK_GOTO(ret, cleanup);
209 LY_CHECK_GOTO(ret, cleanup);
246 if ((ret = ly_path_eval(storage->target, tree, NULL, NULL))) {
249 return ly_err_new(err, ret,
LYVE_DATA, path, strdup(
"instance-required"), LY_ERRMSG_NOINST, value);
267 struct ly_path *s1 = &val1->target[u];
268 struct ly_path *s2 = &val2->target[u];
274 struct ly_path_predicate *pred1 = &s1->predicates[v];
275 struct ly_path_predicate *pred2 = &s2->predicates[v];
277 if (pred1->type != pred2->type) {
281 switch (pred1->type) {
282 case LY_PATH_PREDTYPE_POSITION:
284 if (pred1->position != pred2->position) {
288 case LY_PATH_PREDTYPE_LIST:
290 if ((pred1->key != pred2->key) ||
291 ((
struct lysc_node_leaf *)pred1->key)->type->plugin->compare(&pred1->value, &pred2->value)) {
295 case LY_PATH_PREDTYPE_LEAFLIST:
297 if (((
struct lysc_node_leaflist *)s1->node)->type->plugin->compare(&pred1->value, &pred2->value)) {
301 case LY_PATH_PREDTYPE_LIST_VAR:
303 if ((pred1->key != pred2->key) || strcmp(pred1->variable, pred2->variable)) {
314LIBYANG_API_DEF
const void *
316 void *prefix_data,
ly_bool *dynamic,
size_t *value_len)
331 if (instanceid_path2str(value->target, format, prefix_data, &ret)) {
336 *value_len = strlen(ret);
346 memset(dup, 0,
sizeof *dup);
350 LY_CHECK_GOTO(ret, error);
353 ret = ly_path_dup(ctx, original->target, &dup->target);
354 LY_CHECK_GOTO(ret, error);
369 ly_path_free(ctx, value->target);
383 .name = LY_TYPE_INST_STR,
385 .plugin.id =
"libyang 2 - instance-identifier, version 1",
393 .plugin.lyb_data_len = -1,
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 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_zc(const struct ly_ctx *ctx, char *value, const char **str_p)
Insert string into dictionary - zerocopy version. If the string is already present,...
LY_ERR
libyang's error codes returned by the libyang functions.
Libyang full error structure.
Structure to hold a set of (not necessary somehow connected) objects. Usually used for lyd_node,...
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 char * lyplg_type_get_prefix(const struct lys_module *mod, LY_VALUE_FORMAT format, void *prefix_data)
Get format-specific prefix for a module.
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.
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's hints (if any) in the specified format.
LIBYANG_API_DECL LY_ERR lyplg_type_lypath_new(const struct ly_ctx *ctx, const char *value, size_t value_len, uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, const struct lysc_node *ctx_node, 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...
LIBYANG_API_DEF LY_ERR lyplg_type_store_instanceid(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 instance-identifier type.
LIBYANG_API_DEF LY_ERR lyplg_type_dup_instanceid(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
Implementation of lyplg_type_dup_clb for the built-in instance-identifier type.
LIBYANG_API_DEF LY_ERR lyplg_type_compare_instanceid(const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for the built-in instance-identifier type.
LIBYANG_API_DEF 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.
#define LYPLG_TYPE_STORE_DYNAMIC
Available YANG schema tree structures representing YANG module.
#define LY_ARRAY_COUNT(ARRAY)
Get the number of records in the ARRAY.
#define LY_ARRAY_FOR(ARRAY,...)
Sized-array iterator (for-loop).
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
@ LY_VALUE_SCHEMA_RESOLVED
LIBYANG_API_DEF const void * lyplg_type_print_instanceid(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *value, LY_VALUE_FORMAT format, void *prefix_data, ly_bool *dynamic, size_t *value_len)
LIBYANG_API_DEF LY_ERR lyplg_type_validate_instanceid(const struct ly_ctx *ctx, const struct lysc_type *UNUSED(type), const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err)
const struct lyplg_type_record plugins_instanceid[]
Plugin information for instance-identifier type implementation.
The main libyang public header.
uint8_t ly_bool
Type to indicate boolean value.
API for (user) types plugins.
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.
const struct lysc_type * realtype
Generic structure for a data node.
YANG data representation.