@gfean/react-native-bundle-drop 0.3.9 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BundleDrop.podspec +9 -2
- package/README.md +19 -0
- package/android/build.gradle +43 -4
- package/android/src/main/cpp/CMakeLists.txt +45 -0
- package/android/src/main/cpp/bundle_drop_xdelta_jni.c +55 -0
- package/android/src/main/java/com/bundledrop/BundleDropBundleVerifier.kt +73 -0
- package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +193 -8
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +60 -7
- package/android/src/main/java/com/bundledrop/BundleDropOtaPrefs.kt +2 -12
- package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +208 -3
- package/android/src/main/java/com/bundledrop/BundleDropXdeltaNative.kt +57 -0
- package/ios/BundleDropBridge.m +27 -0
- package/ios/BundleDropBundleVerifier.swift +106 -0
- package/ios/BundleDropFileOps.swift +149 -0
- package/ios/BundleDropModule.swift +100 -11
- package/ios/BundleDropOtaResolver.swift +149 -3
- package/ios/BundleDropZipExtractor.m +75 -3
- package/lib/CLI/cli.js +1 -8
- package/lib/CLI/scripts/upload-cli.d.ts +0 -1
- package/lib/CLI/scripts/upload-cli.js +98 -36
- package/lib/api/client.d.ts +11 -1
- package/lib/api/client.js +84 -17
- package/lib/api/clientApi.d.ts +2 -1
- package/lib/api/clientApi.js +9 -0
- package/lib/api/types.d.ts +65 -13
- package/lib/bundleInfo.d.ts +2 -0
- package/lib/fs/bundlePointer.d.ts +2 -1
- package/lib/fs/bundlePointer.js +34 -6
- package/lib/fs/fsUtils.js +4 -1
- package/lib/injectImageResolver.js +82 -75
- package/lib/install/bundleInstallShared.d.ts +8 -0
- package/lib/install/bundleInstallShared.js +97 -0
- package/lib/install/bundleVerification.d.ts +5 -0
- package/lib/install/bundleVerification.js +34 -0
- package/lib/install/installFromZip.d.ts +2 -5
- package/lib/install/installFromZip.js +33 -68
- package/lib/loadConfig.js +12 -1
- package/lib/manager/downloadAndInstall.d.ts +9 -0
- package/lib/manager/downloadAndInstall.js +84 -24
- package/lib/manager/reporting.js +26 -2
- package/lib/manager/rollbackState.js +21 -12
- package/lib/manager/updateCheck.js +89 -11
- package/lib/manager/updateState.js +3 -9
- package/lib/manifest/bundleManifest.d.ts +33 -0
- package/lib/manifest/bundleManifest.js +298 -0
- package/lib/native/bundleDropNative.js +1 -2
- package/lib/native/fs.d.ts +14 -0
- package/lib/native/fs.js +35 -0
- package/lib/patch-engine/installFromPatchSet.d.ts +16 -0
- package/lib/patch-engine/installFromPatchSet.js +143 -0
- package/lib/patch-engine/patchOperations.d.ts +33 -0
- package/lib/patch-engine/patchOperations.js +77 -0
- package/lib/patch-engine/patchTransport.d.ts +18 -0
- package/lib/patch-engine/patchTransport.js +81 -0
- package/lib/patchAlgorithms.d.ts +4 -0
- package/lib/patchAlgorithms.js +9 -0
- package/lib/runtime/service.js +43 -9
- package/lib/scripts/bundle.d.ts +3 -0
- package/lib/scripts/bundle.js +197 -43
- package/lib/scripts/download-bundle.js +18 -7
- package/package.json +44 -6
- package/third_party/xdelta/NOTICE +7 -0
- package/third_party/xdelta/PROVENANCE.md +10 -0
- package/third_party/xdelta/bundle_drop_xdelta.c +252 -0
- package/third_party/xdelta/bundle_drop_xdelta.h +26 -0
- package/third_party/xdelta/xdelta3/LICENSE +176 -0
- package/third_party/xdelta/xdelta3/config.h +34 -0
- package/third_party/xdelta/xdelta3/xdelta3-cfgs.h +171 -0
- package/third_party/xdelta/xdelta3/xdelta3-decode.h +1219 -0
- package/third_party/xdelta/xdelta3/xdelta3-hash.h +159 -0
- package/third_party/xdelta/xdelta3/xdelta3-internal.h +385 -0
- package/third_party/xdelta/xdelta3/xdelta3-list.h +127 -0
- package/third_party/xdelta/xdelta3/xdelta3.c +4819 -0
- package/third_party/xdelta/xdelta3/xdelta3.h +1476 -0
- package/lib/CLI/scripts/init-native-config.d.ts +0 -18
- package/lib/CLI/scripts/init-native-config.js +0 -539
- package/lib/assetExtensions.d.ts +0 -4
- package/lib/assetExtensions.js +0 -35
- package/lib/scripts/upload-bundle.d.ts +0 -9
- package/lib/scripts/upload-bundle.js +0 -320
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/* xdelta3 - delta compression tools and library
|
|
2
|
+
Copyright 2016 Joshua MacDonald
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
#ifndef _XDELTA3_HASH_H_
|
|
17
|
+
#define _XDELTA3_HASH_H_
|
|
18
|
+
|
|
19
|
+
#include "xdelta3-internal.h"
|
|
20
|
+
|
|
21
|
+
#if XD3_DEBUG
|
|
22
|
+
#define SMALL_HASH_DEBUG1(s,inp) \
|
|
23
|
+
uint32_t debug_state; \
|
|
24
|
+
uint32_t debug_hval = xd3_checksum_hash (& (s)->small_hash, \
|
|
25
|
+
xd3_scksum (&debug_state, (inp), (s)->smatcher.small_look))
|
|
26
|
+
#define SMALL_HASH_DEBUG2(s,inp) \
|
|
27
|
+
XD3_ASSERT (debug_hval == xd3_checksum_hash (& (s)->small_hash, \
|
|
28
|
+
xd3_scksum (&debug_state, (inp), (s)->smatcher.small_look)))
|
|
29
|
+
#else
|
|
30
|
+
#define SMALL_HASH_DEBUG1(s,inp)
|
|
31
|
+
#define SMALL_HASH_DEBUG2(s,inp)
|
|
32
|
+
#endif /* XD3_DEBUG */
|
|
33
|
+
|
|
34
|
+
#if UNALIGNED_OK
|
|
35
|
+
#define UNALIGNED_READ32(dest,src) (*(dest)) = (*(uint32_t*)(src))
|
|
36
|
+
#else
|
|
37
|
+
#define UNALIGNED_READ32(dest,src) memcpy((dest), (src), 4);
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
/* These are good hash multipliers for 32-bit and 64-bit LCGs: see
|
|
41
|
+
* "linear congruential generators of different sizes and good lattice
|
|
42
|
+
* structure" */
|
|
43
|
+
#define xd3_hash_multiplier32 1597334677U
|
|
44
|
+
#define xd3_hash_multiplier64 1181783497276652981ULL
|
|
45
|
+
|
|
46
|
+
/* TODO: small cksum is hard-coded for 4 bytes (i.e., "look" is unused) */
|
|
47
|
+
static inline uint32_t
|
|
48
|
+
xd3_scksum (uint32_t *state,
|
|
49
|
+
const uint8_t *base,
|
|
50
|
+
const usize_t look)
|
|
51
|
+
{
|
|
52
|
+
UNALIGNED_READ32(state, base);
|
|
53
|
+
return (*state) * xd3_hash_multiplier32;
|
|
54
|
+
}
|
|
55
|
+
static inline uint32_t
|
|
56
|
+
xd3_small_cksum_update (uint32_t *state,
|
|
57
|
+
const uint8_t *base,
|
|
58
|
+
usize_t look)
|
|
59
|
+
{
|
|
60
|
+
UNALIGNED_READ32(state, base+1);
|
|
61
|
+
return (*state) * xd3_hash_multiplier32;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#if XD3_ENCODER
|
|
65
|
+
inline usize_t
|
|
66
|
+
xd3_checksum_hash (const xd3_hash_cfg *cfg, const usize_t cksum)
|
|
67
|
+
{
|
|
68
|
+
return (cksum >> cfg->shift) ^ (cksum & cfg->mask);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#if SIZEOF_USIZE_T == 4
|
|
72
|
+
inline uint32_t
|
|
73
|
+
xd3_large32_cksum (xd3_hash_cfg *cfg, const uint8_t *base, const usize_t look)
|
|
74
|
+
{
|
|
75
|
+
uint32_t h = 0;
|
|
76
|
+
for (usize_t i = 0; i < look; i++) {
|
|
77
|
+
h += base[i] * cfg->powers[i];
|
|
78
|
+
}
|
|
79
|
+
return h;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
inline uint32_t
|
|
83
|
+
xd3_large32_cksum_update (xd3_hash_cfg *cfg, const uint32_t cksum,
|
|
84
|
+
const uint8_t *base, const usize_t look)
|
|
85
|
+
{
|
|
86
|
+
return xd3_hash_multiplier32 * cksum - cfg->multiplier * base[0] + base[look];
|
|
87
|
+
}
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
#if SIZEOF_USIZE_T == 8
|
|
91
|
+
inline uint64_t
|
|
92
|
+
xd3_large64_cksum (xd3_hash_cfg *cfg, const uint8_t *base, const usize_t look)
|
|
93
|
+
{
|
|
94
|
+
uint64_t h = 0;
|
|
95
|
+
for (usize_t i = 0; i < look; i++) {
|
|
96
|
+
h += base[i] * cfg->powers[i];
|
|
97
|
+
}
|
|
98
|
+
return h;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
inline uint64_t
|
|
102
|
+
xd3_large64_cksum_update (xd3_hash_cfg *cfg, const uint64_t cksum,
|
|
103
|
+
const uint8_t *base, const usize_t look)
|
|
104
|
+
{
|
|
105
|
+
return xd3_hash_multiplier64 * cksum - cfg->multiplier * base[0] + base[look];
|
|
106
|
+
}
|
|
107
|
+
#endif
|
|
108
|
+
|
|
109
|
+
static usize_t
|
|
110
|
+
xd3_size_hashtable_bits (usize_t slots)
|
|
111
|
+
{
|
|
112
|
+
usize_t bits = (SIZEOF_USIZE_T * 8) - 1;
|
|
113
|
+
usize_t i;
|
|
114
|
+
|
|
115
|
+
for (i = 3; i <= bits; i += 1)
|
|
116
|
+
{
|
|
117
|
+
if (slots < (1U << i))
|
|
118
|
+
{
|
|
119
|
+
/* Note: this is the compaction=1 setting measured in
|
|
120
|
+
* checksum_test */
|
|
121
|
+
bits = i - 1;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return bits;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
int
|
|
130
|
+
xd3_size_hashtable (xd3_stream *stream,
|
|
131
|
+
usize_t slots,
|
|
132
|
+
usize_t look,
|
|
133
|
+
xd3_hash_cfg *cfg)
|
|
134
|
+
{
|
|
135
|
+
usize_t bits = xd3_size_hashtable_bits (slots);
|
|
136
|
+
|
|
137
|
+
cfg->size = (1U << bits);
|
|
138
|
+
cfg->mask = (cfg->size - 1);
|
|
139
|
+
cfg->shift = (SIZEOF_USIZE_T * 8) - bits;
|
|
140
|
+
cfg->look = look;
|
|
141
|
+
|
|
142
|
+
if ((cfg->powers =
|
|
143
|
+
(usize_t*) xd3_alloc0 (stream, look, sizeof (usize_t))) == NULL)
|
|
144
|
+
{
|
|
145
|
+
return ENOMEM;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
cfg->powers[look-1] = 1;
|
|
149
|
+
for (int i = look-2; i >= 0; i--)
|
|
150
|
+
{
|
|
151
|
+
cfg->powers[i] = cfg->powers[i+1] * xd3_hash_multiplier;
|
|
152
|
+
}
|
|
153
|
+
cfg->multiplier = cfg->powers[0] * xd3_hash_multiplier;
|
|
154
|
+
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#endif /* XD3_ENCODER */
|
|
159
|
+
#endif /* _XDELTA3_HASH_H_ */
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/* xdelta3 - delta compression tools and library
|
|
2
|
+
Copyright 2016 Joshua MacDonald
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
#ifndef XDELTA3_INTERNAL_H__
|
|
17
|
+
#define XDELTA3_INTERNAL_H__
|
|
18
|
+
|
|
19
|
+
#include "xdelta3.h"
|
|
20
|
+
|
|
21
|
+
typedef struct _main_file main_file;
|
|
22
|
+
typedef struct _main_extcomp main_extcomp;
|
|
23
|
+
|
|
24
|
+
void main_buffree (void *ptr);
|
|
25
|
+
void* main_bufalloc (size_t size);
|
|
26
|
+
void main_file_init (main_file *xfile);
|
|
27
|
+
int main_file_close (main_file *xfile);
|
|
28
|
+
void main_file_cleanup (main_file *xfile);
|
|
29
|
+
int main_file_isopen (main_file *xfile);
|
|
30
|
+
int main_file_open (main_file *xfile, const char* name, int mode);
|
|
31
|
+
int main_file_exists (main_file *xfile);
|
|
32
|
+
int main_file_stat (main_file *xfile, xoff_t *size);
|
|
33
|
+
int xd3_whole_append_window (xd3_stream *stream);
|
|
34
|
+
int xd3_main_cmdline (int argc, char **argv);
|
|
35
|
+
int main_file_read (main_file *ifile,
|
|
36
|
+
uint8_t *buf,
|
|
37
|
+
size_t size,
|
|
38
|
+
size_t *nread,
|
|
39
|
+
const char *msg);
|
|
40
|
+
int main_file_write (main_file *ofile, uint8_t *buf,
|
|
41
|
+
usize_t size, const char *msg);
|
|
42
|
+
void* main_malloc (size_t size);
|
|
43
|
+
void main_free (void *ptr);
|
|
44
|
+
|
|
45
|
+
int test_compare_files (const char* f0, const char* f1);
|
|
46
|
+
usize_t xd3_bytes_on_srcblk (xd3_source *src, xoff_t blkno);
|
|
47
|
+
xoff_t xd3_source_eof(const xd3_source *src);
|
|
48
|
+
|
|
49
|
+
uint32_t xd3_large_cksum_update (uint32_t cksum,
|
|
50
|
+
const uint8_t *base,
|
|
51
|
+
usize_t look);
|
|
52
|
+
int xd3_emit_byte (xd3_stream *stream,
|
|
53
|
+
xd3_output **outputp,
|
|
54
|
+
uint8_t code);
|
|
55
|
+
|
|
56
|
+
int xd3_emit_bytes (xd3_stream *stream,
|
|
57
|
+
xd3_output **outputp,
|
|
58
|
+
const uint8_t *base,
|
|
59
|
+
usize_t size);
|
|
60
|
+
xd3_output* xd3_alloc_output (xd3_stream *stream,
|
|
61
|
+
xd3_output *old_output);
|
|
62
|
+
|
|
63
|
+
int xd3_encode_init_full (xd3_stream *stream);
|
|
64
|
+
usize_t xd3_pow2_roundup (usize_t x);
|
|
65
|
+
long get_millisecs_now (void);
|
|
66
|
+
int xd3_process_stream (int is_encode,
|
|
67
|
+
xd3_stream *stream,
|
|
68
|
+
int (*func) (xd3_stream *),
|
|
69
|
+
int close_stream,
|
|
70
|
+
const uint8_t *input,
|
|
71
|
+
usize_t input_size,
|
|
72
|
+
uint8_t *output,
|
|
73
|
+
usize_t *output_size,
|
|
74
|
+
usize_t output_size_max);
|
|
75
|
+
|
|
76
|
+
#if PYTHON_MODULE || SWIG_MODULE || NOT_MAIN
|
|
77
|
+
int xd3_main_cmdline (int argc, char **argv);
|
|
78
|
+
#endif
|
|
79
|
+
|
|
80
|
+
#if REGRESSION_TEST
|
|
81
|
+
int xd3_selftest (void);
|
|
82
|
+
#endif
|
|
83
|
+
|
|
84
|
+
/* main_file->mode values */
|
|
85
|
+
typedef enum
|
|
86
|
+
{
|
|
87
|
+
XO_READ = 0,
|
|
88
|
+
XO_WRITE = 1
|
|
89
|
+
} main_file_modes;
|
|
90
|
+
|
|
91
|
+
#ifndef XD3_POSIX
|
|
92
|
+
#define XD3_POSIX 0
|
|
93
|
+
#endif
|
|
94
|
+
#ifndef XD3_STDIO
|
|
95
|
+
#define XD3_STDIO 0
|
|
96
|
+
#endif
|
|
97
|
+
#ifndef XD3_WIN32
|
|
98
|
+
#define XD3_WIN32 0
|
|
99
|
+
#endif
|
|
100
|
+
#ifndef NOT_MAIN
|
|
101
|
+
#define NOT_MAIN 0
|
|
102
|
+
#endif
|
|
103
|
+
|
|
104
|
+
/* If none are set, default to posix. */
|
|
105
|
+
#if (XD3_POSIX + XD3_STDIO + XD3_WIN32) == 0
|
|
106
|
+
#undef XD3_POSIX
|
|
107
|
+
#define XD3_POSIX 1
|
|
108
|
+
#endif
|
|
109
|
+
|
|
110
|
+
struct _main_file
|
|
111
|
+
{
|
|
112
|
+
#if XD3_WIN32
|
|
113
|
+
HANDLE file;
|
|
114
|
+
#elif XD3_STDIO
|
|
115
|
+
FILE *file;
|
|
116
|
+
#elif XD3_POSIX
|
|
117
|
+
int file;
|
|
118
|
+
#endif
|
|
119
|
+
|
|
120
|
+
int mode; /* XO_READ and XO_WRITE */
|
|
121
|
+
const char *filename; /* File name or /dev/stdin,
|
|
122
|
+
* /dev/stdout, /dev/stderr. */
|
|
123
|
+
char *filename_copy; /* File name or /dev/stdin,
|
|
124
|
+
* /dev/stdout, /dev/stderr. */
|
|
125
|
+
const char *realname; /* File name or /dev/stdin,
|
|
126
|
+
* /dev/stdout, /dev/stderr. */
|
|
127
|
+
const main_extcomp *compressor; /* External compression struct. */
|
|
128
|
+
int flags; /* RD_FIRST, RD_NONEXTERNAL, ... */
|
|
129
|
+
xoff_t nread; /* for input position */
|
|
130
|
+
xoff_t nwrite; /* for output position */
|
|
131
|
+
uint8_t *snprintf_buf; /* internal snprintf() use */
|
|
132
|
+
int size_known; /* Set by main_set_souze */
|
|
133
|
+
xoff_t source_position; /* for avoiding seek in getblk_func */
|
|
134
|
+
int seek_failed; /* after seek fails once, try FIFO */
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
#ifndef UINT32_MAX
|
|
138
|
+
#define UINT32_MAX 4294967295U
|
|
139
|
+
#endif
|
|
140
|
+
|
|
141
|
+
#ifndef UINT64_MAX
|
|
142
|
+
#define UINT64_MAX 18446744073709551615ULL
|
|
143
|
+
#endif
|
|
144
|
+
|
|
145
|
+
#define UINT32_OFLOW_MASK 0xfe000000U
|
|
146
|
+
#define UINT64_OFLOW_MASK 0xfe00000000000000ULL
|
|
147
|
+
|
|
148
|
+
/*********************************************************************
|
|
149
|
+
Integer encoder/decoder functions
|
|
150
|
+
**********************************************************************/
|
|
151
|
+
|
|
152
|
+
/* Consume N bytes of input, only used by the decoder. */
|
|
153
|
+
#define DECODE_INPUT(n) \
|
|
154
|
+
do { \
|
|
155
|
+
stream->total_in += (xoff_t) (n); \
|
|
156
|
+
stream->avail_in -= (n); \
|
|
157
|
+
stream->next_in += (n); \
|
|
158
|
+
} while (0)
|
|
159
|
+
|
|
160
|
+
#define DECODE_INTEGER_TYPE(PART,OFLOW) \
|
|
161
|
+
while (stream->avail_in != 0) \
|
|
162
|
+
{ \
|
|
163
|
+
usize_t next = stream->next_in[0]; \
|
|
164
|
+
\
|
|
165
|
+
DECODE_INPUT(1); \
|
|
166
|
+
\
|
|
167
|
+
if (PART & OFLOW) \
|
|
168
|
+
{ \
|
|
169
|
+
stream->msg = "overflow in decode_integer"; \
|
|
170
|
+
return XD3_INVALID_INPUT; \
|
|
171
|
+
} \
|
|
172
|
+
\
|
|
173
|
+
PART = (PART << 7) | (next & 127); \
|
|
174
|
+
\
|
|
175
|
+
if ((next & 128) == 0) \
|
|
176
|
+
{ \
|
|
177
|
+
(*val) = PART; \
|
|
178
|
+
PART = 0; \
|
|
179
|
+
return 0; \
|
|
180
|
+
} \
|
|
181
|
+
} \
|
|
182
|
+
\
|
|
183
|
+
stream->msg = "further input required"; \
|
|
184
|
+
return XD3_INPUT
|
|
185
|
+
|
|
186
|
+
#define READ_INTEGER_TYPE(TYPE, OFLOW) \
|
|
187
|
+
TYPE val = 0; \
|
|
188
|
+
const uint8_t *inp = (*inpp); \
|
|
189
|
+
usize_t next; \
|
|
190
|
+
\
|
|
191
|
+
do \
|
|
192
|
+
{ \
|
|
193
|
+
if (inp == maxp) \
|
|
194
|
+
{ \
|
|
195
|
+
stream->msg = "end-of-input in read_integer"; \
|
|
196
|
+
return XD3_INVALID_INPUT; \
|
|
197
|
+
} \
|
|
198
|
+
\
|
|
199
|
+
if (val & OFLOW) \
|
|
200
|
+
{ \
|
|
201
|
+
stream->msg = "overflow in read_intger"; \
|
|
202
|
+
return XD3_INVALID_INPUT; \
|
|
203
|
+
} \
|
|
204
|
+
\
|
|
205
|
+
next = (*inp++); \
|
|
206
|
+
val = (val << 7) | (next & 127); \
|
|
207
|
+
} \
|
|
208
|
+
while (next & 128); \
|
|
209
|
+
\
|
|
210
|
+
(*valp) = val; \
|
|
211
|
+
(*inpp) = inp; \
|
|
212
|
+
\
|
|
213
|
+
return 0
|
|
214
|
+
|
|
215
|
+
#define EMIT_INTEGER_TYPE() \
|
|
216
|
+
/* max 64-bit value in base-7 encoding is 9.1 bytes */ \
|
|
217
|
+
uint8_t buf[10]; \
|
|
218
|
+
usize_t bufi = 10; \
|
|
219
|
+
\
|
|
220
|
+
/* This loop performs division and turns on all MSBs. */ \
|
|
221
|
+
do \
|
|
222
|
+
{ \
|
|
223
|
+
buf[--bufi] = (num & 127) | 128; \
|
|
224
|
+
num >>= 7U; \
|
|
225
|
+
} \
|
|
226
|
+
while (num != 0); \
|
|
227
|
+
\
|
|
228
|
+
/* Turn off MSB of the last byte. */ \
|
|
229
|
+
buf[9] &= 127; \
|
|
230
|
+
\
|
|
231
|
+
return xd3_emit_bytes (stream, output, buf + bufi, 10 - bufi)
|
|
232
|
+
|
|
233
|
+
#define IF_SIZEOF32(x) if (num < (1U << (7 * (x)))) return (x);
|
|
234
|
+
#define IF_SIZEOF64(x) if (num < (1ULL << (7 * (x)))) return (x);
|
|
235
|
+
|
|
236
|
+
#if USE_UINT32
|
|
237
|
+
static inline uint32_t
|
|
238
|
+
xd3_sizeof_uint32_t (uint32_t num)
|
|
239
|
+
{
|
|
240
|
+
IF_SIZEOF32(1);
|
|
241
|
+
IF_SIZEOF32(2);
|
|
242
|
+
IF_SIZEOF32(3);
|
|
243
|
+
IF_SIZEOF32(4);
|
|
244
|
+
return 5;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
static inline int
|
|
248
|
+
xd3_decode_uint32_t (xd3_stream *stream, uint32_t *val)
|
|
249
|
+
{ DECODE_INTEGER_TYPE (stream->dec_32part, UINT32_OFLOW_MASK); }
|
|
250
|
+
|
|
251
|
+
static inline int
|
|
252
|
+
xd3_read_uint32_t (xd3_stream *stream, const uint8_t **inpp,
|
|
253
|
+
const uint8_t *maxp, uint32_t *valp)
|
|
254
|
+
{ READ_INTEGER_TYPE (uint32_t, UINT32_OFLOW_MASK); }
|
|
255
|
+
|
|
256
|
+
#if XD3_ENCODER
|
|
257
|
+
static inline int
|
|
258
|
+
xd3_emit_uint32_t (xd3_stream *stream, xd3_output **output, uint32_t num)
|
|
259
|
+
{ EMIT_INTEGER_TYPE (); }
|
|
260
|
+
#endif /* XD3_ENCODER */
|
|
261
|
+
#endif /* USE_UINT32 */
|
|
262
|
+
|
|
263
|
+
#if USE_UINT64
|
|
264
|
+
static inline uint32_t
|
|
265
|
+
xd3_sizeof_uint64_t (uint64_t num)
|
|
266
|
+
{
|
|
267
|
+
IF_SIZEOF64(1);
|
|
268
|
+
IF_SIZEOF64(2);
|
|
269
|
+
IF_SIZEOF64(3);
|
|
270
|
+
IF_SIZEOF64(4);
|
|
271
|
+
IF_SIZEOF64(5);
|
|
272
|
+
IF_SIZEOF64(6);
|
|
273
|
+
IF_SIZEOF64(7);
|
|
274
|
+
IF_SIZEOF64(8);
|
|
275
|
+
IF_SIZEOF64(9);
|
|
276
|
+
|
|
277
|
+
return 10;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
static inline int
|
|
281
|
+
xd3_decode_uint64_t (xd3_stream *stream, uint64_t *val)
|
|
282
|
+
{ DECODE_INTEGER_TYPE (stream->dec_64part, UINT64_OFLOW_MASK); }
|
|
283
|
+
|
|
284
|
+
static inline int
|
|
285
|
+
xd3_read_uint64_t (xd3_stream *stream, const uint8_t **inpp,
|
|
286
|
+
const uint8_t *maxp, uint64_t *valp)
|
|
287
|
+
{ READ_INTEGER_TYPE (uint64_t, UINT64_OFLOW_MASK); }
|
|
288
|
+
|
|
289
|
+
#if XD3_ENCODER
|
|
290
|
+
static inline int
|
|
291
|
+
xd3_emit_uint64_t (xd3_stream *stream, xd3_output **output, uint64_t num)
|
|
292
|
+
{ EMIT_INTEGER_TYPE (); }
|
|
293
|
+
#endif /* XD3_ENCODER */
|
|
294
|
+
#endif /* USE_UINT64 */
|
|
295
|
+
|
|
296
|
+
#if SIZEOF_USIZE_T == 4
|
|
297
|
+
#define USIZE_T_MAX UINT32_MAX
|
|
298
|
+
#define USIZE_T_MAXBLKSZ 0x80000000U
|
|
299
|
+
#define XD3_MAXSRCWINSZ (1ULL << 31)
|
|
300
|
+
#define xd3_large_cksum xd3_large32_cksum
|
|
301
|
+
#define xd3_large_cksum_update xd3_large32_cksum_update
|
|
302
|
+
#define xd3_hash_multiplier xd3_hash_multiplier32
|
|
303
|
+
|
|
304
|
+
static inline uint32_t xd3_sizeof_size (usize_t num)
|
|
305
|
+
{ return xd3_sizeof_uint32_t (num); }
|
|
306
|
+
static inline int xd3_decode_size (xd3_stream *stream, usize_t *valp)
|
|
307
|
+
{ return xd3_decode_uint32_t (stream, (uint32_t*) valp); }
|
|
308
|
+
static inline int xd3_read_size (xd3_stream *stream, const uint8_t **inpp,
|
|
309
|
+
const uint8_t *maxp, usize_t *valp)
|
|
310
|
+
{ return xd3_read_uint32_t (stream, inpp, maxp, (uint32_t*) valp); }
|
|
311
|
+
#if XD3_ENCODER
|
|
312
|
+
static inline int xd3_emit_size (xd3_stream *stream, xd3_output **output, usize_t num)
|
|
313
|
+
{ return xd3_emit_uint32_t (stream, output, num); }
|
|
314
|
+
#endif
|
|
315
|
+
|
|
316
|
+
#elif SIZEOF_USIZE_T == 8
|
|
317
|
+
#define USIZE_T_MAX UINT64_MAX
|
|
318
|
+
#define USIZE_T_MAXBLKSZ 0x8000000000000000ULL
|
|
319
|
+
#define XD3_MAXSRCWINSZ (1ULL << 61)
|
|
320
|
+
#define xd3_large_cksum xd3_large64_cksum
|
|
321
|
+
#define xd3_large_cksum_update xd3_large64_cksum_update
|
|
322
|
+
#define xd3_hash_multiplier xd3_hash_multiplier64
|
|
323
|
+
|
|
324
|
+
static inline uint32_t xd3_sizeof_size (usize_t num)
|
|
325
|
+
{ return xd3_sizeof_uint64_t (num); }
|
|
326
|
+
static inline int xd3_decode_size (xd3_stream *stream, usize_t *valp)
|
|
327
|
+
{ return xd3_decode_uint64_t (stream, (uint64_t*) valp); }
|
|
328
|
+
static inline int xd3_read_size (xd3_stream *stream, const uint8_t **inpp,
|
|
329
|
+
const uint8_t *maxp, usize_t *valp)
|
|
330
|
+
{ return xd3_read_uint64_t (stream, inpp, maxp, (uint64_t*) valp); }
|
|
331
|
+
#if XD3_ENCODER
|
|
332
|
+
static inline int xd3_emit_size (xd3_stream *stream, xd3_output **output, usize_t num)
|
|
333
|
+
{ return xd3_emit_uint64_t (stream, output, num); }
|
|
334
|
+
#endif
|
|
335
|
+
|
|
336
|
+
#endif /* SIZEOF_USIZE_T */
|
|
337
|
+
|
|
338
|
+
#if SIZEOF_XOFF_T == 4
|
|
339
|
+
#define XOFF_T_MAX UINT32_MAX
|
|
340
|
+
|
|
341
|
+
static inline int xd3_decode_offset (xd3_stream *stream, xoff_t *valp)
|
|
342
|
+
{ return xd3_decode_uint32_t (stream, (uint32_t*) valp); }
|
|
343
|
+
#if XD3_ENCODER
|
|
344
|
+
static inline int xd3_emit_offset (xd3_stream *stream, xd3_output **output, xoff_t num)
|
|
345
|
+
{ return xd3_emit_uint32_t (stream, output, num); }
|
|
346
|
+
#endif
|
|
347
|
+
|
|
348
|
+
#elif SIZEOF_XOFF_T == 8
|
|
349
|
+
#define XOFF_T_MAX UINT64_MAX
|
|
350
|
+
|
|
351
|
+
static inline int xd3_decode_offset (xd3_stream *stream, xoff_t *valp)
|
|
352
|
+
{ return xd3_decode_uint64_t (stream, (uint64_t*) valp); }
|
|
353
|
+
#if XD3_ENCODER
|
|
354
|
+
static inline int xd3_emit_offset (xd3_stream *stream, xd3_output **output, xoff_t num)
|
|
355
|
+
{ return xd3_emit_uint64_t (stream, output, num); }
|
|
356
|
+
#endif
|
|
357
|
+
|
|
358
|
+
#endif
|
|
359
|
+
|
|
360
|
+
#define USIZE_T_OVERFLOW(a,b) ((USIZE_T_MAX - (usize_t) (a)) < (usize_t) (b))
|
|
361
|
+
#define XOFF_T_OVERFLOW(a,b) ((XOFF_T_MAX - (xoff_t) (a)) < (xoff_t) (b))
|
|
362
|
+
|
|
363
|
+
int xd3_size_hashtable (xd3_stream *stream,
|
|
364
|
+
usize_t slots,
|
|
365
|
+
usize_t look,
|
|
366
|
+
xd3_hash_cfg *cfg);
|
|
367
|
+
|
|
368
|
+
usize_t xd3_checksum_hash (const xd3_hash_cfg *cfg, const usize_t cksum);
|
|
369
|
+
|
|
370
|
+
#if USE_UINT32
|
|
371
|
+
uint32_t xd3_large32_cksum (xd3_hash_cfg *cfg, const uint8_t *base, const usize_t look);
|
|
372
|
+
uint32_t xd3_large32_cksum_update (xd3_hash_cfg *cfg, const uint32_t cksum,
|
|
373
|
+
const uint8_t *base, const usize_t look);
|
|
374
|
+
#endif /* USE_UINT32 */
|
|
375
|
+
|
|
376
|
+
#if USE_UINT64
|
|
377
|
+
uint64_t xd3_large64_cksum (xd3_hash_cfg *cfg, const uint8_t *base, const usize_t look);
|
|
378
|
+
uint64_t xd3_large64_cksum_update (xd3_hash_cfg *cfg, const uint64_t cksum,
|
|
379
|
+
const uint8_t *base, const usize_t look);
|
|
380
|
+
#endif /* USE_UINT64 */
|
|
381
|
+
|
|
382
|
+
#define MAX_LRU_SIZE 32U
|
|
383
|
+
#define XD3_MINSRCWINSZ (XD3_ALLOCSIZE * MAX_LRU_SIZE)
|
|
384
|
+
|
|
385
|
+
#endif // XDELTA3_INTERNAL_H__
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/* xdelta3 - delta compression tools and library
|
|
2
|
+
Copyright 2016 Joshua MacDonald
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
#ifndef __XDELTA3_LIST__
|
|
17
|
+
#define __XDELTA3_LIST__
|
|
18
|
+
|
|
19
|
+
#define XD3_MAKELIST(LTYPE,ETYPE,LNAME) \
|
|
20
|
+
\
|
|
21
|
+
static inline ETYPE* \
|
|
22
|
+
LTYPE ## _entry (LTYPE* l) \
|
|
23
|
+
{ \
|
|
24
|
+
return (ETYPE*) ((char*) l - (ptrdiff_t) &((ETYPE*) 0)->LNAME); \
|
|
25
|
+
} \
|
|
26
|
+
\
|
|
27
|
+
static inline void \
|
|
28
|
+
LTYPE ## _init (LTYPE *l) \
|
|
29
|
+
{ \
|
|
30
|
+
l->next = l; \
|
|
31
|
+
l->prev = l; \
|
|
32
|
+
} \
|
|
33
|
+
\
|
|
34
|
+
static inline void \
|
|
35
|
+
LTYPE ## _add (LTYPE *prev, LTYPE *next, LTYPE *ins) \
|
|
36
|
+
{ \
|
|
37
|
+
next->prev = ins; \
|
|
38
|
+
prev->next = ins; \
|
|
39
|
+
ins->next = next; \
|
|
40
|
+
ins->prev = prev; \
|
|
41
|
+
} \
|
|
42
|
+
\
|
|
43
|
+
static inline void \
|
|
44
|
+
LTYPE ## _push_back (LTYPE *l, ETYPE *i) \
|
|
45
|
+
{ \
|
|
46
|
+
LTYPE ## _add (l->prev, l, & i->LNAME); \
|
|
47
|
+
} \
|
|
48
|
+
\
|
|
49
|
+
static inline void \
|
|
50
|
+
LTYPE ## _del (LTYPE *next, \
|
|
51
|
+
LTYPE *prev) \
|
|
52
|
+
{ \
|
|
53
|
+
next->prev = prev; \
|
|
54
|
+
prev->next = next; \
|
|
55
|
+
} \
|
|
56
|
+
\
|
|
57
|
+
static inline ETYPE* \
|
|
58
|
+
LTYPE ## _remove (ETYPE *f) \
|
|
59
|
+
{ \
|
|
60
|
+
LTYPE *i = f->LNAME.next; \
|
|
61
|
+
LTYPE ## _del (f->LNAME.next, f->LNAME.prev); \
|
|
62
|
+
return LTYPE ## _entry (i); \
|
|
63
|
+
} \
|
|
64
|
+
\
|
|
65
|
+
static inline ETYPE* \
|
|
66
|
+
LTYPE ## _pop_back (LTYPE *l) \
|
|
67
|
+
{ \
|
|
68
|
+
LTYPE *i = l->prev; \
|
|
69
|
+
LTYPE ## _del (i->next, i->prev); \
|
|
70
|
+
return LTYPE ## _entry (i); \
|
|
71
|
+
} \
|
|
72
|
+
\
|
|
73
|
+
static inline ETYPE* \
|
|
74
|
+
LTYPE ## _pop_front (LTYPE *l) \
|
|
75
|
+
{ \
|
|
76
|
+
LTYPE *i = l->next; \
|
|
77
|
+
LTYPE ## _del (i->next, i->prev); \
|
|
78
|
+
return LTYPE ## _entry (i); \
|
|
79
|
+
} \
|
|
80
|
+
\
|
|
81
|
+
static inline int \
|
|
82
|
+
LTYPE ## _empty (LTYPE *l) \
|
|
83
|
+
{ \
|
|
84
|
+
return l == l->next; \
|
|
85
|
+
} \
|
|
86
|
+
\
|
|
87
|
+
static inline ETYPE* \
|
|
88
|
+
LTYPE ## _front (LTYPE *f) \
|
|
89
|
+
{ \
|
|
90
|
+
return LTYPE ## _entry (f->next); \
|
|
91
|
+
} \
|
|
92
|
+
\
|
|
93
|
+
static inline ETYPE* \
|
|
94
|
+
LTYPE ## _back (LTYPE *f) \
|
|
95
|
+
{ \
|
|
96
|
+
return LTYPE ## _entry (f->prev); \
|
|
97
|
+
} \
|
|
98
|
+
\
|
|
99
|
+
static inline int \
|
|
100
|
+
LTYPE ## _end (LTYPE *f, ETYPE *i) \
|
|
101
|
+
{ \
|
|
102
|
+
return f == & i->LNAME; \
|
|
103
|
+
} \
|
|
104
|
+
\
|
|
105
|
+
static inline ETYPE* \
|
|
106
|
+
LTYPE ## _next (ETYPE *f) \
|
|
107
|
+
{ \
|
|
108
|
+
return LTYPE ## _entry (f->LNAME.next); \
|
|
109
|
+
} \
|
|
110
|
+
\
|
|
111
|
+
static inline usize_t \
|
|
112
|
+
LTYPE ## _length (LTYPE *l) \
|
|
113
|
+
{ \
|
|
114
|
+
LTYPE *p; \
|
|
115
|
+
usize_t c = 0; \
|
|
116
|
+
\
|
|
117
|
+
for (p = l->next; p != l; p = p->next) \
|
|
118
|
+
{ \
|
|
119
|
+
c += 1; \
|
|
120
|
+
} \
|
|
121
|
+
\
|
|
122
|
+
return c; \
|
|
123
|
+
} \
|
|
124
|
+
\
|
|
125
|
+
typedef int unused_ ## LTYPE
|
|
126
|
+
|
|
127
|
+
#endif
|