blob: 014df7ae49fa6cd70ca806a82dff7569827496a6 [file] [log] [blame]
Dieter Baron2d6db591999-07-25 18:26:20 +00001#ifndef _HAD_ZIP_H
2#define _HAD_ZIP_H
3
Dieter Baronbbb63691999-07-26 22:04:20 +00004/*
5 zip.h -- exported declarations.
Dieter Baron416df862008-05-14 14:56:13 +02006 Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
Dieter Baronbbb63691999-07-26 22:04:20 +00007
Dieter Barondd9afca2003-10-02 14:13:37 +00008 This file is part of libzip, a library to manipulate ZIP archives.
Dieter Baronb86c4332007-11-07 14:35:13 +01009 The authors can be contacted at <libzip@nih.at>
Dieter Baronbbb63691999-07-26 22:04:20 +000010
Dieter Barondd9afca2003-10-02 14:13:37 +000011 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions
13 are met:
14 1. Redistributions of source code must retain the above copyright
15 notice, this list of conditions and the following disclaimer.
16 2. Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in
18 the documentation and/or other materials provided with the
19 distribution.
20 3. The names of the authors may not be used to endorse or promote
21 products derived from this software without specific prior
22 written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
25 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
30 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
32 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Dieter Baronbbb63691999-07-26 22:04:20 +000035*/
36
37
38
Dieter Baron8bc12762007-08-22 13:39:13 +020039#ifndef ZIP_EXTERN
40#ifdef _MSC_VER
41#define ZIP_EXTERN __declspec(dllexport)
42#else
43#define ZIP_EXTERN
44#endif
45#endif
46
Dieter Baron08f28512005-07-14 14:08:11 +000047#ifdef __cplusplus
48extern "C" {
49#endif
50
Dieter Baron2d6db591999-07-25 18:26:20 +000051#include <sys/types.h>
52#include <stdio.h>
Thomas Klausner01b2a3c1999-07-27 20:35:58 +000053#include <time.h>
Dieter Baron2d6db591999-07-25 18:26:20 +000054
Dieter Baron2d6db591999-07-25 18:26:20 +000055/* flags for zip_open */
Dieter Baronb2ed74d2004-04-14 14:01:31 +000056
Dieter Baron2d6db591999-07-25 18:26:20 +000057#define ZIP_CREATE 1
58#define ZIP_EXCL 2
59#define ZIP_CHECKCONS 4
60
Dieter Barone3f91ef2003-10-06 02:50:14 +000061
Dieter Baronb2ed74d2004-04-14 14:01:31 +000062/* flags for zip_name_locate, zip_fopen, zip_stat, ... */
63
64#define ZIP_FL_NOCASE 1 /* ignore case on name lookup */
65#define ZIP_FL_NODIR 2 /* ignore directory component */
Thomas Klausnerd0147e92004-11-17 21:55:17 +000066#define ZIP_FL_COMPRESSED 4 /* read compressed data */
Dieter Baronb2ed74d2004-04-14 14:01:31 +000067#define ZIP_FL_UNCHANGED 8 /* use original data, ignoring changes */
68
Dieter Baron416df862008-05-14 14:56:13 +020069/* archive global flags flags */
70
71#define ZIP_AFL_TORRENT 1 /* torrent zipped */
72
Dieter Baronb2ed74d2004-04-14 14:01:31 +000073/* libzip error codes */
Dieter Baron2d6db591999-07-25 18:26:20 +000074
Thomas Klausnerd0147e92004-11-17 21:55:17 +000075#define ZIP_ER_OK 0 /* N No error */
76#define ZIP_ER_MULTIDISK 1 /* N Multi-disk zip archives not supported */
77#define ZIP_ER_RENAME 2 /* S Renaming temporary file failed */
78#define ZIP_ER_CLOSE 3 /* S Closing zip archive failed */
79#define ZIP_ER_SEEK 4 /* S Seek error */
80#define ZIP_ER_READ 5 /* S Read error */
81#define ZIP_ER_WRITE 6 /* S Write error */
82#define ZIP_ER_CRC 7 /* N CRC error */
83#define ZIP_ER_ZIPCLOSED 8 /* N Containing zip archive was closed */
84#define ZIP_ER_NOENT 9 /* N No such file */
85#define ZIP_ER_EXISTS 10 /* N File already exists */
86#define ZIP_ER_OPEN 11 /* S Can't open file */
87#define ZIP_ER_TMPOPEN 12 /* S Failure to create temporary file */
88#define ZIP_ER_ZLIB 13 /* Z Zlib error */
89#define ZIP_ER_MEMORY 14 /* N Malloc failure */
90#define ZIP_ER_CHANGED 15 /* N Entry has been changed */
91#define ZIP_ER_COMPNOTSUPP 16 /* N Compression method not supported */
92#define ZIP_ER_EOF 17 /* N Premature EOF */
93#define ZIP_ER_INVAL 18 /* N Invalid argument */
94#define ZIP_ER_NOZIP 19 /* N Not a zip archive */
95#define ZIP_ER_INTERNAL 20 /* N Internal error */
96#define ZIP_ER_INCONS 21 /* N Zip archive inconsistent */
97#define ZIP_ER_REMOVE 22 /* S Can't remove file */
Dieter Baronca7d39a2005-01-20 21:00:29 +000098#define ZIP_ER_DELETED 23 /* N Entry has been deleted */
Dieter Baron2d6db591999-07-25 18:26:20 +000099
Dieter Baronb2ed74d2004-04-14 14:01:31 +0000100
101/* type of system error value */
102
Dieter Barone3f91ef2003-10-06 02:50:14 +0000103#define ZIP_ET_NONE 0 /* sys_err unused */
104#define ZIP_ET_SYS 1 /* sys_err is errno */
Thomas Klausnerd0147e92004-11-17 21:55:17 +0000105#define ZIP_ET_ZLIB 2 /* sys_err is zlib error code */
Dieter Baron2d6db591999-07-25 18:26:20 +0000106
Dieter Baronb2ed74d2004-04-14 14:01:31 +0000107/* compression methods */
Dieter Baron2d6db591999-07-25 18:26:20 +0000108
Dieter Baronb2ed74d2004-04-14 14:01:31 +0000109#define ZIP_CM_DEFAULT -1 /* better of deflate or store */
110#define ZIP_CM_STORE 0 /* stored (uncompressed) */
111#define ZIP_CM_SHRINK 1 /* shrunk */
112#define ZIP_CM_REDUCE_1 2 /* reduced with factor 1 */
113#define ZIP_CM_REDUCE_2 3 /* reduced with factor 2 */
114#define ZIP_CM_REDUCE_3 4 /* reduced with factor 3 */
115#define ZIP_CM_REDUCE_4 5 /* reduced with factor 4 */
116#define ZIP_CM_IMPLODE 6 /* imploded */
Thomas Klausnere21b0652004-11-17 21:59:00 +0000117/* 7 - Reserved for Tokenizing compression algorithm */
Dieter Baronb2ed74d2004-04-14 14:01:31 +0000118#define ZIP_CM_DEFLATE 8 /* deflated */
119#define ZIP_CM_DEFLATE64 9 /* deflate64 */
120#define ZIP_CM_PKWARE_IMPLODE 10 /* PKWARE imploding */
Thomas Klausnerc3ed8042005-09-06 23:44:25 +0000121/* 11 - Reserved by PKWARE */
122#define ZIP_CM_BZIP2 12 /* compressed using BZIP2 algorithm */
Dieter Baron62e54ee2007-11-08 16:00:25 +0100123/* 13 - Reserved by PKWARE */
124#define ZIP_CM_LZMA 14 /* LZMA (EFS) */
125/* 15-17 - Reserved by PKWARE */
126#define ZIP_CM_TERSE 18 /* compressed using IBM TERSE (new) */
127#define ZIP_CM_LZ77 19 /* IBM LZ77 z Architecture (PFS) */
128#define ZIP_CM_WAVPACK 97 /* WavPack compressed data */
129#define ZIP_CM_PPMD 98 /* PPMd version I, Rev 1 */
Thomas Klausner42dd7b71999-07-25 20:32:18 +0000130
Dieter Baron45b10752006-04-24 14:04:19 +0000131/* encryption methods */
132
133#define ZIP_EM_NONE 0 /* not encrypted */
134#define ZIP_EM_TRAD_PKWARE 1 /* traditional PKWARE encryption */
135#if 0 /* Strong Encryption Header not parsed yet */
136#define ZIP_EM_DES 0x6601 /* strong encryption: DES */
137#define ZIP_EM_RC2_OLD 0x6602 /* strong encryption: RC2, version < 5.2 */
138#define ZIP_EM_3DES_168 0x6603
139#define ZIP_EM_3DES_112 0x6609
140#define ZIP_EM_AES_128 0x660e
141#define ZIP_EM_AES_192 0x660f
142#define ZIP_EM_AES_256 0x6610
143#define ZIP_EM_RC2 0x6702 /* strong encryption: RC2, version >= 5.2 */
144#define ZIP_EM_RC4 0x6801
145#endif
146#define ZIP_EM_UNKNOWN 0xffff /* unknown algorithm */
147
Dieter Baronb2ed74d2004-04-14 14:01:31 +0000148
149
Dieter Baron35bf0fd2004-12-22 16:32:01 +0000150enum zip_source_cmd {
151 ZIP_SOURCE_OPEN, /* prepare for reading */
152 ZIP_SOURCE_READ, /* read data */
153 ZIP_SOURCE_CLOSE, /* reading is done */
154 ZIP_SOURCE_STAT, /* get meta information */
155 ZIP_SOURCE_ERROR, /* get error information */
156 ZIP_SOURCE_FREE /* cleanup and free resources */
Dieter Baron2d6db591999-07-25 18:26:20 +0000157};
158
Dieter Baron35bf0fd2004-12-22 16:32:01 +0000159typedef ssize_t (*zip_source_callback)(void *state, void *data,
160 size_t len, enum zip_source_cmd cmd);
Dieter Baronb2ed74d2004-04-14 14:01:31 +0000161
Dieter Barone3f91ef2003-10-06 02:50:14 +0000162struct zip_stat {
163 const char *name; /* name of the file */
164 int index; /* index within archive */
165 unsigned int crc; /* crc of file data */
Dieter Barone3f91ef2003-10-06 02:50:14 +0000166 time_t mtime; /* modification time */
Dieter Baronb2ed74d2004-04-14 14:01:31 +0000167 off_t size; /* size of file (uncompressed) */
168 off_t comp_size; /* size of file (compressed) */
Dieter Barone3f91ef2003-10-06 02:50:14 +0000169 unsigned short comp_method; /* compression method used */
Thomas Klausnera4dc1792006-04-09 14:52:03 +0000170 unsigned short encryption_method; /* encryption method used */
Dieter Barone3f91ef2003-10-06 02:50:14 +0000171};
172
173struct zip;
174struct zip_file;
Thomas Klausneref9a02f2004-11-18 15:06:20 +0000175struct zip_source;
Dieter Barone3f91ef2003-10-06 02:50:14 +0000176
Dieter Baron2d6db591999-07-25 18:26:20 +0000177
178
Dieter Baron8bc12762007-08-22 13:39:13 +0200179ZIP_EXTERN int zip_add(struct zip *, const char *, struct zip_source *);
180ZIP_EXTERN int zip_add_dir(struct zip *, const char *);
181ZIP_EXTERN int zip_close(struct zip *);
182ZIP_EXTERN int zip_delete(struct zip *, int);
183ZIP_EXTERN void zip_error_clear(struct zip *);
184ZIP_EXTERN void zip_error_get(struct zip *, int *, int *);
185ZIP_EXTERN int zip_error_get_sys_type(int);
186ZIP_EXTERN int zip_error_to_str(char *, size_t, int, int);
187ZIP_EXTERN int zip_fclose(struct zip_file *);
188ZIP_EXTERN void zip_file_error_clear(struct zip_file *);
189ZIP_EXTERN void zip_file_error_get(struct zip_file *, int *, int *);
190ZIP_EXTERN const char *zip_file_strerror(struct zip_file *);
191ZIP_EXTERN struct zip_file *zip_fopen(struct zip *, const char *, int);
192ZIP_EXTERN struct zip_file *zip_fopen_index(struct zip *, int, int);
193ZIP_EXTERN ssize_t zip_fread(struct zip_file *, void *, size_t);
194ZIP_EXTERN const char *zip_get_archive_comment(struct zip *, int *, int);
Dieter Baron416df862008-05-14 14:56:13 +0200195ZIP_EXTERN int zip_get_archive_flag(struct zip *, int, int);
Dieter Baron8bc12762007-08-22 13:39:13 +0200196ZIP_EXTERN const char *zip_get_file_comment(struct zip *, int, int *, int);
197ZIP_EXTERN const char *zip_get_name(struct zip *, int, int);
198ZIP_EXTERN int zip_get_num_files(struct zip *);
199ZIP_EXTERN int zip_name_locate(struct zip *, const char *, int);
200ZIP_EXTERN struct zip *zip_open(const char *, int, int *);
201ZIP_EXTERN int zip_rename(struct zip *, int, const char *);
202ZIP_EXTERN int zip_replace(struct zip *, int, struct zip_source *);
203ZIP_EXTERN int zip_set_archive_comment(struct zip *, const char *, int);
Dieter Baron416df862008-05-14 14:56:13 +0200204ZIP_EXTERN int zip_set_archive_flag(struct zip *, int, int);
Dieter Baron8bc12762007-08-22 13:39:13 +0200205ZIP_EXTERN int zip_set_file_comment(struct zip *, int, const char *, int);
206ZIP_EXTERN struct zip_source *zip_source_buffer(struct zip *, const void *,
207 off_t, int);
208ZIP_EXTERN struct zip_source *zip_source_file(struct zip *, const char *,
209 off_t, off_t);
210ZIP_EXTERN struct zip_source *zip_source_filep(struct zip *, FILE *,
211 off_t, off_t);
212ZIP_EXTERN void zip_source_free(struct zip_source *);
213ZIP_EXTERN struct zip_source *zip_source_function(struct zip *,
214 zip_source_callback, void *);
215ZIP_EXTERN struct zip_source *zip_source_zip(struct zip *, struct zip *,
216 int, int, off_t, off_t);
217ZIP_EXTERN int zip_stat(struct zip *, const char *, int, struct zip_stat *);
218ZIP_EXTERN int zip_stat_index(struct zip *, int, int, struct zip_stat *);
219ZIP_EXTERN void zip_stat_init(struct zip_stat *);
220ZIP_EXTERN const char *zip_strerror(struct zip *);
221ZIP_EXTERN int zip_unchange(struct zip *, int);
222ZIP_EXTERN int zip_unchange_all(struct zip *);
223ZIP_EXTERN int zip_unchange_archive(struct zip *);
Dieter Baron2d6db591999-07-25 18:26:20 +0000224
Dieter Baron08f28512005-07-14 14:08:11 +0000225#ifdef __cplusplus
226}
227#endif
228
Dieter Baron2d6db591999-07-25 18:26:20 +0000229#endif /* _HAD_ZIP_H */