LCOV - code coverage report
Current view: top level - src/server - diff.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 0 65 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 "../asfd.h"
       4             : #include "../async.h"
       5             : #include "../bu.h"
       6             : #include "../conf.h"
       7             : #include "../cmd.h"
       8             : #include "../cntr.h"
       9             : #include "../log.h"
      10             : #include "../prepend.h"
      11             : #include "../sbuf.h"
      12             : #include "bu_get.h"
      13             : #include "child.h"
      14             : #include "manio.h"
      15             : 
      16           0 : static int diff_manifest(struct asfd *asfd,
      17             :         const char *fullpath, struct cntr *cntr, enum protocol protocol)
      18             : {
      19           0 :         int ret=0;
      20           0 :         struct sbuf *sb=NULL;
      21           0 :         struct manio *manio=NULL;
      22           0 :         char *manifest_dir=NULL;
      23             : 
      24           0 :         if(!(manifest_dir=prepend_s(fullpath,
      25           0 :                 protocol==PROTO_1?"manifest.gz":"manifest"))
      26           0 :           || !(manio=manio_open(manifest_dir, "rb", protocol))
      27           0 :           || !(sb=sbuf_alloc(protocol)))
      28             :         {
      29           0 :                 log_and_send_oom(asfd, __func__);
      30           0 :                 goto error;
      31             :         }
      32             : 
      33             :         while(1)
      34             :         {
      35           0 :                 sbuf_free_content(sb);
      36             : 
      37           0 :                 switch(manio_read(manio, sb))
      38             :                 {
      39           0 :                         case 0: break;
      40           0 :                         case 1: goto end; // Finished OK.
      41           0 :                         default: goto error;
      42             :                 }
      43             : 
      44           0 :                 if(protocol==PROTO_2 && sb->endfile.buf)
      45           0 :                         continue;
      46             : 
      47           0 :                 if(write_status(CNTR_STATUS_DIFFING, sb->path.buf, cntr))
      48           0 :                         goto error;
      49             : 
      50           0 :                 if(asfd->write(asfd, &sb->attr)
      51           0 :                   || asfd->write(asfd, &sb->path))
      52           0 :                         goto error;
      53           0 :                 if(sbuf_is_link(sb)
      54           0 :                   && asfd->write(asfd, &sb->link))
      55           0 :                         goto error;
      56             :         }
      57             : 
      58             : error:
      59           0 :         ret=-1;
      60             : end:
      61           0 :         sbuf_free(&sb);
      62           0 :         free_w(&manifest_dir);
      63           0 :         manio_close(&manio);
      64           0 :         return ret;
      65             : }
      66             : 
      67           0 : static int send_backup_name_to_client(struct asfd *asfd, struct bu *bu)
      68             : {
      69           0 :         char msg[64]="";
      70             :         //snprintf(msg, sizeof(msg), "%s%s",
      71             :         //      bu->timestamp, bu->deletable?" (deletable)":"");
      72           0 :         snprintf(msg, sizeof(msg), "%s", bu->timestamp);
      73           0 :         return asfd->write_str(asfd, CMD_TIMESTAMP, msg);
      74             : }
      75             : 
      76           0 : int do_diff_server(struct asfd *asfd, struct sdirs *sdirs, struct cntr *cntr,
      77             :         enum protocol protocol, const char *backup)
      78             : {
      79           0 :         int ret=-1;
      80           0 :         uint8_t found=0;
      81           0 :         unsigned long bno=0;
      82           0 :         struct bu *bu=NULL;
      83           0 :         struct bu *bu_list=NULL;
      84             : 
      85           0 :         printf("in do_diff_server\n");
      86             : 
      87           0 :         if(bu_get_list(sdirs, &bu_list)
      88           0 :           || write_status(CNTR_STATUS_DIFFING, NULL, cntr))
      89           0 :                 goto end;
      90             : 
      91           0 :         if(backup && *backup) bno=strtoul(backup, NULL, 10);
      92             : 
      93           0 :         for(bu=bu_list; bu; bu=bu->next)
      94             :         {
      95             :                 // Search or list a particular backup.
      96           0 :                 if(backup && *backup)
      97             :                 {
      98           0 :                         if(!found
      99           0 :                           && (!strcmp(bu->timestamp, backup)
     100           0 :                                 || bu->bno==bno))
     101             :                         {
     102           0 :                                 found=1;
     103           0 :                                 if(send_backup_name_to_client(asfd, bu)
     104           0 :                                   || diff_manifest(asfd, bu->path,
     105           0 :                                         cntr, protocol))
     106           0 :                                                 goto end;
     107             :                         }
     108             :                 }
     109             :                 // List the backups.
     110             :                 else
     111             :                 {
     112           0 :                         found=1;
     113           0 :                         if(send_backup_name_to_client(asfd, bu))
     114           0 :                                 goto end;
     115             :                 }
     116             :         }
     117             : 
     118           0 :         if(backup && *backup && !found)
     119             :         {
     120           0 :                 asfd->write_str(asfd, CMD_ERROR, "backup not found");
     121           0 :                 goto end;
     122             :         }
     123           0 :         ret=0;
     124             : end:
     125           0 :         bu_list_free(&bu);
     126           0 :         return ret;
     127             : }

Generated by: LCOV version 1.10