libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

unzip.h File Reference

API to access ZIP archives. More...

#include <zlib.h>
Include dependency graph for unzip.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  EXTRACTOR_UnzipDateTimeInfo
 
struct  EXTRACTOR_UnzipFileInfo
 

Macros

#define EXTRACTOR_UNZIP_OK   (0)
 
#define EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE   (-100)
 
#define EXTRACTOR_UNZIP_ERRNO   (Z_ERRNO)
 
#define EXTRACTOR_UNZIP_EOF   (0)
 
#define EXTRACTOR_UNZIP_PARAMERROR   (-102)
 
#define EXTRACTOR_UNZIP_BADZIPFILE   (-103)
 
#define EXTRACTOR_UNZIP_INTERNALERROR   (-104)
 
#define EXTRACTOR_UNZIP_CRCERROR   (-105)
 

Functions

struct EXTRACTOR_UnzipFileEXTRACTOR_common_unzip_open (struct EXTRACTOR_ExtractContext *ec)
 
int EXTRACTOR_common_unzip_get_global_comment (struct EXTRACTOR_UnzipFile *file, char *comment, size_t comment_len)
 
int EXTRACTOR_common_unzip_close (struct EXTRACTOR_UnzipFile *file)
 
int EXTRACTOR_common_unzip_go_to_first_file (struct EXTRACTOR_UnzipFile *file)
 
int EXTRACTOR_common_unzip_go_to_next_file (struct EXTRACTOR_UnzipFile *file)
 
int EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file, const char *szFileName, int iCaseSensitivity)
 
int EXTRACTOR_common_unzip_get_current_file_info (struct EXTRACTOR_UnzipFile *file, struct EXTRACTOR_UnzipFileInfo *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
 
int EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file)
 
ssize_t EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file, void *buf, size_t len)
 
int EXTRACTOR_common_unzip_close_current_file (struct EXTRACTOR_UnzipFile *file)
 

Detailed Description

API to access ZIP archives.

Author
Christian Grothoff

This code is based in part on unzip 1.00 Copyright 1998-2003 Gilles Vollant http://www.winimage.com/zLibDll"

Definition in file unzip.h.

Macro Definition Documentation

◆ EXTRACTOR_UNZIP_BADZIPFILE

#define EXTRACTOR_UNZIP_BADZIPFILE   (-103)

Not a zip file (or malformed)

Definition at line 62 of file unzip.h.

◆ EXTRACTOR_UNZIP_CRCERROR

#define EXTRACTOR_UNZIP_CRCERROR   (-105)

Checksum failure.

Definition at line 72 of file unzip.h.

◆ EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE

#define EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE   (-100)

Cannot move to next file, we are at the end

Definition at line 42 of file unzip.h.

◆ EXTRACTOR_UNZIP_EOF

#define EXTRACTOR_UNZIP_EOF   (0)

Reached end of the file (NOTE: same as OK!)

Definition at line 52 of file unzip.h.

◆ EXTRACTOR_UNZIP_ERRNO

#define EXTRACTOR_UNZIP_ERRNO   (Z_ERRNO)

IO error, see errno.

Definition at line 47 of file unzip.h.

◆ EXTRACTOR_UNZIP_INTERNALERROR

#define EXTRACTOR_UNZIP_INTERNALERROR   (-104)

Internal error.

Definition at line 67 of file unzip.h.

◆ EXTRACTOR_UNZIP_OK

#define EXTRACTOR_UNZIP_OK   (0)

Operation was successful.

Definition at line 37 of file unzip.h.

◆ EXTRACTOR_UNZIP_PARAMERROR

#define EXTRACTOR_UNZIP_PARAMERROR   (-102)

Invalid arguments to call.

Definition at line 57 of file unzip.h.

Function Documentation

◆ EXTRACTOR_common_unzip_close()

int EXTRACTOR_common_unzip_close ( struct EXTRACTOR_UnzipFile file)

Close a ZipFile.

Parameters
filezip file to close
Returns
EXTRACTOR_UNZIP_OK if there is no problem.

Close a ZipFile.

Parameters
filezip file to close
Returns
EXTRACTOR_UNZIP_OK if there is no problem.

Definition at line 854 of file unzip.c.

