51 if ((result = rs_suck_byte(job, &job->
op)) !=
RS_DONE)
53 job->cmd = &rs_prototab[job->
op];
54 rs_trace(
"got command %#04x (%s), len_1=%d, len_2=%d", job->
op,
57 job->
statefn = rs_patch_s_params;
59 job->
param1 = job->cmd->immediate;
70 const size_t len = (size_t)(job->cmd->len_1 + job->cmd->len_2);
78 result = rs_suck_netint(job, &job->
param1, job->cmd->len_1);
81 if (job->cmd->len_2) {
82 result = rs_suck_netint(job, &job->param2, job->cmd->len_2);
92 rs_trace(
"running command %#04x", job->
op);
93 switch (job->cmd->kind) {
95 job->
statefn = rs_patch_s_literal;
101 job->
statefn = rs_patch_s_copy;
104 rs_error(
"bogus command %#04x", job->
op);
112 const rs_long_t len = job->
param1;
115 rs_trace(
"LITERAL(length=" FMT_LONG
")", len);
116 if (len <= 0 || len > SIZE_MAX) {
117 rs_error(
"invalid length=" FMT_LONG
" on LITERAL command", len);
124 job->
statefn = rs_patch_s_cmdbyte;
130 const rs_long_t pos = job->
param1;
131 const rs_long_t len = job->param2;
134 rs_trace(
"COPY(position=" FMT_LONG
", length=" FMT_LONG
")", pos, len);
136 rs_error(
"invalid length=" FMT_LONG
" on COPY command", len);
140 rs_error(
"invalid position=" FMT_LONG
" on COPY command", pos);
144 stats->copy_bytes += len;
145 stats->copy_cmdbytes += 1 + job->cmd->len_1 + job->cmd->len_2;
147 job->basis_len = len;
148 job->
statefn = rs_patch_s_copying;
158 rs_long_t req = job->basis_len;
167 req = (rs_long_t)len;
168 rs_trace(
"copy " FMT_LONG
" bytes from basis at offset " FMT_LONG
"", req,
173 rs_trace(
"copy callback returned %s",
rs_strerror(result));
176 rs_trace(
"got " FMT_SIZE
" bytes back from basis callback", len);
181 rs_warn(
"copy_cb() returned more than the requested length");
191 job->basis_len -= (rs_long_t)len;
192 if (!job->basis_len) {
194 job->
statefn = rs_patch_s_cmdbyte;
205 if ((result = rs_suck_n4(job, &v)) !=
RS_DONE)
208 rs_error(
"got magic number %#x rather than expected value %#x", v,
212 rs_trace(
"got patch magic %#x", v);
213 job->
statefn = rs_patch_s_cmdbyte;
219 rs_job_t *job = rs_job_new(
"patch", rs_patch_s_header);
222 job->copy_arg = copy_arg;
223 rs_mdfour_begin(&job->output_md4);
Description of input and output buffers.
rs_copy_cb * copy_cb
Callback used to copy data from the basis into the output.
void rs_tube_copy(rs_job_t *job, size_t len)
Queue up a request to copy through len bytes from the input to the output of the stream.
rs_long_t lit_cmdbytes
Number of bytes used in literal command headers.
Types of commands present in the encoding stream.
Bad magic number at start of stream.
unsigned char op
Command byte currently being processed, if any.
size_t avail_out
Remaining free space at next_out.
Unbelievable value in stream.
rs_long_t param1
Lengths of expected parameters.
LIBRSYNC_EXPORT char const * 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.
Manage librsync streams of IO.
char * next_out
Next output byte should be put there.
rs_long_t basis_pos
Copy from the basis position.
rs_result(* statefn)(rs_job_t *)
Callback for each processing step.
rs_stats_t stats
Encoding statistics.
Public header for librsync.
int lit_cmds
Number of literal commands.
rs_long_t lit_bytes
Number of literal bytes.
Performance statistics from a librsync encoding or decoding operation.
rs_result
Return codes from nonblocking rsync operations.
Blocked waiting for more data.
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.
The job is still running, and not yet finished or blocked.
rs_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr)
Read from scoop without advancing.
The contents of this structure are private.