@@ -898,7 +898,7 @@ np2srv_rpc_subscribe_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), cons
898898 struct timespec start = {0 }, stop = {0 }, cur_ts ;
899899 int rc = SR_ERR_OK , has_nc_ntf_status = 0 ;
900900 uint32_t idx ;
901- struct ly_set mod_set = { 0 } ;
901+ struct ly_set * mod_set = NULL ;
902902 struct np_ntf_arg * ntf_arg ;
903903
904904 if (np_ignore_rpc (session , event , & rc )) {
@@ -992,42 +992,19 @@ np2srv_rpc_subscribe_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), cons
992992 nc_session_inc_notif_status (ncs );
993993 has_nc_ntf_status = 1 ;
994994
995- /* sysrepo API */
996- if (!strcmp (stream , "NETCONF" )) {
997- /* find all modules with notifications */
998- idx = 0 ;
999- while ((ly_mod = ly_ctx_get_module_iter (LYD_CTX (input ), & idx ))) {
1000- if (!ly_mod -> implemented ) {
1001- continue ;
1002- }
1003-
1004- if (np_ly_mod_has_notif (ly_mod )) {
1005- /* a notification was found */
1006- if (ly_set_add (& mod_set , (void * )ly_mod , 1 , NULL )) {
1007- rc = SR_ERR_INTERNAL ;
1008- goto cleanup ;
1009- }
1010- }
1011- }
995+ /* collect modules */
996+ if ((rc = srsn_stream_collect_mods (stream , xp_filter , LYD_CTX (input ), & mod_set ))) {
997+ sr_session_set_error (session , NULL , rc , "Failed to collect modules to subscribe to (%s)." , sr_strerror (rc ));
998+ goto cleanup ;
999+ }
10121000
1013- /* subscribe to all the modules */
1014- ntf_arg -> sr_sub_count = mod_set .count ;
1015- ntf_arg -> sr_ntf_replay_complete_count = start .tv_sec ? 0 : ntf_arg -> sr_sub_count ;
1016- for (idx = 0 ; idx < mod_set .count ; ++ idx ) {
1017- ly_mod = mod_set .objs [idx ];
1018- rc = sr_notif_subscribe_tree (user_sess -> sess , ly_mod -> name , xp_filter , start .tv_sec ? & start : NULL ,
1019- stop .tv_sec ? & stop : NULL , np2srv_rpc_subscribe_ntf_cb , ntf_arg , 0 , & np2srv .sr_notif_sub );
1020- if (rc != SR_ERR_OK ) {
1021- sr_session_dup_error (user_sess -> sess , session );
1022- goto cleanup ;
1023- }
1024- }
1025- } else {
1026- /* subscribe to the specific module (stream) */
1027- ntf_arg -> sr_sub_count = 1 ;
1028- ntf_arg -> sr_ntf_replay_complete_count = start .tv_sec ? 0 : 1 ;
1029- rc = sr_notif_subscribe_tree (user_sess -> sess , stream , xp_filter , start .tv_sec ? & start : NULL , stop .tv_sec ? & stop : NULL ,
1030- np2srv_rpc_subscribe_ntf_cb , ntf_arg , 0 , & np2srv .sr_notif_sub );
1001+ /* subscribe to the modules */
1002+ ntf_arg -> sr_sub_count = mod_set -> count ;
1003+ ntf_arg -> sr_ntf_replay_complete_count = start .tv_sec ? 0 : ntf_arg -> sr_sub_count ;
1004+ for (idx = 0 ; idx < mod_set -> count ; ++ idx ) {
1005+ ly_mod = mod_set -> objs [idx ];
1006+ rc = sr_notif_subscribe_tree (user_sess -> sess , ly_mod -> name , xp_filter , start .tv_sec ? & start : NULL ,
1007+ stop .tv_sec ? & stop : NULL , np2srv_rpc_subscribe_ntf_cb , ntf_arg , 0 , & np2srv .sr_notif_sub );
10311008 if (rc != SR_ERR_OK ) {
10321009 sr_session_dup_error (user_sess -> sess , session );
10331010 goto cleanup ;
@@ -1038,7 +1015,7 @@ np2srv_rpc_subscribe_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), cons
10381015 if (rc && has_nc_ntf_status ) {
10391016 nc_session_dec_notif_status (ncs );
10401017 }
1041- ly_set_erase ( & mod_set , NULL );
1018+ ly_set_free ( mod_set , NULL );
10421019 free (xp_filter );
10431020 np_release_user_sess (user_sess );
10441021 return rc ;
0 commit comments