Exemplo n.º 1
0
// returns 1 for finished ok.
static int do_stuff_to_receive(struct asfd *asfd,
	struct sdirs *sdirs, struct conf **cconfs,
	struct sbuf *rb, struct fzp *chfp,
	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)
	{
		log_recvd(rbuf, cconfs, 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,
					chfp, 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);
			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(cmd_is_filedata(rbuf->cmd))
	{
		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;
}
Exemplo n.º 2
0
// returns 1 for finished ok.
static int do_stuff_to_receive(struct asfd *asfd,
	struct sdirs *sdirs, struct conf *cconf,
	struct sbuf *rb, FILE *p2fp, struct dpthl *dpthl, 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->rw(asfd->as))
	{
		logp("error in async_rw\n");
		return -1;
	}

	if(!rbuf->buf) return 0;

	if(rbuf->cmd==CMD_WARNING)
	{
		logp("WARNING: %s\n", rbuf->buf);
		cntr_add(cconf->cntr, rbuf->cmd, 0);
	}
	else if(rb->burp1->fp || rb->burp1->zp)
	{
		// Currently writing a file (or meta data)
		if(rbuf->cmd==CMD_APPEND)
		{
			if(deal_with_receive_append(asfd, rb, cconf))
				goto error;
		}
		else if(rbuf->cmd==CMD_END_FILE)
		{
			if(deal_with_receive_end_file(asfd, sdirs, rb, p2fp,
				cconf, last_requested)) goto error;
		}
		else
		{
			iobuf_log_unexpected(rbuf, __func__);
			goto error;
		}
	}
	// Otherwise, expecting to be told of a file to save.
	else if(rbuf->cmd==CMD_DATAPTH)
	{
		iobuf_copy(&rb->burp1->datapth, rbuf);
		rbuf->buf=NULL;
	}
	else if(rbuf->cmd==CMD_ATTRIBS)
	{
		iobuf_copy(&rb->attr, rbuf);
		rbuf->buf=NULL;
	}
	else if(filedata(rbuf->cmd))
	{
		iobuf_copy(&rb->path, rbuf);
		rbuf->buf=NULL;

		if(rb->burp1->datapth.buf)
		{
			// Receiving a delta.
			if(start_to_receive_delta(sdirs, cconf, rb))
			{
				logp("error in start_to_receive_delta\n");
				goto error;
			}
		}
		else
		{
			// Receiving a whole new file.
			if(start_to_receive_new_file(asfd,
				sdirs, cconf, rb, dpthl))
			{
				logp("error in start_to_receive_new_file\n");
				goto error;
			}
		}
	}
	else if(rbuf->cmd==CMD_GEN
	  && !strcmp(rbuf->buf, "okbackupphase2end"))
		goto end_phase2;
	else if(rbuf->cmd==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(*last_requested);
			*last_requested=NULL;
		}
	}
	else
	{
		iobuf_log_unexpected(rbuf, __func__);
		goto error;
	}

	return 0;
end_phase2:
	return 1;
error:
	return -1;
}