diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2008-09-13 12:12:55 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2008-09-13 12:12:55 +0000 |
commit | 78a9c799db76946ba9c266f09a4a18075b8b6965 (patch) | |
tree | a0b1ac11cfa7853a257ffd62d507bee0f25cfb31 | |
parent | 1a5047d649aefdbff708f0a5d2a8de4c5edf7176 (diff) |
Implement adler32 and appheader for merge command.
-rw-r--r-- | xdelta3/testing/delta.h | 2 | ||||
-rw-r--r-- | xdelta3/xdelta3-main.h | 27 | ||||
-rw-r--r-- | xdelta3/xdelta3-merge.h | 42 | ||||
-rw-r--r-- | xdelta3/xdelta3.c | 2 | ||||
-rw-r--r-- | xdelta3/xdelta3.h | 15 |
5 files changed, 59 insertions, 29 deletions
diff --git a/xdelta3/testing/delta.h b/xdelta3/testing/delta.h index 103d7cc..58fbaac 100644 --- a/xdelta3/testing/delta.h +++ b/xdelta3/testing/delta.h | |||
@@ -15,7 +15,7 @@ public: | |||
15 | } | 15 | } |
16 | 16 | ||
17 | xoff_t Windows() const { | 17 | xoff_t Windows() const { |
18 | return stream_.whole_target.windows; | 18 | return stream_.whole_target.wininfolen; |
19 | } | 19 | } |
20 | 20 | ||
21 | void Print() const; | 21 | void Print() const; |
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h index 46b2cfb..9bc438f 100644 --- a/xdelta3/xdelta3-main.h +++ b/xdelta3/xdelta3-main.h | |||
@@ -1807,6 +1807,13 @@ main_merge_output (xd3_stream *stream, main_file *ofile) | |||
1807 | return ret; | 1807 | return ret; |
1808 | } | 1808 | } |
1809 | 1809 | ||
1810 | if (option_use_appheader != 0 && | ||
1811 | option_appheader != NULL) | ||
1812 | { | ||
1813 | xd3_set_appheader (recode_stream, option_appheader, | ||
1814 | strlen ((char*) option_appheader)); | ||
1815 | } | ||
1816 | |||
1810 | /* Enter the ENC_INPUT state and bypass the next_in == NULL test | 1817 | /* Enter the ENC_INPUT state and bypass the next_in == NULL test |
1811 | * and (leftover) input buffering logic. */ | 1818 | * and (leftover) input buffering logic. */ |
1812 | XD3_ASSERT(recode_stream->enc_state == ENC_INIT); | 1819 | XD3_ASSERT(recode_stream->enc_state == ENC_INIT); |
@@ -1839,8 +1846,24 @@ main_merge_output (xd3_stream *stream, main_file *ofile) | |||
1839 | /* Window sizes must match from the input to the output, so that | 1846 | /* Window sizes must match from the input to the output, so that |
1840 | * target copies are in-range (and so that checksums carry | 1847 | * target copies are in-range (and so that checksums carry |
1841 | * over). */ | 1848 | * over). */ |
1842 | XD3_ASSERT (window_num < stream->whole_target.winsizeslen); | 1849 | XD3_ASSERT (window_num < stream->whole_target.wininfolen); |
1843 | window_size = stream->whole_target.winsizes[window_num++]; | 1850 | window_size = stream->whole_target.wininfo[window_num].length; |
1851 | |||
1852 | /* Output position should also match. */ | ||
1853 | if (output_pos != stream->whole_target.wininfo[window_num].offset) | ||
1854 | { | ||
1855 | XPR(NT "internal merge error: offset mismatch\n"); | ||
1856 | return XD3_INVALID; | ||
1857 | } | ||
1858 | |||
1859 | if (option_use_checksum && | ||
1860 | (stream->dec_win_ind & VCD_ADLER32) != 0) | ||
1861 | { | ||
1862 | recode_stream->flags |= XD3_ADLER32_RECODE; | ||
1863 | recode_stream->recode_adler32 = stream->whole_target.wininfo[window_num].adler32; | ||
1864 | } | ||
1865 | |||
1866 | window_num++; | ||
1844 | 1867 | ||
1845 | if (main_bsize < window_size) | 1868 | if (main_bsize < window_size) |
1846 | { | 1869 | { |
diff --git a/xdelta3/xdelta3-merge.h b/xdelta3/xdelta3-merge.h index 553fbf0..2253a2c 100644 --- a/xdelta3/xdelta3-merge.h +++ b/xdelta3/xdelta3-merge.h | |||
@@ -28,19 +28,19 @@ xd3_whole_state_init (xd3_stream *stream) | |||
28 | { | 28 | { |
29 | XD3_ASSERT (stream->whole_target.adds == NULL); | 29 | XD3_ASSERT (stream->whole_target.adds == NULL); |
30 | XD3_ASSERT (stream->whole_target.inst == NULL); | 30 | XD3_ASSERT (stream->whole_target.inst == NULL); |
31 | XD3_ASSERT (stream->whole_target.winsizes == NULL); | 31 | XD3_ASSERT (stream->whole_target.wininfo == NULL); |
32 | XD3_ASSERT (stream->whole_target.length == 0); | 32 | XD3_ASSERT (stream->whole_target.length == 0); |
33 | 33 | ||
34 | stream->whole_target.adds_alloc = XD3_ALLOCSIZE; | 34 | stream->whole_target.adds_alloc = XD3_ALLOCSIZE; |
35 | stream->whole_target.inst_alloc = XD3_ALLOCSIZE; | 35 | stream->whole_target.inst_alloc = XD3_ALLOCSIZE; |
36 | stream->whole_target.winsizes_alloc = XD3_ALLOCSIZE; | 36 | stream->whole_target.wininfo_alloc = XD3_ALLOCSIZE; |
37 | 37 | ||
38 | if ((stream->whole_target.adds = (uint8_t*) | 38 | if ((stream->whole_target.adds = (uint8_t*) |
39 | xd3_alloc (stream, stream->whole_target.adds_alloc, 1)) == NULL || | 39 | xd3_alloc (stream, stream->whole_target.adds_alloc, 1)) == NULL || |
40 | (stream->whole_target.inst = (xd3_winst*) | 40 | (stream->whole_target.inst = (xd3_winst*) |
41 | xd3_alloc (stream, stream->whole_target.inst_alloc, 1)) == NULL || | 41 | xd3_alloc (stream, stream->whole_target.inst_alloc, 1)) == NULL || |
42 | (stream->whole_target.winsizes = (usize_t*) | 42 | (stream->whole_target.wininfo = (xd3_wininfo*) |
43 | xd3_alloc (stream, stream->whole_target.winsizes_alloc, 1)) == NULL) | 43 | xd3_alloc (stream, stream->whole_target.wininfo_alloc, 1)) == NULL) |
44 | { | 44 | { |
45 | return ENOMEM; | 45 | return ENOMEM; |
46 | } | 46 | } |
@@ -54,7 +54,7 @@ xd3_swap_whole_state (xd3_whole_state *a, | |||
54 | xd3_whole_state tmp; | 54 | xd3_whole_state tmp; |
55 | XD3_ASSERT (a->inst != NULL && a->adds != NULL); | 55 | XD3_ASSERT (a->inst != NULL && a->adds != NULL); |
56 | XD3_ASSERT (b->inst != NULL && b->adds != NULL); | 56 | XD3_ASSERT (b->inst != NULL && b->adds != NULL); |
57 | XD3_ASSERT (b->winsizes != NULL && b->winsizes != NULL); | 57 | XD3_ASSERT (b->wininfo != NULL && b->wininfo != NULL); |
58 | memcpy (&tmp, a, sizeof (xd3_whole_state)); | 58 | memcpy (&tmp, a, sizeof (xd3_whole_state)); |
59 | memcpy (a, b, sizeof (xd3_whole_state)); | 59 | memcpy (a, b, sizeof (xd3_whole_state)); |
60 | memcpy (b, &tmp, sizeof (xd3_whole_state)); | 60 | memcpy (b, &tmp, sizeof (xd3_whole_state)); |
@@ -139,22 +139,22 @@ xd3_whole_alloc_adds (xd3_stream *stream, | |||
139 | } | 139 | } |
140 | 140 | ||
141 | static int | 141 | static int |
142 | xd3_whole_alloc_winsize (xd3_stream *stream, | 142 | xd3_whole_alloc_wininfo (xd3_stream *stream, |
143 | usize_t **winsizep) | 143 | xd3_wininfo **wininfop) |
144 | { | 144 | { |
145 | int ret; | 145 | int ret; |
146 | 146 | ||
147 | if ((ret = xd3_realloc_buffer (stream, | 147 | if ((ret = xd3_realloc_buffer (stream, |
148 | stream->whole_target.winsizeslen, | 148 | stream->whole_target.wininfolen, |
149 | sizeof (xd3_winst), | 149 | sizeof (xd3_wininfo), |
150 | 1, | 150 | 1, |
151 | & stream->whole_target.winsizes_alloc, | 151 | & stream->whole_target.wininfo_alloc, |
152 | (void**) & stream->whole_target.winsizes))) | 152 | (void**) & stream->whole_target.wininfo))) |
153 | { | 153 | { |
154 | return ret; | 154 | return ret; |
155 | } | 155 | } |
156 | 156 | ||
157 | *winsizep = &stream->whole_target.winsizes[stream->whole_target.winsizeslen++]; | 157 | *wininfop = &stream->whole_target.wininfo[stream->whole_target.wininfolen++]; |
158 | 158 | ||
159 | return 0; | 159 | return 0; |
160 | } | 160 | } |
@@ -223,13 +223,13 @@ int | |||
223 | xd3_whole_append_window (xd3_stream *stream) | 223 | xd3_whole_append_window (xd3_stream *stream) |
224 | { | 224 | { |
225 | int ret; | 225 | int ret; |
226 | usize_t *winsize; | 226 | xd3_wininfo *wininfo; |
227 | 227 | ||
228 | stream->whole_target.windows += 1; | 228 | if ((ret = xd3_whole_alloc_wininfo (stream, &wininfo))) { return ret; } |
229 | |||
230 | if ((ret = xd3_whole_alloc_winsize (stream, &winsize))) { return ret; } | ||
231 | 229 | ||
232 | *winsize = stream->dec_tgtlen; | 230 | wininfo->length = stream->dec_tgtlen; |
231 | wininfo->offset = stream->dec_winstart; | ||
232 | wininfo->adler32 = stream->dec_adler32; | ||
233 | 233 | ||
234 | while (stream->inst_sect.buf < stream->inst_sect.buf_max) | 234 | while (stream->inst_sect.buf < stream->inst_sect.buf_max) |
235 | { | 235 | { |
@@ -533,12 +533,12 @@ int xd3_merge_inputs (xd3_stream *stream, | |||
533 | usize_t i; | 533 | usize_t i; |
534 | size_t input_i; | 534 | size_t input_i; |
535 | 535 | ||
536 | for (i = 0; i < input->winsizeslen; ++i) { | 536 | for (i = 0; i < input->wininfolen; ++i) { |
537 | usize_t *copysize; | 537 | xd3_wininfo *copyinfo; |
538 | 538 | ||
539 | if ((ret = xd3_whole_alloc_winsize (stream, ©size))) { return ret; } | 539 | if ((ret = xd3_whole_alloc_wininfo (stream, ©info))) { return ret; } |
540 | 540 | ||
541 | *copysize = input->winsizes[i]; | 541 | *copyinfo = input->wininfo[i]; |
542 | } | 542 | } |
543 | 543 | ||
544 | /* iterate over each instruction. */ | 544 | /* iterate over each instruction. */ |
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 7921556..9028d0c 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c | |||
@@ -2295,7 +2295,7 @@ xd3_free_stream (xd3_stream *stream) | |||
2295 | 2295 | ||
2296 | xd3_free (stream, stream->whole_target.adds); | 2296 | xd3_free (stream, stream->whole_target.adds); |
2297 | xd3_free (stream, stream->whole_target.inst); | 2297 | xd3_free (stream, stream->whole_target.inst); |
2298 | xd3_free (stream, stream->whole_target.winsizes); | 2298 | xd3_free (stream, stream->whole_target.wininfo); |
2299 | 2299 | ||
2300 | XD3_ASSERT (stream->alloc_cnt == stream->free_cnt); | 2300 | XD3_ASSERT (stream->alloc_cnt == stream->free_cnt); |
2301 | 2301 | ||
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h index 362e173..3aab8b6 100644 --- a/xdelta3/xdelta3.h +++ b/xdelta3/xdelta3.h | |||
@@ -249,6 +249,7 @@ typedef struct _xd3_code_table_desc xd3_code_table_desc; | |||
249 | typedef struct _xd3_code_table_sizes xd3_code_table_sizes; | 249 | typedef struct _xd3_code_table_sizes xd3_code_table_sizes; |
250 | typedef struct _xd3_slist xd3_slist; | 250 | typedef struct _xd3_slist xd3_slist; |
251 | typedef struct _xd3_whole_state xd3_whole_state; | 251 | typedef struct _xd3_whole_state xd3_whole_state; |
252 | typedef struct _xd3_wininfo xd3_wininfo; | ||
252 | 253 | ||
253 | /* The stream configuration has three callbacks functions, all of | 254 | /* The stream configuration has three callbacks functions, all of |
254 | * which may be supplied with NULL values. If config->getblk is | 255 | * which may be supplied with NULL values. If config->getblk is |
@@ -638,6 +639,13 @@ struct _xd3_slist | |||
638 | usize_t last_pos; | 639 | usize_t last_pos; |
639 | }; | 640 | }; |
640 | 641 | ||
642 | /* window info (for whole state) */ | ||
643 | struct _xd3_wininfo { | ||
644 | xoff_t offset; | ||
645 | usize_t length; | ||
646 | uint32_t adler32; | ||
647 | }; | ||
648 | |||
641 | /* whole state for, e.g., merge */ | 649 | /* whole state for, e.g., merge */ |
642 | struct _xd3_whole_state { | 650 | struct _xd3_whole_state { |
643 | usize_t addslen; | 651 | usize_t addslen; |
@@ -648,12 +656,11 @@ struct _xd3_whole_state { | |||
648 | xd3_winst *inst; | 656 | xd3_winst *inst; |
649 | usize_t inst_alloc; | 657 | usize_t inst_alloc; |
650 | 658 | ||
651 | usize_t winsizeslen; | 659 | usize_t wininfolen; |
652 | usize_t *winsizes; | 660 | xd3_wininfo *wininfo; |
653 | usize_t winsizes_alloc; | 661 | usize_t wininfo_alloc; |
654 | 662 | ||
655 | xoff_t length; | 663 | xoff_t length; |
656 | xoff_t windows; | ||
657 | }; | 664 | }; |
658 | 665 | ||
659 | /******************************************************************** | 666 | /******************************************************************** |