LCOV - code coverage report
Current view: top level - src/server - manios.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 26 37 70.3 %
Date: 2021-07-02 04:40:54 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "../burp.h"
       2             : #include "../alloc.h"
       3             : #include "../fsops.h"
       4             : #include "../log.h"
       5             : #include "manios.h"
       6             : #include "manio.h"
       7             : 
       8             : static struct manios *manios_alloc(void)
       9             : {
      10          23 :         return (struct manios *)calloc_w(1, sizeof(struct manios), __func__);
      11             : }
      12             : 
      13          23 : struct manios *manios_open_phase2(
      14             :         struct sdirs *sdirs,
      15             :         man_off_t *pos_phase1,
      16             :         man_off_t *pos_current,
      17             :         enum protocol p)
      18             : {
      19          23 :         struct manios *m=NULL;
      20             : 
      21          23 :         if(!(m=manios_alloc())
      22          23 :           || !(m->phase1=manio_open_phase1(sdirs->phase1data, "rb", p))
      23          23 :           || !(m->changed=manio_open_phase2(sdirs->changed, "ab", p))
      24          23 :           || !(m->unchanged=manio_open_phase2(sdirs->unchanged, "ab", p))
      25             :         // The counters are always flat files, which is given by PROTO_1.
      26          46 :           || !(m->counters_d=manio_open_phase2(
      27          23 :                 sdirs->counters_d, "ab", PROTO_1))
      28          46 :           || !(m->counters_n=manio_open_phase2(
      29          23 :                 sdirs->counters_n, "ab", PROTO_1))
      30          23 :           || (pos_phase1 && manio_seek(m->phase1, pos_phase1)))
      31             :                 goto error;
      32             : 
      33          23 :         if(!(m->current=manio_open(sdirs->cmanifest, "rb", p)))
      34             :         {
      35           0 :                 if(pos_current)
      36             :                 {
      37           0 :                         logp("Want to seek but could not open %s\n",
      38             :                                 sdirs->cmanifest);
      39           0 :                         goto error;
      40             :                 }
      41           0 :                 if(p==PROTO_1 && is_reg_lstat(sdirs->cmanifest)==1)
      42             :                 {
      43           0 :                         logp("Could not open %s\n", sdirs->cmanifest);
      44           0 :                         goto error;
      45             :                 }
      46           0 :                 if(p==PROTO_2 && is_dir_lstat(sdirs->cmanifest)==1)
      47             :                 {
      48           0 :                         logp("Could not open dir %s\n", sdirs->cmanifest);
      49           0 :                         goto error;
      50             :                 }
      51             :         }
      52          23 :         if(pos_current && manio_seek(m->current, pos_current))
      53             :                 goto error;
      54             : 
      55          23 :         return m;
      56             : error:
      57           0 :         manios_close(&m);
      58           0 :         return NULL;
      59             : }
      60             : 
      61          46 : int manios_close(struct manios **manios)
      62             : {
      63          46 :         int ret=0;
      64          46 :         if(!manios || !*manios) return 0;
      65          23 :         ret|=manio_close(&(*manios)->current);
      66          23 :         ret|=manio_close(&(*manios)->phase1);
      67          23 :         ret|=manio_close(&(*manios)->changed);
      68          23 :         ret|=manio_close(&(*manios)->unchanged);
      69          23 :         ret|=manio_close(&(*manios)->counters_d);
      70          23 :         ret|=manio_close(&(*manios)->counters_n);
      71          23 :         free_v((void **)manios);
      72          23 :         return ret;
      73             : }

Generated by: LCOV version 1.13