1101497Smike/*	$NetBSD$	*/
2101497Smike
3101497Smike/* unzip.h -- IO for uncompress .zip files using zlib
4101497Smike   Version 1.01e, February 12th, 2005
5101497Smike
6101497Smike   Copyright (C) 1998-2005 Gilles Vollant
7101497Smike
8101497Smike   This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
9101497Smike     WinZip, InfoZip tools and compatible.
10101497Smike
11101497Smike   Multi volume ZipFile (span) are not supported.
12101497Smike   Encryption compatible with pkzip 2.04g only supported
13101497Smike   Old compressions used by old PKZip 1.x are not supported
14101497Smike
15101497Smike
16101497Smike   I WAIT FEEDBACK at mail info@winimage.com
17101497Smike   Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
18101497Smike
19101497Smike   Condition of use and distribution are the same than zlib :
20101497Smike
21101497Smike  This software is provided 'as-is', without any express or implied
22101497Smike  warranty.  In no event will the authors be held liable for any damages
23101497Smike  arising from the use of this software.
24101497Smike
25101497Smike  Permission is granted to anyone to use this software for any purpose,
26108637Stjr  including commercial applications, and to alter it and redistribute it
27101497Smike  freely, subject to the following restrictions:
28101497Smike
29101497Smike  1. The origin of this software must not be misrepresented; you must not
30101497Smike     claim that you wrote the original software. If you use this software
31101497Smike     in a product, an acknowledgment in the product documentation would be
32101497Smike     appreciated but is not required.
33101497Smike  2. Altered source versions must be plainly marked as such, and must not be
34101497Smike     misrepresented as being the original software.
35101497Smike  3. This notice may not be removed or altered from any source distribution.
36101497Smike
37101497Smike
38101497Smike*/
39101497Smike
40101497Smike/* for more info about .ZIP format, see
41101497Smike      http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
42101497Smike      http://www.info-zip.org/pub/infozip/doc/
43101497Smike   PkWare has also a specification at :
44107592Sru      ftp://ftp.pkware.com/probdesc.zip
45108087Sru*/
46108637Stjr
47108637Stjr#ifndef _unz_H
48101497Smike#define _unz_H
49101497Smike
50108637Stjr#ifdef __cplusplus
51101497Smikeextern "C" {
52101497Smike#endif
53101497Smike
54101497Smike#ifndef _ZLIB_H
55101497Smike#include "zlib.h"
56101497Smike#endif
57101497Smike
58107592Sru#ifndef _ZLIBIOAPI_H
59108040Sru#include "ioapi.h"
60101497Smike#endif
61101497Smike
62101497Smike#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
63101497Smike/* like the STRICT of WIN32, we define a pointer that cannot be converted
64101497Smike    from (void*) without cast */
65101497Smiketypedef struct TagunzFile__ { int unused; } unzFile__;
66101497Smiketypedef unzFile__ *unzFile;
67101497Smike#else
68101497Smiketypedef voidp unzFile;
69101497Smike#endif
70101497Smike
71101497Smike
72101497Smike#define UNZ_OK                          (0)
73101497Smike#define UNZ_END_OF_LIST_OF_FILE         (-100)
74101497Smike#define UNZ_ERRNO                       (Z_ERRNO)
75101497Smike#define UNZ_EOF                         (0)
76101497Smike#define UNZ_PARAMERROR                  (-102)
77101497Smike#define UNZ_BADZIPFILE                  (-103)
78101497Smike#define UNZ_INTERNALERROR               (-104)
79101497Smike#define UNZ_CRCERROR                    (-105)
80101497Smike
81101497Smike/* tm_unz contain date/time info */
82101497Smiketypedef struct tm_unz_s
83101497Smike{
84101497Smike    uInt tm_sec;            /* seconds after the minute - [0,59] */
85101497Smike    uInt tm_min;            /* minutes after the hour - [0,59] */
86101497Smike    uInt tm_hour;           /* hours since midnight - [0,23] */
87101497Smike    uInt tm_mday;           /* day of the month - [1,31] */
88101497Smike    uInt tm_mon;            /* months since January - [0,11] */
89101497Smike    uInt tm_year;           /* years - [1980..2044] */
90101497Smike} tm_unz;
91101497Smike
92101497Smike/* unz_global_info structure contain global data about the ZIPfile
93101497Smike   These data comes from the end of central dir */
94101497Smiketypedef struct unz_global_info_s
95101497Smike{
96101497Smike    uLong number_entry;         /* total number of entries in
97101497Smike                       the central dir on this disk */
98101497Smike    uLong size_comment;         /* size of the global comment of the zipfile */
99} unz_global_info;
100
101
102/* unz_file_info contain information about a file in the zipfile */
103typedef struct unz_file_info_s
104{
105    uLong version;              /* version made by                 2 bytes */
106    uLong version_needed;       /* version needed to extract       2 bytes */
107    uLong flag;                 /* general purpose bit flag        2 bytes */
108    uLong compression_method;   /* compression method              2 bytes */
109    uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
110    uLong crc;                  /* crc-32                          4 bytes */
111    uLong compressed_size;      /* compressed size                 4 bytes */
112    uLong uncompressed_size;    /* uncompressed size               4 bytes */
113    uLong size_filename;        /* filename length                 2 bytes */
114    uLong size_file_extra;      /* extra field length              2 bytes */
115    uLong size_file_comment;    /* file comment length             2 bytes */
116
117    uLong disk_num_start;       /* disk number start               2 bytes */
118    uLong internal_fa;          /* internal file attributes        2 bytes */
119    uLong external_fa;          /* external file attributes        4 bytes */
120
121    tm_unz tmu_date;
122} unz_file_info;
123
124extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
125                                                 const char* fileName2,
126                                                 int iCaseSensitivity));
127/*
128   Compare two filename (fileName1,fileName2).
129   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
130   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
131                                or strcasecmp)
132   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
133    (like 1 on Unix, 2 on Windows)
134*/
135
136
137extern unzFile ZEXPORT unzOpen OF((const char *path));
138/*
139  Open a Zip file. path contain the full pathname (by example,
140     on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
141     "zlib/zlib113.zip".
142     If the zipfile cannot be opened (file don't exist or in not valid), the
143       return value is NULL.
144     Else, the return value is a unzFile Handle, usable with other function
145       of this unzip package.
146*/
147
148extern unzFile ZEXPORT unzOpen2 OF((const char *path,
149                                    zlib_filefunc_def* pzlib_filefunc_def));
150/*
151   Open a Zip file, like unzOpen, but provide a set of file low level API
152      for read/write the zip file (see ioapi.h)
153*/
154
155extern int ZEXPORT unzClose OF((unzFile file));
156/*
157  Close a ZipFile opened with unzipOpen.
158  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
159    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
160  return UNZ_OK if there is no problem. */
161
162extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
163                                        unz_global_info *pglobal_info));
164/*
165  Write info about the ZipFile in the *pglobal_info structure.
166  No preparation of the structure is needed
167  return UNZ_OK if there is no problem. */
168
169
170extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
171                                           char *szComment,
172                                           uLong uSizeBuf));
173/*
174  Get the global comment string of the ZipFile, in the szComment buffer.
175  uSizeBuf is the size of the szComment buffer.
176  return the number of byte copied or an error code <0
177*/
178
179
180/***************************************************************************/
181/* Unzip package allow you browse the directory of the zipfile */
182
183extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
184/*
185  Set the current file of the zipfile to the first file.
186  return UNZ_OK if there is no problem
187*/
188
189extern int ZEXPORT unzGoToNextFile OF((unzFile file));
190/*
191  Set the current file of the zipfile to the next file.
192  return UNZ_OK if there is no problem
193  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
194*/
195
196extern int ZEXPORT unzLocateFile OF((unzFile file,
197                     const char *szFileName,
198                     int iCaseSensitivity));
199/*
200  Try locate the file szFileName in the zipfile.
201  For the iCaseSensitivity signification, see unzStringFileNameCompare
202
203  return value :
204  UNZ_OK if the file is found. It becomes the current file.
205  UNZ_END_OF_LIST_OF_FILE if the file is not found
206*/
207
208
209/* ****************************************** */
210/* Ryan supplied functions */
211/* unz_file_info contain information about a file in the zipfile */
212typedef struct unz_file_pos_s
213{
214    uLong pos_in_zip_directory;   /* offset in zip file directory */
215    uLong num_of_file;            /* # of file */
216} unz_file_pos;
217
218extern int ZEXPORT unzGetFilePos(
219    unzFile file,
220    unz_file_pos* file_pos);
221
222extern int ZEXPORT unzGoToFilePos(
223    unzFile file,
224    unz_file_pos* file_pos);
225
226/* ****************************************** */
227
228extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
229                         unz_file_info *pfile_info,
230                         char *szFileName,
231                         uLong fileNameBufferSize,
232                         void *extraField,
233                         uLong extraFieldBufferSize,
234                         char *szComment,
235                         uLong commentBufferSize));
236/*
237  Get Info about the current file
238  if pfile_info!=NULL, the *pfile_info structure will contain somes info about
239        the current file
240  if szFileName!=NULL, the filemane string will be copied in szFileName
241            (fileNameBufferSize is the size of the buffer)
242  if extraField!=NULL, the extra field information will be copied in extraField
243            (extraFieldBufferSize is the size of the buffer).
244            This is the Central-header version of the extra field
245  if szComment!=NULL, the comment string of the file will be copied in szComment
246            (commentBufferSize is the size of the buffer)
247*/
248
249/***************************************************************************/
250/* for reading the content of the current zipfile, you can open it, read data
251   from it, and close it (you can close it before reading all the file)
252   */
253
254extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
255/*
256  Open for reading data the current file in the zipfile.
257  If there is no error, the return value is UNZ_OK.
258*/
259
260extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
261                                                  const char* password));
262/*
263  Open for reading data the current file in the zipfile.
264  password is a crypting password
265  If there is no error, the return value is UNZ_OK.
266*/
267
268extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
269                                           int* method,
270                                           int* level,
271                                           int raw));
272/*
273  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
274    if raw==1
275  *method will receive method of compression, *level will receive level of
276     compression
277  note : you can set level parameter as NULL (if you did not want known level,
278         but you CANNOT set method parameter as NULL
279*/
280
281extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
282                                           int* method,
283                                           int* level,
284                                           int raw,
285                                           const char* password));
286/*
287  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
288    if raw==1
289  *method will receive method of compression, *level will receive level of
290     compression
291  note : you can set level parameter as NULL (if you did not want known level,
292         but you CANNOT set method parameter as NULL
293*/
294
295
296extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
297/*
298  Close the file in zip opened with unzOpenCurrentFile
299  Return UNZ_CRCERROR if all the file was read but the CRC is not good
300*/
301
302extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
303                      voidp buf,
304                      unsigned len));
305/*
306  Read bytes from the current file (opened by unzOpenCurrentFile)
307  buf contain buffer where data must be copied
308  len the size of buf.
309
310  return the number of byte copied if somes bytes are copied
311  return 0 if the end of file was reached
312  return <0 with error code if there is an error
313    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
314*/
315
316extern z_off_t ZEXPORT unztell OF((unzFile file));
317/*
318  Give the current position in uncompressed data
319*/
320
321extern int ZEXPORT unzeof OF((unzFile file));
322/*
323  return 1 if the end of file was reached, 0 elsewhere
324*/
325
326extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
327                                             voidp buf,
328                                             unsigned len));
329/*
330  Read extra field from the current file (opened by unzOpenCurrentFile)
331  This is the local-header version of the extra field (sometimes, there is
332    more info in the local-header version than in the central-header)
333
334  if buf==NULL, it return the size of the local extra field
335
336  if buf!=NULL, len is the size of the buffer, the extra header is copied in
337    buf.
338  the return value is the number of bytes copied in buf, or (if <0)
339    the error code
340*/
341
342/***************************************************************************/
343
344/* Get the current file offset */
345extern uLong ZEXPORT unzGetOffset (unzFile file);
346
347/* Set the current file offset */
348extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
349
350
351
352#ifdef __cplusplus
353}
354#endif
355
356#endif /* _unz_H */
357