int restore_interrupt(struct asfd *asfd, struct sbuf *sb, const char *msg, struct cntr *cntr, enum protocol protocol) { int ret=0; char *path=NULL; struct iobuf *rbuf=asfd->rbuf; if(cntr) { cntr_add(cntr, CMD_WARNING, 1); logp("WARNING: %s\n", msg); if(asfd->write_str(asfd, CMD_WARNING, msg)) goto end; } // If it is file data, get the server // to interrupt the flow and move on. if(!iobuf_is_filedata(&sb->path) && !iobuf_is_vssdata(&sb->path)) return 0; if(protocol==PROTO_1) path=sb->protocol1->datapth.buf; else if(protocol==PROTO_2) path=sb->path.buf; if(!path) return 0; if(asfd->write_str(asfd, CMD_INTERRUPT, path)) goto end; // Read to the end file marker. while(1) { iobuf_free_content(rbuf); if(asfd->read(asfd)) goto end; if(!rbuf->len) continue; switch(rbuf->cmd) { case CMD_APPEND: case CMD_DATA: continue; case CMD_END_FILE: ret=0; goto end; default: iobuf_log_unexpected(rbuf, __func__); goto end; } } end: iobuf_free_content(rbuf); return ret; }
// returns 1 for finished ok. static int do_stuff_to_receive(struct asfd *asfd, struct sdirs *sdirs, struct conf **cconfs, struct sbuf *rb, struct manio *chmanio, struct dpth *dpth, char **last_requested) { struct iobuf *rbuf=asfd->rbuf; iobuf_free_content(rbuf); // This also attempts to write anything in the write buffer. if(asfd->as->read_write(asfd->as)) { logp("error in %s\n", __func__); return -1; } if(!rbuf->buf) return 0; if(rbuf->cmd==CMD_MESSAGE || rbuf->cmd==CMD_WARNING) { struct cntr *cntr=NULL; if(cconfs) cntr=get_cntr(cconfs); log_recvd(rbuf, cntr, 0); return 0; } if(rb->protocol1->fzp) { // Currently writing a file (or meta data) switch(rbuf->cmd) { case CMD_APPEND: if(deal_with_receive_append(asfd, rb, cconfs)) goto error; return 0; case CMD_END_FILE: if(deal_with_receive_end_file(asfd, sdirs, rb, chmanio, cconfs, last_requested)) goto error; return 0; default: iobuf_log_unexpected(rbuf, __func__); goto error; } } // Otherwise, expecting to be told of a file to save. switch(rbuf->cmd) { case CMD_DATAPTH: iobuf_move(&rb->protocol1->datapth, rbuf); return 0; case CMD_ATTRIBS: iobuf_move(&rb->attr, rbuf); attribs_decode(rb); return 0; case CMD_GEN: if(!strcmp(rbuf->buf, "okbackupphase2end")) goto end_phase2; iobuf_log_unexpected(rbuf, __func__); goto error; case CMD_INTERRUPT: // Interrupt - forget about the last requested // file if it matches. Otherwise, we can get // stuck on the select in the async stuff, // waiting for something that will never arrive. if(*last_requested && !strcmp(rbuf->buf, *last_requested)) free_w(last_requested); return 0; default: break; } if(iobuf_is_filedata(rbuf) || iobuf_is_vssdata(rbuf)) { if(deal_with_filedata(asfd, sdirs, rb, rbuf, dpth, cconfs)) goto error; return 0; } iobuf_log_unexpected(rbuf, __func__); error: return -1; end_phase2: return 1; }
int sbuf_is_vssdata(struct sbuf *sb) { return iobuf_is_vssdata(&sb->path); }