LCOV - code coverage report
Current view: top level - src/server/monitor - browse.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 32 50 64.0 %
Date: 2020-07-02 21:37:08 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           2 : static int do_browse_manifest(
      15             :         struct manio *manio, struct sbuf *sb, const char *browse)
      16             : {
      17           2 :         int browse_all = (browse && !strncmp(browse, "*", 1))? 1:0;
      18           2 :         int ret=-1;
      19           2 :         int ars=0;
      20             :         //char ls[1024]="";
      21             :         //struct cntr cntr;
      22           2 :         size_t blen=0;
      23           2 :         char *last_bd_match=NULL;
      24           2 :         if(browse) blen=strlen(browse);
      25             :         while(1)
      26             :         {
      27             :                 int r;
      28           2 :                 sbuf_free_content(sb);
      29           2 :                 if((ars=manio_read(manio, sb)))
      30             :                 {
      31           2 :                         if(ars<0) goto end;
      32             :                         // ars==1 means it ended ok.
      33             :                         break;
      34             :                 }
      35             : 
      36           0 :                 if(manio->protocol==PROTO_2 && sb->endfile.buf)
      37           0 :                         continue;
      38             : 
      39           0 :                 if(sb->path.cmd!=CMD_DIRECTORY
      40           0 :                   && sb->path.cmd!=CMD_FILE
      41           0 :                   && sb->path.cmd!=CMD_ENC_FILE
      42           0 :                   && sb->path.cmd!=CMD_EFS_FILE
      43           0 :                   && sb->path.cmd!=CMD_SPECIAL
      44           0 :                   && !cmd_is_link(sb->path.cmd))
      45           0 :                         continue;
      46             : 
      47           0 :                 if(!browse_all) {
      48           0 :                         if((r=check_browsedir(browse, sb, blen, &last_bd_match))<0)
      49             :                                 goto end;
      50           0 :                         if(!r) continue;
      51             :                 }
      52             : 
      53           0 :                 if(json_from_entry(sb->path.buf, sb->link.buf, &sb->statp)) goto end;
      54             :         }
      55             : 
      56           2 :         ret=0;
      57             : end:
      58           2 :         free_w(&last_bd_match);
      59           2 :         return ret;
      60             : }
      61             : 
      62           2 : static int browse_manifest_start(struct cstat *cstat,
      63             :         struct bu *bu, const char *browse, int use_cache)
      64             : {
      65           2 :         int ret=-1;
      66           2 :         char *manifest=NULL;
      67           2 :         struct sbuf *sb=NULL;
      68           2 :         struct manio *manio=NULL;
      69             : 
      70           2 :         if(!(manifest=prepend_s(bu->path,
      71           2 :                 cstat->protocol==PROTO_1?"manifest.gz":"manifest"))
      72           2 :           || !(manio=manio_open(manifest, "rb", cstat->protocol))
      73           2 :           || !(sb=sbuf_alloc(cstat->protocol)))
      74             :                 goto end;
      75           2 :         if(use_cache)
      76           0 :                 ret=cache_load(manio, sb, cstat->name, bu->bno);
      77             :         else
      78           2 :                 ret=do_browse_manifest(manio, sb, browse);
      79             : end:
      80           2 :         free_w(&manifest);
      81           2 :         manio_close(&manio);
      82           2 :         sbuf_free(&sb);
      83           2 :         return ret;
      84             : }
      85             : 
      86           2 : int browse_manifest(struct cstat *cstat,
      87             :         struct bu *bu, const char *browse, int use_cache)
      88             : {
      89             :         /* if browse directory is *, we dump all file entries, with full path
      90             :            we also avoid caching the whole list */
      91           2 :         if (browse && !strncmp(browse, "*", 1))
      92             :         {
      93           0 :                 use_cache = 0;
      94             :         }
      95           2 :         if(use_cache)
      96             :         {
      97           0 :                 if(!cache_loaded(cstat->name, bu->bno)
      98           0 :                   && browse_manifest_start(cstat, bu, browse, use_cache))
      99             :                         return -1;
     100           0 :                 return cache_lookup(browse);
     101             :         }
     102           2 :         return browse_manifest_start(cstat, bu, browse, use_cache);
     103             : }

Generated by: LCOV version 1.13