LCOV - code coverage report
Current view: top level - src/client/protocol2 - rabin_read.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 42 44 95.5 %
Date: 2016-03-31 Functions: 5 5 100.0 %

          Line data    Source code
       1             : #include "../../burp.h"
       2             : #include "../../alloc.h"
       3             : #include "../../attribs.h"
       4             : #include "../../bfile.h"
       5             : #include "../../cntr.h"
       6             : #include "../../log.h"
       7             : #include "../../sbuf.h"
       8             : #include "../extrameta.h"
       9             : 
      10             : static char *meta_buffer=NULL;
      11             : static size_t meta_buffer_len=0;
      12             : static char *mp=NULL;
      13             : 
      14             : static int rabin_close_file_extrameta(struct sbuf *sb)
      15             : {
      16           4 :         free_w(&meta_buffer);
      17           4 :         meta_buffer_len=0;
      18           4 :         mp=NULL;
      19           4 :         sb->protocol2->bfd.mode=BF_CLOSED;
      20             :         return 0;
      21             : }
      22             : 
      23             : // Return -1 for error, 0 for could not get data, 1 for success.
      24           2 : static int rabin_open_file_extrameta(struct sbuf *sb, struct asfd *asfd,
      25             :         struct cntr *cntr)
      26             : {
      27             :         // Load all of the metadata into a buffer.
      28           2 :         rabin_close_file_extrameta(sb);
      29           4 :         if(get_extrameta(asfd, NULL, sb->path.buf, S_ISDIR(sb->statp.st_mode),
      30           2 :                 &meta_buffer, &meta_buffer_len, cntr))
      31             :                         return -1;
      32           2 :         if(!meta_buffer)
      33             :                 return 0;
      34           2 :         mp=meta_buffer;
      35           2 :         sb->protocol2->bfd.mode=BF_READ;
      36           2 :         return 1;
      37             : }
      38             : 
      39          30 : static ssize_t rabin_read_extrameta(struct sbuf *sb, char *buf, size_t bufsize)
      40             : {
      41             :         // Place bufsize of the meta buffer contents into buf.
      42          30 :         size_t to_read=meta_buffer_len;
      43          30 :         if(!meta_buffer_len)
      44             :                 return 0;
      45          28 :         if(bufsize<meta_buffer_len)
      46          26 :                 to_read=bufsize;
      47          28 :         memcpy(buf, mp, to_read);
      48          28 :         meta_buffer_len-=to_read;
      49          28 :         mp+=to_read;
      50          28 :         return (ssize_t)to_read;
      51             : }
      52             : 
      53             : // Return -1 for error, 0 for could not open file, 1 for success.
      54          24 : int rabin_open_file(struct sbuf *sb, struct asfd *asfd, struct cntr *cntr,
      55             :         struct conf **confs)
      56             : {
      57          24 :         BFILE *bfd=&sb->protocol2->bfd;
      58             : #ifdef HAVE_WIN32
      59             :         if(win32_lstat(sb->path.buf, &sb->statp, &sb->winattr))
      60             : #else
      61          48 :         if(lstat(sb->path.buf, &sb->statp))
      62             : #endif
      63             :         {
      64             :                 // This file is no longer available.
      65           3 :                 logw(asfd, cntr, "%s has vanished\n", sb->path.buf);
      66           3 :                 return 0;
      67             :         }
      68          21 :         sb->compression=get_int(confs[OPT_COMPRESSION]);
      69             :         // Encryption not yet implemented in protocol2.
      70             :         //sb->protocol2->encryption=conf->protocol2->encryption_password?1:0;
      71          21 :         if(attribs_encode(sb)) return -1;
      72          21 :         if(sbuf_is_metadata(sb))
      73           2 :                 return rabin_open_file_extrameta(sb, asfd, cntr);
      74             : 
      75          19 :         if(bfd->open_for_send(bfd, asfd,
      76             :                 sb->path.buf, sb->winattr,
      77          19 :                 get_int(confs[OPT_ATIME]), cntr, PROTO_2))
      78             :         {
      79             :                 logw(asfd, get_cntr(confs),
      80           0 :                         "Could not open %s\n", sb->path.buf);
      81           0 :                 return 0;
      82             :         }
      83             :         return 1;
      84             : }
      85             : 
      86          21 : int rabin_close_file(struct sbuf *sb, struct asfd *asfd)
      87             : {
      88             :         BFILE *bfd;
      89          21 :         if(sbuf_is_metadata(sb))
      90           4 :                 return rabin_close_file_extrameta(sb);
      91          19 :         bfd=&sb->protocol2->bfd;
      92          19 :         return bfd->close(bfd, asfd);
      93             : }
      94             : 
      95          68 : ssize_t rabin_read(struct sbuf *sb, char *buf, size_t bufsize)
      96             : {
      97             :         BFILE *bfd;
      98          68 :         if(sbuf_is_metadata(sb))
      99          30 :                 return rabin_read_extrameta(sb, buf, bufsize);
     100          38 :         bfd=&sb->protocol2->bfd;
     101          38 :         return (ssize_t)bfd->read(bfd, buf, bufsize);
     102             : }

Generated by: LCOV version 1.10