56 if ((result = rs_suck_byte(job, &job->
op)) !=
RS_DONE)
59 job->cmd = &rs_prototab[job->
op];
61 rs_trace(
"got command %#04x (%s), len_1=" FMT_SIZE
"", job->
op,
65 job->
statefn = rs_patch_s_params;
67 job->
param1 = job->cmd->immediate;
79 int len = job->cmd->len_1 + job->cmd->len_2;
89 result = rs_suck_netint(job, &job->
param1, job->cmd->len_1);
93 if (job->cmd->len_2) {
94 result = rs_suck_netint(job, &job->param2, job->cmd->len_2);
106 rs_trace(
"running command %#04x", job->
op);
108 switch (job->cmd->kind) {
109 case RS_KIND_LITERAL:
110 job->
statefn = rs_patch_s_literal;
118 job->
statefn = rs_patch_s_copy;
122 rs_error(
"bogus command %#04x", job->
op);
130 rs_long_t len = job->
param1;
132 rs_trace(
"LITERAL(len=" FMT_LONG
")", len);
135 rs_error(
"invalid length=" FMT_LONG
" on LITERAL command", len);
145 job->
statefn = rs_patch_s_cmdbyte;
151 rs_long_t where, len;
157 rs_trace(
"COPY(where=" FMT_LONG
", len=" FMT_LONG
")", where, len);
160 rs_error(
"invalid length=" FMT_LONG
" on COPY command", len);
165 rs_error(
"invalid where=" FMT_LONG
" on COPY command", where);
170 job->basis_len = len;
175 stats->copy_bytes += len;
176 stats->copy_cmdbytes += 1 + job->cmd->len_1 + job->cmd->len_2;
178 job->
statefn = rs_patch_s_copying;
187 size_t desired_len, len;
199 rs_trace(
"copy " FMT_SIZE
" bytes from basis at offset " FMT_LONG
"", len,
208 rs_trace(
"copy callback returned %s",
rs_strerror(result));
210 rs_trace(
"got " FMT_SIZE
" bytes back from basis callback", len);
212 if (len > desired_len) {
213 rs_trace(
"warning: copy_cb returned more than the requested length.");
225 job->basis_len -= len;
227 if (!job->basis_len) {
229 job->
statefn = rs_patch_s_cmdbyte;
241 if ((result = rs_suck_n4(job, &v)) !=
RS_DONE)
245 rs_error(
"got magic number %#x rather than expected value %#x", v,
249 rs_trace(
"got patch magic %#x", v);
251 job->
statefn = rs_patch_s_cmdbyte;
258 rs_job_t *job = rs_job_new(
"patch", rs_patch_s_header);
261 job->copy_arg = copy_arg;
263 rs_mdfour_begin(&job->output_md4);
@ 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.
const char * rs_strerror(rs_result r)
Return an English description of a rs_result value.
@ 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.
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.
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.