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

Generated by: LCOV version 1.10