summaryrefslogtreecommitdiff
path: root/lib/yang.c
diff options
context:
space:
mode:
authorChristian Hopps <chopps@gmail.com>2024-02-14 10:04:11 -0500
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2024-02-20 17:14:55 +0000
commit06ccaac51bc5726690baef359845729a315ec062 (patch)
tree3d3066756b3f4d096dc818aba9f32fae381f7dde /lib/yang.c
parent2a9d407cc517b69dae094757fb87ba7d032b6674 (diff)
lib: mgmtd: add xpath arg to notification message
Signed-off-by: Christian Hopps <chopps@labn.net> (cherry picked from commit 4a93d171c2e3ec1ff6c4fc553d6acf42e035e0d4)
Diffstat (limited to 'lib/yang.c')
-rw-r--r--lib/yang.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/lib/yang.c b/lib/yang.c
index 3ce24a318d..03044fc29e 100644
--- a/lib/yang.c
+++ b/lib/yang.c
@@ -714,12 +714,12 @@ static void ly_log_cb(LY_LOG_LEVEL level, const char *msg, const char *path)
zlog(priority, "libyang: %s", msg);
}
-LY_ERR yang_parse_notification(LYD_FORMAT format, const char *data,
- struct lyd_node **notif)
+LY_ERR yang_parse_notification(const char *xpath, LYD_FORMAT format,
+ const char *data, struct lyd_node **notif)
{
- struct lyd_node *tree, *dnode;
+ struct lyd_node *tree;
+ struct ly_set *set = NULL;
struct ly_in *in = NULL;
- bool found = false;
LY_ERR err;
err = ly_in_new_memory(data, &in);
@@ -736,26 +736,20 @@ LY_ERR yang_parse_notification(LYD_FORMAT format, const char *data,
return err;
}
- /*
- * Notification can be a child of some data node, so traverse the tree
- * until we find the notification.
- */
- LYD_TREE_DFS_BEGIN (tree, dnode) {
- if (dnode->schema->nodetype == LYS_NOTIF) {
- found = true;
- break;
- }
- LYD_TREE_DFS_END(tree, dnode);
+ err = lyd_find_xpath3(NULL, tree, xpath, NULL, &set);
+ if (err) {
+ zlog_err("Failed to parse notification: %s", ly_last_errmsg());
+ lyd_free_all(tree);
+ return err;
}
-
- if (!found) {
- zlog_err("Notification not found in the parsed tree");
+ if (set->count == 0) {
+ zlog_err("Notification not found in the parsed tree: %s", xpath);
+ ly_set_free(set, NULL);
lyd_free_all(tree);
return LY_ENOTFOUND;
}
-
- *notif = dnode;
-
+ *notif = set->dnodes[0];
+ ly_set_free(set, NULL);
return LY_SUCCESS;
}
@@ -790,9 +784,9 @@ uint8_t *yang_print_tree(const struct lyd_node *root, LYD_FORMAT format,
return darr;
}
-char *yang_convert_lyd_format(const uint8_t *data, size_t data_len,
- LYD_FORMAT in_format,
- LYD_FORMAT out_format, bool shrink)
+char *yang_convert_lyd_format(const char *data, size_t data_len,
+ LYD_FORMAT in_format, LYD_FORMAT out_format,
+ bool shrink)
{
struct lyd_node *tree = NULL;
uint32_t options = LYD_PRINT_WD_EXPLICIT | LYD_PRINT_WITHSIBLINGS;