51 if ((result = rs_suck_byte(job, &job->
op)) !=
RS_DONE)
54 job->cmd = &rs_prototab[job->
op];
56 rs_trace(
"got command %#04x (%s), len_1=" FMT_SIZE
"", job->
op,
60 job->
statefn = rs_patch_s_params;
62 job->
param1 = job->cmd->immediate;
74 int len = job->cmd->len_1 + job->cmd->len_2;
84 result = rs_suck_netint(job, &job->
param1, job->cmd->len_1);
88 if (job->cmd->len_2) {
89 result = rs_suck_netint(job, &job->param2, job->cmd->len_2);
101 rs_trace(
"running command %#04x", job->
op);
103 switch (job->cmd->kind) {
104 case RS_KIND_LITERAL:
105 job->
statefn = rs_patch_s_literal;
113 job->
statefn = rs_patch_s_copy;
117 rs_error(
"bogus command %#04x", job->
op);
125 rs_long_t len = job->
param1;
127 rs_trace(
"LITERAL(len=" FMT_LONG
")", len);
130 rs_error(
"invalid length=" FMT_LONG
" on LITERAL command", len);
140 job->
statefn = rs_patch_s_cmdbyte;
146 rs_long_t where, len;
152 rs_trace(
"COPY(where=" FMT_LONG
", len=" FMT_LONG
")", where, len);
155 rs_error(
"invalid length=" FMT_LONG
" on COPY command", len);
160 rs_error(
"invalid where=" FMT_LONG
" on COPY command", where);
165 job->basis_len = len;
170 stats->copy_bytes += len;
171 stats->copy_cmdbytes += 1 + job->cmd->len_1 + job->cmd->len_2;
173 job->
statefn = rs_patch_s_copying;
182 size_t desired_len, len;
194 rs_trace(
"copy " FMT_SIZE
" bytes from basis at offset " FMT_LONG
"", len,
203 rs_trace(
"copy callback returned %s",
rs_strerror(result));
205 rs_trace(
"got " FMT_SIZE
" bytes back from basis callback", len);
207 if (len > desired_len) {
208 rs_trace(
"warning: copy_cb returned more than the requested length.");
220 job->basis_len -= len;
222 if (!job->basis_len) {
224 job->
statefn = rs_patch_s_cmdbyte;
236 if ((result = rs_suck_n4(job, &v)) !=
RS_DONE)
240 rs_error(
"got magic number %#x rather than expected value %#x", v,
244 rs_trace(
"got patch magic %#x", v);
246 job->
statefn = rs_patch_s_cmdbyte;
253 rs_job_t *job = rs_job_new(
"patch", rs_patch_s_header);
256 job->copy_arg = copy_arg;
258 rs_mdfour_begin(&job->output_md4);
rs_result
Return codes from nonblocking rsync operations.
@ RS_DONE
Completed successfully.
rs_long_t param1
Lengths of expected parameters.
rs_result(* statefn)(rs_job_t *)
Callback for each processing step.
rs_long_t basis_pos
Copy from the basis position.
unsigned char op
Command byte currently being processed, if any.
The contents of this structure are private.
@ RS_RUNNING
The job is still running, and not yet finished or blocked.
@ RS_DELTA_MAGIC
A delta file.
int lit_cmds
Number of literal commands.
rs_stats_t stats
Encoding statistics.
rs_long_t lit_bytes
Number of literal bytes.
@ RS_CORRUPT
Unbelievable value in stream.
LIBRSYNC_EXPORT rs_job_t * rs_patch_begin(rs_copy_cb *copy_cb, void *copy_arg)
Apply a delta to a basis file to recreate the new file.
@ RS_BLOCKED
Blocked waiting for more data.
rs_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr)
Read from scoop without advancing.
char * next_out
Next output byte should be put there.
size_t avail_out
Remaining free space at next_out.
LIBRSYNC_EXPORT const char * rs_strerror(rs_result r)
Return an English description of a rs_result value.
rs_result rs_copy_cb(void *opaque, rs_long_t pos, size_t *len, void **buf)
Callback used to retrieve parts of the basis file.
Performance statistics from a librsync encoding or decoding operation.
@ RS_BAD_MAGIC
Bad magic number at start of stream.
rs_copy_cb * copy_cb
Callback used to copy data from the basis into the output.
rs_long_t lit_cmdbytes
Number of bytes used in literal command headers.
void rs_tube_copy(rs_job_t *job, int len)
Queue up a request to copy through len bytes from the input to the output of the stream.
Description of input and output buffers.