"Fossies" - the Fresh Open Source Software Archive

Member "libzip-1.6.0/lib/zipint.h" (24 Jan 2020, 25697 Bytes) of package /linux/misc/libzip-1.6.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "zipint.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.5.2_vs_1.6.0.

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