Skip to content

Commit

Permalink
yin parser BUGFIX resolving leafref path when defined in top level ty…
Browse files Browse the repository at this point in the history
…pedef

Fixes #13
  • Loading branch information
rkrejci committed Jan 8, 2016
1 parent 740fdff commit 2f12f85
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -2377,14 +2377,16 @@ resolve_path_predicate_schema(const char *path, const struct lys_node *source_no
*
* @param[in] path Path to use.
* @param[in] parent_node Parent of the leafref.
* @param[in] parent_tpdf Flag if the parent node is actually typedef, in that case the path
* has to contain absolute path
* @param[in] first Whether this is the first resolution try. Affects logging.
* @param[in] line Line in the input file.
* @param[out] ret Pointer to the resolved schema node. Can be NULL.
*
* @return EXIT_SUCCESS on success, EXIT_FAILURE on forward reference, -1 on error.
*/
static int
resolve_path_arg_schema(const char *path, struct lys_node *parent_node, int first, uint32_t line,
resolve_path_arg_schema(const char *path, struct lys_node *parent_node, int parent_tpdf, int first, uint32_t line,
const struct lys_node **ret)
{
const struct lys_node *node;
Expand Down Expand Up @@ -2414,6 +2416,12 @@ resolve_path_arg_schema(const char *path, struct lys_node *parent_node, int firs
}
} else if (parent_times > 0) {
/* node is the parent already, skip one ".." */
if (parent_tpdf) {
/* the path is not allowed to contain relative path since we are in top level typedef */
LOGVAL(LYE_NORESOLV, line, path);
return -1;
}

node = parent_node;
i = 0;
while (1) {
Expand Down Expand Up @@ -3544,7 +3552,7 @@ static int
resolve_unres_schema_item(struct lys_module *mod, void *item, enum UNRES_ITEM type, void *str_snode,
struct unres_schema *unres, int first, uint32_t line)
{
int rc = -1, has_str = 0;
int rc = -1, has_str = 0, tpdf_flag = 0;
struct lys_node *node;
const char *base_name;

Expand Down Expand Up @@ -3573,7 +3581,15 @@ resolve_unres_schema_item(struct lys_module *mod, void *item, enum UNRES_ITEM ty
node = str_snode;
stype = item;

rc = resolve_path_arg_schema(stype->info.lref.path, node, first, line,
/* HACK - when there is no parent, we are in top level typedef and in that
* case, the path has to contain absolute path, so we let the resolve_path_arg_schema()
* know it via tpdf_flag */
if (!node) {
tpdf_flag = 1;
node = (struct lys_node *)stype->parent;
}

rc = resolve_path_arg_schema(stype->info.lref.path, node, tpdf_flag, first, line,
(const struct lys_node **)&stype->info.lref.target);
has_str = 0;
break;
Expand Down

0 comments on commit 2f12f85

Please sign in to comment.