1 /* zip.h -- IO on .zip files using zlib
2    Version 1.1, February 14h, 2010
3    part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
4 
5          Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
6 
7          Modifications for Zip64 support
8          Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
9 
10          For more info read MiniZip_info.txt
11 
12          ---------------------------------------------------------------------------
13 
14    Condition of use and distribution are the same than zlib :
15 
16   This software is provided 'as-is', without any express or implied
17   warranty.  In no event will the authors be held liable for any damages
18   arising from the use of this software.
19 
20   Permission is granted to anyone to use this software for any purpose,
21   including commercial applications, and to alter it and redistribute it
22   freely, subject to the following restrictions:
23 
24   1. The origin of this software must not be misrepresented; you must not
25      claim that you wrote the original software. If you use this software
26      in a product, an acknowledgment in the product documentation would be
27      appreciated but is not required.
28   2. Altered source versions must be plainly marked as such, and must not be
29      misrepresented as being the original software.
30   3. This notice may not be removed or altered from any source distribution.
31 
32         ---------------------------------------------------------------------------
33 
34         Changes
35 
36         See header of zip.h
37 
38 */
39 
40 #ifndef _zip12_H
41 #define _zip12_H
42 
43 #ifdef __cplusplus
44 extern "C"
45 {
46 #endif
47 
48 	//#define HAVE_BZIP2
49 
50 #ifndef _ZLIB_H
51 #include "../zlib/zlib.h"
52 #endif
53 
54 #ifndef _ZLIBIOAPI_H
55 #include "ioapi.h"
56 #endif
57 
58 #ifdef HAVE_BZIP2
59 #include "bzlib.h"
60 #endif
61 
62 #define Z_BZIP2ED 12
63 
64 #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
65 	/* like the STRICT of WIN32, we define a pointer that cannot be converted
66     from (void*) without cast */
67 	typedef struct TagzipFile__
68 	{
69 		int unused;
70 	} zipFile__;
71 	typedef zipFile__* zipFile;
72 #else
73 typedef voidp zipFile;
74 #endif
75 
76 #define ZIP_OK (0)
77 #define ZIP_EOF (0)
78 #define ZIP_ERRNO (Z_ERRNO)
79 #define ZIP_PARAMERROR (-102)
80 #define ZIP_BADZIPFILE (-103)
81 #define ZIP_INTERNALERROR (-104)
82 
83 #ifndef DEF_MEM_LEVEL
84 #if MAX_MEM_LEVEL >= 8
85 #define DEF_MEM_LEVEL 8
86 #else
87 #define DEF_MEM_LEVEL MAX_MEM_LEVEL
88 #endif
89 #endif
90 	/* default memLevel */
91 
92 	/* tm_zip contain date/time info */
93 	typedef struct tm_zip_s
94 	{
95 		uInt tm_sec;  /* seconds after the minute - [0,59] */
96 		uInt tm_min;  /* minutes after the hour - [0,59] */
97 		uInt tm_hour; /* hours since midnight - [0,23] */
98 		uInt tm_mday; /* day of the month - [1,31] */
99 		uInt tm_mon;  /* months since January - [0,11] */
100 		uInt tm_year; /* years - [1980..2044] */
101 	} tm_zip;
102 
103 	typedef struct
104 	{
105 		tm_zip tmz_date;                  /* date in understandable format           */
106 		uLong dosDate;                    /* if dos_date == 0, tmu_date is used      */
107 		/*    uLong       flag;        */ /* general purpose bit flag        2 bytes */
108 
109 		uLong internal_fa; /* internal file attributes        2 bytes */
110 		uLong external_fa; /* external file attributes        4 bytes */
111 	} zip_fileinfo;
112 
113 	typedef const char* zipcharpc;
114 
115 #define APPEND_STATUS_CREATE (0)
116 #define APPEND_STATUS_CREATEAFTER (1)
117 #define APPEND_STATUS_ADDINZIP (2)
118 
119 	extern zipFile ZEXPORT zipOpen OF((const char* pathname, int append));
120 	extern zipFile ZEXPORT zipOpen64 OF((const void* pathname, int append));
121 	/*
122   Create a zipfile.
123      pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
124        an Unix computer "zlib/zlib113.zip".
125      if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
126        will be created at the end of the file.
127          (useful if the file contain a self extractor code)
128      if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
129        add files in existing zip (be sure you don't add file that doesn't exist)
130      If the zipfile cannot be opened, the return value is NULL.
131      Else, the return value is a zipFile Handle, usable with other function
132        of this zip package.
133 */
134 
135 	/* Note : there is no delete function into a zipfile.
136    If you want delete file into a zipfile, you must open a zipfile, and create another
137    Of couse, you can use RAW reading and writing to copy the file you did not want delte
138 */
139 
140 	extern zipFile ZEXPORT zipOpen2 OF((const char* pathname,
141 										int append,
142 										zipcharpc* globalcomment,
143 										zlib_filefunc_def* pzlib_filefunc_def));
144 
145 	extern zipFile ZEXPORT zipOpen2_64 OF((const void* pathname,
146 										   int append,
147 										   zipcharpc* globalcomment,
148 										   zlib_filefunc64_def* pzlib_filefunc_def));
149 
150 	extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
151 											   const char* filename,
152 											   const zip_fileinfo* zipfi,
153 											   const void* extrafield_local,
154 											   uInt size_extrafield_local,
155 											   const void* extrafield_global,
156 											   uInt size_extrafield_global,
157 											   const char* comment,
158 											   int method,
159 											   int level));
160 
161 	extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
162 												 const char* filename,
163 												 const zip_fileinfo* zipfi,
164 												 const void* extrafield_local,
165 												 uInt size_extrafield_local,
166 												 const void* extrafield_global,
167 												 uInt size_extrafield_global,
168 												 const char* comment,
169 												 int method,
170 												 int level,
171 												 int zip64));
172 
173 	/*
174   Open a file in the ZIP for writing.
175   filename : the filename in zip (if NULL, '-' without quote will be used
176   *zipfi contain supplemental information
177   if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
178     contains the extrafield data the the local header
179   if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
180     contains the extrafield data the the local header
181   if comment != NULL, comment contain the comment string
182   method contain the compression method (0 for store, Z_DEFLATED for deflate)
183   level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
184   zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
185                     this MUST be '1' if the uncompressed size is >= 0xffffffff.
186 
187 */
188 
189 	extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
190 												const char* filename,
191 												const zip_fileinfo* zipfi,
192 												const void* extrafield_local,
193 												uInt size_extrafield_local,
194 												const void* extrafield_global,
195 												uInt size_extrafield_global,
196 												const char* comment,
197 												int method,
198 												int level,
199 												int raw));
200 
201 	extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
202 												   const char* filename,
203 												   const zip_fileinfo* zipfi,
204 												   const void* extrafield_local,
205 												   uInt size_extrafield_local,
206 												   const void* extrafield_global,
207 												   uInt size_extrafield_global,
208 												   const char* comment,
209 												   int method,
210 												   int level,
211 												   int raw,
212 												   int zip64));
213 	/*
214   Same than zipOpenNewFileInZip, except if raw=1, we write raw file
215  */
216 
217 	extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
218 												const char* filename,
219 												const zip_fileinfo* zipfi,
220 												const void* extrafield_local,
221 												uInt size_extrafield_local,
222 												const void* extrafield_global,
223 												uInt size_extrafield_global,
224 												const char* comment,
225 												int method,
226 												int level,
227 												int raw,
228 												int windowBits,
229 												int memLevel,
230 												int strategy,
231 												const char* password,
232 												uLong crcForCrypting));
233 
234 	extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
235 												   const char* filename,
236 												   const zip_fileinfo* zipfi,
237 												   const void* extrafield_local,
238 												   uInt size_extrafield_local,
239 												   const void* extrafield_global,
240 												   uInt size_extrafield_global,
241 												   const char* comment,
242 												   int method,
243 												   int level,
244 												   int raw,
245 												   int windowBits,
246 												   int memLevel,
247 												   int strategy,
248 												   const char* password,
249 												   uLong crcForCrypting,
250 												   int zip64));
251 
252 	/*
253   Same than zipOpenNewFileInZip2, except
254     windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
255     password : crypting password (NULL for no crypting)
256     crcForCrypting : crc of file to compress (needed for crypting)
257  */
258 
259 	extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
260 												const char* filename,
261 												const zip_fileinfo* zipfi,
262 												const void* extrafield_local,
263 												uInt size_extrafield_local,
264 												const void* extrafield_global,
265 												uInt size_extrafield_global,
266 												const char* comment,
267 												int method,
268 												int level,
269 												int raw,
270 												int windowBits,
271 												int memLevel,
272 												int strategy,
273 												const char* password,
274 												uLong crcForCrypting,
275 												uLong versionMadeBy,
276 												uLong flagBase));
277 
278 	extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
279 												   const char* filename,
280 												   const zip_fileinfo* zipfi,
281 												   const void* extrafield_local,
282 												   uInt size_extrafield_local,
283 												   const void* extrafield_global,
284 												   uInt size_extrafield_global,
285 												   const char* comment,
286 												   int method,
287 												   int level,
288 												   int raw,
289 												   int windowBits,
290 												   int memLevel,
291 												   int strategy,
292 												   const char* password,
293 												   uLong crcForCrypting,
294 												   uLong versionMadeBy,
295 												   uLong flagBase,
296 												   int zip64));
297 	/*
298   Same than zipOpenNewFileInZip4, except
299     versionMadeBy : value for Version made by field
300     flag : value for flag field (compression level info will be added)
301  */
302 
303 	extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
304 											   const void* buf,
305 											   unsigned len));
306 	/*
307   Write data in the zipfile
308 */
309 
310 	extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
311 	/*
312   Close the current file in the zipfile
313 */
314 
315 	extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
316 												uLong uncompressed_size,
317 												uLong crc32));
318 
319 	extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
320 												  ZPOS64_T uncompressed_size,
321 												  uLong crc32));
322 
323 	/*
324   Close the current file in the zipfile, for file opened with
325     parameter raw=1 in zipOpenNewFileInZip2
326   uncompressed_size and crc32 are value for the uncompressed size
327 */
328 
329 	extern int ZEXPORT zipClose OF((zipFile file,
330 									const char* global_comment));
331 	/*
332   Close the zipfile
333 */
334 
335 	extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
336 	/*
337   zipRemoveExtraInfoBlock -  Added by Mathias Svensson
338 
339   Remove extra information block from a extra information data for the local file header or central directory header
340 
341   It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
342 
343   0x0001 is the signature header for the ZIP64 extra information blocks
344 
345   usage.
346                         Remove ZIP64 Extra information from a central director extra field data
347               zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
348 
349                         Remove ZIP64 Extra information from a Local File Header extra field data
350         zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
351 */
352 
353 #ifdef __cplusplus
354 }
355 #endif
356 
357 #endif /* _zip64_H */
358