0N/A/*
3261N/A * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * Prototypes for zip file support
0N/A */
0N/A
0N/A#ifndef _ZIP_H_
0N/A#define _ZIP_H_
0N/A
0N/A/*
0N/A * Header signatures
0N/A */
0N/A#define LOCSIG 0x04034b50L /* "PK\003\004" */
0N/A#define EXTSIG 0x08074b50L /* "PK\007\008" */
0N/A#define CENSIG 0x02014b50L /* "PK\001\002" */
0N/A#define ENDSIG 0x06054b50L /* "PK\005\006" */
0N/A
1032N/A#define ZIP64_ENDSIG 0x06064b50L /* "PK\006\006" */
1032N/A#define ZIP64_LOCSIG 0x07064b50L /* "PK\006\007" */
1032N/A
0N/A/*
0N/A * Header sizes including signatures
0N/A */
1032N/A
0N/A#define LOCHDR 30
0N/A#define EXTHDR 16
0N/A#define CENHDR 46
0N/A#define ENDHDR 22
0N/A
1032N/A#define ZIP64_ENDHDR 56 // ZIP64 end header size
1032N/A#define ZIP64_LOCHDR 20 // ZIP64 end loc header size
1032N/A#define ZIP64_EXTHDR 24 // EXT header size
1032N/A#define ZIP64_EXTID 1 // Extra field Zip64 header ID
1032N/A
1032N/A#define ZIP64_MAGICVAL 0xffffffffLL
1032N/A#define ZIP64_MAGICCOUNT 0xffff
1032N/A
1032N/A
0N/A/*
0N/A * Header field access macros
0N/A */
0N/A#define CH(b, n) (((unsigned char *)(b))[n])
0N/A#define SH(b, n) (CH(b, n) | (CH(b, n+1) << 8))
1032N/A#define LG(b, n) ((SH(b, n) | (SH(b, n+2) << 16)) &0xffffffffUL)
1032N/A#define LL(b, n) (((jlong)LG(b, n)) | (((jlong)LG(b, n+4)) << 32))
0N/A#define GETSIG(b) LG(b, 0)
0N/A
0N/A/*
0N/A * Macros for getting local file (LOC) header fields
0N/A */
0N/A#define LOCVER(b) SH(b, 4) /* version needed to extract */
0N/A#define LOCFLG(b) SH(b, 6) /* general purpose bit flags */
0N/A#define LOCHOW(b) SH(b, 8) /* compression method */
0N/A#define LOCTIM(b) LG(b, 10) /* modification time */
0N/A#define LOCCRC(b) LG(b, 14) /* crc of uncompressed data */
0N/A#define LOCSIZ(b) LG(b, 18) /* compressed data size */
0N/A#define LOCLEN(b) LG(b, 22) /* uncompressed data size */
0N/A#define LOCNAM(b) SH(b, 26) /* filename length */
0N/A#define LOCEXT(b) SH(b, 28) /* extra field length */
0N/A
0N/A/*
0N/A * Macros for getting extra local (EXT) header fields
0N/A */
0N/A#define EXTCRC(b) LG(b, 4) /* crc of uncompressed data */
0N/A#define EXTSIZ(b) LG(b, 8) /* compressed size */
0N/A#define EXTLEN(b) LG(b, 12) /* uncompressed size */
0N/A
0N/A/*
0N/A * Macros for getting central directory header (CEN) fields
0N/A */
0N/A#define CENVEM(b) SH(b, 4) /* version made by */
0N/A#define CENVER(b) SH(b, 6) /* version needed to extract */
0N/A#define CENFLG(b) SH(b, 8) /* general purpose bit flags */
0N/A#define CENHOW(b) SH(b, 10) /* compression method */
0N/A#define CENTIM(b) LG(b, 12) /* modification time */
0N/A#define CENCRC(b) LG(b, 16) /* crc of uncompressed data */
0N/A#define CENSIZ(b) LG(b, 20) /* compressed size */
0N/A#define CENLEN(b) LG(b, 24) /* uncompressed size */
0N/A#define CENNAM(b) SH(b, 28) /* length of filename */
0N/A#define CENEXT(b) SH(b, 30) /* length of extra field */
0N/A#define CENCOM(b) SH(b, 32) /* file comment length */
0N/A#define CENDSK(b) SH(b, 34) /* disk number start */
0N/A#define CENATT(b) SH(b, 36) /* internal file attributes */
0N/A#define CENATX(b) LG(b, 38) /* external file attributes */
0N/A#define CENOFF(b) LG(b, 42) /* offset of local header */
0N/A
0N/A/*
0N/A * Macros for getting end of central directory header (END) fields
0N/A */
0N/A#define ENDSUB(b) SH(b, 8) /* number of entries on this disk */
0N/A#define ENDTOT(b) SH(b, 10) /* total number of entries */
0N/A#define ENDSIZ(b) LG(b, 12) /* central directory size */
0N/A#define ENDOFF(b) LG(b, 16) /* central directory offset */
0N/A#define ENDCOM(b) SH(b, 20) /* size of zip file comment */
0N/A
0N/A/*
1032N/A * Macros for getting Zip64 end of central directory header fields
1032N/A */
1032N/A#define ZIP64_ENDLEN(b) LL(b, 4) /* size of zip64 end of central dir */
1032N/A#define ZIP64_ENDVEM(b) SH(b, 12) /* version made by */
1032N/A#define ZIP64_ENDVER(b) SH(b, 14) /* version needed to extract */
1032N/A#define ZIP64_ENDNMD(b) LG(b, 16) /* number of this disk */
1032N/A#define ZIP64_ENDDSK(b) LG(b, 20) /* disk number of start */
1032N/A#define ZIP64_ENDTOD(b) LL(b, 24) /* total number of entries on this disk */
1032N/A#define ZIP64_ENDTOT(b) LL(b, 32) /* total number of entries */
1032N/A#define ZIP64_ENDSIZ(b) LL(b, 40) /* central directory size in bytes */
1032N/A#define ZIP64_ENDOFF(b) LL(b, 48) /* offset of first CEN header */
1032N/A
1032N/A/*
1032N/A * Macros for getting Zip64 end of central directory locator fields
1032N/A */
1032N/A#define ZIP64_LOCDSK(b) LG(b, 4) /* disk number start */
1032N/A#define ZIP64_LOCOFF(b) LL(b, 8) /* offset of zip64 end */
1032N/A#define ZIP64_LOCTOT(b) LG(b, 16) /* total number of disks */
1032N/A
1032N/A/*
0N/A * Supported compression methods
0N/A */
0N/A#define STORED 0
0N/A#define DEFLATED 8
0N/A
0N/A/*
0N/A * Support for reading ZIP/JAR files. Some things worth noting:
0N/A *
0N/A * - Zip file entries larger than 2**32 bytes are not supported.
0N/A * - jzentry time and crc fields are signed even though they really
0N/A * represent unsigned quantities.
0N/A * - If csize is zero then the entry is uncompressed.
0N/A * - If extra != 0 then the first two bytes are the length of the extra
0N/A * data in intel byte order.
0N/A * - If pos <= 0 then it is the position of entry LOC header.
0N/A * If pos > 0 then it is the position of entry data.
0N/A * pos should not be accessed directly, but only by ZIP_GetEntryDataOffset.
0N/A */
0N/A
0N/Atypedef struct jzentry { /* Zip file entry */
0N/A char *name; /* entry name */
0N/A jlong time; /* modification time */
0N/A jlong size; /* size of uncompressed data */
0N/A jlong csize; /* size of compressed data (zero if uncompressed) */
0N/A jint crc; /* crc of uncompressed data */
0N/A char *comment; /* optional zip file comment */
0N/A jbyte *extra; /* optional extra data */
0N/A jlong pos; /* position of LOC header or entry data */
1107N/A jint flag; /* general purpose flag */
0N/A} jzentry;
0N/A
0N/A/*
0N/A * In-memory hash table cell.
0N/A * In a typical system we have a *lot* of these, as we have one for
0N/A * every entry in every active JAR.
0N/A * Note that in order to save space we don't keep the name in memory,
0N/A * but merely remember a 32 bit hash.
0N/A */
0N/Atypedef struct jzcell {
0N/A unsigned int hash; /* 32 bit hashcode on name */
5840N/A unsigned int next; /* hash chain: index into jzfile->entries */
1032N/A jlong cenpos; /* Offset of central directory file header */
0N/A} jzcell;
0N/A
0N/Atypedef struct cencache {
0N/A char *data; /* A cached page of CEN headers */
0N/A jlong pos; /* file offset of data */
0N/A} cencache;
0N/A
0N/A/*
0N/A * Use ZFILE to represent access to a file in a platform-indepenent
0N/A * fashion.
0N/A */
0N/A#ifdef WIN32
0N/A#define ZFILE jlong
0N/A#else
0N/A#define ZFILE int
0N/A#endif
0N/A
0N/A/*
0N/A * Descriptor for a ZIP file.
0N/A */
0N/Atypedef struct jzfile { /* Zip file */
0N/A char *name; /* zip file name */
0N/A jint refs; /* number of active references */
0N/A jlong len; /* length (in bytes) of zip file */
0N/A#ifdef USE_MMAP
0N/A unsigned char *maddr; /* beginning address of the CEN & ENDHDR */
0N/A jlong mlen; /* length (in bytes) mmaped */
910N/A jlong offset; /* offset of the mmapped region from the
0N/A start of the file. */
2227N/A jboolean usemmap; /* if mmap is used. */
2227N/A#endif
6329N/A jboolean locsig; /* if zip file starts with LOCSIG */
0N/A cencache cencache; /* CEN header cache */
0N/A ZFILE zfd; /* open file descriptor */
0N/A void *lock; /* read lock */
0N/A char *comment; /* zip file comment */
1332N/A jint clen; /* length of the zip file comment */
0N/A char *msg; /* zip error message */
0N/A jzcell *entries; /* array of hash cells */
0N/A jint total; /* total number of entries */
0N/A jint *table; /* Hash chain heads: indexes into entries */
0N/A jint tablelen; /* number of hash heads */
0N/A struct jzfile *next; /* next zip file in search list */
0N/A jzentry *cache; /* we cache the most recently freed jzentry */
0N/A /* Information on metadata names in META-INF directory */
0N/A char **metanames; /* array of meta names (may have null names) */
0N/A jint metacurrent; /* the next empty slot in metanames array */
0N/A jint metacount; /* number of slots in metanames array */
0N/A jlong lastModified; /* last modified time */
0N/A jlong locpos; /* position of first LOC header (usually 0) */
0N/A} jzfile;
0N/A
0N/A/*
0N/A * Index representing end of hash chain
0N/A */
0N/A#define ZIP_ENDCHAIN ((jint)-1)
0N/A
0N/Ajzentry * JNICALL
0N/AZIP_FindEntry(jzfile *zip, char *name, jint *sizeP, jint *nameLenP);
0N/A
0N/Ajboolean JNICALL
0N/AZIP_ReadEntry(jzfile *zip, jzentry *entry, unsigned char *buf, char *entrynm);
0N/A
0N/Ajzentry * JNICALL
0N/AZIP_GetNextEntry(jzfile *zip, jint n);
0N/A
0N/Ajzfile * JNICALL
0N/AZIP_Open(const char *name, char **pmsg);
0N/A
0N/Ajzfile *
0N/AZIP_Open_Generic(const char *name, char **pmsg, int mode, jlong lastModified);
0N/A
0N/Ajzfile *
0N/AZIP_Get_From_Cache(const char *name, char **pmsg, jlong lastModified);
0N/A
0N/Ajzfile *
0N/AZIP_Put_In_Cache(const char *name, ZFILE zfd, char **pmsg, jlong lastModified);
0N/A
2227N/Ajzfile *
2227N/AZIP_Put_In_Cache0(const char *name, ZFILE zfd, char **pmsg, jlong lastModified, jboolean usemmap);
2227N/A
0N/Avoid JNICALL
0N/AZIP_Close(jzfile *zip);
0N/A
0N/Ajzentry * ZIP_GetEntry(jzfile *zip, char *name, jint ulen);
0N/Avoid ZIP_Lock(jzfile *zip);
0N/Avoid ZIP_Unlock(jzfile *zip);
0N/Ajint ZIP_Read(jzfile *zip, jzentry *entry, jlong pos, void *buf, jint len);
0N/Avoid ZIP_FreeEntry(jzfile *zip, jzentry *ze);
0N/Ajlong ZIP_GetEntryDataOffset(jzfile *zip, jzentry *entry);
0N/A
0N/A#endif /* !_ZIP_H_ */