1*5c66ce18SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5c66ce18SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5c66ce18SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5c66ce18SAndrew Rist  * distributed with this work for additional information
6*5c66ce18SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5c66ce18SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5c66ce18SAndrew Rist  * "License"); you may not use this file except in compliance
9*5c66ce18SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5c66ce18SAndrew Rist  *
11*5c66ce18SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5c66ce18SAndrew Rist  *
13*5c66ce18SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5c66ce18SAndrew Rist  * software distributed under the License is distributed on an
15*5c66ce18SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5c66ce18SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5c66ce18SAndrew Rist  * specific language governing permissions and limitations
18*5c66ce18SAndrew Rist  * under the License.
19*5c66ce18SAndrew Rist  *
20*5c66ce18SAndrew Rist  *************************************************************/
21*5c66ce18SAndrew Rist 
22*5c66ce18SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir /* unzip.h -- IO for uncompress .zip files using zlib
25cdf0e10cSrcweir    Version 1.01e, February 12th, 2005
26cdf0e10cSrcweir 
27cdf0e10cSrcweir    Copyright (C) 1998-2005 Gilles Vollant
28cdf0e10cSrcweir 
29cdf0e10cSrcweir    This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
30cdf0e10cSrcweir      WinZip, InfoZip tools and compatible.
31cdf0e10cSrcweir 
32cdf0e10cSrcweir    Multi volume ZipFile (span) are not supported.
33cdf0e10cSrcweir    Encryption compatible with pkzip 2.04g only supported
34cdf0e10cSrcweir    Old compressions used by old PKZip 1.x are not supported
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir    I WAIT FEEDBACK at mail info@winimage.com
38cdf0e10cSrcweir    Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
39cdf0e10cSrcweir 
40cdf0e10cSrcweir    Condition of use and distribution are the same than zlib :
41cdf0e10cSrcweir 
42cdf0e10cSrcweir   This software is provided 'as-is', without any express or implied
43cdf0e10cSrcweir   warranty.  In no event will the authors be held liable for any damages
44cdf0e10cSrcweir   arising from the use of this software.
45cdf0e10cSrcweir 
46cdf0e10cSrcweir   Permission is granted to anyone to use this software for any purpose,
47cdf0e10cSrcweir   including commercial applications, and to alter it and redistribute it
48cdf0e10cSrcweir   freely, subject to the following restrictions:
49cdf0e10cSrcweir 
50cdf0e10cSrcweir   1. The origin of this software must not be misrepresented; you must not
51cdf0e10cSrcweir      claim that you wrote the original software. If you use this software
52cdf0e10cSrcweir      in a product, an acknowledgment in the product documentation would be
53cdf0e10cSrcweir      appreciated but is not required.
54cdf0e10cSrcweir   2. Altered source versions must be plainly marked as such, and must not be
55cdf0e10cSrcweir      misrepresented as being the original software.
56cdf0e10cSrcweir   3. This notice may not be removed or altered from any source distribution.
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir */
60cdf0e10cSrcweir 
61cdf0e10cSrcweir /* for more info about .ZIP format, see
62cdf0e10cSrcweir       http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
63cdf0e10cSrcweir       http://www.info-zip.org/pub/infozip/doc/
64cdf0e10cSrcweir    PkWare has also a specification at :
65cdf0e10cSrcweir       ftp://ftp.pkware.com/probdesc.zip
66cdf0e10cSrcweir */
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #ifndef _unz_H
69cdf0e10cSrcweir #define _unz_H
70cdf0e10cSrcweir 
71cdf0e10cSrcweir #ifdef __cplusplus
72cdf0e10cSrcweir extern "C" {
73cdf0e10cSrcweir #endif
74cdf0e10cSrcweir 
75cdf0e10cSrcweir #include <zlib.h>
76cdf0e10cSrcweir 
77cdf0e10cSrcweir #include "ioapi.h"
78cdf0e10cSrcweir 
79cdf0e10cSrcweir #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
80cdf0e10cSrcweir /* like the STRICT of WIN32, we define a pointer that cannot be converted
81cdf0e10cSrcweir     from (void*) without cast */
82cdf0e10cSrcweir typedef struct TagunzFile__ { int unused; } unzFile__;
83cdf0e10cSrcweir typedef unzFile__ *unzFile;
84cdf0e10cSrcweir #else
85cdf0e10cSrcweir typedef voidp unzFile;
86cdf0e10cSrcweir #endif
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 
89cdf0e10cSrcweir #define UNZ_OK                          (0)
90cdf0e10cSrcweir #define UNZ_END_OF_LIST_OF_FILE         (-100)
91cdf0e10cSrcweir #define UNZ_ERRNO                       (Z_ERRNO)
92cdf0e10cSrcweir #define UNZ_EOF                         (0)
93cdf0e10cSrcweir #define UNZ_PARAMERROR                  (-102)
94cdf0e10cSrcweir #define UNZ_BADZIPFILE                  (-103)
95cdf0e10cSrcweir #define UNZ_INTERNALERROR               (-104)
96cdf0e10cSrcweir #define UNZ_CRCERROR                    (-105)
97cdf0e10cSrcweir 
98cdf0e10cSrcweir /* tm_unz contain date/time info */
99cdf0e10cSrcweir typedef struct tm_unz_s
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     uInt tm_sec;            /* seconds after the minute - [0,59] */
102cdf0e10cSrcweir     uInt tm_min;            /* minutes after the hour - [0,59] */
103cdf0e10cSrcweir     uInt tm_hour;           /* hours since midnight - [0,23] */
104cdf0e10cSrcweir     uInt tm_mday;           /* day of the month - [1,31] */
105cdf0e10cSrcweir     uInt tm_mon;            /* months since January - [0,11] */
106cdf0e10cSrcweir     uInt tm_year;           /* years - [1980..2044] */
107cdf0e10cSrcweir } tm_unz;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir /* unz_global_info structure contain global data about the ZIPfile
110cdf0e10cSrcweir    These data comes from the end of central dir */
111cdf0e10cSrcweir typedef struct unz_global_info_s
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     uLong number_entry;         /* total number of entries in
114cdf0e10cSrcweir                        the central dir on this disk */
115cdf0e10cSrcweir     uLong size_comment;         /* size of the global comment of the zipfile */
116cdf0e10cSrcweir } unz_global_info;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir /* unz_file_info contain information about a file in the zipfile */
120cdf0e10cSrcweir typedef struct unz_file_info_s
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     uLong version;              /* version made by                 2 bytes */
123cdf0e10cSrcweir     uLong version_needed;       /* version needed to extract       2 bytes */
124cdf0e10cSrcweir     uLong flag;                 /* general purpose bit flag        2 bytes */
125cdf0e10cSrcweir     uLong compression_method;   /* compression method              2 bytes */
126cdf0e10cSrcweir     uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
127cdf0e10cSrcweir     uLong crc;                  /* crc-32                          4 bytes */
128cdf0e10cSrcweir     uLong compressed_size;      /* compressed size                 4 bytes */
129cdf0e10cSrcweir     uLong uncompressed_size;    /* uncompressed size               4 bytes */
130cdf0e10cSrcweir     uLong size_filename;        /* filename length                 2 bytes */
131cdf0e10cSrcweir     uLong size_file_extra;      /* extra field length              2 bytes */
132cdf0e10cSrcweir     uLong size_file_comment;    /* file comment length             2 bytes */
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     uLong disk_num_start;       /* disk number start               2 bytes */
135cdf0e10cSrcweir     uLong internal_fa;          /* internal file attributes        2 bytes */
136cdf0e10cSrcweir     uLong external_fa;          /* external file attributes        4 bytes */
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     tm_unz tmu_date;
139cdf0e10cSrcweir } unz_file_info;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
142cdf0e10cSrcweir                                                  const char* fileName2,
143cdf0e10cSrcweir                                                  int iCaseSensitivity));
144cdf0e10cSrcweir /*
145cdf0e10cSrcweir    Compare two filename (fileName1,fileName2).
146cdf0e10cSrcweir    If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
147cdf0e10cSrcweir    If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
148cdf0e10cSrcweir                                 or strcasecmp)
149cdf0e10cSrcweir    If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
150cdf0e10cSrcweir     (like 1 on Unix, 2 on Windows)
151cdf0e10cSrcweir */
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 
154cdf0e10cSrcweir extern unzFile ZEXPORT unzOpen OF((const char *path));
155cdf0e10cSrcweir /*
156cdf0e10cSrcweir   Open a Zip file. path contain the full pathname (by example,
157cdf0e10cSrcweir      on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
158cdf0e10cSrcweir      "zlib/zlib113.zip".
159cdf0e10cSrcweir      If the zipfile cannot be opened (file don't exist or in not valid), the
160cdf0e10cSrcweir        return value is NULL.
161cdf0e10cSrcweir      Else, the return value is a unzFile Handle, usable with other function
162cdf0e10cSrcweir        of this unzip package.
163cdf0e10cSrcweir */
164cdf0e10cSrcweir 
165cdf0e10cSrcweir extern unzFile ZEXPORT unzOpen2 OF((const char *path,
166cdf0e10cSrcweir                                     zlib_filefunc_def* pzlib_filefunc_def));
167cdf0e10cSrcweir /*
168cdf0e10cSrcweir    Open a Zip file, like unzOpen, but provide a set of file low level API
169cdf0e10cSrcweir       for read/write the zip file (see ioapi.h)
170cdf0e10cSrcweir */
171cdf0e10cSrcweir 
172cdf0e10cSrcweir extern int ZEXPORT unzClose OF((unzFile file));
173cdf0e10cSrcweir /*
174cdf0e10cSrcweir   Close a ZipFile opened with unzipOpen.
175cdf0e10cSrcweir   If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
176cdf0e10cSrcweir     these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
177cdf0e10cSrcweir   return UNZ_OK if there is no problem. */
178cdf0e10cSrcweir 
179cdf0e10cSrcweir extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
180cdf0e10cSrcweir                                         unz_global_info *pglobal_info));
181cdf0e10cSrcweir /*
182cdf0e10cSrcweir   Write info about the ZipFile in the *pglobal_info structure.
183cdf0e10cSrcweir   No preparation of the structure is needed
184cdf0e10cSrcweir   return UNZ_OK if there is no problem. */
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
187cdf0e10cSrcweir extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
188cdf0e10cSrcweir                                            char *szComment,
189cdf0e10cSrcweir                                            uLong uSizeBuf));
190cdf0e10cSrcweir /*
191cdf0e10cSrcweir   Get the global comment string of the ZipFile, in the szComment buffer.
192cdf0e10cSrcweir   uSizeBuf is the size of the szComment buffer.
193cdf0e10cSrcweir   return the number of byte copied or an error code <0
194cdf0e10cSrcweir */
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 
197cdf0e10cSrcweir /***************************************************************************/
198cdf0e10cSrcweir /* Unzip package allow you browse the directory of the zipfile */
199cdf0e10cSrcweir 
200cdf0e10cSrcweir extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
201cdf0e10cSrcweir /*
202cdf0e10cSrcweir   Set the current file of the zipfile to the first file.
203cdf0e10cSrcweir   return UNZ_OK if there is no problem
204cdf0e10cSrcweir */
205cdf0e10cSrcweir 
206cdf0e10cSrcweir extern int ZEXPORT unzGoToNextFile OF((unzFile file));
207cdf0e10cSrcweir /*
208cdf0e10cSrcweir   Set the current file of the zipfile to the next file.
209cdf0e10cSrcweir   return UNZ_OK if there is no problem
210cdf0e10cSrcweir   return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
211cdf0e10cSrcweir */
212cdf0e10cSrcweir 
213cdf0e10cSrcweir extern int ZEXPORT unzLocateFile OF((unzFile file,
214cdf0e10cSrcweir                      const char *szFileName,
215cdf0e10cSrcweir                      int iCaseSensitivity));
216cdf0e10cSrcweir /*
217cdf0e10cSrcweir   Try locate the file szFileName in the zipfile.
218cdf0e10cSrcweir   For the iCaseSensitivity signification, see unzStringFileNameCompare
219cdf0e10cSrcweir 
220cdf0e10cSrcweir   return value :
221cdf0e10cSrcweir   UNZ_OK if the file is found. It becomes the current file.
222cdf0e10cSrcweir   UNZ_END_OF_LIST_OF_FILE if the file is not found
223cdf0e10cSrcweir */
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 
226cdf0e10cSrcweir /* ****************************************** */
227cdf0e10cSrcweir /* Ryan supplied functions */
228cdf0e10cSrcweir /* unz_file_info contain information about a file in the zipfile */
229cdf0e10cSrcweir typedef struct unz_file_pos_s
230cdf0e10cSrcweir {
231cdf0e10cSrcweir     uLong pos_in_zip_directory;   /* offset in zip file directory */
232cdf0e10cSrcweir     uLong num_of_file;            /* # of file */
233cdf0e10cSrcweir } unz_file_pos;
234cdf0e10cSrcweir 
235cdf0e10cSrcweir extern int ZEXPORT unzGetFilePos(
236cdf0e10cSrcweir     unzFile file,
237cdf0e10cSrcweir     unz_file_pos* file_pos);
238cdf0e10cSrcweir 
239cdf0e10cSrcweir extern int ZEXPORT unzGoToFilePos(
240cdf0e10cSrcweir     unzFile file,
241cdf0e10cSrcweir     unz_file_pos* file_pos);
242cdf0e10cSrcweir 
243cdf0e10cSrcweir /* ****************************************** */
244cdf0e10cSrcweir 
245cdf0e10cSrcweir extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
246cdf0e10cSrcweir                          unz_file_info *pfile_info,
247cdf0e10cSrcweir                          char *szFileName,
248cdf0e10cSrcweir                          uLong fileNameBufferSize,
249cdf0e10cSrcweir                          void *extraField,
250cdf0e10cSrcweir                          uLong extraFieldBufferSize,
251cdf0e10cSrcweir                          char *szComment,
252cdf0e10cSrcweir                          uLong commentBufferSize));
253cdf0e10cSrcweir /*
254cdf0e10cSrcweir   Get Info about the current file
255cdf0e10cSrcweir   if pfile_info!=NULL, the *pfile_info structure will contain somes info about
256cdf0e10cSrcweir         the current file
257cdf0e10cSrcweir   if szFileName!=NULL, the filemane string will be copied in szFileName
258cdf0e10cSrcweir             (fileNameBufferSize is the size of the buffer)
259cdf0e10cSrcweir   if extraField!=NULL, the extra field information will be copied in extraField
260cdf0e10cSrcweir             (extraFieldBufferSize is the size of the buffer).
261cdf0e10cSrcweir             This is the Central-header version of the extra field
262cdf0e10cSrcweir   if szComment!=NULL, the comment string of the file will be copied in szComment
263cdf0e10cSrcweir             (commentBufferSize is the size of the buffer)
264cdf0e10cSrcweir */
265cdf0e10cSrcweir 
266cdf0e10cSrcweir /***************************************************************************/
267cdf0e10cSrcweir /* for reading the content of the current zipfile, you can open it, read data
268cdf0e10cSrcweir    from it, and close it (you can close it before reading all the file)
269cdf0e10cSrcweir    */
270cdf0e10cSrcweir 
271cdf0e10cSrcweir extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
272cdf0e10cSrcweir /*
273cdf0e10cSrcweir   Open for reading data the current file in the zipfile.
274cdf0e10cSrcweir   If there is no error, the return value is UNZ_OK.
275cdf0e10cSrcweir */
276cdf0e10cSrcweir 
277cdf0e10cSrcweir extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
278cdf0e10cSrcweir                                                   const char* password));
279cdf0e10cSrcweir /*
280cdf0e10cSrcweir   Open for reading data the current file in the zipfile.
281cdf0e10cSrcweir   password is a crypting password
282cdf0e10cSrcweir   If there is no error, the return value is UNZ_OK.
283cdf0e10cSrcweir */
284cdf0e10cSrcweir 
285cdf0e10cSrcweir extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
286cdf0e10cSrcweir                                            int* method,
287cdf0e10cSrcweir                                            int* level,
288cdf0e10cSrcweir                                            int raw));
289cdf0e10cSrcweir /*
290cdf0e10cSrcweir   Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
291cdf0e10cSrcweir     if raw==1
292cdf0e10cSrcweir   *method will receive method of compression, *level will receive level of
293cdf0e10cSrcweir      compression
294cdf0e10cSrcweir   note : you can set level parameter as NULL (if you did not want known level,
295cdf0e10cSrcweir          but you CANNOT set method parameter as NULL
296cdf0e10cSrcweir */
297cdf0e10cSrcweir 
298cdf0e10cSrcweir extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
299cdf0e10cSrcweir                                            int* method,
300cdf0e10cSrcweir                                            int* level,
301cdf0e10cSrcweir                                            int raw,
302cdf0e10cSrcweir                                            const char* password));
303cdf0e10cSrcweir /*
304cdf0e10cSrcweir   Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
305cdf0e10cSrcweir     if raw==1
306cdf0e10cSrcweir   *method will receive method of compression, *level will receive level of
307cdf0e10cSrcweir      compression
308cdf0e10cSrcweir   note : you can set level parameter as NULL (if you did not want known level,
309cdf0e10cSrcweir          but you CANNOT set method parameter as NULL
310cdf0e10cSrcweir */
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 
313cdf0e10cSrcweir extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
314cdf0e10cSrcweir /*
315cdf0e10cSrcweir   Close the file in zip opened with unzOpenCurrentFile
316cdf0e10cSrcweir   Return UNZ_CRCERROR if all the file was read but the CRC is not good
317cdf0e10cSrcweir */
318cdf0e10cSrcweir 
319cdf0e10cSrcweir extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
320cdf0e10cSrcweir                       voidp buf,
321cdf0e10cSrcweir                       unsigned len));
322cdf0e10cSrcweir /*
323cdf0e10cSrcweir   Read bytes from the current file (opened by unzOpenCurrentFile)
324cdf0e10cSrcweir   buf contain buffer where data must be copied
325cdf0e10cSrcweir   len the size of buf.
326cdf0e10cSrcweir 
327cdf0e10cSrcweir   return the number of byte copied if somes bytes are copied
328cdf0e10cSrcweir   return 0 if the end of file was reached
329cdf0e10cSrcweir   return <0 with error code if there is an error
330cdf0e10cSrcweir     (UNZ_ERRNO for IO error, or zLib error for uncompress error)
331cdf0e10cSrcweir */
332cdf0e10cSrcweir 
333cdf0e10cSrcweir extern z_off_t ZEXPORT unztell OF((unzFile file));
334cdf0e10cSrcweir /*
335cdf0e10cSrcweir   Give the current position in uncompressed data
336cdf0e10cSrcweir */
337cdf0e10cSrcweir 
338cdf0e10cSrcweir extern int ZEXPORT unzeof OF((unzFile file));
339cdf0e10cSrcweir /*
340cdf0e10cSrcweir   return 1 if the end of file was reached, 0 elsewhere
341cdf0e10cSrcweir */
342cdf0e10cSrcweir 
343cdf0e10cSrcweir extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
344cdf0e10cSrcweir                                              voidp buf,
345cdf0e10cSrcweir                                              unsigned len));
346cdf0e10cSrcweir /*
347cdf0e10cSrcweir   Read extra field from the current file (opened by unzOpenCurrentFile)
348cdf0e10cSrcweir   This is the local-header version of the extra field (sometimes, there is
349cdf0e10cSrcweir     more info in the local-header version than in the central-header)
350cdf0e10cSrcweir 
351cdf0e10cSrcweir   if buf==NULL, it return the size of the local extra field
352cdf0e10cSrcweir 
353cdf0e10cSrcweir   if buf!=NULL, len is the size of the buffer, the extra header is copied in
354cdf0e10cSrcweir     buf.
355cdf0e10cSrcweir   the return value is the number of bytes copied in buf, or (if <0)
356cdf0e10cSrcweir     the error code
357cdf0e10cSrcweir */
358cdf0e10cSrcweir 
359cdf0e10cSrcweir /***************************************************************************/
360cdf0e10cSrcweir 
361cdf0e10cSrcweir /* Get the current file offset */
362cdf0e10cSrcweir extern uLong ZEXPORT unzGetOffset (unzFile file);
363cdf0e10cSrcweir 
364cdf0e10cSrcweir /* Set the current file offset */
365cdf0e10cSrcweir extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 
369cdf0e10cSrcweir #ifdef __cplusplus
370cdf0e10cSrcweir }
371cdf0e10cSrcweir #endif
372cdf0e10cSrcweir 
373cdf0e10cSrcweir #endif /* _unz_H */
374