26 #include "plugins_internal.h"
48 instanceid_path2str(
const struct ly_path *path,
LY_VALUE_FORMAT format,
void *prefix_data,
char **str)
52 char *result = NULL, quot;
75 if (!inherit_prefix || (mod != path[u].node->module)) {
76 mod = path[u].node->module;
77 ret = ly_strcat(&result,
"/%s:%s",
lyplg_type_get_prefix(mod, format, prefix_data), path[u].node->name);
79 ret = ly_strcat(&result,
"/%s", path[u].node->name);
81 LY_CHECK_GOTO(ret, cleanup);
85 struct ly_path_predicate *pred = &path[u].predicates[v];
87 switch (path[u].pred_type) {
88 case LY_PATH_PREDTYPE_NONE:
90 case LY_PATH_PREDTYPE_POSITION:
92 ret = ly_strcat(&result,
"[%" PRIu64
"]", pred->position);
94 case LY_PATH_PREDTYPE_LIST:
96 strval = pred->value.realtype->plugin->print(path[u].node->module->ctx, &pred->value, format, prefix_data,
101 if (strchr(strval, quot)) {
104 if (inherit_prefix) {
106 ret = ly_strcat(&result,
"[%s=%c%s%c]", pred->key->name, quot, strval, quot);
108 ret = ly_strcat(&result,
"[%s:%s=%c%s%c]",
lyplg_type_get_prefix(pred->key->module, format, prefix_data),
109 pred->key->name, quot, strval, quot);
112 free((
char *)strval);
115 case LY_PATH_PREDTYPE_LEAFLIST:
117 strval = pred->value.realtype->plugin->print(path[u].node->module->ctx, &pred->value, format, prefix_data,
122 if (strchr(strval, quot)) {
125 ret = ly_strcat(&result,
"[.=%c%s%c]", quot, strval, quot);
127 free((
char *)strval);
132 LY_CHECK_GOTO(ret, cleanup);
149 lyplg_type_store_node_instanceid(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value,
size_t value_len,
154 struct lyxp_expr *exp = NULL;
155 uint32_t prefix_opt = 0;
156 struct ly_path *path;
160 memset(storage, 0,
sizeof *storage);
165 LY_CHECK_GOTO(ret, cleanup);
171 prefix_opt = LY_PATH_PREFIX_MANDATORY;
177 prefix_opt = LY_PATH_PREFIX_STRICT_INHERIT;
182 ret = ly_path_parse(ctx, ctx_node, value, value_len, 0, LY_PATH_BEGIN_ABSOLUTE, prefix_opt, LY_PATH_PRED_SIMPLE, &exp);
185 "Invalid instance-identifier \"%.*s\" value - syntax error.", (
int)value_len, (
char *)value);
191 LY_CHECK_GOTO(ret = lys_compile_expr_implement(ctx, exp, format, prefix_data, 1, unres, NULL), cleanup);
196 ret = ly_path_compile(ctx, NULL, ctx_node, NULL, exp, (ctx_node && (ctx_node->
flags &
LYS_IS_OUTPUT)) ?
197 LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_MANY, 1, (format ==
LY_VALUE_LYB) ?
201 "Invalid instance-identifier \"%.*s\" value - semantic error.", (
int)value_len, (
char *)value);
206 storage->target = path;
213 LY_CHECK_GOTO(ret, cleanup);
216 LY_CHECK_GOTO(ret, cleanup);
220 ret = instanceid_path2str(path,
LY_VALUE_JSON, NULL, &canon);
221 LY_CHECK_GOTO(ret, cleanup);
224 LY_CHECK_GOTO(ret, cleanup);
228 lyxp_expr_free(ctx, exp);
248 .
module =
"ietf-netconf-acm",
249 .revision =
"2012-02-22",
250 .name =
"node-instance-identifier",
252 .plugin.id =
"libyang 2 - node-instance-identifier, version 1",
253 .plugin.store = lyplg_type_store_node_instanceid,
254 .plugin.validate = NULL,
260 .plugin.lyb_data_len = -1,
263 .module =
"ietf-netconf-acm",
264 .revision =
"2018-02-14",
265 .name =
"node-instance-identifier",
267 .plugin.id =
"libyang 2 - node-instance-identifier, version 1",
268 .plugin.store = lyplg_type_store_node_instanceid,
269 .plugin.validate = NULL,
275 .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_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.
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_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_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_DECL 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_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 const void * lyplg_type_print_instanceid(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 instance-identifier type.
#define LYPLG_TYPE_STORE_DYNAMIC
#define LYPLG_TYPE_STORE_IMPLEMENT
Available YANG schema tree structures representing YANG module.
#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
The main libyang public header.
uint8_t ly_bool
Type to indicate boolean value.
const struct lyplg_type_record plugins_node_instanceid[]
Plugin information for instance-identifier type implementation.
API for (user) types plugins.
const struct lysc_type * realtype
YANG data representation.