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