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

Generated by: LCOV version 1.10