#ifndef _HAD_ZIPINT_H
#define _HAD_ZIPINT_H
#include <zlib.h>
#include "zip.h"
#ifdef PHP_WIN32
#include <windows.h>
#include <wchar.h>
#define _zip_rename(s, t) \
(!MoveFileExA((s), (t), \
MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING))
#else
#define _zip_rename rename
#endif
#ifndef strcasecmp
# 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
#define CENTRAL_MAGIC "PK\1\2"
#define LOCAL_MAGIC "PK\3\4"
#define EOCD_MAGIC "PK\5\6"
#define DATADES_MAGIC "PK\7\8"
#define TORRENT_SIG "TORRENTZIPPED-"
#define TORRENT_SIG_LEN 14
#define TORRENT_CRC_LEN 8
#define TORRENT_MEM_LEVEL 8
#define CDENTRYSIZE 46u
#define LENTRYSIZE 30
#undef MAXCOMLEN
#define MAXCOMLEN 65536
#define EOCDLEN 22
#define CDBUFSIZE (MAXCOMLEN+EOCDLEN)
#define BUFSIZE 8192
enum zip_state { ZIP_ST_UNCHANGED, ZIP_ST_DELETED, ZIP_ST_REPLACED,
ZIP_ST_ADDED, ZIP_ST_RENAMED };
#define ZIP_ZF_EOF 1
#define ZIP_ZF_DECOMP 2
#define ZIP_ZF_CRC 4
#define ZIP_GPBF_ENCRYPTED 0x0001
#define ZIP_GPBF_DATA_DESCRIPTOR 0x0008
#define ZIP_GPBF_STRONG_ENCRYPTION 0x0040
struct zip_error {
int zip_err;
int sys_err;
char *str;
};
struct zip {
char *zn;
FILE *zp;
struct zip_error error;
unsigned int flags;
unsigned int ch_flags;
struct zip_cdir *cdir;
char *ch_comment;
int ch_comment_len;
int nentry;
int nentry_alloc;
struct zip_entry *entry;
int nfile;
int nfile_alloc;
struct zip_file **file;
};
struct zip_file {
struct zip *za;
struct zip_error error;
int flags;
int method;
off_t fpos;
unsigned long bytes_left;
unsigned long cbytes_left;
unsigned long crc;
unsigned long crc_orig;
char *buffer;
z_stream *zstr;
};
struct zip_dirent {
unsigned short version_madeby;
unsigned short version_needed;
unsigned short bitflags;
unsigned short comp_method;
time_t last_mod;
unsigned int crc;
unsigned int comp_size;
unsigned int uncomp_size;
char *filename;
unsigned short filename_len;
char *extrafield;
unsigned short extrafield_len;
char *comment;
unsigned short comment_len;
unsigned short disk_number;
unsigned short int_attrib;
unsigned int ext_attrib;
unsigned int offset;
};
struct zip_cdir {
struct zip_dirent *entry;
int nentry;
unsigned int size;
unsigned int offset;
char *comment;
unsigned short comment_len;
};
struct zip_source {
zip_source_callback f;
void *ud;
};
struct zip_entry {
enum zip_state state;
struct zip_source *source;
char *ch_filename;
char *ch_comment;
int ch_comment_len;
};
extern const char * const _zip_err_str[];
extern const int _zip_nerr_str;
extern const int _zip_err_type[];
#define ZIP_ENTRY_DATA_CHANGED(x) \
((x)->state == ZIP_ST_REPLACED \
|| (x)->state == ZIP_ST_ADDED)
int _zip_cdir_compute_crc(struct zip *, uLong *);
void _zip_cdir_free(struct zip_cdir *);
struct zip_cdir *_zip_cdir_new(int, struct zip_error *);
int _zip_cdir_write(struct zip_cdir *, FILE *, struct zip_error *);
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 *);
void _zip_dirent_torrent_normalize(struct zip_dirent *);
int _zip_dirent_write(struct zip_dirent *, FILE *, int, struct zip_error *);
void _zip_entry_free(struct zip_entry *);
void _zip_entry_init(struct zip *, int);
struct zip_entry *_zip_entry_new(struct zip *);
void _zip_error_clear(struct zip_error *);
void _zip_error_copy(struct zip_error *, struct zip_error *);
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);
const char *_zip_error_strerror(struct zip_error *);
int _zip_file_fillbuf(void *, size_t, struct zip_file *);
unsigned int _zip_file_get_offset(struct zip *, int);
int _zip_filerange_crc(FILE *, off_t, off_t, uLong *, struct zip_error *);
struct zip_source *_zip_source_file_or_p(struct zip *, const char *, FILE *,
off_t, off_t);
void _zip_free(struct zip *);
const char *_zip_get_name(struct zip *, int, 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);
void _zip_unchange_data(struct zip_entry *);
#endif