Imported Upstream version 1.4.0
[platform/upstream/libzip.git] / lib / zipint.h
1 #ifndef _HAD_ZIPINT_H
2 #define _HAD_ZIPINT_H
3
4 /*
5   zipint.h -- internal declarations.
6   Copyright (C) 1999-2017 Dieter Baron and Thomas Klausner
7
8   This file is part of libzip, a library to manipulate ZIP archives.
9   The authors can be contacted at <libzip@nih.at>
10
11   Redistribution and use in source and binary forms, with or without
12   modification, are permitted provided that the following conditions
13   are met:
14   1. Redistributions of source code must retain the above copyright
15      notice, this list of conditions and the following disclaimer.
16   2. Redistributions in binary form must reproduce the above copyright
17      notice, this list of conditions and the following disclaimer in
18      the documentation and/or other materials provided with the
19      distribution.
20   3. The names of the authors may not be used to endorse or promote
21      products derived from this software without specific prior
22      written permission.
23
24   THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
25   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
28   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
30   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
32   IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #ifdef HAVE_CONFIG_H
38 #include "config.h"
39 #endif
40
41 #include "compat.h"
42
43 #include <zlib.h>
44
45 #ifndef _ZIP_COMPILING_DEPRECATED
46 #define ZIP_DISABLE_DEPRECATED
47 #endif
48
49 #include "zip.h"
50
51 #define CENTRAL_MAGIC "PK\1\2"
52 #define LOCAL_MAGIC   "PK\3\4"
53 #define EOCD_MAGIC    "PK\5\6"
54 #define DATADES_MAGIC "PK\7\10"
55 #define EOCD64LOC_MAGIC "PK\6\7"
56 #define EOCD64_MAGIC  "PK\6\6"
57 #define CDENTRYSIZE         46u
58 #define LENTRYSIZE          30
59 #define MAXCOMLEN        65536
60 #define MAXEXTLEN        65536
61 #define EOCDLEN             22
62 #define EOCD64LOCLEN        20
63 #define EOCD64LEN           56
64 #define CDBUFSIZE       (MAXCOMLEN+EOCDLEN+EOCD64LOCLEN)
65 #define BUFSIZE         8192
66 #define EFZIP64SIZE 28
67 #define EF_WINZIP_AES_SIZE 7
68
69 #define ZIP_CM_REPLACED_DEFAULT (-2)
70 #define ZIP_CM_WINZIP_AES         99  /* Winzip AES encrypted */
71
72 #define ZIP_CM_IS_DEFAULT(x)    ((x) == ZIP_CM_DEFAULT || (x) == ZIP_CM_REPLACED_DEFAULT)
73 #define ZIP_CM_ACTUAL(x)        ((zip_uint16_t)(ZIP_CM_IS_DEFAULT(x) ? ZIP_CM_DEFLATE : (x)))
74
75 #define ZIP_EF_UTF_8_COMMENT    0x6375
76 #define ZIP_EF_UTF_8_NAME       0x7075
77 #define ZIP_EF_WINZIP_AES       0x9901
78 #define ZIP_EF_ZIP64            0x0001
79
80 #define ZIP_EF_IS_INTERNAL(id)  ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_WINZIP_AES || (id) == ZIP_EF_ZIP64)
81
82 /* according to unzip-6.0's zipinfo.c, this corresponds to a regular file with rw permissions for everyone */
83 #define ZIP_EXT_ATTRIB_DEFAULT          (0100666u<<16)
84 /* according to unzip-6.0's zipinfo.c, this corresponds to a directory with rwx permissions for everyone */
85 #define ZIP_EXT_ATTRIB_DEFAULT_DIR      (0040777u<<16)
86
87
88 #define ZIP_MAX(a, b)           ((a) > (b) ? (a) : (b))
89 #define ZIP_MIN(a, b)           ((a) < (b) ? (a) : (b))
90
91 /* This section contains API that won't materialize like this.  It's
92    placed in the internal section, pending cleanup. */
93
94 /* flags for compression and encryption sources */
95
96 #define ZIP_CODEC_DECODE        0 /* decompress/decrypt (encode flag not set) */
97 #define ZIP_CODEC_ENCODE        1 /* compress/encrypt */
98
99 typedef zip_source_t *(*zip_encryption_implementation)(zip_t *, zip_source_t *, zip_uint16_t, int, const char *);
100
101 zip_encryption_implementation _zip_get_encryption_implementation(zip_uint16_t method, int operation);
102
103 enum zip_compression_status {
104     ZIP_COMPRESSION_OK,
105     ZIP_COMPRESSION_END,
106     ZIP_COMPRESSION_ERROR,
107     ZIP_COMPRESSION_NEED_DATA
108 };
109 typedef enum zip_compression_status zip_compression_status_t;
110
111 struct zip_compression_algorithm {
112     /* called once to create new context */
113     void *(*allocate)(zip_uint16_t method, int compression_flags, zip_error_t *error);
114     /* called once to free context */
115     void (*deallocate)(void *ctx);
116
117     /* get compression specific general purpose bitflags */
118     int (*compression_flags)(void *ctx);
119
120     /* start processing */
121     bool (*start)(void *ctx);
122     /* stop processing */
123     bool (*end)(void *ctx);
124
125     /* provide new input data, remains valid until next call to input or end */
126     bool (*input)(void *ctx, zip_uint8_t *data, zip_uint64_t length);
127
128     /* all input data has been provided */
129     void (*end_of_input)(void *ctx);
130
131     /* process input data, writing to data, which has room for length bytes, update length to number of bytes written */
132     zip_compression_status_t (*process)(void *ctx, zip_uint8_t *data, zip_uint64_t *length);
133 };
134 typedef struct zip_compression_algorithm zip_compression_algorithm_t;
135
136 extern zip_compression_algorithm_t zip_algorithm_bzip2_compress;
137 extern zip_compression_algorithm_t zip_algorithm_bzip2_decompress;
138 extern zip_compression_algorithm_t zip_algorithm_deflate_compress;
139 extern zip_compression_algorithm_t zip_algorithm_deflate_decompress;
140
141 bool zip_compression_method_supported(zip_int32_t method, bool compress);
142
143 /* This API is not final yet, but we need it internally, so it's private for now. */
144
145 const zip_uint8_t *zip_get_extra_field_by_id(zip_t *, int, int, zip_uint16_t, int, zip_uint16_t *);
146
147 /* This section contains API that is of limited use until support for
148    user-supplied compression/encryption implementation is finished.
149    Thus we will keep it private for now. */
150
151 typedef zip_int64_t (*zip_source_layered_callback)(zip_source_t *, void *, void *, zip_uint64_t, enum zip_source_cmd);
152 zip_source_t *zip_source_compress(zip_t *za, zip_source_t *src, zip_int32_t cm, int compression_flags);
153 zip_source_t *zip_source_crc(zip_t *, zip_source_t *, int);
154 zip_source_t *zip_source_decompress(zip_t *za, zip_source_t *src, zip_int32_t cm);
155 zip_source_t *zip_source_layered(zip_t *, zip_source_t *, zip_source_layered_callback, void *);
156 zip_source_t *zip_source_layered_create(zip_source_t *src, zip_source_layered_callback cb, void *ud, zip_error_t *error);
157 zip_source_t *zip_source_pkware(zip_t *, zip_source_t *, zip_uint16_t, int, const char *);
158 int zip_source_remove(zip_source_t *);
159 zip_int64_t zip_source_supports(zip_source_t *src);
160 zip_source_t *zip_source_window(zip_t *, zip_source_t *, zip_uint64_t, zip_uint64_t);
161 zip_source_t *zip_source_winzip_aes_decode(zip_t *, zip_source_t *, zip_uint16_t, int, const char *);
162 zip_source_t *zip_source_winzip_aes_encode(zip_t *, zip_source_t *, zip_uint16_t, int, const char *);
163
164
165 /* error source for layered sources */
166
167 enum zip_les { ZIP_LES_NONE, ZIP_LES_UPPER, ZIP_LES_LOWER, ZIP_LES_INVAL };
168
169 /* directory entry: general purpose bit flags */
170
171 #define ZIP_GPBF_ENCRYPTED              0x0001u /* is encrypted */
172 #define ZIP_GPBF_DATA_DESCRIPTOR        0x0008u /* crc/size after file data */
173 #define ZIP_GPBF_STRONG_ENCRYPTION      0x0040u /* uses strong encryption */
174 #define ZIP_GPBF_ENCODING_UTF_8         0x0800u /* file name encoding is UTF-8 */
175
176
177 /* extra fields */
178 #define ZIP_EF_LOCAL            ZIP_FL_LOCAL                    /* include in local header */
179 #define ZIP_EF_CENTRAL          ZIP_FL_CENTRAL                  /* include in central directory */
180 #define ZIP_EF_BOTH             (ZIP_EF_LOCAL|ZIP_EF_CENTRAL)   /* include in both */
181
182 #define ZIP_FL_FORCE_ZIP64      1024  /* force zip64 extra field (_zip_dirent_write) */
183
184 #define ZIP_FL_ENCODING_ALL     (ZIP_FL_ENC_GUESS|ZIP_FL_ENC_CP437|ZIP_FL_ENC_UTF_8)
185
186
187 /* encoding type */
188 enum zip_encoding_type {
189     ZIP_ENCODING_UNKNOWN,       /* not yet analyzed */
190     ZIP_ENCODING_ASCII,         /* plain ASCII */
191     ZIP_ENCODING_UTF8_KNOWN,    /* is UTF-8 */
192     ZIP_ENCODING_UTF8_GUESSED,  /* possibly UTF-8 */
193     ZIP_ENCODING_CP437,         /* Code Page 437 */
194     ZIP_ENCODING_ERROR          /* should be UTF-8 but isn't */
195 };
196
197 typedef enum zip_encoding_type zip_encoding_type_t;
198
199 struct zip_hash;
200 struct zip_progress;
201
202 typedef struct zip_cdir zip_cdir_t;
203 typedef struct zip_dirent zip_dirent_t;
204 typedef struct zip_entry zip_entry_t;
205 typedef struct zip_extra_field zip_extra_field_t;
206 typedef struct zip_string zip_string_t;
207 typedef struct zip_buffer zip_buffer_t;
208 typedef struct zip_hash zip_hash_t;
209 typedef struct zip_progress zip_progress_t;
210
211 /* zip archive, part of API */
212
213 struct zip {
214     zip_source_t *src;                  /* data source for archive */
215     unsigned int open_flags;            /* flags passed to zip_open */
216     zip_error_t error;                  /* error information */
217
218     unsigned int flags;                 /* archive global flags */
219     unsigned int ch_flags;              /* changed archive global flags */
220
221     char *default_password;             /* password used when no other supplied */
222
223     zip_string_t *comment_orig;         /* archive comment */
224     zip_string_t *comment_changes;      /* changed archive comment */
225     bool comment_changed;               /* whether archive comment was changed */
226
227     zip_uint64_t nentry;                /* number of entries */
228     zip_uint64_t nentry_alloc;          /* number of entries allocated */
229     zip_entry_t *entry;                 /* entries */
230
231     unsigned int nopen_source;          /* number of open sources using archive */
232     unsigned int nopen_source_alloc;    /* number of sources allocated */
233     zip_source_t **open_source;         /* open sources using archive */
234
235     zip_hash_t *names;                  /* hash table for name lookup */
236
237     zip_progress_t *progress;            /* progress callback for zip_close() */
238 };
239
240 /* file in zip archive, part of API */
241
242 struct zip_file {
243     zip_t *za;          /* zip archive containing this file */
244     zip_error_t error;  /* error information */
245     bool eof;
246     zip_source_t *src;  /* data source */
247 };
248
249 /* zip archive directory entry (central or local) */
250
251 #define ZIP_DIRENT_COMP_METHOD          0x0001u
252 #define ZIP_DIRENT_FILENAME             0x0002u
253 #define ZIP_DIRENT_COMMENT              0x0004u
254 #define ZIP_DIRENT_EXTRA_FIELD          0x0008u
255 #define ZIP_DIRENT_ATTRIBUTES           0x0010u
256 #define ZIP_DIRENT_LAST_MOD             0x0020u
257 #define ZIP_DIRENT_ENCRYPTION_METHOD    0x0040u
258 #define ZIP_DIRENT_PASSWORD             0x0080u
259 #define ZIP_DIRENT_ALL                  ZIP_UINT32_MAX
260
261 struct zip_dirent {
262     zip_uint32_t changed;
263     bool local_extra_fields_read;       /*      whether we already read in local header extra fields */
264     bool cloned;                        /*      whether this instance is cloned, and thus shares non-changed strings */
265
266     bool crc_valid;                     /*      if CRC is valid (sometimes not for encrypted archives) */
267
268     zip_uint16_t version_madeby;        /* (c)  version of creator */
269     zip_uint16_t version_needed;        /* (cl) version needed to extract */
270     zip_uint16_t bitflags;              /* (cl) general purpose bit flag */
271     zip_int32_t comp_method;            /* (cl) compression method used (uint16 and ZIP_CM_DEFAULT (-1)) */
272     time_t last_mod;                    /* (cl) time of last modification */
273     zip_uint32_t crc;                   /* (cl) CRC-32 of uncompressed data */
274     zip_uint64_t comp_size;             /* (cl) size of compressed data */
275     zip_uint64_t uncomp_size;           /* (cl) size of uncompressed data */
276     zip_string_t *filename;             /* (cl) file name (NUL-terminated) */
277     zip_extra_field_t *extra_fields;    /* (cl) extra fields, parsed */
278     zip_string_t *comment;              /* (c)  file comment */
279     zip_uint32_t disk_number;           /* (c)  disk number start */
280     zip_uint16_t int_attrib;            /* (c)  internal file attributes */
281     zip_uint32_t ext_attrib;            /* (c)  external file attributes */
282     zip_uint64_t offset;                /* (c)  offset of local header */
283
284     zip_uint16_t compression_level;     /*      level of compression to use (never valid in orig) */
285     zip_uint16_t encryption_method;     /*      encryption method, computed from other fields */
286     char *password;                     /*      file specific encryption password */
287 };
288
289 /* zip archive central directory */
290
291 struct zip_cdir {
292     zip_entry_t *entry;                 /* directory entries */
293     zip_uint64_t nentry;                /* number of entries */
294     zip_uint64_t nentry_alloc;          /* number of entries allocated */
295
296     zip_uint64_t size;                  /* size of central directory */
297     zip_uint64_t offset;                /* offset of central directory in file */
298     zip_string_t *comment;              /* zip archive comment */
299     bool is_zip64;                      /* central directory in zip64 format */
300 };
301
302 struct zip_extra_field {
303     zip_extra_field_t *next;
304     zip_flags_t flags;                  /* in local/central header */
305     zip_uint16_t id;                    /* header id */
306     zip_uint16_t size;                  /* data size */
307     zip_uint8_t *data;
308 };
309
310 enum zip_source_write_state {
311     ZIP_SOURCE_WRITE_CLOSED,    /* write is not in progress */
312     ZIP_SOURCE_WRITE_OPEN,      /* write is in progress */
313     ZIP_SOURCE_WRITE_FAILED,    /* commit failed, only rollback allowed */
314     ZIP_SOURCE_WRITE_REMOVED    /* file was removed */
315 };
316 typedef enum zip_source_write_state zip_source_write_state_t;
317
318 struct zip_source {
319     zip_source_t *src;
320     union {
321         zip_source_callback f;
322         zip_source_layered_callback l;
323     } cb;
324     void *ud;
325     zip_error_t error;
326     zip_int64_t supports;       /* supported commands */
327     unsigned int open_count;    /* number of times source was opened (directly or as lower layer) */
328     zip_source_write_state_t write_state;          /* whether source is open for writing */
329     bool source_closed;         /* set if source archive is closed */
330     zip_t *source_archive;      /* zip archive we're reading from, NULL if not from archive */
331     unsigned int refcount;
332     bool eof;                   /* EOF reached */
333     bool had_read_error;        /* a previous ZIP_SOURCE_READ reported an error */
334 };
335
336 #define ZIP_SOURCE_IS_OPEN_READING(src) ((src)->open_count > 0)
337 #define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN)
338 #define ZIP_SOURCE_IS_LAYERED(src)  ((src)->src != NULL)
339
340 /* entry in zip archive directory */
341
342 struct zip_entry {
343     zip_dirent_t *orig;
344     zip_dirent_t *changes;
345     zip_source_t *source;
346     bool deleted;
347 };
348
349
350 /* file or archive comment, or filename */
351
352 struct zip_string {
353     zip_uint8_t *raw;                   /* raw string */
354     zip_uint16_t length;                /* length of raw string */
355     enum zip_encoding_type encoding;    /* autorecognized encoding */
356     zip_uint8_t *converted;             /* autoconverted string */
357     zip_uint32_t converted_length;      /* length of converted */
358 };
359
360
361 /* bounds checked access to memory buffer */
362
363 struct zip_buffer {
364     bool ok;
365     bool free_data;
366
367     zip_uint8_t *data;
368     zip_uint64_t size;
369     zip_uint64_t offset;
370 };
371
372 /* which files to write in which order */
373
374 struct zip_filelist {
375     zip_uint64_t idx;
376 /* TODO    const char *name; */
377 };
378
379 typedef struct zip_filelist zip_filelist_t;
380
381
382 extern const char * const _zip_err_str[];
383 extern const int _zip_nerr_str;
384 extern const int _zip_err_type[];
385
386 #define ZIP_MAX(a, b)  ((a) > (b) ? (a) : (b))
387 #define ZIP_MIN(a, b)  ((a) < (b) ? (a) : (b))
388
389 #define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f)))
390 #define ZIP_ENTRY_DATA_CHANGED(x)       ((x)->source != NULL)
391 #define ZIP_ENTRY_HAS_CHANGES(e)    (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL))
392
393 #define ZIP_IS_RDONLY(za)       ((za)->ch_flags & ZIP_AFL_RDONLY)
394
395
396 #ifdef HAVE_EXPLICIT_MEMSET
397 #define _zip_crypto_clear(b, l) explicit_memset((b), 0, (l))
398 #else
399 #ifdef HAVE_EXPLICIT_BZERO
400 #define _zip_crypto_clear(b, l) explicit_bzero((b), (l))
401 #else
402 #define _zip_crypto_clear(b, l) memset((b), 0, (l))
403 #endif
404 #endif
405
406
407 zip_int64_t _zip_add_entry(zip_t *);
408
409 zip_uint8_t *_zip_buffer_data(zip_buffer_t *buffer);
410 bool _zip_buffer_eof(zip_buffer_t *buffer);
411 void _zip_buffer_free(zip_buffer_t *buffer);
412 zip_uint8_t *_zip_buffer_get(zip_buffer_t *buffer, zip_uint64_t length);
413 zip_uint16_t _zip_buffer_get_16(zip_buffer_t *buffer);
414 zip_uint32_t _zip_buffer_get_32(zip_buffer_t *buffer);
415 zip_uint64_t _zip_buffer_get_64(zip_buffer_t *buffer);
416 zip_uint8_t _zip_buffer_get_8(zip_buffer_t *buffer);
417 zip_uint64_t _zip_buffer_left(zip_buffer_t *buffer);
418 zip_buffer_t *_zip_buffer_new(zip_uint8_t *data, zip_uint64_t size);
419 zip_buffer_t *_zip_buffer_new_from_source(zip_source_t *src, zip_uint64_t size, zip_uint8_t *buf, zip_error_t *error);
420 zip_uint64_t _zip_buffer_offset(zip_buffer_t *buffer);
421 bool _zip_buffer_ok(zip_buffer_t *buffer);
422 zip_uint8_t *_zip_buffer_peek(zip_buffer_t *buffer, zip_uint64_t length);
423 int _zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length);
424 int _zip_buffer_put_16(zip_buffer_t *buffer, zip_uint16_t i);
425 int _zip_buffer_put_32(zip_buffer_t *buffer, zip_uint32_t i);
426 int _zip_buffer_put_64(zip_buffer_t *buffer, zip_uint64_t i);
427 int _zip_buffer_put_8(zip_buffer_t *buffer, zip_uint8_t i);
428 zip_uint64_t _zip_buffer_read(zip_buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length);
429 int _zip_buffer_skip(zip_buffer_t *buffer, zip_uint64_t length);
430 int _zip_buffer_set_offset(zip_buffer_t *buffer, zip_uint64_t offset);
431 zip_uint64_t _zip_buffer_size(zip_buffer_t *buffer);
432
433 int _zip_cdir_compute_crc(zip_t *, uLong *);
434 void _zip_cdir_free(zip_cdir_t *);
435 bool _zip_cdir_grow(zip_cdir_t *cd, zip_uint64_t additional_entries, zip_error_t *error);
436 zip_cdir_t *_zip_cdir_new(zip_uint64_t, zip_error_t *);
437 zip_int64_t _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors);
438 void _zip_deregister_source(zip_t *za, zip_source_t *src);
439
440 zip_dirent_t *_zip_dirent_clone(const zip_dirent_t *);
441 void _zip_dirent_free(zip_dirent_t *);
442 void _zip_dirent_finalize(zip_dirent_t *);
443 void _zip_dirent_init(zip_dirent_t *);
444 bool _zip_dirent_needs_zip64(const zip_dirent_t *, zip_flags_t);
445 zip_dirent_t *_zip_dirent_new(void);
446 zip_int64_t _zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, bool local, zip_error_t *error);
447 void _zip_dirent_set_version_needed(zip_dirent_t *de, bool force_zip64);
448 zip_int32_t _zip_dirent_size(zip_source_t *src, zip_uint16_t, zip_error_t *);
449 int _zip_dirent_write(zip_t *za, zip_dirent_t *dirent, zip_flags_t flags);
450
451 zip_extra_field_t *_zip_ef_clone(const zip_extra_field_t *, zip_error_t *);
452 zip_extra_field_t *_zip_ef_delete_by_id(zip_extra_field_t *, zip_uint16_t, zip_uint16_t, zip_flags_t);
453 void _zip_ef_free(zip_extra_field_t *);
454 const zip_uint8_t *_zip_ef_get_by_id(const zip_extra_field_t *, zip_uint16_t *, zip_uint16_t, zip_uint16_t, zip_flags_t, zip_error_t *);
455 zip_extra_field_t *_zip_ef_merge(zip_extra_field_t *, zip_extra_field_t *);
456 zip_extra_field_t *_zip_ef_new(zip_uint16_t, zip_uint16_t, const zip_uint8_t *, zip_flags_t);
457 bool _zip_ef_parse(const zip_uint8_t *, zip_uint16_t, zip_flags_t, zip_extra_field_t **, zip_error_t *);
458 zip_extra_field_t *_zip_ef_remove_internal(zip_extra_field_t *);
459 zip_uint16_t _zip_ef_size(const zip_extra_field_t *, zip_flags_t);
460 int _zip_ef_write(zip_t *za, const zip_extra_field_t *ef, zip_flags_t flags);
461
462 void _zip_entry_finalize(zip_entry_t *);
463 void _zip_entry_init(zip_entry_t *);
464
465 void _zip_error_clear(zip_error_t *);
466 void _zip_error_get(const zip_error_t *, int *, int *);
467
468 void _zip_error_copy(zip_error_t *dst, const zip_error_t *src);
469 void _zip_error_set_from_source(zip_error_t *, zip_source_t *);
470
471 const zip_uint8_t *_zip_extract_extra_field_by_id(zip_error_t *, zip_uint16_t, int, const zip_uint8_t *, zip_uint16_t, zip_uint16_t *);
472
473 int _zip_file_extra_field_prepare_for_change(zip_t *, zip_uint64_t);
474 int _zip_file_fillbuf(void *, size_t, zip_file_t *);
475 zip_uint64_t _zip_file_get_end(const zip_t *za, zip_uint64_t index, zip_error_t *error);
476 zip_uint64_t _zip_file_get_offset(const zip_t *, zip_uint64_t, zip_error_t *);
477
478 int _zip_filerange_crc(zip_source_t *src, zip_uint64_t offset, zip_uint64_t length, uLong *crcp, zip_error_t *error);
479
480 zip_dirent_t *_zip_get_dirent(zip_t *, zip_uint64_t, zip_flags_t, zip_error_t *);
481
482 enum zip_encoding_type _zip_guess_encoding(zip_string_t *, enum zip_encoding_type);
483 zip_uint8_t *_zip_cp437_to_utf8(const zip_uint8_t * const, zip_uint32_t, zip_uint32_t *, zip_error_t *);
484
485 bool _zip_hash_add(zip_hash_t *hash, const zip_uint8_t *name, zip_uint64_t index, zip_flags_t flags, zip_error_t *error);
486 bool _zip_hash_delete(zip_hash_t *hash, const zip_uint8_t *key, zip_error_t *error);
487 void _zip_hash_free(zip_hash_t *hash);
488 zip_int64_t _zip_hash_lookup(zip_hash_t *hash, const zip_uint8_t *name, zip_flags_t flags, zip_error_t *error);
489 zip_hash_t *_zip_hash_new(zip_error_t *error);
490 bool _zip_hash_reserve_capacity(zip_hash_t *hash, zip_uint64_t capacity, zip_error_t *error);
491 bool _zip_hash_revert(zip_hash_t *hash, zip_error_t *error);
492
493 zip_t *_zip_open(zip_source_t *, unsigned int, zip_error_t *);
494
495 void _zip_progress_end(zip_progress_t *progress);
496 void _zip_progress_free(zip_progress_t *progress);
497 zip_progress_t *_zip_progress_new(zip_t *za, double precision, zip_progress_callback callback, void (*ud_free)(void *), void *ud);
498 void _zip_progress_start(zip_progress_t *progress);
499 void _zip_progress_subrange(zip_progress_t *progress, double start, double end);
500 void _zip_progress_update(zip_progress_t *progress, double value);
501
502 bool zip_random(zip_uint8_t *buffer, zip_uint16_t length);
503
504 int _zip_read(zip_source_t *src, zip_uint8_t *data, zip_uint64_t length, zip_error_t *error);
505 int _zip_read_at_offset(zip_source_t *src, zip_uint64_t offset, unsigned char *b, size_t length, zip_error_t *error);
506 zip_uint8_t *_zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp, zip_error_t *error);
507 int _zip_read_local_ef(zip_t *, zip_uint64_t);
508 zip_string_t *_zip_read_string(zip_buffer_t *buffer, zip_source_t *src, zip_uint16_t lenght, bool nulp, zip_error_t *error);
509 int _zip_register_source(zip_t *za, zip_source_t *src);
510
511 void _zip_set_open_error(int *zep, const zip_error_t *err, int ze);
512
513 zip_int64_t _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command);
514 bool _zip_source_eof(zip_source_t *);
515 zip_source_t *_zip_source_file_or_p(const char *, FILE *, zip_uint64_t, zip_int64_t, const zip_stat_t *, zip_error_t *error);
516 zip_int8_t zip_source_get_compression_flags(zip_source_t *);
517 bool _zip_source_had_error(zip_source_t *);
518 void _zip_source_invalidate(zip_source_t *src);
519 zip_source_t *_zip_source_new(zip_error_t *error);
520 int _zip_source_set_source_archive(zip_source_t *, zip_t *);
521 zip_source_t *_zip_source_window_new(zip_source_t *src, zip_uint64_t start, zip_uint64_t length, zip_stat_t *st, zip_int8_t compression_flags, zip_t *source_archive, zip_uint64_t source_index, zip_error_t *error);
522 zip_source_t *_zip_source_zip_new(zip_t *, zip_t *, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_uint64_t, const char *);
523
524 int _zip_stat_merge(zip_stat_t *dst, const zip_stat_t *src, zip_error_t *error);
525 int _zip_string_equal(const zip_string_t *, const zip_string_t *);
526 void _zip_string_free(zip_string_t *);
527 zip_uint32_t _zip_string_crc32(const zip_string_t *);
528 const zip_uint8_t *_zip_string_get(zip_string_t *, zip_uint32_t *, zip_flags_t, zip_error_t *);
529 zip_uint16_t _zip_string_length(const zip_string_t *);
530 zip_string_t *_zip_string_new(const zip_uint8_t *, zip_uint16_t, zip_flags_t, zip_error_t *);
531 int _zip_string_write(zip_t *za, const zip_string_t *string);
532
533 int _zip_changed(const zip_t *, zip_uint64_t *);
534 const char *_zip_get_name(zip_t *, zip_uint64_t, zip_flags_t, zip_error_t *);
535 int _zip_local_header_read(zip_t *, int);
536 void *_zip_memdup(const void *, size_t, zip_error_t *);
537 zip_int64_t _zip_name_locate(zip_t *, const char *, zip_flags_t, zip_error_t *);
538 zip_t *_zip_new(zip_error_t *);
539
540 zip_int64_t _zip_file_replace(zip_t *, zip_uint64_t, const char *, zip_source_t *, zip_flags_t);
541 int _zip_set_name(zip_t *, zip_uint64_t, const char *, zip_flags_t);
542 void _zip_u2d_time(time_t, zip_uint16_t *, zip_uint16_t *);
543 int _zip_unchange(zip_t *, zip_uint64_t, int);
544 void _zip_unchange_data(zip_entry_t *);
545 int _zip_write(zip_t *za, const void *data, zip_uint64_t length);
546
547 #endif /* zipint.h */