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;
59 ret = ly_strcat(&result,
"/");
81 if (!inherit_prefix || (mod != path[u].node->module)) {
82 mod = path[u].node->module;
83 ret = ly_strcat(&result,
"/%s:%s",
lyplg_type_get_prefix(mod, format, prefix_data), path[u].node->name);
85 ret = ly_strcat(&result,
"/%s", path[u].node->name);
87 LY_CHECK_GOTO(ret, cleanup);
91 struct ly_path_predicate *pred = &path[u].predicates[v];
94 case LY_PATH_PREDTYPE_POSITION:
96 ret = ly_strcat(&result,
"[%" PRIu64
"]", pred->position);
98 case LY_PATH_PREDTYPE_LIST:
100 strval = pred->value.realtype->plugin->print(path[u].node->module->ctx, &pred->value, format, prefix_data,
105 if (strchr(strval, quot)) {
108 if (inherit_prefix) {
110 ret = ly_strcat(&result,
"[%s=%c%s%c]", pred->key->name, quot, strval, quot);
112 ret = ly_strcat(&result,
"[%s:%s=%c%s%c]",
lyplg_type_get_prefix(pred->key->module, format, prefix_data),
113 pred->key->name, quot, strval, quot);
116 free((
char *)strval);
119 case LY_PATH_PREDTYPE_LEAFLIST:
121 strval = pred->value.realtype->plugin->print(path[u].node->module->ctx, &pred->value, format, prefix_data,
126 if (strchr(strval, quot)) {
129 ret = ly_strcat(&result,
"[.=%c%s%c]", quot, strval, quot);
131 free((
char *)strval);
134 case LY_PATH_PREDTYPE_LIST_VAR:
136 if (inherit_prefix) {
138 ret = ly_strcat(&result,
"[%s=$%s]", pred->key->name, pred->variable);
140 ret = ly_strcat(&result,
"[%s:%s=$%s]",
lyplg_type_get_prefix(pred->key->module, format, prefix_data),
141 pred->key->name, pred->variable);
146 LY_CHECK_GOTO(ret, cleanup);
163 lyplg_type_store_node_instanceid(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value,
size_t value_len,
168 struct lyxp_expr *exp = NULL;
169 uint32_t prefix_opt = 0;
170 struct ly_path *path = NULL;
174 memset(storage, 0,
sizeof *storage);
179 LY_CHECK_GOTO(ret, cleanup);
181 if ((((
char *)value)[0] ==
'/') && (value_len == 1)) {
190 prefix_opt = LY_PATH_PREFIX_MANDATORY;
196 prefix_opt = LY_PATH_PREFIX_STRICT_INHERIT;
201 ret = ly_path_parse(ctx, ctx_node, value, value_len, 0, LY_PATH_BEGIN_ABSOLUTE, prefix_opt, LY_PATH_PRED_SIMPLE, &exp);
204 "Invalid node-instance-identifier \"%.*s\" value - syntax error.", (
int)value_len, (
char *)value);
210 LY_CHECK_GOTO(ret = lys_compile_expr_implement(ctx, exp, format, prefix_data, 1, unres, NULL), cleanup);
215 ret = ly_path_compile(ctx, NULL, ctx_node, NULL, exp, (ctx_node && (ctx_node->
flags &
LYS_IS_OUTPUT)) ?
216 LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_MANY, 1, (format ==
LY_VALUE_LYB) ?
220 "Invalid node-instance-identifier \"%.*s\" value - semantic error.", (
int)value_len, (
char *)value);
226 storage->target = path;
232 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
233 LY_CHECK_GOTO(ret, cleanup);
236 LY_CHECK_GOTO(ret, cleanup);
240 ret = node_instanceid_path2str(path,
LY_VALUE_JSON, NULL, &canon);
241 LY_CHECK_GOTO(ret, cleanup);
244 LY_CHECK_GOTO(ret, cleanup);
248 lyxp_expr_free(ctx, exp);
249 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
264 void *prefix_data,
ly_bool *dynamic,
size_t *value_len)
279 if (node_instanceid_path2str(value->target, format, prefix_data, &ret)) {
284 *value_len = strlen(ret);
298 .
module =
"ietf-netconf-acm",
299 .revision =
"2012-02-22",
300 .name =
"node-instance-identifier",
302 .plugin.id =
"libyang 2 - node-instance-identifier, version 1",
303 .plugin.store = lyplg_type_store_node_instanceid,
304 .plugin.validate = NULL,
307 .plugin.print = lyplg_type_print_node_instanceid,
310 .plugin.lyb_data_len = -1,
313 .module =
"ietf-netconf-acm",
314 .revision =
"2018-02-14",
315 .name =
"node-instance-identifier",
317 .plugin.id =
"libyang 2 - node-instance-identifier, version 1",
318 .plugin.store = lyplg_type_store_node_instanceid,
319 .plugin.validate = NULL,
322 .plugin.print = lyplg_type_print_node_instanceid,
325 .plugin.lyb_data_len = -1,
struct lysc_type * realtype
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.
uint8_t ly_bool
Type to indicate boolean value.
#define LYPLG_TYPE_STORE_DYNAMIC
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 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 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.
LY_ERR
libyang's error codes returned by the libyang functions.
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.