summaryrefslogtreecommitdiff
path: root/lib/yang.c
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2018-11-24 21:56:48 -0200
committerRenato Westphal <renato@opensourcerouting.org>2018-11-26 15:52:12 -0200
commit3f662078965405c6363dcecc2cc43c658c108229 (patch)
tree427c43caa58530c2f2e09a88000ec8a7a4d6912c /lib/yang.c
parenta7d055e4ff4d476814c8b2ee56691ed5e853b6bd (diff)
lib: introduce function to retrieve the schema name of a data node
In some cases it might be desirable to obtain the schema name of a libyang data node. Introduce the yang_dnode_get_schema_name() function for this purpose. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/yang.c')
-rw-r--r--lib/yang.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/yang.c b/lib/yang.c
index 6236dc5a66..f41c645758 100644
--- a/lib/yang.c
+++ b/lib/yang.c
@@ -344,6 +344,29 @@ void yang_dnode_get_path(const struct lyd_node *dnode, char *xpath,
free(xpath_ptr);
}
+const char *yang_dnode_get_schema_name(const struct lyd_node *dnode,
+ const char *xpath_fmt, ...)
+{
+ if (xpath_fmt) {
+ va_list ap;
+ char xpath[XPATH_MAXLEN];
+
+ va_start(ap, xpath_fmt);
+ vsnprintf(xpath, sizeof(xpath), xpath_fmt, ap);
+ va_end(ap);
+
+ dnode = yang_dnode_get(dnode, xpath);
+ if (!dnode) {
+ flog_err(EC_LIB_YANG_DNODE_NOT_FOUND,
+ "%s: couldn't find %s", __func__, xpath);
+ zlog_backtrace(LOG_ERR);
+ abort();
+ }
+ }
+
+ return dnode->schema->name;
+}
+
struct lyd_node *yang_dnode_get(const struct lyd_node *dnode,
const char *xpath_fmt, ...)
{