Back to index

php5  5.3.10
zip.h
Go to the documentation of this file.
00001 #ifndef _HAD_ZIP_H
00002 #define _HAD_ZIP_H
00003 
00004 /*
00005   zip.h -- exported declarations.
00006   Copyright (C) 1999-2009 Dieter Baron and Thomas Klausner
00007 
00008   This file is part of libzip, a library to manipulate ZIP archives.
00009   The authors can be contacted at <libzip@nih.at>
00010 
00011   Redistribution and use in source and binary forms, with or without
00012   modification, are permitted provided that the following conditions
00013   are met:
00014   1. Redistributions of source code must retain the above copyright
00015      notice, this list of conditions and the following disclaimer.
00016   2. Redistributions in binary form must reproduce the above copyright
00017      notice, this list of conditions and the following disclaimer in
00018      the documentation and/or other materials provided with the
00019      distribution.
00020   3. The names of the authors may not be used to endorse or promote
00021      products derived from this software without specific prior
00022      written permission.
00023 
00024   THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
00025   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00027   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
00028   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00030   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00031   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00032   IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00033   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00034   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035 */
00036 
00037 
00038 #include "main/php.h"
00039 
00040 #ifdef PHP_WIN32
00041 #      include "zip_win32.h"
00042 #      ifdef PHP_ZIP_EXPORTS
00043 #             define ZIP_EXTERN(rt) __declspec(dllexport)rt _stdcall
00044 #      else
00045 #             define ZIP_EXTERN(rt) rt
00046 #      endif
00047 #elif defined(__GNUC__) && __GNUC__ >= 4
00048 #      define ZIP_EXTERN(rt) __attribute__ ((visibility("default"))) rt
00049 #else
00050 #      define ZIP_EXTERN(rt) rt
00051 #endif
00052 
00053 BEGIN_EXTERN_C()
00054 
00055 #include <sys/types.h>
00056 #include <stdio.h>
00057 #include <time.h>
00058 
00059 /* flags for zip_open */
00060 
00061 #define ZIP_CREATE           1
00062 #define ZIP_EXCL             2
00063 #define ZIP_CHECKCONS        4
00064 #define ZIP_OVERWRITE        8
00065 
00066 
00067 /* flags for zip_name_locate, zip_fopen, zip_stat, ... */
00068 
00069 #define ZIP_FL_NOCASE              1 /* ignore case on name lookup */
00070 #define ZIP_FL_NODIR        2 /* ignore directory component */
00071 #define ZIP_FL_COMPRESSED   4 /* read compressed data */
00072 #define ZIP_FL_UNCHANGED    8 /* use original data, ignoring changes */
00073 #define ZIP_FL_RECOMPRESS      16 /* force recompression of data */
00074 
00075 /* archive global flags flags */
00076 
00077 #define ZIP_AFL_TORRENT            1 /* torrent zipped */
00078 
00079 /* libzip error codes */
00080 
00081 #define ZIP_ER_OK             0  /* N No error */
00082 #define ZIP_ER_MULTIDISK      1  /* N Multi-disk zip archives not supported */
00083 #define ZIP_ER_RENAME         2  /* S Renaming temporary file failed */
00084 #define ZIP_ER_CLOSE          3  /* S Closing zip archive failed */
00085 #define ZIP_ER_SEEK           4  /* S Seek error */
00086 #define ZIP_ER_READ           5  /* S Read error */
00087 #define ZIP_ER_WRITE          6  /* S Write error */
00088 #define ZIP_ER_CRC            7  /* N CRC error */
00089 #define ZIP_ER_ZIPCLOSED      8  /* N Containing zip archive was closed */
00090 #define ZIP_ER_NOENT          9  /* N No such file */
00091 #define ZIP_ER_EXISTS        10  /* N File already exists */
00092 #define ZIP_ER_OPEN          11  /* S Can't open file */
00093 #define ZIP_ER_TMPOPEN       12  /* S Failure to create temporary file */
00094 #define ZIP_ER_ZLIB          13  /* Z Zlib error */
00095 #define ZIP_ER_MEMORY        14  /* N Malloc failure */
00096 #define ZIP_ER_CHANGED       15  /* N Entry has been changed */
00097 #define ZIP_ER_COMPNOTSUPP   16  /* N Compression method not supported */
00098 #define ZIP_ER_EOF           17  /* N Premature EOF */
00099 #define ZIP_ER_INVAL         18  /* N Invalid argument */
00100 #define ZIP_ER_NOZIP         19  /* N Not a zip archive */
00101 #define ZIP_ER_INTERNAL      20  /* N Internal error */
00102 #define ZIP_ER_INCONS        21  /* N Zip archive inconsistent */
00103 #define ZIP_ER_REMOVE        22  /* S Can't remove file */
00104 #define ZIP_ER_DELETED       23  /* N Entry has been deleted */
00105 
00106 
00107 /* type of system error value */
00108 
00109 #define ZIP_ET_NONE        0  /* sys_err unused */
00110 #define ZIP_ET_SYS         1  /* sys_err is errno */
00111 #define ZIP_ET_ZLIB        2  /* sys_err is zlib error code */
00112 
00113 /* compression methods */
00114 
00115 #define ZIP_CM_DEFAULT            -1  /* better of deflate or store */
00116 #define ZIP_CM_STORE        0  /* stored (uncompressed) */
00117 #define ZIP_CM_SHRINK              1  /* shrunk */
00118 #define ZIP_CM_REDUCE_1            2  /* reduced with factor 1 */
00119 #define ZIP_CM_REDUCE_2            3  /* reduced with factor 2 */
00120 #define ZIP_CM_REDUCE_3            4  /* reduced with factor 3 */
00121 #define ZIP_CM_REDUCE_4            5  /* reduced with factor 4 */
00122 #define ZIP_CM_IMPLODE             6  /* imploded */
00123 /* 7 - Reserved for Tokenizing compression algorithm */
00124 #define ZIP_CM_DEFLATE             8  /* deflated */
00125 #define ZIP_CM_DEFLATE64       9  /* deflate64 */
00126 #define ZIP_CM_PKWARE_IMPLODE 10  /* PKWARE imploding */
00127 /* 11 - Reserved by PKWARE */
00128 #define ZIP_CM_BZIP2          12  /* compressed using BZIP2 algorithm */
00129 /* 13 - Reserved by PKWARE */
00130 #define ZIP_CM_LZMA        14  /* LZMA (EFS) */
00131 /* 15-17 - Reserved by PKWARE */
00132 #define ZIP_CM_TERSE       18  /* compressed using IBM TERSE (new) */
00133 #define ZIP_CM_LZ77           19  /* IBM LZ77 z Architecture (PFS) */
00134 #define ZIP_CM_WAVPACK            97  /* WavPack compressed data */
00135 #define ZIP_CM_PPMD        98  /* PPMd version I, Rev 1 */
00136 
00137 /* encryption methods */
00138 
00139 #define ZIP_EM_NONE         0  /* not encrypted */
00140 #define ZIP_EM_TRAD_PKWARE     1  /* traditional PKWARE encryption */
00141 #if 0 /* Strong Encryption Header not parsed yet */
00142 #define ZIP_EM_DES        0x6601  /* strong encryption: DES */
00143 #define ZIP_EM_RC2_OLD    0x6602  /* strong encryption: RC2, version < 5.2 */
00144 #define ZIP_EM_3DES_168   0x6603
00145 #define ZIP_EM_3DES_112   0x6609
00146 #define ZIP_EM_AES_128    0x660e
00147 #define ZIP_EM_AES_192    0x660f
00148 #define ZIP_EM_AES_256    0x6610
00149 #define ZIP_EM_RC2        0x6702  /* strong encryption: RC2, version >= 5.2 */
00150 #define ZIP_EM_RC4        0x6801
00151 #endif
00152 #define ZIP_EM_UNKNOWN    0xffff  /* unknown algorithm */
00153 
00154 
00155 
00156 enum zip_source_cmd {
00157     ZIP_SOURCE_OPEN, /* prepare for reading */
00158     ZIP_SOURCE_READ,        /* read data */
00159     ZIP_SOURCE_CLOSE,       /* reading is done */
00160     ZIP_SOURCE_STAT, /* get meta information */
00161     ZIP_SOURCE_ERROR,       /* get error information */
00162     ZIP_SOURCE_FREE  /* cleanup and free resources */
00163 };
00164 
00165 typedef ssize_t (*zip_source_callback)(void *state, void *data,
00166                                    size_t len, enum zip_source_cmd cmd);
00167 
00168 struct zip_stat {
00169     const char *name;                     /* name of the file */
00170     int index;                            /* index within archive */
00171     unsigned int crc;                     /* crc of file data */
00172     time_t mtime;                  /* modification time */
00173     off_t size;                           /* size of file (uncompressed) */
00174     off_t comp_size;               /* size of file (compressed) */
00175     unsigned short comp_method;           /* compression method used */
00176     unsigned short encryption_method;     /* encryption method used */
00177 };
00178 
00179 struct zip;
00180 struct zip_file;
00181 struct zip_source;
00182 
00183 
00184 
00185 ZIP_EXTERN(int) zip_add(struct zip *, const char *, struct zip_source *);
00186 ZIP_EXTERN(int) zip_add_dir(struct zip *, const char *);
00187 ZIP_EXTERN(int) zip_close(struct zip *);
00188 ZIP_EXTERN(int) zip_delete(struct zip *, int);
00189 ZIP_EXTERN(void) zip_error_clear(struct zip *);
00190 ZIP_EXTERN(void) zip_error_get(struct zip *, int *, int *);
00191 ZIP_EXTERN(int) zip_error_get_sys_type(int);
00192 ZIP_EXTERN(int) zip_error_to_str(char *, size_t, int, int);
00193 ZIP_EXTERN(int) zip_fclose(struct zip_file *);
00194 ZIP_EXTERN(void) zip_file_error_clear(struct zip_file *);
00195 ZIP_EXTERN(void) zip_file_error_get(struct zip_file *, int *, int *);
00196 ZIP_EXTERN(const char *)zip_file_strerror(struct zip_file *);
00197 ZIP_EXTERN(struct zip_file *)zip_fopen(struct zip *, const char *, int);
00198 ZIP_EXTERN(struct zip_file *)zip_fopen_index(struct zip *, int, int);
00199 ZIP_EXTERN(ssize_t) zip_fread(struct zip_file *, void *, size_t);
00200 ZIP_EXTERN(const char *)zip_get_archive_comment(struct zip *, int *, int);
00201 ZIP_EXTERN(int) zip_get_archive_flag(struct zip *, int, int);
00202 ZIP_EXTERN(const char *)zip_get_file_comment(struct zip *, int, int *, int);
00203 ZIP_EXTERN(const char *)zip_get_name(struct zip *, int, int);
00204 ZIP_EXTERN(int) zip_get_num_files(struct zip *);
00205 ZIP_EXTERN(int) zip_name_locate(struct zip *, const char *, int);
00206 ZIP_EXTERN(struct zip *)zip_open(const char *, int, int *);
00207 ZIP_EXTERN(int) zip_rename(struct zip *, int, const char *);
00208 ZIP_EXTERN(int) zip_replace(struct zip *, int, struct zip_source *);
00209 ZIP_EXTERN(int) zip_set_archive_comment(struct zip *, const char *, int);
00210 ZIP_EXTERN(int) zip_set_archive_flag(struct zip *, int, int);
00211 ZIP_EXTERN(int) zip_set_file_comment(struct zip *, int, const char *, int);
00212 ZIP_EXTERN(struct zip_source *)zip_source_buffer(struct zip *, const void *,
00213                                           off_t, int);
00214 ZIP_EXTERN(struct zip_source *)zip_source_file(struct zip *, const char *,
00215                                          off_t, off_t);
00216 ZIP_EXTERN(struct zip_source *)zip_source_filep(struct zip *, FILE *,
00217                                           off_t, off_t);
00218 ZIP_EXTERN(void) zip_source_free(struct zip_source *);
00219 ZIP_EXTERN(struct zip_source *)zip_source_function(struct zip *,
00220                                             zip_source_callback, void *);
00221 ZIP_EXTERN(struct zip_source *)zip_source_zip(struct zip *, struct zip *,
00222                                         int, int, off_t, off_t);
00223 ZIP_EXTERN(int) zip_stat(struct zip *, const char *, int, struct zip_stat *);
00224 ZIP_EXTERN(int) zip_stat_index(struct zip *, int, int, struct zip_stat *);
00225 ZIP_EXTERN(void) zip_stat_init(struct zip_stat *);
00226 ZIP_EXTERN(const char *)zip_strerror(struct zip *);
00227 ZIP_EXTERN(int) zip_unchange(struct zip *, int);
00228 ZIP_EXTERN(int) zip_unchange_all(struct zip *);
00229 ZIP_EXTERN(int) zip_unchange_archive(struct zip *);
00230 
00231 END_EXTERN_C();
00232 #endif /* _HAD_ZIP_H */