J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | #define ushort unsigned short |
| 27 | #define uint unsigned int |
| 28 | #define uchar unsigned char |
| 29 | |
| 30 | struct unpacker; |
| 31 | |
| 32 | struct jar { |
| 33 | // JAR file writer |
| 34 | FILE* jarfp; |
| 35 | int default_modtime; |
| 36 | |
| 37 | // Used by unix2dostime: |
| 38 | int modtime_cache; |
| 39 | uLong dostime_cache; |
| 40 | |
| 41 | // Private members |
| 42 | fillbytes central_directory; |
| 43 | ushort central_directory_count; |
| 44 | uint output_file_offset; |
| 45 | fillbytes deflated; // temporary buffer |
| 46 | |
| 47 | // pointer to outer unpacker, for error checks etc. |
| 48 | unpacker* u; |
| 49 | |
| 50 | // Public Methods |
| 51 | void openJarFile(const char* fname); |
| 52 | void addJarEntry(const char* fname, |
| 53 | bool deflate_hint, int modtime, |
| 54 | bytes& head, bytes& tail); |
| 55 | void addDirectoryToJarFile(const char* dir_name); |
| 56 | void closeJarFile(bool central); |
| 57 | |
| 58 | void init(unpacker* u_); |
| 59 | |
| 60 | void free() { |
| 61 | central_directory.free(); |
| 62 | deflated.free(); |
| 63 | } |
| 64 | |
| 65 | void reset() { |
| 66 | free(); |
| 67 | init(u); |
| 68 | } |
| 69 | |
| 70 | // Private Methods |
| 71 | void write_data(void* ptr, int len); |
| 72 | void write_data(bytes& b) { write_data(b.ptr, b.len); } |
| 73 | void add_to_jar_directory(const char* fname, bool store, int modtime, |
| 74 | int len, int clen, uLong crc); |
| 75 | void write_jar_header(const char* fname, bool store, int modtime, |
| 76 | int len, int clen, unsigned int crc); |
| 77 | void write_central_directory(); |
| 78 | uLong dostime(int y, int n, int d, int h, int m, int s); |
| 79 | uLong get_dostime(int modtime); |
| 80 | |
| 81 | // The definitions of these depend on the NO_ZLIB option: |
| 82 | bool deflate_bytes(bytes& head, bytes& tail); |
| 83 | static uint get_crc32(uint c, unsigned char *ptr, uint len); |
| 84 | |
| 85 | // error handling |
| 86 | void abort(const char* msg) { unpack_abort(msg, u); } |
| 87 | bool aborting() { return unpack_aborting(u); } |
| 88 | }; |
| 89 | |
| 90 | struct gunzip { |
| 91 | // optional gzip input stream control block |
| 92 | |
| 93 | // pointer to outer unpacker, for error checks etc. |
| 94 | unpacker* u; |
| 95 | |
| 96 | void* read_input_fn; // underlying byte stream |
| 97 | void* zstream; // inflater state |
| 98 | char inbuf[1 << 14]; // input buffer |
| 99 | |
| 100 | void init(unpacker* u_); // pushes new value on u->read_input_fn |
| 101 | |
| 102 | void free(); |
| 103 | |
| 104 | void start(int magic); |
| 105 | |
| 106 | // private stuff |
| 107 | void read_fixed_field(char* buf, size_t buflen); |
| 108 | |
| 109 | // error handling |
| 110 | void abort(const char* msg) { unpack_abort(msg, u); } |
| 111 | bool aborting() { return unpack_aborting(u); } |
| 112 | }; |