--- embedaddon/php/ext/zip/lib/zipint.h 2012/02/21 23:48:05 1.1.1.1 +++ embedaddon/php/ext/zip/lib/zipint.h 2013/07/22 01:32:11 1.1.1.2 @@ -3,7 +3,7 @@ /* zipint.h -- internal declarations. - Copyright (C) 1999-2009 Dieter Baron and Thomas Klausner + Copyright (C) 1999-2011 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at @@ -38,12 +38,37 @@ #include "zip.h" +#ifndef HAVE_FSEEKO +#define fseeko(s, o, w) (fseek((s), (long int)(o), (w))) +#endif + +#ifndef HAVE_FTELLO +#define ftello(s) ((long)ftell((s))) +#endif + +#ifndef PHP_WIN32 +#ifndef HAVE_MKSTEMP +int _zip_mkstemp(char *); +#define mkstemp _zip_mkstemp +#endif +#endif + #ifdef PHP_WIN32 #include #include #define _zip_rename(s, t) \ (!MoveFileExA((s), (t), \ MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING)) + +/* for dup(), close(), etc. */ +#include + +#if !defined(HAVE_OPEN) +#if defined(HAVE__OPEN) +#define open(a, b, c) _open((a), (b)) +#endif +#endif + #else #define _zip_rename rename #endif @@ -52,12 +77,6 @@ # define strcmpi strcasecmp #endif -#ifndef HAVE_FSEEKO -#define fseeko(s, o, w) (fseek((s), (long int)(o), (w))) -#endif -#ifndef HAVE_FTELLO -#define ftello(s) ((long)ftell((s))) -#endif @@ -73,22 +92,77 @@ #define LENTRYSIZE 30 #undef MAXCOMLEN /* defined as 19 on BSD for max command name */ #define MAXCOMLEN 65536 +#define MAXEXTLEN 65536 #define EOCDLEN 22 #define CDBUFSIZE (MAXCOMLEN+EOCDLEN) #define BUFSIZE 8192 +/* This section contains API that won't materialize like this. It's + placed in the internal section, pending cleanup. */ + +typedef struct zip_source *(*zip_compression_implementation)(struct zip *, + struct zip_source *, + zip_uint16_t, int); +typedef struct zip_source *(*zip_encryption_implementation)(struct zip *, + struct zip_source *, + zip_uint16_t, int, + const char *); + +ZIP_EXTERN(zip_compression_implementation) zip_get_compression_implementation( + zip_uint16_t); +ZIP_EXTERN(zip_encryption_implementation) zip_get_encryption_implementation( + zip_uint16_t); + + + + +/* This section contains API that is of limited use until support for + user-supplied compression/encryption implementation is finished. + Thus we will keep it private for now. */ + +typedef zip_int64_t (*zip_source_layered_callback)(struct zip_source *, void *, + void *, zip_uint64_t, + enum zip_source_cmd); + +ZIP_EXTERN(void) zip_source_close(struct zip_source *); +ZIP_EXTERN(struct zip_source *)zip_source_crc(struct zip *, struct zip_source *, + int); +ZIP_EXTERN(struct zip_source *)zip_source_deflate(struct zip *, + struct zip_source *, + zip_uint16_t, int); +ZIP_EXTERN(void) zip_source_error(struct zip_source *, int *, int *); +ZIP_EXTERN(struct zip_source *)zip_source_layered(struct zip *, + struct zip_source *, + zip_source_layered_callback, + void *); +ZIP_EXTERN(int) zip_source_open(struct zip_source *); +ZIP_EXTERN(struct zip_source *)zip_source_pkware(struct zip *, + struct zip_source *, + zip_uint16_t, int, + const char *); +ZIP_EXTERN(zip_int64_t) zip_source_read(struct zip_source *, void *, + zip_uint64_t); +ZIP_EXTERN(int) zip_source_stat(struct zip_source *, struct zip_stat *); + + +/* This function will probably remain private. It is not needed to + implement compression/encryption routines. (We should probably + rename it to _zip_source_pop.) */ + +ZIP_EXTERN(struct zip_source *)zip_source_pop(struct zip_source *); + + + /* state of change of a file in zip archive */ enum zip_state { ZIP_ST_UNCHANGED, ZIP_ST_DELETED, ZIP_ST_REPLACED, ZIP_ST_ADDED, ZIP_ST_RENAMED }; -/* constants for struct zip_file's member flags */ +/* error source for layered sources */ -#define ZIP_ZF_EOF 1 /* EOF reached */ -#define ZIP_ZF_DECOMP 2 /* decompress data */ -#define ZIP_ZF_CRC 4 /* compute and compare CRC */ +enum zip_les { ZIP_LES_NONE, ZIP_LES_UPPER, ZIP_LES_LOWER, ZIP_LES_INVAL }; /* directory entry: general purpose bit flags */ @@ -114,12 +188,14 @@ struct zip { unsigned int flags; /* archive global flags */ unsigned int ch_flags; /* changed archive global flags */ + char *default_password; /* password used when no other supplied */ + struct zip_cdir *cdir; /* central directory */ char *ch_comment; /* changed archive comment */ int ch_comment_len; /* length of changed zip archive * comment, -1 if unchanged */ - int nentry; /* number of entries */ - int nentry_alloc; /* number of entries allocated */ + zip_uint64_t nentry; /* number of entries */ + zip_uint64_t nentry_alloc; /* number of entries allocated */ struct zip_entry *entry; /* entries */ int nfile; /* number of opened files within archive */ int nfile_alloc; /* number of files allocated */ @@ -131,18 +207,8 @@ struct zip { struct zip_file { struct zip *za; /* zip archive containing this file */ struct zip_error error; /* error information */ - int flags; /* -1: eof, >0: error */ - - int method; /* compression method */ - off_t fpos; /* position within zip file (fread/fwrite) */ - unsigned long bytes_left; /* number of bytes left to read */ - unsigned long cbytes_left; /* number of bytes of compressed data left */ - - unsigned long crc; /* CRC so far */ - unsigned long crc_orig; /* CRC recorded in archive */ - - char *buffer; - z_stream *zstr; + int eof; + struct zip_source *src; /* data source */ }; /* zip archive directory entry (central or local) */ @@ -183,8 +249,14 @@ struct zip_cdir { struct zip_source { - zip_source_callback f; + struct zip_source *src; + union { + zip_source_callback f; + zip_source_layered_callback l; + } cb; void *ud; + enum zip_les error_source; + int is_open; }; /* entry in zip archive directory */ @@ -193,6 +265,8 @@ struct zip_entry { enum zip_state state; struct zip_source *source; char *ch_filename; + char *ch_extra; + int ch_extra_len; char *ch_comment; int ch_comment_len; }; @@ -209,6 +283,8 @@ extern const int _zip_err_type[]; ((x)->state == ZIP_ST_REPLACED \ || (x)->state == ZIP_ST_ADDED) +#define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY) + int _zip_cdir_compute_crc(struct zip *, uLong *); @@ -220,7 +296,7 @@ int _zip_cdir_write(struct zip_cdir *, FILE *, struct void _zip_dirent_finalize(struct zip_dirent *); void _zip_dirent_init(struct zip_dirent *); int _zip_dirent_read(struct zip_dirent *, FILE *, unsigned char **, - unsigned int *, int, struct zip_error *); + zip_uint32_t *, int, struct zip_error *); void _zip_dirent_torrent_normalize(struct zip_dirent *); int _zip_dirent_write(struct zip_dirent *, FILE *, int, struct zip_error *); @@ -234,6 +310,7 @@ void _zip_error_fini(struct zip_error *); void _zip_error_get(struct zip_error *, int *, int *); void _zip_error_init(struct zip_error *); void _zip_error_set(struct zip_error *, int, int); +void _zip_error_set_from_source(struct zip_error *, struct zip_source *); const char *_zip_error_strerror(struct zip_error *); int _zip_file_fillbuf(void *, size_t, struct zip_file *); @@ -241,20 +318,27 @@ unsigned int _zip_file_get_offset(struct zip *, int); int _zip_filerange_crc(FILE *, off_t, off_t, uLong *, struct zip_error *); +struct zip *_zip_open(const char *, FILE *, int, int, int *); + struct zip_source *_zip_source_file_or_p(struct zip *, const char *, FILE *, - off_t, off_t); + zip_uint64_t, zip_int64_t, int, + const struct zip_stat *); +struct zip_source *_zip_source_new(struct zip *); +int _zip_changed(struct zip *, int *); void _zip_free(struct zip *); -const char *_zip_get_name(struct zip *, int, int, struct zip_error *); +const char *_zip_get_name(struct zip *, zip_uint64_t, int, struct zip_error *); int _zip_local_header_read(struct zip *, int); void *_zip_memdup(const void *, size_t, struct zip_error *); int _zip_name_locate(struct zip *, const char *, int, struct zip_error *); struct zip *_zip_new(struct zip_error *); unsigned short _zip_read2(unsigned char **); unsigned int _zip_read4(unsigned char **); -int _zip_replace(struct zip *, int, const char *, struct zip_source *); -int _zip_set_name(struct zip *, int, const char *); -int _zip_unchange(struct zip *, int, int); +zip_int64_t _zip_replace(struct zip *, zip_uint64_t, const char *, + struct zip_source *); +int _zip_set_name(struct zip *, zip_uint64_t, const char *); +void _zip_u2d_time(time_t, unsigned short *, unsigned short *); +int _zip_unchange(struct zip *, zip_uint64_t, int); void _zip_unchange_data(struct zip_entry *); #endif /* zipint.h */