cpl_minizip_unzip.h

00001 /* Modified version by Even Rouault. :
00002      - Addition of cpl_unzGetCurrentFileZStreamPos
00003      - Decoration of symbol names unz* -> cpl_unz*
00004      - Undef EXPORT so that we are sure the symbols are not exported
00005      - Add support for ZIP64
00006 
00007  * Copyright (c) 2008, Even Rouault <even dot rouault at mines-paris dot org>
00008 
00009    Original licence available in port/LICENCE_minizip
00010 */
00011 
00012 /* unzip.h -- IO for uncompress .zip files using zlib
00013    Version 1.01e, February 12th, 2005
00014 
00015    Copyright (C) 1998-2005 Gilles Vollant
00016 
00017    This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
00018      WinZip, InfoZip tools and compatible.
00019 
00020    Multi volume ZipFile (span) are not supported.
00021    Encryption compatible with pkzip 2.04g only supported
00022    Old compressions used by old PKZip 1.x are not supported
00023 
00024 
00025    I WAIT FEEDBACK at mail info@winimage.com
00026    Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
00027 
00028    Condition of use and distribution are the same than zlib :
00029 
00030   This software is provided 'as-is', without any express or implied
00031   warranty.  In no event will the authors be held liable for any damages
00032   arising from the use of this software.
00033 
00034   Permission is granted to anyone to use this software for any purpose,
00035   including commercial applications, and to alter it and redistribute it
00036   freely, subject to the following restrictions:
00037 
00038   1. The origin of this software must not be misrepresented; you must not
00039      claim that you wrote the original software. If you use this software
00040      in a product, an acknowledgment in the product documentation would be
00041      appreciated but is not required.
00042   2. Altered source versions must be plainly marked as such, and must not be
00043      misrepresented as being the original software.
00044   3. This notice may not be removed or altered from any source distribution.
00045 
00046 
00047 */
00048 
00049 /* for more info about .ZIP format, see
00050       http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
00051       http://www.info-zip.org/pub/infozip/doc/
00052    PkWare has also a specification at :
00053       ftp://ftp.pkware.com/probdesc.zip
00054 */
00055 
00056 #ifndef CPL_MINIZIP_UNZIP_H_INCLUDED
00057 #define CPL_MINIZIP_UNZIP_H_INCLUDED
00058 
00059 #include "cpl_vsi.h"
00060 #define uLong64 vsi_l_offset
00061 
00062 #ifdef __cplusplus
00063 extern "C" {
00064 #endif
00065 
00066 #ifndef _ZLIB_H
00067 #include <zlib.h>
00068 #endif
00069 
00070 #ifndef CPL_MINIZIP_IOAPI_H_INCLUDED
00071 #include "cpl_minizip_ioapi.h"
00072 #endif
00073 
00074 /* GDAL addition */
00075 #define NOUNCRYPT
00076 #undef ZEXPORT
00077 #define ZEXPORT
00078 
00079 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
00080 /* like the STRICT of WIN32, we define a pointer that cannot be converted
00081     from (void*) without cast */
00082 typedef struct TagunzFile__ { int unused; } unzFile__;
00083 typedef unzFile__ *unzFile;
00084 #else
00085 typedef voidp unzFile;
00086 #endif
00087 
00088 
00089 #define UNZ_OK                          (0)
00090 #define UNZ_END_OF_LIST_OF_FILE         (-100)
00091 #define UNZ_ERRNO                       (Z_ERRNO)
00092 #define UNZ_EOF                         (0)
00093 #define UNZ_PARAMERROR                  (-102)
00094 #define UNZ_BADZIPFILE                  (-103)
00095 #define UNZ_INTERNALERROR               (-104)
00096 #define UNZ_CRCERROR                    (-105)
00097 
00098 /* tm_unz contain date/time info */
00099 typedef struct tm_unz_s
00100 {
00101     uInt tm_sec;            /* seconds after the minute - [0,59] */
00102     uInt tm_min;            /* minutes after the hour - [0,59] */
00103     uInt tm_hour;           /* hours since midnight - [0,23] */
00104     uInt tm_mday;           /* day of the month - [1,31] */
00105     uInt tm_mon;            /* months since January - [0,11] */
00106     uInt tm_year;           /* years - [1980..2044] */
00107 } tm_unz;
00108 
00109 /* unz_global_info structure contain global data about the ZIPfile
00110    These data comes from the end of central dir */
00111 typedef struct unz_global_info_s
00112 {
00113     uLong64 number_entry;         /* total number of entries in
00114                                      the central dir on this disk */
00115     uLong size_comment;         /* size of the global comment of the zipfile */
00116 } unz_global_info;
00117 
00118 
00119 /* unz_file_info contain information about a file in the zipfile */
00120 typedef struct unz_file_info_s
00121 {
00122     uLong version;              /* version made by                 2 bytes */
00123     uLong version_needed;       /* version needed to extract       2 bytes */
00124     uLong flag;                 /* general purpose bit flag        2 bytes */
00125     uLong compression_method;   /* compression method              2 bytes */
00126     uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
00127     uLong crc;                  /* crc-32                          4 bytes */
00128     uLong64 compressed_size;      /* compressed size                 4 bytes */
00129     uLong64 uncompressed_size;    /* uncompressed size               4 bytes */
00130     uLong size_filename;        /* filename length                 2 bytes */
00131     uLong size_file_extra;      /* extra field length              2 bytes */
00132     uLong size_file_comment;    /* file comment length             2 bytes */
00133 
00134     uLong disk_num_start;       /* disk number start               2 bytes */
00135     uLong internal_fa;          /* internal file attributes        2 bytes */
00136     uLong external_fa;          /* external file attributes        4 bytes */
00137 
00138     tm_unz tmu_date;
00139 } unz_file_info;
00140 
00141 extern int ZEXPORT cpl_unzStringFileNameCompare OF ((const char* fileName1,
00142                                                  const char* fileName2,
00143                                                  int iCaseSensitivity));
00144 /*
00145    Compare two filename (fileName1,fileName2).
00146    If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
00147    If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
00148                                 or strcasecmp)
00149    If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
00150     (like 1 on Unix, 2 on Windows)
00151 */
00152 
00153 
00154 extern unzFile ZEXPORT cpl_unzOpen OF((const char *path));
00155 /*
00156   Open a Zip file. path contain the full pathname (by example,
00157      on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
00158      "zlib/zlib113.zip".
00159      If the zipfile cannot be opened (file don't exist or in not valid), the
00160        return value is NULL.
00161      Else, the return value is a unzFile Handle, usable with other function
00162        of this unzip package.
00163 */
00164 
00165 extern unzFile ZEXPORT cpl_unzOpen2 OF((const char *path,
00166                                     zlib_filefunc_def* pzlib_filefunc_def));
00167 /*
00168    Open a Zip file, like unzOpen, but provide a set of file low level API
00169       for read/write the zip file (see ioapi.h)
00170 */
00171 
00172 extern int ZEXPORT cpl_unzClose OF((unzFile file));
00173 /*
00174   Close a ZipFile opened with unzipOpen.
00175   If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
00176     these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
00177   return UNZ_OK if there is no problem. */
00178 
00179 extern int ZEXPORT cpl_unzGetGlobalInfo OF((unzFile file,
00180                                         unz_global_info *pglobal_info));
00181 /*
00182   Write info about the ZipFile in the *pglobal_info structure.
00183   No preparation of the structure is needed
00184   return UNZ_OK if there is no problem. */
00185 
00186 
00187 extern int ZEXPORT cpl_unzGetGlobalComment OF((unzFile file,
00188                                            char *szComment,
00189                                            uLong uSizeBuf));
00190 /*
00191   Get the global comment string of the ZipFile, in the szComment buffer.
00192   uSizeBuf is the size of the szComment buffer.
00193   return the number of byte copied or an error code <0
00194 */
00195 
00196 
00197 /***************************************************************************/
00198 /* Unzip package allow you browse the directory of the zipfile */
00199 
00200 extern int ZEXPORT cpl_unzGoToFirstFile OF((unzFile file));
00201 /*
00202   Set the current file of the zipfile to the first file.
00203   return UNZ_OK if there is no problem
00204 */
00205 
00206 extern int ZEXPORT cpl_unzGoToNextFile OF((unzFile file));
00207 /*
00208   Set the current file of the zipfile to the next file.
00209   return UNZ_OK if there is no problem
00210   return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
00211 */
00212 
00213 extern int ZEXPORT cpl_unzLocateFile OF((unzFile file,
00214                      const char *szFileName,
00215                      int iCaseSensitivity));
00216 /*
00217   Try locate the file szFileName in the zipfile.
00218   For the iCaseSensitivity signification, see unzStringFileNameCompare
00219 
00220   return value :
00221   UNZ_OK if the file is found. It becomes the current file.
00222   UNZ_END_OF_LIST_OF_FILE if the file is not found
00223 */
00224 
00225 
00226 /* ****************************************** */
00227 /* Ryan supplied functions */
00228 /* unz_file_info contain information about a file in the zipfile */
00229 typedef struct unz_file_pos_s
00230 {
00231     uLong64 pos_in_zip_directory;   /* offset in zip file directory */
00232     uLong64 num_of_file;            /* # of file */
00233 } unz_file_pos;
00234 
00235 extern int ZEXPORT cpl_unzGetFilePos(
00236     unzFile file,
00237     unz_file_pos* file_pos);
00238 
00239 extern int ZEXPORT cpl_unzGoToFilePos(
00240     unzFile file,
00241     unz_file_pos* file_pos);
00242 
00243 /* ****************************************** */
00244 
00245 extern int ZEXPORT cpl_unzGetCurrentFileInfo OF((unzFile file,
00246                          unz_file_info *pfile_info,
00247                          char *szFileName,
00248                          uLong fileNameBufferSize,
00249                          void *extraField,
00250                          uLong extraFieldBufferSize,
00251                          char *szComment,
00252                          uLong commentBufferSize));
00253 /*
00254   Get Info about the current file
00255   if pfile_info!=NULL, the *pfile_info structure will contain somes info about
00256         the current file
00257   if szFileName!=NULL, the filemane string will be copied in szFileName
00258             (fileNameBufferSize is the size of the buffer)
00259   if extraField!=NULL, the extra field information will be copied in extraField
00260             (extraFieldBufferSize is the size of the buffer).
00261             This is the Central-header version of the extra field
00262   if szComment!=NULL, the comment string of the file will be copied in szComment
00263             (commentBufferSize is the size of the buffer)
00264 */
00265 
00266 
00269 extern uLong64 ZEXPORT cpl_unzGetCurrentFileZStreamPos OF(( unzFile file));
00270 
00274 /***************************************************************************/
00275 /* for reading the content of the current zipfile, you can open it, read data
00276    from it, and close it (you can close it before reading all the file)
00277    */
00278 
00279 extern int ZEXPORT cpl_unzOpenCurrentFile OF((unzFile file));
00280 /*
00281   Open for reading data the current file in the zipfile.
00282   If there is no error, the return value is UNZ_OK.
00283 */
00284 
00285 extern int ZEXPORT cpl_unzOpenCurrentFilePassword OF((unzFile file,
00286                                                   const char* password));
00287 /*
00288   Open for reading data the current file in the zipfile.
00289   password is a crypting password
00290   If there is no error, the return value is UNZ_OK.
00291 */
00292 
00293 extern int ZEXPORT cpl_unzOpenCurrentFile2 OF((unzFile file,
00294                                            int* method,
00295                                            int* level,
00296                                            int raw));
00297 /*
00298   Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
00299     if raw==1
00300   *method will receive method of compression, *level will receive level of
00301      compression
00302   note : you can set level parameter as NULL (if you did not want known level,
00303          but you CANNOT set method parameter as NULL
00304 */
00305 
00306 extern int ZEXPORT cpl_unzOpenCurrentFile3 OF((unzFile file,
00307                                            int* method,
00308                                            int* level,
00309                                            int raw,
00310                                            const char* password));
00311 /*
00312   Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
00313     if raw==1
00314   *method will receive method of compression, *level will receive level of
00315      compression
00316   note : you can set level parameter as NULL (if you did not want known level,
00317          but you CANNOT set method parameter as NULL
00318 */
00319 
00320 
00321 extern int ZEXPORT cpl_unzCloseCurrentFile OF((unzFile file));
00322 /*
00323   Close the file in zip opened with unzOpenCurrentFile
00324   Return UNZ_CRCERROR if all the file was read but the CRC is not good
00325 */
00326 
00327 extern int ZEXPORT cpl_unzReadCurrentFile OF((unzFile file,
00328                       voidp buf,
00329                       unsigned len));
00330 /*
00331   Read bytes from the current file (opened by unzOpenCurrentFile)
00332   buf contain buffer where data must be copied
00333   len the size of buf.
00334 
00335   return the number of byte copied if somes bytes are copied
00336   return 0 if the end of file was reached
00337   return <0 with error code if there is an error
00338     (UNZ_ERRNO for IO error, or zLib error for uncompress error)
00339 */
00340 
00341 extern z_off_t ZEXPORT cpl_unztell OF((unzFile file));
00342 /*
00343   Give the current position in uncompressed data
00344 */
00345 
00346 extern int ZEXPORT cpl_unzeof OF((unzFile file));
00347 /*
00348   return 1 if the end of file was reached, 0 elsewhere
00349 */
00350 
00351 extern int ZEXPORT cpl_unzGetLocalExtrafield OF((unzFile file,
00352                                              voidp buf,
00353                                              unsigned len));
00354 /*
00355   Read extra field from the current file (opened by unzOpenCurrentFile)
00356   This is the local-header version of the extra field (sometimes, there is
00357     more info in the local-header version than in the central-header)
00358 
00359   if buf==NULL, it return the size of the local extra field
00360 
00361   if buf!=NULL, len is the size of the buffer, the extra header is copied in
00362     buf.
00363   the return value is the number of bytes copied in buf, or (if <0)
00364     the error code
00365 */
00366 
00367 /***************************************************************************/
00368 
00369 /* Get the current file offset */
00370 extern uLong64 ZEXPORT cpl_unzGetOffset (unzFile file);
00371 
00372 /* Set the current file offset */
00373 extern int ZEXPORT cpl_unzSetOffset (unzFile file, uLong64 pos);
00374 
00375 
00376 
00377 #ifdef __cplusplus
00378 }
00379 #endif
00380 
00381 #endif /* CPL_MINIZIP_UNZIP_H_INCLUDED */

Generated for GDAL by doxygen 1.7.1.