static int send_file(struct asfd *asfd, struct sbuf *sb, int patches, const char *best, uint64_t *bytes, struct cntr *cntr) { int ret=0; static BFILE *bfd=NULL; if(!bfd && !(bfd=bfile_alloc())) return -1; bfile_init(bfd, 0, cntr); if(bfd->open_for_send(bfd, asfd, best, sb->winattr, 1 /* no O_NOATIME */, cntr, PROTO_1)) return -1; //logp("sending: %s\n", best); if(asfd->write(asfd, &sb->path)) ret=-1; else if(patches) { // If we did some patches, the resulting file // is not gzipped. Gzip it during the send. ret=send_whole_file_gzl(asfd, best, sb->protocol1->datapth.buf, 1, bytes, NULL, cntr, 9, bfd, NULL, 0); } else { // If it was encrypted, it may or may not have been compressed // before encryption. Send it as it as, and let the client // sort it out. if(sbuf_is_encrypted(sb)) { ret=send_whole_filel(asfd, sb->path.cmd, best, sb->protocol1->datapth.buf, 1, bytes, cntr, bfd, NULL, 0); } // It might have been stored uncompressed. Gzip it during // the send. If the client knew what kind of file it would be // receiving, this step could disappear. else if(!dpth_protocol1_is_compressed(sb->compression, sb->protocol1->datapth.buf)) { ret=send_whole_file_gzl(asfd, best, sb->protocol1->datapth.buf, 1, bytes, NULL, cntr, 9, bfd, NULL, 0); } else { // If we did not do some patches, the resulting // file might already be gzipped. Send it as it is. ret=send_whole_filel(asfd, sb->path.cmd, best, sb->protocol1->datapth.buf, 1, bytes, cntr, bfd, NULL, 0); } } bfd->close(bfd, asfd); return ret; }
static int send_whole_file_w(struct asfd *asfd, struct sbuf *sb, const char *datapth, int quick_read, unsigned long long *bytes, const char *encpassword, struct conf *conf, int compression, BFILE *bfd, FILE *fp, const char *extrameta, size_t elen, size_t datalen) { if((compression || encpassword) && sb->path.cmd!=CMD_EFS_FILE) return send_whole_file_gzl(asfd, sb->path.buf, datapth, quick_read, bytes, encpassword, conf, compression, bfd, fp, extrameta, elen, datalen); else return send_whole_filel(asfd, sb->path.cmd, sb->path.buf, datapth, quick_read, bytes, conf, bfd, fp, extrameta, elen, datalen); }
static int do_send_file(struct asfd *asfd, struct sbuf *sb, int patches, const char *best, struct cntr *cntr) { enum send_e ret=SEND_FATAL; struct BFILE bfd; uint64_t bytes=0; // Unused. bfile_init(&bfd, 0, cntr); if(bfd.open_for_send(&bfd, asfd, best, sb->winattr, 1 /* no O_NOATIME */, cntr, PROTO_1)) return SEND_FATAL; if(asfd->write(asfd, &sb->path)) ret=SEND_FATAL; else if(patches) { // If we did some patches, the resulting file // is not gzipped. Gzip it during the send. ret=send_whole_file_gzl( asfd, sb->protocol1->datapth.buf, /*quick_read*/1, &bytes, /*encpassword*/NULL, cntr, /*compression*/9, &bfd, /*extrameta*/NULL, /*elen*/0, /*key_deriv*/ENCRYPTION_UNSET, /*salt*/0 ); } else { // If it was encrypted, it may or may not have been compressed // before encryption. Send it as it as, and let the client // sort it out. if(sbuf_is_encrypted(sb)) { ret=send_whole_filel(asfd, #ifdef HAVE_WIN32 sb->path.cmd #endif sb->protocol1->datapth.buf, 1, &bytes, cntr, &bfd, NULL, 0); } // It might have been stored uncompressed. Gzip it during // the send. If the client knew what kind of file it would be // receiving, this step could disappear. else if(!dpth_protocol1_is_compressed(sb->compression, sb->protocol1->datapth.buf)) { ret=send_whole_file_gzl( asfd, sb->protocol1->datapth.buf, /*quick_read*/1, &bytes, /*encpassword*/NULL, cntr, /*compression*/9, &bfd, /*extrameta*/NULL, /*elen*/0, /*key_deriv*/ENCRYPTION_UNSET, /*salt*/0 ); } else { // If we did not do some patches, the resulting // file might already be gzipped. Send it as it is. ret=send_whole_filel(asfd, #ifdef HAVE_WIN32 sb->path.cmd #endif sb->protocol1->datapth.buf, 1, &bytes, cntr, &bfd, NULL, 0); } } bfd.close(&bfd, asfd); switch(ret) { case SEND_OK: case SEND_ERROR: // Carry on. return 0; case SEND_FATAL: default: return -1; } }