25#include "plugins_internal.h"
47node_instanceid_path2str(
const struct ly_path *path,
LY_VALUE_FORMAT format,
void *prefix_data,
char **str)
51 char *result = NULL, quot;
52 const struct lys_module *mod = NULL, *local_mod = NULL;
59 ret = ly_strcat(&result,
"/");
68 local_mod = mods->objs[0];
103 if (!inherit_prefix || (mod != path[u].node->module)) {
104 mod = path[u].node->module;
105 ret = ly_strcat(&result,
"/%s:%s",
lyplg_type_get_prefix(mod, format, prefix_data), path[u].node->name);
107 ret = ly_strcat(&result,
"/%s", path[u].node->name);
109 LY_CHECK_GOTO(ret, cleanup);
112 LYA_FOR(path[u].predicates, v) {
113 struct ly_path_predicate *pred = &path[u].predicates[v];
115 switch (pred->type) {
116 case LY_PATH_PREDTYPE_POSITION:
118 ret = ly_strcat(&result,
"[%" PRIu64
"]", pred->position);
120 case LY_PATH_PREDTYPE_LIST:
123 LY_CHECK_GOTO(ret, cleanup);
126 LY_CHECK_GOTO(ret = ly_val_get_quot(pred->key->module->ctx, strval, "), cleanup);
127 if (inherit_prefix) {
129 ret = ly_strcat(&result,
"[%s=%c%s%c]", pred->key->name, quot, strval, quot);
131 ret = ly_strcat(&result,
"[%s:%s=%c%s%c]",
lyplg_type_get_prefix(pred->key->module, format, prefix_data),
132 pred->key->name, quot, strval, quot);
136 case LY_PATH_PREDTYPE_LEAFLIST:
139 LY_CHECK_GOTO(ret, cleanup);
142 LY_CHECK_GOTO(ret = ly_val_get_quot(path[u].node->module->ctx, strval, "), cleanup);
143 ret = ly_strcat(&result,
"[.=%c%s%c]", quot, strval, quot);
146 case LY_PATH_PREDTYPE_LIST_VAR:
148 if (inherit_prefix) {
150 ret = ly_strcat(&result,
"[%s=$%s]", pred->key->name, pred->variable);
152 ret = ly_strcat(&result,
"[%s:%s=$%s]",
lyplg_type_get_prefix(pred->key->module, format, prefix_data),
153 pred->key->name, pred->variable);
158 LY_CHECK_GOTO(ret, cleanup);
164 mods->objs[0] = (
void *)local_mod;
178lyplg_type_store_node_instanceid(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value, uint64_t value_size_bits,
183 struct lyxp_expr *exp = NULL;
184 uint32_t value_size, prefix_opt = 0;
185 struct ly_path *path = NULL;
189 memset(storage, 0,
sizeof *storage);
194 0, &value_size, err);
195 LY_CHECK_GOTO(ret, cleanup);
199 LY_CHECK_GOTO(ret, cleanup);
201 if ((((
char *)value)[0] ==
'/') && (value_size == 1)) {
211 prefix_opt = LY_PATH_PREFIX_MANDATORY;
218 prefix_opt = LY_PATH_PREFIX_STRICT_INHERIT;
223 ret = ly_path_parse(ctx, ctx_node, value, value_size, 0, LY_PATH_BEGIN_ABSOLUTE, prefix_opt, LY_PATH_PRED_SIMPLE, &exp);
226 "Invalid node-instance-identifier \"%.*s\" value - syntax error.", (
int)value_size, (
char *)value);
232 LY_CHECK_GOTO(ret = lys_compile_expr_implement(ctx, exp, format, prefix_data, 1, unres, NULL), cleanup);
237 ret = ly_path_compile(ctx, ctx_node, exp, (ctx_node && (ctx_node->
flags &
LYS_IS_OUTPUT)) ?
238 LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_MANY, 1, (format ==
LY_VALUE_LYB) ?
242 "Invalid node-instance-identifier \"%.*s\" value - semantic error.", (
int)value_size, (
char *)value);
248 storage->target = path;
254 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
255 LY_CHECK_GOTO(ret, cleanup);
258 LY_CHECK_GOTO(ret, cleanup);
262 ret = node_instanceid_path2str(path,
LY_VALUE_JSON, NULL, &canon);
263 LY_CHECK_GOTO(ret, cleanup);
266 LY_CHECK_GOTO(ret, cleanup);
286 void *prefix_data,
ly_bool *dynamic, uint64_t *value_size_bits)
294 if (value_size_bits) {
295 *value_size_bits = strlen(value->
_canonical) * 8;
301 if (node_instanceid_path2str(value->target, format, prefix_data, &ret)) {
305 if (value_size_bits) {
306 *value_size_bits = strlen(ret) * 8;
319 memset(dup, 0,
sizeof *dup);
323 LY_CHECK_GOTO(ret, error);
325 if (original->target) {
327 ret = ly_path_dup(ctx, original->target, &dup->target);
328 LY_CHECK_GOTO(ret, error);
348 .module =
"ietf-netconf-acm",
350 .name =
"node-instance-identifier",
352 .plugin.id =
"ly2 node-instance-identifier",
354 .plugin.store = lyplg_type_store_node_instanceid,
355 .plugin.validate_value = NULL,
356 .plugin.validate_tree = NULL,
359 .plugin.print = lyplg_type_print_node_instanceid,
360 .plugin.duplicate = lyplg_type_dup_node_instanceid,
#define LYA_FOR(ARRAY, INDEX)
Helper macro to go through sized-arrays with a numeric iterator.
#define LYA_COUNT_T
Type (i.e. size) of the sized array's size counter.
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,...
const char *const char * revision
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.
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_value_size(const char *type_name, LY_VALUE_FORMAT format, uint64_t value_size_bits, enum lyplg_lyb_size_type lyb_size_type, uint64_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.
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 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 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.
@ LYPLG_LYB_SIZE_VARIABLE_BYTES
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 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.
LIBYANG_API_DECL void lyplg_type_lyb_size_variable_bytes(const struct lysc_type *type, enum lyplg_lyb_size_type *size_type, uint64_t *fixed_size_bits)
Implementation of lyplg_type_lyb_size_clb for a type with variable length rounded to bytes.
#define LYPLG_TYPE_STORE_DYNAMIC
#define LYPLG_TYPE_STORE_IMPLEMENT
Available YANG schema tree structures representing YANG module.
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.
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
@ LY_VALUE_SCHEMA_RESOLVED