@@ -381,27 +381,27 @@ ly_get_log_clb(void)
381381}
382382
383383void
384- ly_log_location (const struct lysc_node * scnode , const struct lyd_node * dnode , const char * spath , const struct ly_in * in )
384+ ly_log_location (const struct lysc_node * scnode , const struct lyd_node * dnode , const char * path , const struct ly_in * in )
385385{
386386 if (scnode ) {
387387 ly_set_add (& log_location .scnodes , (void * )scnode , 1 , NULL );
388388 }
389- if (dnode || (!scnode && !spath && !in )) {
389+ if (dnode || (!scnode && !path && !in )) {
390390 ly_set_add (& log_location .dnodes , (void * )dnode , 1 , NULL );
391391 }
392- if (spath ) {
393- char * s = strdup (spath );
392+ if (path ) {
393+ char * s = strdup (path );
394394
395395 LY_CHECK_ERR_RET (!s , LOGMEM (NULL ), );
396- ly_set_add (& log_location .spaths , s , 1 , NULL );
396+ ly_set_add (& log_location .paths , s , 1 , NULL );
397397 }
398398 if (in ) {
399399 ly_set_add (& log_location .inputs , (void * )in , 1 , NULL );
400400 }
401401}
402402
403403void
404- ly_log_location_revert (uint32_t scnode_steps , uint32_t dnode_steps , uint32_t spath_steps , uint32_t in_steps )
404+ ly_log_location_revert (uint32_t scnode_steps , uint32_t dnode_steps , uint32_t path_steps , uint32_t in_steps )
405405{
406406 for (uint32_t i = scnode_steps ; i && log_location .scnodes .count ; i -- ) {
407407 log_location .scnodes .count -- ;
@@ -411,8 +411,8 @@ ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t spa
411411 log_location .dnodes .count -- ;
412412 }
413413
414- for (uint32_t i = spath_steps ; i && log_location .spaths .count ; i -- ) {
415- ly_set_rm_index (& log_location .spaths , log_location .spaths .count - 1 , free );
414+ for (uint32_t i = path_steps ; i && log_location .paths .count ; i -- ) {
415+ ly_set_rm_index (& log_location .paths , log_location .paths .count - 1 , free );
416416 }
417417
418418 for (uint32_t i = in_steps ; i && log_location .inputs .count ; i -- ) {
@@ -426,8 +426,8 @@ ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t spa
426426 if (dnode_steps && !log_location .dnodes .count ) {
427427 ly_set_erase (& log_location .dnodes , NULL );
428428 }
429- if (spath_steps && !log_location .spaths .count ) {
430- ly_set_erase (& log_location .spaths , free );
429+ if (path_steps && !log_location .paths .count ) {
430+ ly_set_erase (& log_location .paths , free );
431431 }
432432 if (in_steps && !log_location .inputs .count ) {
433433 ly_set_erase (& log_location .inputs , NULL );
@@ -808,21 +808,38 @@ ly_vlog_build_data_path(const struct ly_ctx *ctx, char **path)
808808static LY_ERR
809809ly_vlog_build_path_line (const struct ly_ctx * ctx , char * * data_path , char * * schema_path , uint64_t * line )
810810{
811+ int r ;
812+ char * path ;
813+
811814 * data_path = NULL ;
812815 * schema_path = NULL ;
813816 * line = 0 ;
814817
815- if (log_location .spaths .count && ((const char * )(log_location .spaths .objs [log_location .spaths .count - 1 ]))[0 ]) {
816- /* simply get what is in the provided path string */
817- * schema_path = strdup (log_location .spaths .objs [log_location .spaths .count - 1 ]);
818+ /* data/schema node */
819+ if (log_location .dnodes .count ) {
820+ LY_CHECK_RET (ly_vlog_build_data_path (ctx , data_path ));
821+ } else if (log_location .scnodes .count ) {
822+ * schema_path = lysc_path (log_location .scnodes .objs [log_location .scnodes .count - 1 ], LYSC_PATH_LOG , NULL , 0 );
818823 LY_CHECK_ERR_RET (!* schema_path , LOGMEM (ctx ), LY_EMEM );
819- } else {
820- /* data/schema node */
821- if (log_location .dnodes .count ) {
822- LY_CHECK_RET (ly_vlog_build_data_path (ctx , data_path ));
823- } else if (log_location .scnodes .count ) {
824- * schema_path = lysc_path (log_location .scnodes .objs [log_location .scnodes .count - 1 ], LYSC_PATH_LOG , NULL , 0 );
825- LY_CHECK_ERR_RET (!* schema_path , LOGMEM (ctx ), LY_EMEM );
824+ }
825+
826+ if (log_location .paths .count && ((const char * )(log_location .paths .objs [log_location .paths .count - 1 ]))[0 ]) {
827+ /* append the provided path string to data/schema path, if any */
828+ if (* data_path ) {
829+ r = asprintf (& path , "%s%s" , * data_path , (char * )log_location .paths .objs [log_location .paths .count - 1 ]);
830+ } else if (* schema_path ) {
831+ r = asprintf (& path , "%s%s" , * schema_path , (char * )log_location .paths .objs [log_location .paths .count - 1 ]);
832+ } else {
833+ r = asprintf (& path , "%s" , (char * )log_location .paths .objs [log_location .paths .count - 1 ]);
834+ }
835+ LY_CHECK_ERR_RET (r == -1 , LOGMEM (ctx ), LY_EMEM );
836+
837+ if (* data_path ) {
838+ free (* data_path );
839+ * data_path = path ;
840+ } else {
841+ free (* schema_path );
842+ * schema_path = path ;
826843 }
827844 }
828845
0 commit comments