|
Packit |
8fb591 |
/**
|
|
Packit |
8fb591 |
* @file resolve.h
|
|
Packit |
8fb591 |
* @author Michal Vasko <mvasko@cesnet.cz>
|
|
Packit |
8fb591 |
* @brief libyang resolve header
|
|
Packit |
8fb591 |
*
|
|
Packit |
8fb591 |
* Copyright (c) 2015 CESNET, z.s.p.o.
|
|
Packit |
8fb591 |
*
|
|
Packit |
8fb591 |
* This source code is licensed under BSD 3-Clause License (the "License").
|
|
Packit |
8fb591 |
* You may not use this file except in compliance with the License.
|
|
Packit |
8fb591 |
* You may obtain a copy of the License at
|
|
Packit |
8fb591 |
*
|
|
Packit |
8fb591 |
* https://opensource.org/licenses/BSD-3-Clause
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
#ifndef _RESOLVE_H
|
|
Packit |
8fb591 |
#define _RESOLVE_H
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
#include "libyang.h"
|
|
Packit |
8fb591 |
#include "extensions.h"
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/**
|
|
Packit |
8fb591 |
* @brief Type of an unresolved item (in either SCHEMA or DATA)
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
enum UNRES_ITEM {
|
|
Packit |
8fb591 |
/* SCHEMA */
|
|
Packit |
8fb591 |
UNRES_USES = 0x00000001, /* unresolved uses grouping (refines and augments in it are resolved as well) */
|
|
Packit |
8fb591 |
UNRES_IFFEAT = 0x00000002, /* unresolved if-feature */
|
|
Packit |
8fb591 |
UNRES_TYPE_DER = 0x00000004, /* unresolved derived type defined in leaf/leaflist */
|
|
Packit |
8fb591 |
UNRES_TYPE_DER_TPDF = 0x00000008, /* unresolved derived type defined as typedef */
|
|
Packit |
8fb591 |
UNRES_TYPE_DER_EXT = 0x00000010,
|
|
Packit |
8fb591 |
UNRES_TYPE_LEAFREF = 0x00000020, /* check leafref value */
|
|
Packit |
8fb591 |
UNRES_AUGMENT = 0x00000040, /* unresolved augment targets */
|
|
Packit |
8fb591 |
UNRES_CHOICE_DFLT = 0x00000080, /* check choice default case */
|
|
Packit |
8fb591 |
UNRES_IDENT = 0x00000100, /* unresolved derived identities */
|
|
Packit |
8fb591 |
UNRES_TYPE_IDENTREF = 0x00000200, /* check identityref value */
|
|
Packit |
8fb591 |
UNRES_FEATURE = 0x00000400, /* feature for circular check, it must be postponed when all if-features are resolved */
|
|
Packit |
8fb591 |
UNRES_TYPEDEF_DFLT = 0x00000800, /* validate default type value (from typedef) */
|
|
Packit |
8fb591 |
UNRES_TYPE_DFLT = 0x00001000, /* validate default type value (from lys_node) */
|
|
Packit |
8fb591 |
UNRES_LIST_KEYS = 0x00002000, /* list keys */
|
|
Packit |
8fb591 |
UNRES_LIST_UNIQ = 0x00004000, /* list uniques */
|
|
Packit |
8fb591 |
UNRES_MOD_IMPLEMENT = 0x00008000, /* unimplemented module */
|
|
Packit |
8fb591 |
UNRES_EXT = 0x00010000, /* extension instances */
|
|
Packit |
8fb591 |
UNRES_XPATH = 0x00020000, /* unchecked XPath expression */
|
|
Packit |
8fb591 |
UNRES_EXT_FINALIZE = 0x00040000, /* extension is already resolved, but needs to be finalized via plugin callbacks */
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/* DATA */
|
|
Packit |
8fb591 |
UNRES_LEAFREF = 0x00080000, /* unresolved leafref reference */
|
|
Packit |
8fb591 |
UNRES_INSTID = 0x00100000, /* unresolved instance-identifier reference */
|
|
Packit |
8fb591 |
UNRES_WHEN = 0x00200000, /* unresolved when condition */
|
|
Packit |
8fb591 |
UNRES_MUST = 0x00400000, /* unresolved must condition */
|
|
Packit |
8fb591 |
UNRES_MUST_INOUT = 0x00800000, /* unresolved must condition in parent input or output */
|
|
Packit |
8fb591 |
UNRES_UNION = 0x01000000, /* union with leafref which must be checked because the type can change without changing the
|
|
Packit |
8fb591 |
value itself, but removing the target node */
|
|
Packit |
8fb591 |
UNRES_UNIQ_LEAVES = 0x02000000, /* list with a unique statement(s) whose leaves need to be checked */
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/* generic */
|
|
Packit |
8fb591 |
UNRES_RESOLVED = 0x04000000, /* a resolved item */
|
|
Packit |
8fb591 |
UNRES_DELETE = 0x08000000, /* prepared for auto-delete */
|
|
Packit |
8fb591 |
};
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/**
|
|
Packit |
8fb591 |
* @brief auxiliaty structure to hold all necessary information for UNRES_EXT
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
struct unres_ext {
|
|
Packit |
8fb591 |
union {
|
|
Packit |
8fb591 |
struct lyxml_elem *yin; /**< YIN content of the extension instance */
|
|
Packit |
8fb591 |
struct yang_ext_substmt *yang; /**< YANG content of strings */
|
|
Packit |
8fb591 |
} data;
|
|
Packit |
8fb591 |
LYS_INFORMAT datatype; /**< type of the data in data union */
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/* data for lys_ext_instance structure */
|
|
Packit |
8fb591 |
void *parent;
|
|
Packit |
8fb591 |
struct lys_module *mod;
|
|
Packit |
8fb591 |
LYEXT_PAR parent_type;
|
|
Packit |
8fb591 |
LYEXT_SUBSTMT substmt;
|
|
Packit |
8fb591 |
uint8_t substmt_index;
|
|
Packit |
8fb591 |
uint8_t ext_index;
|
|
Packit |
8fb591 |
};
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/**
|
|
Packit |
8fb591 |
* @brief auxiliary structure to hold all necessary information for UNRES_LIST_UNIQ
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
struct unres_list_uniq {
|
|
Packit |
8fb591 |
struct lys_node *list;
|
|
Packit |
8fb591 |
const char *expr;
|
|
Packit |
8fb591 |
uint8_t *trg_type;
|
|
Packit |
8fb591 |
};
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/**
|
|
Packit |
8fb591 |
* @brief Unresolved items in DATA
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
struct unres_data {
|
|
Packit |
8fb591 |
struct lyd_node **node;
|
|
Packit |
8fb591 |
enum UNRES_ITEM *type;
|
|
Packit |
8fb591 |
uint32_t count;
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int store_diff;
|
|
Packit |
8fb591 |
struct lyd_difflist *diff;
|
|
Packit |
8fb591 |
unsigned int diff_size;
|
|
Packit |
8fb591 |
unsigned int diff_idx;
|
|
Packit |
8fb591 |
};
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/**
|
|
Packit |
8fb591 |
* @brief Unresolved items in a SCHEMA
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
struct unres_schema {
|
|
Packit |
8fb591 |
void **item; /* array of pointers, each is determined by the type (one of lys_* structures) */
|
|
Packit |
8fb591 |
enum UNRES_ITEM *type; /* array of unres types */
|
|
Packit |
8fb591 |
void **str_snode; /* array of pointers, each is determined by the type (a string, a lys_node *, or NULL) */
|
|
Packit |
8fb591 |
struct lys_module **module; /* array of pointers to the item's module */
|
|
Packit |
8fb591 |
uint32_t count; /* count of unres items */
|
|
Packit |
8fb591 |
};
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
struct len_ran_intv {
|
|
Packit |
8fb591 |
/* 0 - unsigned, 1 - signed, 2 - floating point */
|
|
Packit |
8fb591 |
uint8_t kind;
|
|
Packit |
8fb591 |
union {
|
|
Packit |
8fb591 |
struct {
|
|
Packit |
8fb591 |
uint64_t min;
|
|
Packit |
8fb591 |
uint64_t max;
|
|
Packit |
8fb591 |
} uval;
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
struct {
|
|
Packit |
8fb591 |
int64_t min;
|
|
Packit |
8fb591 |
int64_t max;
|
|
Packit |
8fb591 |
} sval;
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
struct {
|
|
Packit |
8fb591 |
int64_t min;
|
|
Packit |
8fb591 |
int64_t max;
|
|
Packit |
8fb591 |
} fval;
|
|
Packit |
8fb591 |
} value;
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
struct lys_type *type; /* just to be able to get to optional error-message and/or error-app-tag */
|
|
Packit |
8fb591 |
struct len_ran_intv *next;
|
|
Packit |
8fb591 |
};
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/**
|
|
Packit |
8fb591 |
* @brief Convert a string with a decimal64 value into our representation.
|
|
Packit |
8fb591 |
* Syntax is expected to be correct. Does not log.
|
|
Packit |
8fb591 |
*
|
|
Packit |
8fb591 |
* @param[in,out] str_num Pointer to the beginning of the decimal64 number, returns the first unparsed character.
|
|
Packit |
8fb591 |
* @param[in] dig Fraction-digits of the resulting number.
|
|
Packit |
8fb591 |
* @param[out] num Decimal64 base value, fraction-digits equal \p dig.
|
|
Packit |
8fb591 |
* @return 0 on success, non-zero on error.
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
int parse_range_dec64(const char **str_num, uint8_t dig, int64_t *num);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
unsigned int parse_identifier(const char *id);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int parse_schema_nodeid(const char *id, const char **mod_name, int *mod_name_len, const char **name, int *nam_len,
|
|
Packit |
8fb591 |
int *is_relative, int *has_predicate, int *all_desc, int extended);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int parse_schema_json_predicate(const char *id, const char **mod_name, int *mod_name_len, const char **name,
|
|
Packit |
8fb591 |
int *nam_len, const char **value, int *val_len, int *has_predicate);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/**
|
|
Packit |
8fb591 |
* @param[in] expr compiled if-feature expression
|
|
Packit |
8fb591 |
* @return 1 if enabled, 0 if disabled
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
int resolve_iffeature(struct lys_iffeature *expr);
|
|
Packit |
8fb591 |
void resolve_iffeature_getsizes(struct lys_iffeature *iffeat, unsigned int *expr_size, unsigned int *feat_size);
|
|
Packit |
8fb591 |
int resolve_iffeature_compile(struct lys_iffeature *iffeat_expr, const char *value, struct lys_node *node,
|
|
Packit |
8fb591 |
int infeature, struct unres_schema *unres);
|
|
Packit |
8fb591 |
uint8_t iff_getop(uint8_t *list, int pos);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int inherit_config_flag(struct lys_node *node, int flags, int clear);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
void resolve_identity_backlink_update(struct lys_ident *der, struct lys_ident *base);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
struct lyd_node *resolve_data_descendant_schema_nodeid(const char *nodeid, struct lyd_node *start);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_schema_nodeid(const char *nodeid, const struct lys_node *start, const struct lys_module *cur_module,
|
|
Packit |
8fb591 |
struct ly_set **ret, int extended, int no_node_error);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_descendant_schema_nodeid(const char *nodeid, const struct lys_node *start, int ret_nodetype,
|
|
Packit |
8fb591 |
int no_innerlist, const struct lys_node **ret);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_choice_default_schema_nodeid(const char *nodeid, const struct lys_node *start, const struct lys_node **ret);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_absolute_schema_nodeid(const char *nodeid, const struct lys_module *module, int ret_nodetype,
|
|
Packit |
8fb591 |
const struct lys_node **ret);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
const struct lys_node *resolve_json_nodeid(const char *nodeid, struct ly_ctx *ctx, const struct lys_node *start, int output);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
struct lyd_node *resolve_partial_json_data_nodeid(const char *nodeid, const char *llist_value, struct lyd_node *start,
|
|
Packit |
8fb591 |
int options, int *parsed);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_len_ran_interval(struct ly_ctx *ctx, const char *str_restr, struct lys_type *type, struct len_ran_intv **ret);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_superior_type(const char *name, const char *prefix, const struct lys_module *module,
|
|
Packit |
8fb591 |
const struct lys_node *parent, struct lys_tpdf **ret);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_unique(struct lys_node *parent, const char *uniq_str_path, uint8_t *trg_type);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
void resolve_when_ctx_snode(const struct lys_node *schema, struct lys_node **ctx_snode,
|
|
Packit |
8fb591 |
enum lyxp_node_type *ctx_snode_type);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/* get know if resolve_when() is applicable to the node (there is when condition connected with this node)
|
|
Packit |
8fb591 |
*
|
|
Packit |
8fb591 |
* @param[in] mode 0 - search for when in parent until there is another possible data node
|
|
Packit |
8fb591 |
* 2 - search for when until reached the stop node, if NULL, search in all parents
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
int resolve_applies_when(const struct lys_node *schema, int mode, const struct lys_node *stop);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/* return: 0x0 - no applicable must,
|
|
Packit |
8fb591 |
* 0x1 - node's schema has must,
|
|
Packit |
8fb591 |
* 0x2 - node's parent is inout with must,
|
|
Packit |
8fb591 |
* 0x3 - 0x2 & 0x1 combined */
|
|
Packit |
8fb591 |
int resolve_applies_must(const struct lyd_node *node);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
struct lys_ident *resolve_identref(struct lys_type *type, const char *ident_name, struct lyd_node *node,
|
|
Packit |
8fb591 |
struct lys_module *mod, int dflt);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_unres_schema(struct lys_module *mod, struct unres_schema *unres);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_when(struct lyd_node *node, int ignore_fail, struct lys_when **failed_when);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int unres_schema_add_str(struct lys_module *mod, struct unres_schema *unres, void *item, enum UNRES_ITEM type,
|
|
Packit |
8fb591 |
const char *str);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int unres_schema_add_node(struct lys_module *mod, struct unres_schema *unres, void *item, enum UNRES_ITEM type,
|
|
Packit |
8fb591 |
struct lys_node *node);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int unres_schema_dup(struct lys_module *mod, struct unres_schema *unres, void *item, enum UNRES_ITEM type,
|
|
Packit |
8fb591 |
void *new_item);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/* start_on_backwards - unres is searched from the end to beginning, so the search will start
|
|
Packit |
8fb591 |
* on start_on_backwards index in unres (unless -1) and skip indices
|
|
Packit |
8fb591 |
* larger than start_on_backards
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
int unres_schema_find(struct unres_schema *unres, int start_on_backwards, void *item, enum UNRES_ITEM type);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
void unres_schema_free(struct lys_module *module, struct unres_schema **unres, int all);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_union(struct lyd_node_leaf_list *leaf, struct lys_type *type, int store, int ignore_fail,
|
|
Packit |
8fb591 |
struct lys_type **resolved_type);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_unres_data_item(struct lyd_node *dnode, enum UNRES_ITEM type, int ignore_fail, struct lys_when **failed_when);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int unres_data_addonly(struct unres_data *unres, struct lyd_node *node, enum UNRES_ITEM type);
|
|
Packit |
8fb591 |
int unres_data_add(struct unres_data *unres, struct lyd_node *node, enum UNRES_ITEM type);
|
|
Packit |
8fb591 |
void unres_data_del(struct unres_data *unres, uint32_t i);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int resolve_unres_data(struct ly_ctx *ctx, struct unres_data *unres, struct lyd_node **root, int options);
|
|
Packit |
8fb591 |
int schema_nodeid_siblingcheck(const struct lys_node *sibling, const struct lys_module *cur_module,
|
|
Packit |
8fb591 |
const char *mod_name, int mod_name_len, const char *name, int nam_len);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
#endif /* _RESOLVE_H */
|