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: 2016-09-04 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 ret=-1;
      18           2 :         int ars=0;
      19             :         //char ls[1024]="";
      20             :         //struct cntr cntr;
      21           2 :         size_t blen=0;
      22           2 :         char *last_bd_match=NULL;
      23           2 :         if(browse) blen=strlen(browse);
      24             :         while(1)
      25             :         {
      26             :                 int r;
      27           2 :                 sbuf_free_content(sb);
      28           2 :                 if((ars=manio_read(manio, sb)))
      29             :                 {
      30           2 :                         if(ars<0) goto end;
      31             :                         // ars==1 means it ended ok.
      32             :                         break;
      33             :                 }
      34             : 
      35           0 :                 if(manio->protocol==PROTO_2 && sb->endfile.buf)
      36           0 :                         continue;
      37             : 
      38           0 :                 if(sb->path.cmd!=CMD_DIRECTORY
      39           0 :                   && sb->path.cmd!=CMD_FILE
      40           0 :                   && sb->path.cmd!=CMD_ENC_FILE
      41           0 :                   && sb->path.cmd!=CMD_EFS_FILE
      42           0 :                   && sb->path.cmd!=CMD_SPECIAL
      43           0 :                   && !cmd_is_link(sb->path.cmd))
      44           0 :                         continue;
      45             : 
      46           0 :                 if((r=check_browsedir(browse, sb, blen, &last_bd_match))<0)
      47             :                         goto end;
      48           0 :                 if(!r) continue;
      49             : 
      50           0 :                 if(json_from_statp(sb->path.buf, &sb->statp)) goto end;
      51             :         }
      52             : 
      53           2 :         ret=0;
      54             : end:
      55           2 :         free_w(&last_bd_match);
      56           2 :         return ret;
      57             : }
      58             : 
      59           2 : static int browse_manifest_start(struct cstat *cstat,
      60             :         struct bu *bu, const char *browse, int use_cache)
      61             : {
      62           2 :         int ret=-1;
      63           2 :         char *manifest=NULL;
      64           2 :         struct sbuf *sb=NULL;
      65           2 :         struct manio *manio=NULL;
      66             : 
      67           2 :         if(!(manifest=prepend_s(bu->path,
      68           2 :                 cstat->protocol==PROTO_1?"manifest.gz":"manifest"))
      69           2 :           || !(manio=manio_open(manifest, "rb", cstat->protocol))
      70           2 :           || !(sb=sbuf_alloc(cstat->protocol)))
      71             :                 goto end;
      72           2 :         if(use_cache)
      73           0 :                 ret=cache_load(manio, sb, cstat->name, bu->bno);
      74             :         else
      75           2 :                 ret=do_browse_manifest(manio, sb, browse);
      76             : end:
      77           2 :         free_w(&manifest);
      78           2 :         manio_close(&manio);
      79           2 :         sbuf_free(&sb);
      80           2 :         return ret;
      81             : }
      82             : 
      83           2 : int browse_manifest(struct cstat *cstat,
      84           2 :         struct bu *bu, const char *browse, int use_cache)
      85             : {
      86           2 :         if(use_cache)
      87             :         {
      88           0 :                 if(!cache_loaded(cstat->name, bu->bno)
      89           0 :                   && browse_manifest_start(cstat, bu, browse, use_cache))
      90             :                         return -1;
      91           0 :                 return cache_lookup(browse);
      92             :         }
      93           4 :         return browse_manifest_start(cstat, bu, browse, use_cache);
      94             : }

Generated by: LCOV version 1.10