References EXTRACTOR_common_unzip_close_current_file(), EXTRACTOR_UNZIP_OK, EXTRACTOR_UNZIP_PARAMERROR, NULL, and EXTRACTOR_UnzipFile::pfile_in_zip_read.

Referenced by EXTRACTOR_odf_extract_method(), and EXTRACTOR_zip_extract_method().

◆ EXTRACTOR_common_unzip_close_current_file()

int EXTRACTOR_common_unzip_close_current_file ( struct EXTRACTOR_UnzipFile file)

Close the file in zip opened with EXTRACTOR_common_unzip_open_current_file.

Returns
EXTRACTOR_UNZIP_CRCERROR if all the file was read but the CRC is not good

Close the file in zip opened with EXTRACTOR_common_unzip_open_current_file().

Returns
EXTRACTOR_UNZIP_CRCERROR if all the file was read but the CRC is not good

Definition at line 823 of file unzip.c.

References FileInZipReadInfo::crc32, FileInZipReadInfo::crc32_wait, EXTRACTOR_UNZIP_CRCERROR, EXTRACTOR_UNZIP_OK, EXTRACTOR_UNZIP_PARAMERROR, NULL, EXTRACTOR_UnzipFile::pfile_in_zip_read, FileInZipReadInfo::read_buffer, FileInZipReadInfo::rest_read_uncompressed, FileInZipReadInfo::stream, and FileInZipReadInfo::stream_initialised.

Referenced by EXTRACTOR_common_unzip_close(), EXTRACTOR_common_unzip_open_current_file(), EXTRACTOR_odf_extract_method(), and libextractor_oo_getmimetype().

◆ EXTRACTOR_common_unzip_get_current_file_info()

int EXTRACTOR_common_unzip_get_current_file_info ( struct EXTRACTOR_UnzipFile file,
struct EXTRACTOR_UnzipFileInfo pfile_info,
char *  szFileName,
uLong  fileNameBufferSize,
void *  extraField,
uLong  extraFieldBufferSize,
char *  szComment,
uLong  commentBufferSize 
)

Write info about the ZipFile in the *pglobal_info structure. No preparation of the structure is needed.

Parameters
filezipfile to manipulate
pfile_infofile information to initialize
szFileNamewhere to write the name of the current file
fileNameBufferSizenumber of bytes available in szFileName
extraFieldwhere to write extra data
extraFieldBufferSizenumber of bytes available in extraField
szCommentwhere to write the comment on the current file
commentBufferSizenumber of bytes available in szComment
Returns
EXTRACTOR_UNZIP_OK if there is no problem.

Write info about the ZipFile in the *pglobal_info structure. No preparation of the structure is needed.

Parameters
filezipfile to manipulate
pfile_infofile information to initialize
szFileNamewhere to write the name of the current file
fileNameBufferSizenumber of bytes available in szFileName
extraFieldwhere to write extra data
extraFieldBufferSizenumber of bytes available in extraField
szCommentwhere to write the comment on the current file
commentBufferSizenumber of bytes available in szComment
Returns
EXTRACTOR_UNZIP_OK if there is no problem.

Definition at line 908 of file unzip.c.

References get_current_file_info(), and NULL.

Referenced by EXTRACTOR_common_unzip_go_find_local_file(), EXTRACTOR_odf_extract_method(), EXTRACTOR_zip_extract_method(), and libextractor_oo_getmimetype().

◆ EXTRACTOR_common_unzip_get_global_comment()

int EXTRACTOR_common_unzip_get_global_comment ( struct EXTRACTOR_UnzipFile file,
char *  comment,
size_t  comment_len 
)

Obtain the global comment from a ZIP file.

Parameters
fileunzip file to inspect
commentwhere to copy the comment
comment_lenmaximum number of bytes available in comment
Returns
EXTRACTOR_UNZIP_OK on success

Obtain the global comment from a ZIP file.

Parameters
fileunzip file to inspect
commentwhere to copy the comment
comment_lenmaximum number of bytes available in comment
Returns
EXTRACTOR_UNZIP_OK on success

Definition at line 874 of file unzip.c.

References EXTRACTOR_UNZIP_ERRNO, EXTRACTOR_UNZIP_OK, EXTRACTOR_UNZIP_PARAMERROR, EXTRACTOR_UnzipFile::gi, NULL, GlobalInfo::offset_comment, GlobalInfo::size_comment, EXTRACTOR_UnzipFile::z_filefunc, ZREAD, and ZSEEK.

