55 if ((result = rs_suck_byte(job, &job->
op)) !=
RS_DONE)
57 job->cmd = &rs_prototab[job->
op];
58 rs_trace(
"got command %#04x (%s), len_1=%d, len_2=%d", job->
op,
63 job->
param1 = job->cmd->immediate;
74 const size_t len = (size_t)(job->cmd->len_1 + job->cmd->len_2);
82 result = rs_suck_netint(job, &job->
param1, job->cmd->len_1);
85 if (job->cmd->len_2) {
86 result = rs_suck_netint(job, &job->param2, job->cmd->len_2);
96 rs_trace(
"running command %#04x", job->
op);
97 switch (job->cmd->kind) {
105 job->
statefn = rs_patch_s_copy;
108 rs_error(
"bogus command %#04x", job->
op);
116 const rs_long_t len = job->
param1;
119 rs_trace(
"LITERAL(length=" FMT_LONG
")", len);
120 if (len <= 0 || len > SIZE_MAX) {
121 rs_error(
"invalid length=" FMT_LONG
" on LITERAL command", len);
134 const rs_long_t pos = job->
param1;
135 const rs_long_t len = job->param2;
138 rs_trace(
"COPY(position=" FMT_LONG
", length=" FMT_LONG
")", pos, len);
140 rs_error(
"invalid length=" FMT_LONG
" on COPY command", len);
144 rs_error(
"invalid position=" FMT_LONG
" on COPY command", pos);
148 stats->copy_bytes += len;
149 stats->copy_cmdbytes += 1 + job->cmd->len_1 + job->cmd->len_2;
151 job->basis_len = len;
162 rs_long_t req = job->basis_len;
170 if ((rs_long_t)len < req)
171 req = (rs_long_t)len;
172 rs_trace(
"copy " FMT_LONG
" bytes from basis at offset " FMT_LONG
"", req,
177 rs_trace(
"copy callback returned %s",
rs_strerror(result));
180 rs_trace(
"got " FMT_SIZE
" bytes back from basis callback", len);
184 if ((rs_long_t)len > req) {
185 rs_warn(
"copy_cb() returned more than the requested length");
195 job->basis_len -= (rs_long_t)len;
196 if (!job->basis_len) {
209 if ((result = rs_suck_n4(job, &v)) !=
RS_DONE)
212 rs_error(
"got magic number %#x rather than expected value %#x", v,
216 rs_trace(
"got patch magic %#x", v);
226 job->copy_arg = copy_arg;
227 rs_mdfour_begin(&job->output_md4);
Types of commands present in the encoding stream.
Generic state-machine interface.
Public header for librsync.
LIBRSYNC_EXPORT char const * rs_strerror(rs_result r)
Return an English description of a rs_result value.
rs_result
Return codes from nonblocking rsync operations.
@ RS_RUNNING
The job is still running, and not yet finished or blocked.
@ RS_DONE
Completed successfully.
@ RS_CORRUPT
Unbelievable value in stream.
@ RS_BAD_MAGIC
Bad magic number at start of stream.
@ RS_BLOCKED
Blocked waiting for more data.
@ RS_DELTA_MAGIC
A delta file.
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.
Network-byte-order output to the tube.
static rs_result rs_patch_s_literal(rs_job_t *)
Called when trying to copy through literal data.
static rs_result rs_patch_s_params(rs_job_t *)
Called after reading a command byte to pull in its parameters and then setup to execute the command.
static rs_result rs_patch_s_cmdbyte(rs_job_t *)
State of trying to read the first byte of a command.
static rs_result rs_patch_s_copying(rs_job_t *)
Called when we're executing a COPY command and waiting for all the data to be retrieved from the call...
static rs_result rs_patch_s_header(rs_job_t *job)
Called while we're trying to read the header of the patch.
static rs_result rs_patch_s_run(rs_job_t *)
Called when we've read in the whole command and we need to execute it.
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_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr)
Read from scoop without advancing.
Manage librsync streams of IO.
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.
Description of input and output buffers.
size_t avail_out
Remaining free space at next_out.
char * next_out
Next output byte should be put there.
The contents of this structure are private.
rs_long_t basis_pos
Copy from the basis position.
unsigned char op
Command byte currently being processed, if any.
rs_copy_cb * copy_cb
Callback used to copy data from the basis into the output.
rs_result(* statefn)(rs_job_t *)
Callback for each processing step.
rs_stats_t stats
Encoding statistics.
rs_long_t param1
Lengths of expected parameters.
Performance statistics from a librsync encoding or decoding operation.
int lit_cmds
Number of literal commands.
rs_long_t lit_cmdbytes
Number of bytes used in literal command headers.
rs_long_t lit_bytes
Number of literal bytes.