Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 1 | #ifndef _HAD_ZIP_H |
| 2 | #define _HAD_ZIP_H |
| 3 | |
Dieter Baron | bbb6369 | 1999-07-26 22:04:20 +0000 | [diff] [blame] | 4 | /* |
| 5 | zip.h -- exported declarations. |
Dieter Baron | 416df86 | 2008-05-14 14:56:13 +0200 | [diff] [blame^] | 6 | Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner |
Dieter Baron | bbb6369 | 1999-07-26 22:04:20 +0000 | [diff] [blame] | 7 | |
Dieter Baron | dd9afca | 2003-10-02 14:13:37 +0000 | [diff] [blame] | 8 | This file is part of libzip, a library to manipulate ZIP archives. |
Dieter Baron | b86c433 | 2007-11-07 14:35:13 +0100 | [diff] [blame] | 9 | The authors can be contacted at <libzip@nih.at> |
Dieter Baron | bbb6369 | 1999-07-26 22:04:20 +0000 | [diff] [blame] | 10 | |
Dieter Baron | dd9afca | 2003-10-02 14:13:37 +0000 | [diff] [blame] | 11 | 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 Baron | bbb6369 | 1999-07-26 22:04:20 +0000 | [diff] [blame] | 35 | */ |
| 36 | |
| 37 | |
| 38 | |
Dieter Baron | 8bc1276 | 2007-08-22 13:39:13 +0200 | [diff] [blame] | 39 | #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 Baron | 08f2851 | 2005-07-14 14:08:11 +0000 | [diff] [blame] | 47 | #ifdef __cplusplus |
| 48 | extern "C" { |
| 49 | #endif |
| 50 | |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 51 | #include <sys/types.h> |
| 52 | #include <stdio.h> |
Thomas Klausner | 01b2a3c | 1999-07-27 20:35:58 +0000 | [diff] [blame] | 53 | #include <time.h> |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 54 | |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 55 | /* flags for zip_open */ |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 56 | |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 57 | #define ZIP_CREATE 1 |
| 58 | #define ZIP_EXCL 2 |
| 59 | #define ZIP_CHECKCONS 4 |
| 60 | |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 61 | |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 62 | /* 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 Klausner | d0147e9 | 2004-11-17 21:55:17 +0000 | [diff] [blame] | 66 | #define ZIP_FL_COMPRESSED 4 /* read compressed data */ |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 67 | #define ZIP_FL_UNCHANGED 8 /* use original data, ignoring changes */ |
| 68 | |
Dieter Baron | 416df86 | 2008-05-14 14:56:13 +0200 | [diff] [blame^] | 69 | /* archive global flags flags */ |
| 70 | |
| 71 | #define ZIP_AFL_TORRENT 1 /* torrent zipped */ |
| 72 | |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 73 | /* libzip error codes */ |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 74 | |
Thomas Klausner | d0147e9 | 2004-11-17 21:55:17 +0000 | [diff] [blame] | 75 | #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 Baron | ca7d39a | 2005-01-20 21:00:29 +0000 | [diff] [blame] | 98 | #define ZIP_ER_DELETED 23 /* N Entry has been deleted */ |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 99 | |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 100 | |
| 101 | /* type of system error value */ |
| 102 | |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 103 | #define ZIP_ET_NONE 0 /* sys_err unused */ |
| 104 | #define ZIP_ET_SYS 1 /* sys_err is errno */ |
Thomas Klausner | d0147e9 | 2004-11-17 21:55:17 +0000 | [diff] [blame] | 105 | #define ZIP_ET_ZLIB 2 /* sys_err is zlib error code */ |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 106 | |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 107 | /* compression methods */ |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 108 | |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 109 | #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 Klausner | e21b065 | 2004-11-17 21:59:00 +0000 | [diff] [blame] | 117 | /* 7 - Reserved for Tokenizing compression algorithm */ |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 118 | #define ZIP_CM_DEFLATE 8 /* deflated */ |
| 119 | #define ZIP_CM_DEFLATE64 9 /* deflate64 */ |
| 120 | #define ZIP_CM_PKWARE_IMPLODE 10 /* PKWARE imploding */ |
Thomas Klausner | c3ed804 | 2005-09-06 23:44:25 +0000 | [diff] [blame] | 121 | /* 11 - Reserved by PKWARE */ |
| 122 | #define ZIP_CM_BZIP2 12 /* compressed using BZIP2 algorithm */ |
Dieter Baron | 62e54ee | 2007-11-08 16:00:25 +0100 | [diff] [blame] | 123 | /* 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 Klausner | 42dd7b7 | 1999-07-25 20:32:18 +0000 | [diff] [blame] | 130 | |
Dieter Baron | 45b1075 | 2006-04-24 14:04:19 +0000 | [diff] [blame] | 131 | /* 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 Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 148 | |
| 149 | |
Dieter Baron | 35bf0fd | 2004-12-22 16:32:01 +0000 | [diff] [blame] | 150 | enum 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 Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
Dieter Baron | 35bf0fd | 2004-12-22 16:32:01 +0000 | [diff] [blame] | 159 | typedef ssize_t (*zip_source_callback)(void *state, void *data, |
| 160 | size_t len, enum zip_source_cmd cmd); |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 161 | |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 162 | struct 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 Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 166 | time_t mtime; /* modification time */ |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 167 | off_t size; /* size of file (uncompressed) */ |
| 168 | off_t comp_size; /* size of file (compressed) */ |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 169 | unsigned short comp_method; /* compression method used */ |
Thomas Klausner | a4dc179 | 2006-04-09 14:52:03 +0000 | [diff] [blame] | 170 | unsigned short encryption_method; /* encryption method used */ |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | struct zip; |
| 174 | struct zip_file; |
Thomas Klausner | ef9a02f | 2004-11-18 15:06:20 +0000 | [diff] [blame] | 175 | struct zip_source; |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 176 | |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 177 | |
| 178 | |
Dieter Baron | 8bc1276 | 2007-08-22 13:39:13 +0200 | [diff] [blame] | 179 | ZIP_EXTERN int zip_add(struct zip *, const char *, struct zip_source *); |
| 180 | ZIP_EXTERN int zip_add_dir(struct zip *, const char *); |
| 181 | ZIP_EXTERN int zip_close(struct zip *); |
| 182 | ZIP_EXTERN int zip_delete(struct zip *, int); |
| 183 | ZIP_EXTERN void zip_error_clear(struct zip *); |
| 184 | ZIP_EXTERN void zip_error_get(struct zip *, int *, int *); |
| 185 | ZIP_EXTERN int zip_error_get_sys_type(int); |
| 186 | ZIP_EXTERN int zip_error_to_str(char *, size_t, int, int); |
| 187 | ZIP_EXTERN int zip_fclose(struct zip_file *); |
| 188 | ZIP_EXTERN void zip_file_error_clear(struct zip_file *); |
| 189 | ZIP_EXTERN void zip_file_error_get(struct zip_file *, int *, int *); |
| 190 | ZIP_EXTERN const char *zip_file_strerror(struct zip_file *); |
| 191 | ZIP_EXTERN struct zip_file *zip_fopen(struct zip *, const char *, int); |
| 192 | ZIP_EXTERN struct zip_file *zip_fopen_index(struct zip *, int, int); |
| 193 | ZIP_EXTERN ssize_t zip_fread(struct zip_file *, void *, size_t); |
| 194 | ZIP_EXTERN const char *zip_get_archive_comment(struct zip *, int *, int); |
Dieter Baron | 416df86 | 2008-05-14 14:56:13 +0200 | [diff] [blame^] | 195 | ZIP_EXTERN int zip_get_archive_flag(struct zip *, int, int); |
Dieter Baron | 8bc1276 | 2007-08-22 13:39:13 +0200 | [diff] [blame] | 196 | ZIP_EXTERN const char *zip_get_file_comment(struct zip *, int, int *, int); |
| 197 | ZIP_EXTERN const char *zip_get_name(struct zip *, int, int); |
| 198 | ZIP_EXTERN int zip_get_num_files(struct zip *); |
| 199 | ZIP_EXTERN int zip_name_locate(struct zip *, const char *, int); |
| 200 | ZIP_EXTERN struct zip *zip_open(const char *, int, int *); |
| 201 | ZIP_EXTERN int zip_rename(struct zip *, int, const char *); |
| 202 | ZIP_EXTERN int zip_replace(struct zip *, int, struct zip_source *); |
| 203 | ZIP_EXTERN int zip_set_archive_comment(struct zip *, const char *, int); |
Dieter Baron | 416df86 | 2008-05-14 14:56:13 +0200 | [diff] [blame^] | 204 | ZIP_EXTERN int zip_set_archive_flag(struct zip *, int, int); |
Dieter Baron | 8bc1276 | 2007-08-22 13:39:13 +0200 | [diff] [blame] | 205 | ZIP_EXTERN int zip_set_file_comment(struct zip *, int, const char *, int); |
| 206 | ZIP_EXTERN struct zip_source *zip_source_buffer(struct zip *, const void *, |
| 207 | off_t, int); |
| 208 | ZIP_EXTERN struct zip_source *zip_source_file(struct zip *, const char *, |
| 209 | off_t, off_t); |
| 210 | ZIP_EXTERN struct zip_source *zip_source_filep(struct zip *, FILE *, |
| 211 | off_t, off_t); |
| 212 | ZIP_EXTERN void zip_source_free(struct zip_source *); |
| 213 | ZIP_EXTERN struct zip_source *zip_source_function(struct zip *, |
| 214 | zip_source_callback, void *); |
| 215 | ZIP_EXTERN struct zip_source *zip_source_zip(struct zip *, struct zip *, |
| 216 | int, int, off_t, off_t); |
| 217 | ZIP_EXTERN int zip_stat(struct zip *, const char *, int, struct zip_stat *); |
| 218 | ZIP_EXTERN int zip_stat_index(struct zip *, int, int, struct zip_stat *); |
| 219 | ZIP_EXTERN void zip_stat_init(struct zip_stat *); |
| 220 | ZIP_EXTERN const char *zip_strerror(struct zip *); |
| 221 | ZIP_EXTERN int zip_unchange(struct zip *, int); |
| 222 | ZIP_EXTERN int zip_unchange_all(struct zip *); |
| 223 | ZIP_EXTERN int zip_unchange_archive(struct zip *); |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 224 | |
Dieter Baron | 08f2851 | 2005-07-14 14:08:11 +0000 | [diff] [blame] | 225 | #ifdef __cplusplus |
| 226 | } |
| 227 | #endif |
| 228 | |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 229 | #endif /* _HAD_ZIP_H */ |