Referenced by EXTRACTOR_zip_extract_method().

◆ EXTRACTOR_common_unzip_go_find_local_file()

int EXTRACTOR_common_unzip_go_find_local_file ( struct EXTRACTOR_UnzipFile file,
const char *  szFileName,
int  iCaseSensitivity 
)

Try locate the file szFileName in the zipfile.

Parameters
filezipfile to manipulate
szFileNamename to find
iCaseSensitivity,use1 for case sensitivity (like strcmp); 2 for no case sensitivity (like strcmpi or strcasecmp); or 0 for defaut of your operating system (like 1 on Unix, 2 on Windows)
Returns
EXTRACTOR_UNZIP_OK if the file is found. It becomes the current file. EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the file is not found

Try locate the file szFileName in the zipfile.

Parameters
filezipfile to manipulate
szFileNamename to find
iCaseSensitivity,use1 for case sensitivity (like strcmp); 2 for no case sensitivity (like strcmpi or strcasecmp); or 0 for default of your operating system (like 1 on Unix, 2 on Windows)
Returns
EXTRACTOR_UNZIP_OK if the file is found. It becomes the current file. EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the file is not found

Definition at line 969 of file unzip.c.

References EXTRACTOR_UnzipFile::cur_file_info, EXTRACTOR_UnzipFile::cur_file_info_internal, EXTRACTOR_UnzipFile::current_file_ok, EXTRACTOR_common_unzip_get_current_file_info(), EXTRACTOR_common_unzip_go_to_first_file(), EXTRACTOR_common_unzip_go_to_next_file(), EXTRACTOR_common_unzip_string_file_name_compare(), EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE, EXTRACTOR_UNZIP_OK, EXTRACTOR_UNZIP_PARAMERROR, NULL, EXTRACTOR_UnzipFile::num_file, EXTRACTOR_UnzipFile::pos_in_central_dir, and UNZ_MAXFILENAMEINZIP.

Referenced by EXTRACTOR_odf_extract_method(), EXTRACTOR_zip_extract_method(), and libextractor_oo_getmimetype().

◆ EXTRACTOR_common_unzip_go_to_first_file()

int EXTRACTOR_common_unzip_go_to_first_file ( struct EXTRACTOR_UnzipFile file)

◆ EXTRACTOR_common_unzip_go_to_next_file()

int EXTRACTOR_common_unzip_go_to_next_file ( struct EXTRACTOR_UnzipFile file)

Set the current file of the zipfile to the next file.

Parameters
filezipfile to manipulate
Returns
EXTRACTOR_UNZIP_OK if there is no problem, EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the actual file was the latest.

Set the current file of the zipfile to the next file.

Parameters
filezipfile to manipulate
Returns
EXTRACTOR_UNZIP_OK if there is no problem, EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the actual file was the latest.

Definition at line 933 of file unzip.c.

References EXTRACTOR_UnzipFile::cur_file_info, EXTRACTOR_UnzipFile::cur_file_info_internal, EXTRACTOR_UnzipFile::current_file_ok, EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE, EXTRACTOR_UNZIP_OK, EXTRACTOR_UNZIP_PARAMERROR, get_current_file_info(), EXTRACTOR_UnzipFile::gi, NULL, EXTRACTOR_UnzipFile::num_file, GlobalInfo::number_entry, EXTRACTOR_UnzipFile::pos_in_central_dir, EXTRACTOR_UnzipFileInfo::size_file_comment, EXTRACTOR_UnzipFileInfo::size_file_extra, EXTRACTOR_UnzipFileInfo::size_filename, and SIZECENTRALDIRITEM.

Referenced by EXTRACTOR_common_unzip_go_find_local_file(), and EXTRACTOR_zip_extract_method().

◆ EXTRACTOR_common_unzip_open()

struct EXTRACTOR_UnzipFile* EXTRACTOR_common_unzip_open ( struct EXTRACTOR_ExtractContext ec)

Open a zip file for processing using the data access functions from the extract context.

Parameters
ecextract context to use
Returns
handle to zip data, NULL on error

Definition at line 1421 of file unzip.c.

References ec_read_file_func(), ec_seek_file_func(), ec_tell_file_func(), FileFuncDefs::opaque, unzip_open_using_ffd(), FileFuncDefs::zread_file, FileFuncDefs::zseek_file, and FileFuncDefs::ztell_file.

