Skip to content

Commit bbab76f

Browse files
committed
Fix parsing for notification after leaf
This commit fixes parsing of notification messages for the case where the notification follows a leaf. Prior to this change, if the notification followed a leaf, the notification would be missed. In the `LYS_LEAF` case, `elem` would be advanced to `elem->next` (the notification), but the `for` loop condition to detect the notification would not be re-evaluated due to the `goto next_node` jump. By the time the loop condition was re-evaluated, `elem` would have been advanced to the notification's child. We've written integration tests that demonstrate the problem. This commit, together with a forthcoming commit to sysrepo, will allow those failing test cases to pass. (See [CI results], lines 7282-7284, or [test source code].) These test cases cover several different variations of notifications tied to data nodes. [CI results]: https://travis-ci.org/ADTRAN/netopeer2-integration-tests/builds/414144146#L7282 [test source code]: https://github.com/ADTRAN/netopeer2-integration-tests/blob/master/tests/test_notif.py#L229
1 parent 8f1d355 commit bbab76f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/messages_server.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <stdlib.h>
1717
#include <string.h>
1818
#include <stdarg.h>
19+
#include <stdbool.h>
1920

2021
#include <libyang/libyang.h>
2122

@@ -828,6 +829,7 @@ nc_server_notif_new(struct lyd_node* event, char *eventtime, NC_PARAMTYPE paramt
828829
{
829830
struct nc_server_notif *ntf;
830831
struct lyd_node *elem;
832+
bool found_notif = false;
831833

832834
if (!event) {
833835
ERRARG("event");
@@ -838,7 +840,7 @@ nc_server_notif_new(struct lyd_node* event, char *eventtime, NC_PARAMTYPE paramt
838840
}
839841

840842
/* check that there is a notification */
841-
for (elem = event; elem && (elem->schema->nodetype != LYS_NOTIF); elem = elem->child) {
843+
for (elem = event; elem && !found_notif; elem = elem->child) {
842844
next_node:
843845
switch (elem->schema->nodetype) {
844846
case LYS_LEAF:
@@ -852,16 +854,18 @@ nc_server_notif_new(struct lyd_node* event, char *eventtime, NC_PARAMTYPE paramt
852854
goto next_node;
853855
case LYS_CONTAINER:
854856
case LYS_LIST:
855-
case LYS_NOTIF:
856857
/* ok */
857858
break;
859+
case LYS_NOTIF:
860+
found_notif = true;
861+
break;
858862
default:
859863
/* error */
860864
ERRARG("event");
861865
return NULL;
862866
}
863867
}
864-
if (!elem) {
868+
if (!found_notif) {
865869
ERRARG("event");
866870
return NULL;
867871
}

0 commit comments

Comments
 (0)