24 #include "ly_common.h"
26 #include "plugins_internal.h"
48 node_instanceid_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;
60 ret = ly_strcat(&result,
"/");
68 local_mod = mods->objs[0];
88 if (!inherit_prefix || (mod != path[u].node->module)) {
89 mod = path[u].node->module;
90 ret = ly_strcat(&result,
"/%s:%s",
lyplg_type_get_prefix(mod, format, prefix_data), path[u].node->name);
92 ret = ly_strcat(&result,
"/%s", path[u].node->name);
94 LY_CHECK_GOTO(ret, cleanup);
98 struct ly_path_predicate *pred = &path[u].predicates[v];
100 switch (pred->type) {
101 case LY_PATH_PREDTYPE_POSITION:
103 ret = ly_strcat(&result,
"[%" PRIu64
"]", pred->position);
105 case LY_PATH_PREDTYPE_LIST:
107 strval = pred->value.realtype->plugin->print(path[u].node->module->ctx, &pred->value, format, prefix_data,
112 if (strchr(strval, quot)) {
115 if (inherit_prefix) {
117 ret = ly_strcat(&result,
"[%s=%c%s%c]", pred->key->name, quot, strval, quot);
119 ret = ly_strcat(&result,
"[%s:%s=%c%s%c]",
lyplg_type_get_prefix(pred->key->module, format, prefix_data),
120 pred->key->name, quot, strval, quot);
123 free((
char *)strval);
126 case LY_PATH_PREDTYPE_LEAFLIST:
128 strval = pred->value.realtype->plugin->print(path[u].node->module->ctx, &pred->value, format, prefix_data,
133 if (strchr(strval, quot)) {
136 ret = ly_strcat(&result,
"[.=%c%s%c]", quot, strval, quot);
138 free((
char *)strval);
141 case LY_PATH_PREDTYPE_LIST_VAR:
143 if (inherit_prefix) {
145 ret = ly_strcat(&result,
"[%s=$%s]", pred->key->name, pred->variable);
147 ret = ly_strcat(&result,
"[%s:%s=$%s]",
lyplg_type_get_prefix(pred->key->module, format, prefix_data),
148 pred->key->name, pred->variable);
153 LY_CHECK_GOTO(ret, cleanup);
159 mods->objs[0] = (
void *)local_mod;
173 lyplg_type_store_node_instanceid(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value,
size_t value_len,
178 struct lyxp_expr *exp = NULL;
179 uint32_t prefix_opt = 0;
180 struct ly_path *path = NULL;
184 memset(storage, 0,
sizeof *storage);
189 LY_CHECK_GOTO(ret, cleanup);
191 if ((((
char *)value)[0] ==
'/') && (value_len == 1)) {
200 prefix_opt = LY_PATH_PREFIX_MANDATORY;
206 prefix_opt = LY_PATH_PREFIX_STRICT_INHERIT;
211 ret = ly_path_parse(ctx, ctx_node, value, value_len, 0, LY_PATH_BEGIN_ABSOLUTE, prefix_opt, LY_PATH_PRED_SIMPLE, &exp);
214 "Invalid node-instance-identifier \"%.*s\" value - syntax error.", (
int)value_len, (
char *)value);
220 LY_CHECK_GOTO(ret = lys_compile_expr_implement(ctx, exp, format, prefix_data, 1, unres, NULL), cleanup);
225 ret = ly_path_compile(ctx, NULL, ctx_node, NULL, exp, (ctx_node && (ctx_node->
flags &
LYS_IS_OUTPUT)) ?
226 LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_MANY, 1, (format ==
LY_VALUE_LYB) ?
230 "Invalid node-instance-identifier \"%.*s\" value - semantic error.", (
int)value_len, (
char *)value);
236 storage->target = path;
242 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
243 LY_CHECK_GOTO(ret, cleanup);
246 LY_CHECK_GOTO(ret, cleanup);
250 ret = node_instanceid_path2str(path,
LY_VALUE_JSON, NULL, &canon);
251 LY_CHECK_GOTO(ret, cleanup);
254 LY_CHECK_GOTO(ret, cleanup);
258 lyxp_expr_free(ctx, exp);
259 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
274 void *prefix_data,
ly_bool *dynamic,
size_t *value_len)
289 if (node_instanceid_path2str(value->target, format, prefix_data, &ret)) {
294 *value_len = strlen(ret);
308 .
module =
"ietf-netconf-acm",
309 .revision =
"2012-02-22",
310 .name =
"node-instance-identifier",
312 .plugin.id =
"libyang 2 - node-instance-identifier, version 1",
313 .plugin.store = lyplg_type_store_node_instanceid,
314 .plugin.validate = NULL,
317 .plugin.print = lyplg_type_print_node_instanceid,
320 .plugin.lyb_data_len = -1,
323 .module =
"ietf-netconf-acm",
324 .revision =
"2018-02-14",
325 .name =
"node-instance-identifier",
327 .plugin.id =
"libyang 2 - node-instance-identifier, version 1",
328 .plugin.store = lyplg_type_store_node_instanceid,
329 .plugin.validate = NULL,
332 .plugin.print = lyplg_type_print_node_instanceid,
335 .plugin.lyb_data_len = -1,
struct lysc_type * realtype
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
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.
uint8_t ly_bool
Type to indicate boolean value.
#define LYPLG_TYPE_STORE_DYNAMIC
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 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_free_instanceid(const struct ly_ctx *ctx, struct lyd_value *value)
Implementation of lyplg_type_free_clb for the built-in instance-identifier type.
YANG data representation.
struct lyplg_type_record plugins_node_instanceid[]
Plugin information for instance-identifier type implementation.
Libyang full error structure.
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_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.
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.
#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.
#define LYPLG_TYPE_STORE_IMPLEMENT
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
API for (user) types plugins.
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.
LY_ERR
libyang's error codes returned by the libyang functions.