diff options
-rw-r--r-- | lib/northbound.c | 2 | ||||
-rw-r--r-- | lib/yang.c | 17 | ||||
-rw-r--r-- | lib/yang.h | 21 | ||||
-rw-r--r-- | lib/yang_translator.c | 9 | ||||
-rw-r--r-- | lib/yang_wrappers.c | 6 |
5 files changed, 46 insertions, 9 deletions
diff --git a/lib/northbound.c b/lib/northbound.c index 307cf0fb4..ba9b6d59b 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -167,7 +167,7 @@ struct nb_node *nb_node_find(const char *path) * Use libyang to find the schema node associated to the path and get * the northbound node from there (snode private pointer). */ - snode = lys_find_path(ly_native_ctx, NULL, path, 0); + snode = yang_find_snode(ly_native_ctx, path, 0); if (!snode) return NULL; diff --git a/lib/yang.c b/lib/yang.c index 70a3251ab..4dd865421 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -250,6 +250,23 @@ void yang_snode_get_path(const struct lysc_node *snode, } } +struct lysc_node *yang_find_snode(struct ly_ctx *ly_ctx, const char *xpath, + uint32_t options) +{ + struct lysc_node *snode; + struct ly_set *set; + LY_ERR err; + + err = lys_find_xpath(ly_native_ctx, NULL, xpath, options, &set); + if (err || !set->count) + return NULL; + + snode = set->snodes[0]; + ly_set_free(set, NULL); + + return snode; +} + struct lysc_node *yang_snode_real_parent(const struct lysc_node *snode) { struct lysc_node *parent = snode->parent; diff --git a/lib/yang.h b/lib/yang.h index 654c246f0..37369c09b 100644 --- a/lib/yang.h +++ b/lib/yang.h @@ -210,6 +210,27 @@ extern void yang_snode_get_path(const struct lysc_node *snode, enum yang_path_type type, char *xpath, size_t xpath_len); + +/* + * Find libyang schema node for the given xpath. Uses `lys_find_xpath`, + * returning only the first of a set of nodes -- normally there should only + * be one. + * + * ly_ctx + * libyang context to operate on. + * + * xpath + * XPath expression (absolute or relative) to find the schema node for. + * + * options + * Libyang findxpathoptions value (see lys_find_xpath). + * + * Returns: + * The libyang schema node if found, or NULL if not found. + */ +extern struct lysc_node *yang_find_snode(struct ly_ctx *ly_ctx, + const char *xpath, uint32_t options); + /* * Find first parent schema node which is a presence-container or a list * (non-presence containers are ignored). diff --git a/lib/yang_translator.c b/lib/yang_translator.c index de668230a..eae7577a0 100644 --- a/lib/yang_translator.c +++ b/lib/yang_translator.c @@ -235,8 +235,8 @@ struct yang_translator *yang_translator_load(const char *path) xpath_custom = yang_dnode_get_string(set->dnodes[i], "./custom"); - snode_custom = lys_find_path(translator->ly_ctx, NULL, - xpath_custom, 0); + snode_custom = + yang_find_snode(translator->ly_ctx, xpath_custom, 0); if (!snode_custom) { flog_warn(EC_LIB_YANG_TRANSLATOR_LOAD, "%s: unknown data path: %s", __func__, @@ -247,8 +247,7 @@ struct yang_translator *yang_translator_load(const char *path) xpath_native = yang_dnode_get_string(set->dnodes[i], "./native"); - snode_native = - lys_find_path(ly_native_ctx, NULL, xpath_native, 0); + snode_native = yang_find_snode(ly_native_ctx, xpath_native, 0); if (!snode_native) { flog_warn(EC_LIB_YANG_TRANSLATOR_LOAD, "%s: unknown data path: %s", __func__, @@ -315,7 +314,7 @@ yang_translate_xpath(const struct yang_translator *translator, int dir, else ly_ctx = ly_native_ctx; - snode = lys_find_path(ly_ctx, NULL, xpath, 0); + snode = yang_find_snode(ly_ctx, xpath, 0); if (!snode) { flog_warn(EC_LIB_YANG_TRANSLATION_ERROR, "%s: unknown data path: %s", __func__, xpath); diff --git a/lib/yang_wrappers.c b/lib/yang_wrappers.c index 509c4dd85..dc049a374 100644 --- a/lib/yang_wrappers.c +++ b/lib/yang_wrappers.c @@ -89,7 +89,7 @@ static const char *yang_get_default_value(const char *xpath) const struct lysc_node *snode; const char *value; - snode = lys_find_path(ly_native_ctx, NULL, xpath, 0); + snode = yang_find_snode(ly_native_ctx, xpath, 0); if (snode == NULL) { flog_err(EC_LIB_YANG_UNKNOWN_DATA_PATH, "%s: unknown data path: %s", __func__, xpath); @@ -206,7 +206,7 @@ int yang_str2enum(const char *xpath, const char *value) const struct lysc_type_enum *type; const struct lysc_type_bitenum_item *enums; - snode = lys_find_path(ly_native_ctx, NULL, xpath, 0); + snode = yang_find_snode(ly_native_ctx, xpath, 0); if (snode == NULL) { flog_err(EC_LIB_YANG_UNKNOWN_DATA_PATH, "%s: unknown data path: %s", __func__, xpath); @@ -241,7 +241,7 @@ struct yang_data *yang_data_new_enum(const char *xpath, int value) const struct lysc_type_enum *type; const struct lysc_type_bitenum_item *enums; - snode = lys_find_path(ly_native_ctx, NULL, xpath, 0); + snode = yang_find_snode(ly_native_ctx, xpath, 0); if (snode == NULL) { flog_err(EC_LIB_YANG_UNKNOWN_DATA_PATH, "%s: unknown data path: %s", __func__, xpath); |