Back to index

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