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);
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.
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.
Public header for librsync.
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.
Types of commands present in the encoding stream.
LIBRSYNC_EXPORT char const * rs_strerror(rs_result r)
Return an English description of a rs_result value.
@ 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.
Manage librsync streams of IO.
@ 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.
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.
Description of input and output buffers.