"Fossies" - the Fresh Open Source Software Archive

Member "burp-2.3.6/src/server/monitor/browse.c" (28 Apr 2019, 2366 Bytes) of package /linux/privat/burp-2.3.6.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "browse.c" see the Fossies "Dox" file reference documentation.

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