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:
108 LY_CHECK_GOTO(ret, cleanup);
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);
124 case LY_PATH_PREDTYPE_LEAFLIST:
127 LY_CHECK_GOTO(ret, cleanup);
131 if (strchr(strval, quot)) {
134 ret = ly_strcat(&result,
"[.=%c%s%c]", quot, strval, quot);
137 case LY_PATH_PREDTYPE_LIST_VAR:
139 if (inherit_prefix) {
141 ret = ly_strcat(&result,
"[%s=$%s]", pred->key->name, pred->variable);
143 ret = ly_strcat(&result,
"[%s:%s=$%s]",
lyplg_type_get_prefix(pred->key->module, format, prefix_data),
144 pred->key->name, pred->variable);
149 LY_CHECK_GOTO(ret, cleanup);
155 mods->objs[0] = (
void *)local_mod;
169 lyplg_type_store_node_instanceid(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value, uint32_t value_size_bits,
175 struct lyxp_expr *exp = NULL;
176 uint32_t value_size, prefix_opt = 0;
177 struct ly_path *path = NULL;
181 memset(storage, 0,
sizeof *storage);
186 0, &value_size, err);
187 LY_CHECK_GOTO(ret, cleanup);
191 LY_CHECK_GOTO(ret, cleanup);
193 if ((((
char *)value)[0] ==
'/') && (value_size == 1)) {
203 prefix_opt = LY_PATH_PREFIX_MANDATORY;
209 prefix_opt = LY_PATH_PREFIX_STRICT_INHERIT;
214 ret = ly_path_parse(ctx, ctx_node, value, value_size, 0, LY_PATH_BEGIN_ABSOLUTE, prefix_opt, LY_PATH_PRED_SIMPLE, &exp);
217 "Invalid node-instance-identifier \"%.*s\" value - syntax error.", (
int)value_size, (
char *)value);
223 LY_CHECK_GOTO(ret = lys_compile_expr_implement(ctx, exp, format, prefix_data, 1, unres, NULL), cleanup);
228 ret = ly_path_compile(ctx, NULL, ctx_node, top_ext, exp, (ctx_node && (ctx_node->
flags &
LYS_IS_OUTPUT)) ?
229 LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_MANY, 1, (format ==
LY_VALUE_LYB) ?
233 "Invalid node-instance-identifier \"%.*s\" value - semantic error.", (
int)value_size, (
char *)value);
239 storage->target = path;
245 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
246 LY_CHECK_GOTO(ret, cleanup);
249 LY_CHECK_GOTO(ret, cleanup);
253 ret = node_instanceid_path2str(path,
LY_VALUE_JSON, NULL, &canon);
254 LY_CHECK_GOTO(ret, cleanup);
257 LY_CHECK_GOTO(ret, cleanup);
262 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
277 void *prefix_data,
ly_bool *dynamic, uint32_t *value_size_bits)
285 if (value_size_bits) {
286 *value_size_bits = strlen(value->
_canonical) * 8;
292 if (node_instanceid_path2str(value->target, format, prefix_data, &ret)) {
296 if (value_size_bits) {
297 *value_size_bits = strlen(ret) * 8;
310 memset(dup, 0,
sizeof *dup);
314 LY_CHECK_GOTO(ret, error);
316 if (original->target) {
318 ret = ly_path_dup(ctx, original->target, &dup->target);
319 LY_CHECK_GOTO(ret, error);
339 .
module =
"ietf-netconf-acm",
340 .revision =
"2012-02-22",
341 .name =
"node-instance-identifier",
343 .plugin.id =
"ly2 node-instance-identifier",
345 .plugin.store = lyplg_type_store_node_instanceid,
346 .plugin.validate_value = NULL,
347 .plugin.validate_tree = NULL,
350 .plugin.print = lyplg_type_print_node_instanceid,
351 .plugin.duplicate = lyplg_type_dup_node_instanceid,
355 .module =
"ietf-netconf-acm",
356 .revision =
"2018-02-14",
357 .name =
"node-instance-identifier",
359 .plugin.id =
"ly2 node-instance-identifier",
361 .plugin.store = lyplg_type_store_node_instanceid,
362 .plugin.validate_value = NULL,
363 .plugin.validate_tree = NULL,
366 .plugin.print = lyplg_type_print_node_instanceid,
367 .plugin.duplicate = lyplg_type_dup_node_instanceid,
struct lysc_type * realtype
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
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.
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.
#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 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.
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_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.
#define LYPLG_TYPE_STORE_IMPLEMENT
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.