"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "token.c" between
rsync-3.2.1.tar.gz and rsync-3.2.2.tar.gz

About: rsync is a fast incremental file-copying tool for bringing remote (and local) files into sync.

token.c  (rsync-3.2.1):token.c  (rsync-3.2.2)
skipping to change at line 132 skipping to change at line 132
if (node->letter == ltr) { if (node->letter == ltr) {
if (*str) if (*str)
add_suffix(&node->child, *str, str+1); add_suffix(&node->child, *str, str+1);
else else
node->word_end = 1; node->word_end = 1;
return; return;
} }
if (node->letter > ltr) if (node->letter > ltr)
break; break;
} }
if (!(newnode = new(struct suffix_tree))) newnode = new(struct suffix_tree);
out_of_memory("add_suffix");
newnode->sibling = node; newnode->sibling = node;
newnode->child = NULL; newnode->child = NULL;
newnode->letter = ltr; newnode->letter = ltr;
*prior = newnode; *prior = newnode;
if (*str) { if (*str) {
add_suffix(&newnode->child, *str, str+1); add_suffix(&newnode->child, *str, str+1);
newnode->word_end = 0; newnode->word_end = 0;
} else } else
newnode->word_end = 1; newnode->word_end = 1;
} }
static void add_nocompress_suffixes(const char *str) static void add_nocompress_suffixes(const char *str)
{ {
char *buf, *t; char *buf, *t;
const char *f = str; const char *f = str;
if (!(buf = new_array(char, strlen(f) + 1))) buf = new_array(char, strlen(f) + 1);
out_of_memory("add_nocompress_suffixes");
while (*f) { while (*f) {
if (*f == '/') { if (*f == '/') {
f++; f++;
continue; continue;
} }
t = buf; t = buf;
do { do {
if (isUpper(f)) if (isUpper(f))
skipping to change at line 189 skipping to change at line 187
if (skip_compress) if (skip_compress)
add_nocompress_suffixes(skip_compress); add_nocompress_suffixes(skip_compress);
/* A non-daemon transfer skips the default suffix list if the /* A non-daemon transfer skips the default suffix list if the
* user specified --skip-compress. */ * user specified --skip-compress. */
if (skip_compress && module_id < 0) if (skip_compress && module_id < 0)
f = ""; f = "";
else else
f = lp_dont_compress(module_id); f = lp_dont_compress(module_id);
if (!(match_list = t = new_array(char, strlen(f) + 2))) match_list = t = new_array(char, strlen(f) + 2);
out_of_memory("set_compression");
per_file_default_level = do_compression_level; per_file_default_level = do_compression_level;
while (*f) { while (*f) {
if (*f == ' ') { if (*f == ' ') {
f++; f++;
continue; continue;
} }
start = t; start = t;
skipping to change at line 285 skipping to change at line 282
} }
} }
/* non-compressing recv token */ /* non-compressing recv token */
static int32 simple_recv_token(int f, char **data) static int32 simple_recv_token(int f, char **data)
{ {
static int32 residue; static int32 residue;
static char *buf; static char *buf;
int32 n; int32 n;
if (!buf) { if (!buf)
buf = new_array(char, CHUNK_SIZE); buf = new_array(char, CHUNK_SIZE);
if (!buf)
out_of_memory("simple_recv_token");
}
if (residue == 0) { if (residue == 0) {
int32 i = read_int(f); int32 i = read_int(f);
if (i <= 0) if (i <= 0)
return i; return i;
residue = i; residue = i;
} }
*data = buf; *data = buf;
n = MIN(CHUNK_SIZE,residue); n = MIN(CHUNK_SIZE,residue);
skipping to change at line 376 skipping to change at line 370
if (!init_done) { if (!init_done) {
tx_strm.next_in = NULL; tx_strm.next_in = NULL;
tx_strm.zalloc = NULL; tx_strm.zalloc = NULL;
tx_strm.zfree = NULL; tx_strm.zfree = NULL;
if (deflateInit2(&tx_strm, compression_level, if (deflateInit2(&tx_strm, compression_level,
Z_DEFLATED, -15, 8, Z_DEFLATED, -15, 8,
Z_DEFAULT_STRATEGY) != Z_OK) { Z_DEFAULT_STRATEGY) != Z_OK) {
rprintf(FERROR, "compression init failed\n"); rprintf(FERROR, "compression init failed\n");
exit_cleanup(RERR_PROTOCOL); exit_cleanup(RERR_PROTOCOL);
} }
if ((obuf = new_array(char, OBUF_SIZE)) == NULL) obuf = new_array(char, OBUF_SIZE);
out_of_memory("send_deflated_token");
init_done = 1; init_done = 1;
} else } else
deflateReset(&tx_strm); deflateReset(&tx_strm);
last_run_end = 0; last_run_end = 0;
run_start = token; run_start = token;
flush_pending = 0; flush_pending = 0;
} else if (last_token == -2) { } else if (last_token == -2) {
run_start = token; run_start = token;
} else if (nb != 0 || token != last_token + 1 } else if (nb != 0 || token != last_token + 1 || token >= run_start + 655
|| token >= run_start + 65536) { 36) {
/* output previous run */ /* output previous run */
r = run_start - last_run_end; r = run_start - last_run_end;
n = last_token - run_start; n = last_token - run_start;
if (r >= 0 && r <= 63) { if (r >= 0 && r <= 63) {
write_byte(f, (n==0? TOKEN_REL: TOKENRUN_REL) + r); write_byte(f, (n==0? TOKEN_REL: TOKENRUN_REL) + r);
} else { } else {
write_byte(f, (n==0? TOKEN_LONG: TOKENRUN_LONG)); write_byte(f, (n==0? TOKEN_LONG: TOKENRUN_LONG));
write_int(f, run_start); write_int(f, run_start);
} }
if (n != 0) { if (n != 0) {
skipping to change at line 521 skipping to change at line 513
switch (recv_state) { switch (recv_state) {
case r_init: case r_init:
if (!init_done) { if (!init_done) {
rx_strm.next_out = NULL; rx_strm.next_out = NULL;
rx_strm.zalloc = NULL; rx_strm.zalloc = NULL;
rx_strm.zfree = NULL; rx_strm.zfree = NULL;
if (inflateInit2(&rx_strm, -15) != Z_OK) { if (inflateInit2(&rx_strm, -15) != Z_OK) {
rprintf(FERROR, "inflate init failed\n"); rprintf(FERROR, "inflate init failed\n");
exit_cleanup(RERR_PROTOCOL); exit_cleanup(RERR_PROTOCOL);
} }
if (!(cbuf = new_array(char, MAX_DATA_COUNT)) cbuf = new_array(char, MAX_DATA_COUNT);
|| !(dbuf = new_array(char, AVAIL_OUT_SIZE(CHUNK dbuf = new_array(char, AVAIL_OUT_SIZE(CHUNK_SIZE)
_SIZE)))) );
out_of_memory("recv_deflated_token");
init_done = 1; init_done = 1;
} else { } else {
inflateReset(&rx_strm); inflateReset(&rx_strm);
} }
recv_state = r_idle; recv_state = r_idle;
rx_token = 0; rx_token = 0;
break; break;
case r_idle: case r_idle:
case r_inflated: case r_inflated:
skipping to change at line 690 skipping to change at line 681
static ZSTD_CCtx *zstd_cctx; static ZSTD_CCtx *zstd_cctx;
static void send_zstd_token(int f, int32 token, struct map_struct *buf, OFF_T of fset, int32 nb) static void send_zstd_token(int f, int32 token, struct map_struct *buf, OFF_T of fset, int32 nb)
{ {
static int comp_init_done, flush_pending; static int comp_init_done, flush_pending;
ZSTD_EndDirective flush = ZSTD_e_continue; ZSTD_EndDirective flush = ZSTD_e_continue;
int32 n, r; int32 n, r;
/* initialization */ /* initialization */
if (!comp_init_done) { if (!comp_init_done) {
zstd_cctx = ZSTD_createCCtx(); zstd_cctx = ZSTD_createCCtx();
if (!zstd_cctx) { if (!zstd_cctx) {
rprintf(FERROR, "compression init failed\n"); rprintf(FERROR, "compression init failed\n");
exit_cleanup(RERR_PROTOCOL); exit_cleanup(RERR_PROTOCOL);
} }
obuf = new_array(char, OBUF_SIZE); obuf = new_array(char, OBUF_SIZE);
if (!obuf)
out_of_memory("send_deflated_token");
ZSTD_CCtx_setParameter(zstd_cctx, ZSTD_c_compressionLevel, do_com pression_level); ZSTD_CCtx_setParameter(zstd_cctx, ZSTD_c_compressionLevel, do_com pression_level);
zstd_out_buff.dst = obuf + 2; zstd_out_buff.dst = obuf + 2;
comp_init_done = 1; comp_init_done = 1;
} }
if (last_token == -1) { if (last_token == -1) {
last_run_end = 0; last_run_end = 0;
run_start = token; run_start = token;
flush_pending = 0; flush_pending = 0;
} else if (last_token == -2) { } else if (last_token == -2) {
run_start = token; run_start = token;
} else if (nb != 0 || token != last_token + 1 || token >= run_start + 655
} else if (nb != 0 || token != last_token + 1 36) {
|| token >= run_start + 65536) {
/* output previous run */ /* output previous run */
r = run_start - last_run_end; r = run_start - last_run_end;
n = last_token - run_start; n = last_token - run_start;
if (r >= 0 && r <= 63) { if (r >= 0 && r <= 63) {
write_byte(f, (n==0? TOKEN_REL: TOKENRUN_REL) + r); write_byte(f, (n==0? TOKEN_REL: TOKENRUN_REL) + r);
} else { } else {
write_byte(f, (n==0? TOKEN_LONG: TOKENRUN_LONG)); write_byte(f, (n==0? TOKEN_LONG: TOKENRUN_LONG));
write_int(f, run_start); write_int(f, run_start);
} }
skipping to change at line 798 skipping to change at line 783
static ZSTD_DCtx *zstd_dctx; static ZSTD_DCtx *zstd_dctx;
static int32 recv_zstd_token(int f, char **data) static int32 recv_zstd_token(int f, char **data)
{ {
static int decomp_init_done; static int decomp_init_done;
static int out_buffer_size; static int out_buffer_size;
int32 n, flag; int32 n, flag;
int r; int r;
if (!decomp_init_done) { if (!decomp_init_done) {
zstd_dctx = ZSTD_createDCtx(); zstd_dctx = ZSTD_createDCtx();
if (!zstd_dctx) { if (!zstd_dctx) {
rprintf(FERROR, "ZSTD_createDStream failed\n"); rprintf(FERROR, "ZSTD_createDStream failed\n");
exit_cleanup(RERR_PROTOCOL); exit_cleanup(RERR_PROTOCOL);
} }
/* Output buffer fits two decompressed blocks */ /* Output buffer fits two decompressed blocks */
out_buffer_size = ZSTD_DStreamOutSize() * 2; out_buffer_size = ZSTD_DStreamOutSize() * 2;
cbuf = new_array(char, MAX_DATA_COUNT); cbuf = new_array(char, MAX_DATA_COUNT);
dbuf = new_array(char, out_buffer_size); dbuf = new_array(char, out_buffer_size);
if (!cbuf || !dbuf)
out_of_memory("recv_zstd_token");
zstd_in_buff.src = cbuf; zstd_in_buff.src = cbuf;
zstd_out_buff.dst = dbuf; zstd_out_buff.dst = dbuf;
decomp_init_done = 1; decomp_init_done = 1;
} }
do { for (;;) {
switch (recv_state) { switch (recv_state) {
case r_init: case r_init:
recv_state = r_idle; recv_state = r_idle;
rx_token = 0; rx_token = 0;
break; break;
case r_idle:
flag = read_byte(f);
if ((flag & 0xC0) == DEFLATED_DATA) {
n = ((flag & 0x3f) << 8) + read_byte(f);
read_buf(f, cbuf, n);
zstd_in_buff.size = n;
zstd_in_buff.pos = 0;
recv_state = r_inflating;
} else if (flag == END_FLAG) {
/* that's all folks */
recv_state = r_init;
return 0;
} else { case r_idle:
flag = read_byte(f);
if ((flag & 0xC0) == DEFLATED_DATA) {
n = ((flag & 0x3f) << 8) + read_byte(f);
read_buf(f, cbuf, n);
zstd_in_buff.size = n;
zstd_in_buff.pos = 0;
recv_state = r_inflating;
break;
}
if (flag == END_FLAG) {
/* that's all folks */
recv_state = r_init;
return 0;
}
/* here we have a token of some kind */ /* here we have a token of some kind */
if (flag & TOKEN_REL) { if (flag & TOKEN_REL) {
rx_token += flag & 0x3f; rx_token += flag & 0x3f;
flag >>= 6; flag >>= 6;
} else } else
rx_token = read_int(f); rx_token = read_int(f);
if (flag & 1) { if (flag & 1) {
rx_run = read_byte(f); rx_run = read_byte(f);
rx_run += read_byte(f) << 8; rx_run += read_byte(f) << 8;
recv_state = r_running; recv_state = r_running;
} }
return -1 - rx_token; return -1 - rx_token;
}
break;
case r_inflating: case r_inflated: /* zstd doesn't get into this state */
zstd_out_buff.size = out_buffer_size; break;
zstd_out_buff.pos = 0;
r = ZSTD_decompressStream(zstd_dctx, &zstd_out_buff, &zstd_in_buf
f);
n = zstd_out_buff.pos;
if (ZSTD_isError(r)) {
rprintf(FERROR, "ZSTD decomp returned %d (%d bytes)\n", r
, n);
exit_cleanup(RERR_STREAMIO);
}
/* case r_inflating:
* If the input buffer is fully consumed and the output zstd_out_buff.size = out_buffer_size;
* buffer is not full then next step is to read more zstd_out_buff.pos = 0;
* data.
*/
if (zstd_in_buff.size == zstd_in_buff.pos && n < out_buffer_size)
recv_state = r_idle;
if (n != 0) { r = ZSTD_decompressStream(zstd_dctx, &zstd_out_buff, &zst
*data = dbuf; d_in_buff);
return n; n = zstd_out_buff.pos;
} if (ZSTD_isError(r)) {
break; rprintf(FERROR, "ZSTD decomp returned %d (%d byte
s)\n", r, n);
exit_cleanup(RERR_STREAMIO);
}
case r_running: /*
++rx_token; * If the input buffer is fully consumed and the output
if (--rx_run == 0) * buffer is not full then next step is to read more
recv_state = r_idle; * data.
return -1 - rx_token; */
break; if (zstd_in_buff.size == zstd_in_buff.pos && n < out_buff
er_size)
recv_state = r_idle;
case r_inflated: if (n != 0) {
break; *data = dbuf;
return n;
}
break;
case r_running:
++rx_token;
if (--rx_run == 0)
recv_state = r_idle;
return -1 - rx_token;
}
} }
} while (1);
} }
#endif /* SUPPORT_ZSTD */ #endif /* SUPPORT_ZSTD */
#ifdef SUPPORT_LZ4 #ifdef SUPPORT_LZ4
static void static void
send_compressed_token(int f, int32 token, struct map_struct *buf, OFF_T offset, int32 nb) send_compressed_token(int f, int32 token, struct map_struct *buf, OFF_T offset, int32 nb)
{ {
static int init_done, flush_pending; static int init_done, flush_pending;
int size = MAX(LZ4_compressBound(CHUNK_SIZE), MAX_DATA_COUNT+2); int size = MAX(LZ4_compressBound(CHUNK_SIZE), MAX_DATA_COUNT+2);
int32 n, r; int32 n, r;
if (last_token == -1) { if (last_token == -1) {
if (!init_done) { if (!init_done) {
if ((obuf = new_array(char, size)) == NULL) obuf = new_array(char, size);
out_of_memory("send_compressed_token");
init_done = 1; init_done = 1;
} }
last_run_end = 0; last_run_end = 0;
run_start = token; run_start = token;
flush_pending = 0; flush_pending = 0;
} else if (last_token == -2) { } else if (last_token == -2) {
run_start = token; run_start = token;
} else if (nb != 0 || token != last_token + 1 } else if (nb != 0 || token != last_token + 1 || token >= run_start + 655
|| token >= run_start + 65536) { 36) {
/* output previous run */ /* output previous run */
r = run_start - last_run_end; r = run_start - last_run_end;
n = last_token - run_start; n = last_token - run_start;
if (r >= 0 && r <= 63) { if (r >= 0 && r <= 63) {
write_byte(f, (n==0? TOKEN_REL: TOKENRUN_REL) + r); write_byte(f, (n==0? TOKEN_REL: TOKENRUN_REL) + r);
} else { } else {
write_byte(f, (n==0? TOKEN_LONG: TOKENRUN_LONG)); write_byte(f, (n==0? TOKEN_LONG: TOKENRUN_LONG));
write_int(f, run_start); write_int(f, run_start);
} }
if (n != 0) { if (n != 0) {
skipping to change at line 941 skipping to change at line 919
run_start = token; run_start = token;
} }
last_token = token; last_token = token;
if (nb != 0 || flush_pending) { if (nb != 0 || flush_pending) {
int available_in, available_out = 0; int available_in, available_out = 0;
const char *next_in; const char *next_in;
do { do {
char *ptr = obuf;
char *next_out = obuf + 2; char *next_out = obuf + 2;
if (available_out == 0) { if (available_out == 0) {
available_in = MIN(nb, MAX_DATA_COUNT); available_in = MIN(nb, MAX_DATA_COUNT);
next_in = map_ptr(buf, offset, available_in); next_in = map_ptr(buf, offset, available_in);
} else } else
available_in /= 2; available_in /= 2;
available_out = LZ4_compress_default(next_in, next_out, a vailable_in, size - 2); available_out = LZ4_compress_default(next_in, next_out, a vailable_in, size - 2);
if (!available_out) { if (!available_out) {
rprintf(FERROR, "compress returned %d\n", availab le_out); rprintf(FERROR, "compress returned %d\n", availab le_out);
exit_cleanup(RERR_STREAMIO); exit_cleanup(RERR_STREAMIO);
} }
if (available_out <= MAX_DATA_COUNT) { if (available_out <= MAX_DATA_COUNT) {
ptr[0] = DEFLATED_DATA + (available_out >> 8); obuf[0] = DEFLATED_DATA + (available_out >> 8);
ptr[1] = available_out; obuf[1] = available_out;
write_buf(f, ptr, available_out + 2); write_buf(f, obuf, available_out + 2);
available_out = 0; available_out = 0;
nb -= available_in; nb -= available_in;
offset += available_in; offset += available_in;
} }
} while (nb != 0); } while (nb != 0);
flush_pending = token == -2; flush_pending = token == -2;
} }
if (token == -1) if (token == -1) {
/* end of file - clean up */ /* end of file - clean up */
write_byte(f, END_FLAG); write_byte(f, END_FLAG);
}
} }
static int32 recv_compressed_token(int f, char **data) static int32 recv_compressed_token(int f, char **data)
{ {
static int32 saved_flag;
static int init_done; static int init_done;
int32 n, flag; int32 n, flag;
int size = MAX(LZ4_compressBound(CHUNK_SIZE), MAX_DATA_COUNT+2); int size = MAX(LZ4_compressBound(CHUNK_SIZE), MAX_DATA_COUNT+2);
static const char *next_in; static const char *next_in;
static int avail_in; static int avail_in;
int avail_out; int avail_out;
for (;;) { for (;;) {
switch (recv_state) { switch (recv_state) {
case r_init: case r_init:
if (!init_done) { if (!init_done) {
if (!(cbuf = new_array(char, MAX_DATA_COUNT)) cbuf = new_array(char, MAX_DATA_COUNT);
|| !(dbuf = new_array(char, size))) dbuf = new_array(char, size);
out_of_memory("recv_compressed_token");
init_done = 1; init_done = 1;
} }
recv_state = r_idle; recv_state = r_idle;
rx_token = 0; rx_token = 0;
break; break;
case r_idle: case r_idle:
case r_inflated: flag = read_byte(f);
if (saved_flag) {
flag = saved_flag & 0xff;
saved_flag = 0;
} else
flag = read_byte(f);
if ((flag & 0xC0) == DEFLATED_DATA) { if ((flag & 0xC0) == DEFLATED_DATA) {
n = ((flag & 0x3f) << 8) + read_byte(f); n = ((flag & 0x3f) << 8) + read_byte(f);
read_buf(f, cbuf, n); read_buf(f, cbuf, n);
next_in = (char *)cbuf; next_in = (char *)cbuf;
avail_in = n; avail_in = n;
recv_state = r_inflating; recv_state = r_inflating;
break; break;
} }
if (recv_state == r_inflated)
recv_state = r_idle;
if (flag == END_FLAG) { if (flag == END_FLAG) {
/* that's all folks */ /* that's all folks */
recv_state = r_init; recv_state = r_init;
return 0; return 0;
} }
/* here we have a token of some kind */ /* here we have a token of some kind */
if (flag & TOKEN_REL) { if (flag & TOKEN_REL) {
rx_token += flag & 0x3f; rx_token += flag & 0x3f;
flag >>= 6; flag >>= 6;
skipping to change at line 1039 skipping to change at line 1008
recv_state = r_running; recv_state = r_running;
} }
return -1 - rx_token; return -1 - rx_token;
case r_inflating: case r_inflating:
avail_out = LZ4_decompress_safe(next_in, dbuf, avail_in, size); avail_out = LZ4_decompress_safe(next_in, dbuf, avail_in, size);
if (avail_out < 0) { if (avail_out < 0) {
rprintf(FERROR, "uncompress failed: %d\n", avail_ out); rprintf(FERROR, "uncompress failed: %d\n", avail_ out);
exit_cleanup(RERR_STREAMIO); exit_cleanup(RERR_STREAMIO);
} }
recv_state = r_inflated; recv_state = r_idle;
*data = dbuf; *data = dbuf;
return avail_out; return avail_out;
case r_inflated: /* lz4 doesn't get into this state */
break;
case r_running: case r_running:
++rx_token; ++rx_token;
if (--rx_run == 0) if (--rx_run == 0)
recv_state = r_idle; recv_state = r_idle;
return -1 - rx_token; return -1 - rx_token;
} }
} }
}
# if 0
static void see_uncompressed_token(char *buf, int32 len)
{
static const char *next_in;
static int avail_in;
int avail_out;
int32 blklen;
char hdr[5];
avail_in = 0;
blklen = 0;
hdr[0] = 0;
do {
if (avail_in == 0 && len != 0) {
if (blklen == 0) {
/* Give it a fake stored-block header. */
next_in = hdr;
avail_in = 5;
blklen = len;
if (blklen > 0xffff)
blklen = 0xffff;
hdr[1] = blklen;
hdr[2] = blklen >> 8;
hdr[3] = ~hdr[1];
hdr[4] = ~hdr[2];
} else {
next_in = (char *)buf;
avail_in = blklen;
if (protocol_version >= 31) /* Newer protocols av
oid a data-duplicating bug */
buf += blklen;
len -= blklen;
blklen = 0;
}
}
avail_out = LZ4_decompress_safe(next_in, dbuf, avail_in, LZ4_comp
ressBound(CHUNK_SIZE));
if (avail_out < 0) {
rprintf(FERROR, "uncompress failed: %d\n", avail_out);
exit_cleanup(RERR_STREAMIO);
}
} while (len);
} }
# endif /* 0 */
#endif /* SUPPORT_LZ4 */ #endif /* SUPPORT_LZ4 */
/** /**
* Transmit a verbatim buffer of length @p n followed by a token. * Transmit a verbatim buffer of length @p n followed by a token.
* If token == -1 then we have reached EOF * If token == -1 then we have reached EOF
* If n == 0 then don't send a buffer * If n == 0 then don't send a buffer
*/ */
void send_token(int f, int32 token, struct map_struct *buf, OFF_T offset, void send_token(int f, int32 token, struct map_struct *buf, OFF_T offset,
int32 n, int32 toklen) int32 n, int32 toklen)
{ {
 End of changes. 38 change blocks. 
157 lines changed or deleted 85 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)