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