LCOV - code coverage report
Current view: top level - src/server/monitor - browse.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 31 47 66.0 %
Date: 2022-12-03 01:09:05 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #include "../../burp.h"
       2             : #include "../../alloc.h"
       3             : #include "../../bu.h"
       4             : #include "../../cmd.h"
       5             : #include "../../cstat.h"
       6             : #include "../../prepend.h"
       7             : #include "../../sbuf.h"
       8             : #include "../list.h"
       9             : #include "../manio.h"
      10             : #include "cache.h"
      11             : #include "json_output.h"
      12             : #include "browse.h"
      13             : 
      14           1 : static int do_browse_manifest(
      15             :         struct manio *manio, struct sbuf *sb, const char *browse)
      16             : {
      17           1 :         int browse_all = (browse && !strncmp(browse, "*", 1))? 1:0;
      18           1 :         int ret=-1;
      19           1 :         int ars=0;
      20             :         //char ls[1024]="";
      21             :         //struct cntr cntr;
      22           1 :         size_t blen=0;
      23           1 :         char *last_bd_match=NULL;
      24           1 :         if(browse) blen=strlen(browse);
      25             :         while(1)
      26             :         {
      27             :                 int r;
      28           1 :                 sbuf_free_content(sb);
      29           1 :                 if((ars=manio_read(manio, sb)))
      30             :                 {
      31           1 :                         if(ars<0) goto end;
      32             :                         // ars==1 means it ended ok.
      33             :                         break;
      34             :                 }
      35             : 
      36           0 :                 if(sb->path.cmd!=CMD_DIRECTORY
      37           0 :                   && sb->path.cmd!=CMD_FILE
      38           0 :                   && sb->path.cmd!=CMD_ENC_FILE
      39           0 :                   && sb->path.cmd!=CMD_EFS_FILE
      40           0 :                   && sb->path.cmd!=CMD_SPECIAL
      41           0 :                   && !cmd_is_link(sb->path.cmd))
      42           0 :                         continue;
      43             : 
      44           0 :                 if(!browse_all) {
      45           0 :                         if((r=check_browsedir(browse, sb, blen, &last_bd_match))<0)
      46             :                                 goto end;
      47           0 :                         if(!r) continue;
      48             :                 }
      49             : 
      50           0 :                 if(json_from_entry(sb->path.buf, sb->link.buf, &sb->statp)) goto end;
      51             :         }
      52             : 
      53           1 :         ret=0;
      54             : end:
      55           1 :         free_w(&last_bd_match);
      56           1 :         return ret;
      57             : }
      58             : 
      59           1 : static int browse_manifest_start(struct cstat *cstat,
      60             :         struct bu *bu, const char *browse, int use_cache)
      61             : {
      62           1 :         int ret=-1;
      63           1 :         char *manifest=NULL;
      64           1 :         struct sbuf *sb=NULL;
      65           1 :         struct manio *manio=NULL;
      66             : 
      67           1 :         if(!(manifest=prepend_s(bu->path, "manifest.gz"))
      68           1 :           || !(manio=manio_open(manifest, "rb"))
      69           1 :           || !(sb=sbuf_alloc()))
      70             :                 goto end;
      71           1 :         if(use_cache)
      72           0 :                 ret=cache_load(manio, sb, cstat->name, bu->bno);
      73             :         else
      74           1 :                 ret=do_browse_manifest(manio, sb, browse);
      75             : end:
      76           1 :         free_w(&manifest);
      77           1 :         manio_close(&manio);
      78           1 :         sbuf_free(&sb);
      79           1 :         return ret;
      80             : }
      81             : 
      82           1 : int browse_manifest(struct cstat *cstat,
      83             :         struct bu *bu, const char *browse, int use_cache)
      84             : {
      85             :         /* if browse directory is *, we dump all file entries, with full path
      86             :            we also avoid caching the whole list */
      87           1 :         if (browse && !strncmp(browse, "*", 1))
      88             :         {
      89           0 :                 use_cache = 0;
      90             :         }
      91           1 :         if(use_cache)
      92             :         {
      93           0 :                 if(!cache_loaded(cstat->name, bu->bno)
      94           0 :                   && browse_manifest_start(cstat, bu, browse, use_cache))
      95             :                         return -1;
      96           0 :                 return cache_lookup(browse);
      97             :         }
      98           1 :         return browse_manifest_start(cstat, bu, browse, use_cache);
      99             : }

Generated by: LCOV version 1.13