GDAL
cpl_minizip_unzip.h
1 /* $Id$ */
2 /* Modified version by Even Rouault. :
3  - Addition of cpl_unzGetCurrentFileZStreamPos
4  - Decoration of symbol names unz* -> cpl_unz*
5  - Undef EXPORT so that we are sure the symbols are not exported
6  - Add support for ZIP64
7 
8  * Copyright (c) 2008, Even Rouault <even dot rouault at spatialys.com>
9 
10  Original licence available in port/LICENCE_minizip
11 */
12 
13 /* unzip.h -- IO for uncompress .zip files using zlib
14  Version 1.01e, February 12th, 2005
15 
16  Copyright (C) 1998-2005 Gilles Vollant
17 
18  This unzip package allow extract file from .ZIP file, compatible with
19  PKZip 2.04g WinZip, InfoZip tools and compatible.
20 
21  Multi volume ZipFile (span) are not supported.
22  Encryption compatible with pkzip 2.04g only supported
23  Old compressions used by old PKZip 1.x are not supported
24 
25  I WAIT FEEDBACK at mail info@winimage.com
26  Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
27 
28  Condition of use and distribution are the same than zlib :
29 
30  This software is provided 'as-is', without any express or implied
31  warranty. In no event will the authors be held liable for any damages
32  arising from the use of this software.
33 
34  Permission is granted to anyone to use this software for any purpose,
35  including commercial applications, and to alter it and redistribute it
36  freely, subject to the following restrictions:
37 
38  1. The origin of this software must not be misrepresented; you must not
39  claim that you wrote the original software. If you use this software
40  in a product, an acknowledgment in the product documentation would be
41  appreciated but is not required.
42  2. Altered source versions must be plainly marked as such, and must not be
43  misrepresented as being the original software.
44  3. This notice may not be removed or altered from any source distribution.
45 */
46 
47 /* for more info about .ZIP format, see
48  http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
49  http://www.info-zip.org/pub/infozip/doc/
50  PkWare has also a specification at :
51  ftp://ftp.pkware.com/probdesc.zip
52 */
53 
54 #ifndef CPL_MINIZIP_UNZIP_H_INCLUDED
55 #define CPL_MINIZIP_UNZIP_H_INCLUDED
56 
57 #ifndef DOXYGEN_SKIP
58 
59 #include "cpl_vsi.h"
60 #define uLong64 vsi_l_offset
61 
62 #ifdef __cplusplus
63 extern "C"
64 {
65 #endif
66 
67 #ifndef _ZLIB_H
68 #include "cpl_zlib_header.h" // to avoid warnings when including zlib.h
69 #endif
70 
71 #ifndef CPL_MINIZIP_IOAPI_H_INCLUDED
72 #include "cpl_minizip_ioapi.h"
73 #endif
74 
75 /* GDAL addition */
76 #define NOUNCRYPT
77 #undef ZEXPORT
78 #define ZEXPORT
79 
80 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
81  /* like the STRICT of WIN32, we define a pointer that cannot be converted
82  from (void*) without cast */
83  typedef struct TagunzFile__
84  {
85  int unused;
86  } unzFile__;
87  typedef unzFile__ *unzFile;
88 #else
89 typedef voidp unzFile;
90 #endif
91 
92 #define UNZ_OK (0)
93 #define UNZ_END_OF_LIST_OF_FILE (-100)
94 #define UNZ_ERRNO (Z_ERRNO)
95 #define UNZ_EOF (0)
96 #define UNZ_PARAMERROR (-102)
97 #define UNZ_BADZIPFILE (-103)
98 #define UNZ_INTERNALERROR (-104)
99 #define UNZ_CRCERROR (-105)
100 
101  /* tm_unz contain date/time info */
102  typedef struct tm_unz_s
103  {
104  uInt tm_sec; /* seconds after the minute - [0,59] */
105  uInt tm_min; /* minutes after the hour - [0,59] */
106  uInt tm_hour; /* hours since midnight - [0,23] */
107  uInt tm_mday; /* day of the month - [1,31] */
108  uInt tm_mon; /* months since January - [0,11] */
109  uInt tm_year; /* years - [1980..2044] */
110  } tm_unz;
111 
112  /* unz_global_info structure contain global data about the ZIPfile
113  These data comes from the end of central dir */
114  typedef struct unz_global_info_s
115  {
116  uLong64 number_entry; /* total number of entries in
117  the central dir on this disk */
118  uLong size_comment; /* size of the global comment of the zipfile */
119  } unz_global_info;
120 
121  /* unz_file_info contain information about a file in the zipfile */
122  typedef struct unz_file_info_s
123  {
124  uLong version; /* version made by 2 bytes */
125  uLong version_needed; /* version needed to extract 2 bytes */
126  uLong flag; /* general purpose bit flag 2 bytes */
127  uLong compression_method; /* compression method 2 bytes */
128  uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
129  uLong crc; /* crc-32 4 bytes */
130  uLong64 compressed_size; /* compressed size 4 bytes */
131  uLong64 uncompressed_size; /* uncompressed size 4 bytes */
132  uLong size_filename; /* filename length 2 bytes */
133  uLong64
134  file_extra_abs_offset; /* absolute offset in the file where file_extra is located */
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 cpl_unzStringFileNameCompare(const char *fileName1,
146  const char *fileName2,
147  int iCaseSensitivity);
148  /*
149  Compare two filename (fileName1,fileName2).
150  If iCaseSenisivity = 1, comparison is case sensitivity (like strcmp)
151  If iCaseSenisivity = 2, comparison is not case sensitivity (like strcmpi
152  or strcasecmp)
153  If iCaseSenisivity = 0, case sensitivity is default of your operating
154  system (like 1 on Unix, 2 on Windows)
155  */
156 
157  extern unzFile ZEXPORT cpl_unzOpen(const char *path);
158  /*
159  Open a Zip file. path contain the full pathname (by example,
160  on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
161  "zlib/zlib113.zip".
162  If the zipfile cannot be opened (file don't exist or in not valid), the
163  return value is NULL.
164  Else, the return value is a unzFile Handle, usable with other function
165  of this unzip package.
166  */
167 
168  extern unzFile ZEXPORT cpl_unzOpen2(const char *path,
169  zlib_filefunc_def *pzlib_filefunc_def);
170  /*
171  Open a Zip file, like unzOpen, but provide a set of file low level API
172  for read/write the zip file (see ioapi.h)
173  */
174 
175  extern int ZEXPORT cpl_unzClose(unzFile file);
176  /*
177  Close a ZipFile opened with unzipOpen.
178  If there is files inside the .Zip opened with unzOpenCurrentFile (see
179  later), these files MUST be closed with unzipCloseCurrentFile before call
180  unzipClose. return UNZ_OK if there is no problem. */
181 
182  extern int ZEXPORT cpl_unzGetGlobalInfo(unzFile file,
183  unz_global_info *pglobal_info);
184  /*
185  Write info about the ZipFile in the *pglobal_info structure.
186  No preparation of the structure is needed
187  return UNZ_OK if there is no problem. */
188 
189  extern int ZEXPORT cpl_unzGetGlobalComment(unzFile file, char *szComment,
190  uLong uSizeBuf);
191  /*
192  Get the global comment string of the ZipFile, in the szComment buffer.
193  uSizeBuf is the size of the szComment buffer.
194  return the number of byte copied or an error code <0
195  */
196 
197  /***************************************************************************/
198  /* Unzip package allow you browse the directory of the zipfile */
199 
200  extern int ZEXPORT cpl_unzGoToFirstFile(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 cpl_unzGoToNextFile(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 cpl_unzLocateFile(unzFile file, const char *szFileName,
214  int iCaseSensitivity);
215  /*
216  Try locate the file szFileName in the zipfile.
217  For the iCaseSensitivity signification, see unzStringFileNameCompare
218 
219  return value :
220  UNZ_OK if the file is found. It becomes the current file.
221  UNZ_END_OF_LIST_OF_FILE if the file is not found
222  */
223 
224  /* ****************************************** */
225  /* Ryan supplied functions */
226  /* unz_file_info contain information about a file in the zipfile */
227  typedef struct unz_file_pos_s
228  {
229  uLong64 pos_in_zip_directory; /* offset in zip file directory */
230  uLong64 num_of_file; /* # of file */
231  } unz_file_pos;
232 
233  extern int ZEXPORT cpl_unzGetFilePos(unzFile file, unz_file_pos *file_pos);
234 
235  extern int ZEXPORT cpl_unzGoToFilePos(unzFile file, unz_file_pos *file_pos);
236 
237  /* ****************************************** */
238 
239  extern int ZEXPORT cpl_unzGetCurrentFileInfo(
240  unzFile file, unz_file_info *pfile_info, char *szFileName,
241  uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize,
242  char *szComment, uLong commentBufferSize);
243  /*
244  Get Info about the current file
245  if pfile_info!=NULL, the *pfile_info structure will contain some info
246  about the current file if szFileName!=NULL, the filename string will be
247  copied in szFileName (fileNameBufferSize is the size of the buffer) if
248  extraField!=NULL, the extra field information will be copied in extraField
249  (extraFieldBufferSize is the size of the buffer).
250  This is the Central-header version of the extra field
251  if szComment!=NULL, the comment string of the file will be copied in
252  szComment (commentBufferSize is the size of the buffer)
253  */
254 
257  extern uLong64 ZEXPORT cpl_unzGetCurrentFileZStreamPos(unzFile file);
258 
259  extern int cpl_unzGetLocalHeaderPos(unzFile file,
260  uLong64 *pos_local_header);
261 
262  extern int cpl_unzCurrentFileInfoFromLocalHeader(
263  unzFile file, uLong64 pos_local_header, unz_file_info *pfile_info,
264  char *szFileName, size_t fileNameBufferSize, uLong64 *posData);
265 
268  /***************************************************************************/
269  /* for reading the content of the current zipfile, you can open it, read
270  data from it, and close it (you can close it before reading all the file)
271  */
272 
273  extern int ZEXPORT cpl_unzOpenCurrentFile(unzFile file);
274  /*
275  Open for reading data the current file in the zipfile.
276  If there is no error, the return value is UNZ_OK.
277  */
278 
279  extern int ZEXPORT cpl_unzOpenCurrentFilePassword(unzFile file,
280  const char *password);
281  /*
282  Open for reading data the current file in the zipfile.
283  password is a crypting password
284  If there is no error, the return value is UNZ_OK.
285  */
286 
287  extern int ZEXPORT cpl_unzOpenCurrentFile2(unzFile file, int *method,
288  int *level, int raw);
289  /*
290  Same than unzOpenCurrentFile, but open for read raw the file (not
291  uncompress) if raw==1 *method will receive method of compression, *level
292  will receive level of compression note : you can set level parameter as
293  NULL (if you did not want known level, but you CANNOT set method parameter
294  as NULL
295  */
296 
297  extern int ZEXPORT cpl_unzOpenCurrentFile3(unzFile file, int *method,
298  int *level, int raw,
299  const char *password);
300  /*
301  Same than unzOpenCurrentFile, but open for read raw the file (not
302  uncompress) if raw==1 *method will receive method of compression, *level
303  will receive level of compression note : you can set level parameter as
304  NULL (if you did not want known level, but you CANNOT set method parameter
305  as NULL
306  */
307 
308  extern int ZEXPORT cpl_unzCloseCurrentFile(unzFile file);
309  /*
310  Close the file in zip opened with unzOpenCurrentFile
311  Return UNZ_CRCERROR if all the file was read but the CRC is not good
312  */
313 
314  extern int ZEXPORT cpl_unzReadCurrentFile(unzFile file, voidp buf,
315  unsigned len);
316  /*
317  Read bytes from the current file (opened by unzOpenCurrentFile)
318  buf contain buffer where data must be copied
319  len the size of buf.
320 
321  return the number of byte copied if some bytes are copied
322  return 0 if the end of file was reached
323  return <0 with error code if there is an error
324  (UNZ_ERRNO for IO error, or zLib error for uncompress error)
325  */
326 
327  extern z_off_t ZEXPORT cpl_unztell(unzFile file);
328  /*
329  Give the current position in uncompressed data
330  */
331 
332  extern int ZEXPORT cpl_unzeof(unzFile file);
333  /*
334  return 1 if the end of file was reached, 0 elsewhere
335  */
336 
337  extern int ZEXPORT cpl_unzGetLocalExtrafield(unzFile file, voidp buf,
338  unsigned len);
339  /*
340  Read extra field from the current file (opened by unzOpenCurrentFile)
341  This is the local-header version of the extra field (sometimes, there is
342  more info in the local-header version than in the central-header)
343 
344  if buf==NULL, it return the size of the local extra field
345 
346  if buf!=NULL, len is the size of the buffer, the extra header is copied in
347  buf.
348  the return value is the number of bytes copied in buf, or (if <0)
349  the error code
350  */
351 
352  /***************************************************************************/
353 
354  /* Get the current file offset */
355  extern uLong64 ZEXPORT cpl_unzGetOffset(unzFile file);
356 
357  /* Set the current file offset */
358  extern int ZEXPORT cpl_unzSetOffset(unzFile file, uLong64 pos);
359 
360 #ifdef __cplusplus
361 }
362 #endif
363 
364 #endif /* #ifndef DOXYGEN_SKIP */
365 
366 #endif /* CPL_MINIZIP_UNZIP_H_INCLUDED */
cpl_vsi.h