1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** 19* Zip Support Header 20*/ 21 22#if !defined(ZIPSUP_H) 23#define ZIPSUP_H 24#if defined(__cplusplus) 25extern "C" 26{ 27#endif 28#include "hy2sie.h" 29 30#include <stdlib.h> 31#include <unistd.h> 32#include <memory.h> 33 34#include "zlib.h" 35 36 37typedef struct HyZipCachePool HyZipCachePool; 38 39HyZipCachePool * 40zipsup_GetZipCachePool(HyPortLibrary * portLib); 41 42 43#if defined(HY_LOCAL_ZLIB) 44#define HY_ZIP_DLL_NAME "z" 45#else 46#define HY_ZIP_DLL_NAME "hyzlib" 47#endif 48 49#define ZIP_INTERNAL_MAX 80 50#define ZIP_CM_Reduced1 2 51#define ZIP_Unknown 0 52#define ZIP_GZIP 2 53#define ZIP_ERR_OUT_OF_MEMORY -3 54#define ZIP_ERR_FILE_CORRUPT -6 55#define ZIP_ERR_INTERNAL_ERROR -11 56#define ZIP_CM_Imploded 6 57#define ZIP_CM_Reduced4 5 58#define ZIP_CM_Shrunk 1 59#define ZIP_CM_Reduced2 3 60#define ZIP_ERR_FILE_READ_ERROR -1 61#define ZIP_CentralHeader 0x2014B50 62#define ZIP_ERR_FILE_CLOSE_ERROR -10 63#define ZIP_ERR_BUFFER_TOO_SMALL -7 64#define ZIP_CM_Reduced3 4 65#define ZIP_CM_Deflated 8 66#define ZIP_LocalHeader 0x4034B50 67#define ZIP_CM_Tokenized 7 68#define ZIP_PKZIP 1 69#define ZIP_CM_Stored 0 70#define ZIP_ERR_UNSUPPORTED_FILE_TYPE -5 71#define ZIP_ERR_NO_MORE_ENTRIES -2 72#define ZIP_CentralEnd 0x6054B50 73#define ZIP_ERR_FILE_OPEN_ERROR -9 74#define ZIP_ERR_UNKNOWN_FILE_TYPE -4 75#define ZIP_ERR_ENTRY_NOT_FOUND -8 76#define ZIP_DataDescriptor 0x8074B50 77 78 typedef struct HyZipCache 79 { 80 U_8 *zipFileName; 81 IDATA zipFileSize; 82 I_64 zipTimeStamp; 83 IDATA startCentralDir; 84 HyPortLibrary *portLib; 85 void *cachePool; 86 void *cachePoolEntry; 87 } HyZipCache; 88 89 90 typedef struct HyZipCentralEnd 91 { 92 U_16 diskNumber; 93 U_16 dirStartDisk; 94 U_16 thisDiskEntries; 95 U_16 totalEntries; 96 U_32 dirSize; 97 U_32 dirOffset; 98 U_16 commentLength; 99 char _hypadding0012[2]; /* 2 bytes of automatic padding */ 100 U_8 *comment; 101 } HyZipCentralEnd; 102 103 104 typedef struct HyZipDataDescriptor 105 { 106 U_32 crc32; 107 U_32 compressedSize; 108 U_32 uncompressedSize; 109 } HyZipDataDescriptor; 110 111 112 typedef struct HyZipEntry 113 { 114 U_8 *data; 115 U_8 *filename; 116 U_8 *extraField; 117 U_8 *fileComment; 118 I_32 dataPointer; 119 I_32 filenamePointer; 120 I_32 extraFieldPointer; 121 I_32 fileCommentPointer; 122 U_32 compressedSize; 123 U_32 uncompressedSize; 124 U_32 crc32; 125 U_16 filenameLength; 126 U_16 extraFieldLength; 127 U_16 fileCommentLength; 128 U_16 internalAttributes; 129 U_16 versionCreated; 130 U_16 versionNeeded; 131 U_16 flags; 132 U_16 compressionMethod; 133 U_16 lastModTime; 134 U_16 lastModDate; 135 U_8 internalFilename[80]; 136 } HyZipEntry; 137 138 139 typedef struct HyZipFile 140 { 141 U_8 *filename; 142 struct HyZipCache *cache; 143 void *cachePool; 144 I_32 fd; 145 I_32 pointer; 146 U_8 internalFilename[80]; 147 U_8 type; 148 char _hypadding0065[3]; /* 3 bytes of automatic padding */ 149 } HyZipFile; 150 151 152 153#include "hymutex.h" 154extern MUTEX zip_GlobalMutex; 155 156 157 158#define jclmem_allocate_memory(env, byteCount) sieb_malloc(env, byteCount) 159#define jclmem_free_memory(env, pointer) sieb_free(env, pointer) 160 161 162/* HySourceZipSupport*/ 163 extern HY_CFUNC I_32 zip_getZipEntryData 164 PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, 165 HyZipEntry * entry, U_8 * buffer, U_32 bufferSize)); 166 extern HY_CFUNC I_32 zip_getZipEntryFromOffset 167 PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, 168 HyZipEntry * entry, IDATA offset)); 169 extern HY_CFUNC I_32 zip_establishCache 170 PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile)); 171 extern HY_CFUNC void zip_resetZipFile 172 PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, 173 IDATA * nextEntryPointer)); 174 extern HY_CFUNC I_32 zip_getNextZipEntry 175 PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, 176 HyZipEntry * zipEntry, IDATA * nextEntryPointer)); 177 extern HY_CFUNC I_32 zip_getZipEntry 178 PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, 179 HyZipEntry * entry, const char *filename, 180 BOOLEAN findDirectory)); 181 extern HY_CFUNC I_32 zip_getZipEntryExtraField 182 PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, 183 HyZipEntry * entry, U_8 * buffer, U_32 bufferSize)); 184 extern HY_CFUNC void zip_initZipEntry 185 PROTOTYPE ((HyPortLibrary * portLib, HyZipEntry * entry)); 186 extern HY_CFUNC I_32 zip_openZipFile 187 PROTOTYPE ((HyPortLibrary * portLib, char *filename, HyZipFile * zipFile, 188 HyZipCachePool * cachePool)); 189 extern HY_CFUNC void zip_freeZipEntry 190 PROTOTYPE ((HyPortLibrary * portLib, HyZipEntry * entry)); 191 struct HyZipFile; 192 extern HY_CFUNC I_32 VMCALL zip_closeZipFile 193 PROTOTYPE ((HyPortLibrary * portLib, struct HyZipFile * zipFile)); 194 extern HY_CFUNC I_32 zip_getZipEntryComment 195 PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, 196 HyZipEntry * entry, U_8 * buffer, U_32 bufferSize)); 197/* HySourceZipCache*/ 198 extern HY_CFUNC UDATA zipCache_findElement 199 PROTOTYPE ((HyZipCache * zipCache, const char *elementName, 200 BOOLEAN searchDirList)); 201 extern HY_CFUNC void zipCache_kill PROTOTYPE ((HyZipCache * zipCache)); 202 extern HY_CFUNC IDATA zipCache_enumGetDirName 203 PROTOTYPE ((void *handle, char *nameBuf, UDATA nameBufSize)); 204 extern HY_CFUNC HyZipCache *zipCache_new 205 PROTOTYPE ((HyPortLibrary * portLib, char *zipName, IDATA zipNameLength)); 206 extern HY_CFUNC IDATA zipCache_enumNew 207 PROTOTYPE ((HyZipCache * zipCache, char *directoryName, void **handle)); 208 extern HY_CFUNC IDATA zipCache_enumElement 209 PROTOTYPE ((void *handle, char *nameBuf, UDATA nameBufSize, 210 UDATA * offset)); 211 extern HY_CFUNC void zipCache_enumKill PROTOTYPE ((void *handle)); 212 extern HY_CFUNC BOOLEAN zipCache_addElement 213 PROTOTYPE ((HyZipCache * zipCache, char *elementName, 214 UDATA elementOffset)); 215/* HySourceZipCachePool*/ 216 extern HY_CFUNC BOOLEAN zipCachePool_release 217 PROTOTYPE ((HyZipCachePool * zcp, HyZipCache * zipCache)); 218 extern HY_CFUNC void zipCachePool_kill PROTOTYPE ((HyZipCachePool * zcp)); 219 extern HY_CFUNC HyZipCache *zipCachePool_findCache 220 PROTOTYPE ((HyZipCachePool * zcp, char const *zipFileName, 221 IDATA zipFileNameLength, IDATA zipFileSize, 222 I_64 zipTimeStamp)); 223 extern HY_CFUNC HyZipCachePool *zipCachePool_new 224 PROTOTYPE ((HyPortLibrary * portLib)); 225 extern HY_CFUNC BOOLEAN zipCachePool_addCache 226 PROTOTYPE ((HyZipCachePool * zcp, HyZipCache * zipCache)); 227 extern HY_CFUNC BOOLEAN zipCachePool_addRef 228 PROTOTYPE ((HyZipCachePool * zcp, HyZipCache * zipCache)); 229#if defined(__cplusplus) 230} 231#endif 232#endif /* ZIPSUP_H */ 233