Referenced by EXTRACTOR_odf_extract_method(), and EXTRACTOR_zip_extract_method().

◆ EXTRACTOR_common_unzip_open_current_file()

int EXTRACTOR_common_unzip_open_current_file ( struct EXTRACTOR_UnzipFile file)

Open for reading data the current file in the zipfile.

Parameters
filezipfile to manipulate
Returns
EXTRACTOR_UNZIP_OK on success

Open for reading data the current file in the zipfile.

Parameters
filezipfile to manipulate
Returns
EXTRACTOR_UNZIP_OK on success

Definition at line 1259 of file unzip.c.

References FileInZipReadInfo::byte_before_the_zipfile, EXTRACTOR_UnzipFile::byte_before_the_zipfile, EXTRACTOR_UnzipFileInfo::compressed_size, FileInZipReadInfo::compression_method, EXTRACTOR_UnzipFileInfo::compression_method, EXTRACTOR_UnzipFileInfo::crc, FileInZipReadInfo::crc32, FileInZipReadInfo::crc32_wait, EXTRACTOR_UnzipFile::cur_file_info, EXTRACTOR_UnzipFile::cur_file_info_internal, EXTRACTOR_UnzipFile::current_file_ok, EXTRACTOR_common_unzip_close_current_file(), EXTRACTOR_UNZIP_BADZIPFILE, EXTRACTOR_UNZIP_INTERNALERROR, EXTRACTOR_UNZIP_OK, EXTRACTOR_UNZIP_PARAMERROR, NULL, UnzipFileInfoInternal::offset_curfile, FileInZipReadInfo::offset_local_extrafield, parse_current_file_coherency_header(), EXTRACTOR_UnzipFile::pfile_in_zip_read, FileInZipReadInfo::pos_in_zipfile, FileInZipReadInfo::pos_local_extrafield, FileInZipReadInfo::read_buffer, FileInZipReadInfo::rest_read_compressed, FileInZipReadInfo::rest_read_uncompressed, FileInZipReadInfo::size_local_extrafield, SIZEZIPLOCALHEADER, FileInZipReadInfo::stream, FileInZipReadInfo::stream_initialised, EXTRACTOR_UnzipFileInfo::uncompressed_size, UNZ_BUFSIZE, FileInZipReadInfo::z_filefunc, and EXTRACTOR_UnzipFile::z_filefunc.

Referenced by EXTRACTOR_odf_extract_method(), and libextractor_oo_getmimetype().

◆ EXTRACTOR_common_unzip_read_current_file()

ssize_t EXTRACTOR_common_unzip_read_current_file ( struct EXTRACTOR_UnzipFile file,
void *  buf,
size_t  len 
)

Read bytes from the current file (must have been opened).

Parameters
bufcontain buffer where data must be copied
lenthe size of buf.
Returns
the number of byte copied if somes bytes are copied 0 if the end of file was reached <0 with error code if there is an error (EXTRACTOR_UNZIP_ERRNO for IO error, or zLib error for uncompress error)

Read bytes from the current file (must have been opened).

Parameters
bufcontain buffer where data must be copied
lenthe size of buf.
Returns
the number of byte copied if some bytes are copied 0 if the end of file was reached <0 with error code if there is an error (EXTRACTOR_UNZIP_ERRNO for IO error, or zLib error for uncompress error)

Definition at line 1038 of file unzip.c.

References FileInZipReadInfo::byte_before_the_zipfile, FileInZipReadInfo::compression_method, FileInZipReadInfo::crc32, EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE, EXTRACTOR_UNZIP_EOF, EXTRACTOR_UNZIP_ERRNO, EXTRACTOR_UNZIP_OK, EXTRACTOR_UNZIP_PARAMERROR, NULL, EXTRACTOR_UnzipFile::pfile_in_zip_read, FileInZipReadInfo::pos_in_zipfile, FileInZipReadInfo::read_buffer, FileInZipReadInfo::rest_read_compressed, FileInZipReadInfo::rest_read_uncompressed, FileInZipReadInfo::stream, UNZ_BUFSIZE, FileInZipReadInfo::z_filefunc, ZREAD, and ZSEEK.

Referenced by EXTRACTOR_odf_extract_method(), and libextractor_oo_getmimetype().