server messages CHANGE check for notification presence in a notif tree
@@ -827,6 +827,7 @@ API struct nc_server_notif *
nc_server_notif_new(struct lyd_node* event, char *eventtime, NC_PARAMTYPE paramtype)
{
struct nc_server_notif *ntf;
+ struct lyd_node *elem;
if (!event) {
ERRARG("event");
@@ -836,6 +837,34 @@ nc_server_notif_new(struct lyd_node* event, char *eventtime, NC_PARAMTYPE paramt
return NULL;
}
+ /* check that there is a notification */
+ for (elem = event; elem && (elem->schema->nodetype != LYS_NOTIF); elem = elem->child) {
+next_node:
+ switch (elem->schema->nodetype) {
+ case LYS_LEAF:
+ /* key, skip it */
+ elem = elem->next;
+ if (!elem) {
+ /* error */
+ break;
+ }
+ goto next_node;
+ case LYS_CONTAINER:
+ case LYS_LIST:
+ case LYS_NOTIF:
+ /* ok */
+ break;
+ default:
+ /* error */
+ elem = NULL;
+ break;
+ }
+ }
+ if (!elem) {
+ ERRARG("event");
+ return NULL;
+ }
+
ntf = malloc(sizeof *ntf);
if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
ntf->eventtime = strdup(eventtime);
