Barracuda Application Server C/C++ Reference
NO
ZipFileIterator.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Embedded Web-Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: ZipFileIterator.h 5355 2022-11-16 10:33:45Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2003-2019
17 *
18 * This software is copyrighted by and is the sole property of Real
19 * Time Logic LLC. All rights, title, ownership, or other interests in
20 * the software remain the property of Real Time Logic LLC. This
21 * software may only be used in accordance with the terms and
22 * conditions stipulated in the corresponding license agreement under
23 * which the software has been supplied. Any unauthorized use,
24 * duplication, transmission, distribution, or disclosure of this
25 * software is expressly forbidden.
26 *
27 * This Copyright notice may not be removed or modified without prior
28 * written consent of Real Time Logic LLC.
29 *
30 * Real Time Logic LLC. reserves the right to modify this software
31 * without notice.
32 *
33 * http://www.realtimelogic.com
34 ****************************************************************************
35 *
36 *
37 */
38#ifndef __ZipFileIterator_h
39#define __ZipFileIterator_h
40
41#include <HttpServer.h>
42#include <CspRunTm.h>
43
44#ifndef __DOXYGEN__
45struct ZipContainer;
46struct ZipFileHeaderData;
47#endif
48
49#ifdef _SHARK_DOXY
57#else
61#endif
62
69typedef struct ZipReader
70#ifdef __cplusplus
71: public CspReader
72{
73 ZipReader() {}
74 ZipReader(CspReader_Read r, U32 zipFileSize);
75#else
76{
77 CspReader super; /* As if inherited. */
78#endif
79 U32 size;
81
82#ifdef __cplusplus
83extern "C" {
84#endif
85BA_API void ZipReader_constructor(
86 ZipReader* o, CspReader_Read r, U32 zipFileSize);
87#ifdef __cplusplus
88}
89inline ZipReader::ZipReader(CspReader_Read r, U32 zipFileSize) {
90 ZipReader_constructor(this, r, zipFileSize); }
91#endif
92
93
94typedef enum {
95 ZipErr_Buf = -2000, /* The buffer is too small. */
96 ZipErr_Reading, /* Reading failed. */
97 ZipErr_Spanned, /* Spanned/Split archives not supported. */
98 ZipErr_Compression, /* Unsupported compr. Can be one of Stored or Deflated */
99 ZipErr_Incompatible, /* Unknown ZIP Central Directory Structure. */
100 ZipErr_NoError = 0
101} ZipErr;
102
103
104typedef enum {
105 ZipComprMethod_Stored=0,
106 ZipComprMethod_Deflated=8,
107 ZipComprMethod_AES=99 /* Gianluca 9/22 */
108} ZipComprMethod;
109
110
111#ifndef __DOXYGEN__
112
113typedef struct ZipFileHeader
114{
115#ifdef __cplusplus
116 const char* getFn();
117 const char* getEf();
118 const char* getAESef();
119 bool isDirectory();
120 U16 getFnLen();
121 U16 getEfLen();
122 U16 getFcLen();
123 ZipComprMethod getComprMethod();
124 U32 getUncompressedSizeLittleEndian();
125 U32 getCrc32LittleEndian();
126 U32 getCompressedSize();
127 U32 getUncompressedSize();
128 U32 getCrc32();
129 static const char* e2str(ZipErr e);
130 U16 getVersionMade();
131 U16 getFlag();
132 U32 getDataOffset();
133 U32 getTime();
134 CspReader* getReader();
135 private:
136#endif
137 struct ZipFileHeaderData* data;
138 char* fn; /* File name. Not null terminated. */
139 U8* ef; /* Extra field - GV 9/28 */
140 U8* AESef; /* AES extra field - GV 11/30/2010 */
141 ZipReader* reader;
142 U8* buf;
143 U32 bufSize;
144 U32 fileHeaderOffs;
145 ZipComprMethod comprMethod;
146 U16 fnLen;
147 U16 efLen;
148 U16 fcLen;
149} ZipFileHeader;
150
151#ifdef __cplusplus
152extern "C" {
153#endif
154#define ZipFileHeader_getFn(o) (o)->fn
155#define ZipFileHeader_getEf(o) (o)->ef
156#define ZipFileHeader_getAESef(o) (o)->AESef
157#define ZipFileHeader_isDirectory(o) ((o)->fn[(o)->fnLen-1] == '/')
158#define ZipFileHeader_getFnLen(o) (o)->fnLen
159#define ZipFileHeader_getEfLen(o) (o)->efLen
160#define ZipFileHeader_getFcLen(o) (o)->fcLen
161#define ZipFileHeader_getComprMethod(o) (o)->comprMethod
162#define ZipFileHeader_getReader(o) (CspReader*)(o)->reader
163BA_API U32 ZipFileHeader_getUncompressedSizeLittleEndian(ZipFileHeader* o);
164BA_API U32 ZipFileHeader_getCrc32LittleEndian(ZipFileHeader* o);
165BA_API U32 ZipFileHeader_getCompressedSize(ZipFileHeader* o);
166BA_API U32 ZipFileHeader_getUncompressedSize(ZipFileHeader* o);
167BA_API U32 ZipFileHeader_getCrc32(ZipFileHeader* o);
168BA_API const char* ZipFileHeader_e2str(ZipErr e);
169
170/* Return: The operating system that compressed the file. */
171BA_API U16 ZipFileHeader_getVersionMade(ZipFileHeader* o);
172
173/* ZipFileHeader_getFlag
174 Bit 0: If set, indicates that the file is encrypted.
175 Bit 2 Bit 1
176 0 0 Normal (-en) compression option was used.
177 0 1 Maximum (-exx/-ex) compression option was used.
178 1 0 Fast (-ef) compression option was used.
179 1 1 Super Fast (-es) compression option was used.
180*/
181BA_API U16 ZipFileHeader_getFlag(ZipFileHeader* o);
182
183BA_API U32 ZipFileHeader_getDataOffset(ZipFileHeader* o);
184BA_API U32 ZipFileHeader_getTime(ZipFileHeader* o);
185
186#ifdef __cplusplus
187}
188inline const char* ZipFileHeader::getFn() {
189 return ZipFileHeader_getFn(this);
190}
191inline const char* ZipFileHeader::getEf() {
192 return (char*)ZipFileHeader_getEf(this);
193}
194inline const char* ZipFileHeader::getAESef() {
195 return (char*)ZipFileHeader_getAESef(this);
196}
197inline bool ZipFileHeader::isDirectory() {
198 return ZipFileHeader_isDirectory(this) ? true : false;
199}
200inline U16 ZipFileHeader::getFnLen() {
201 return ZipFileHeader_getFnLen(this);
202}
203inline U16 ZipFileHeader::getEfLen() {
204 return ZipFileHeader_getEfLen(this);
205}
206inline U16 ZipFileHeader::getFcLen() {
207 return ZipFileHeader_getFcLen(this);
208}
209inline ZipComprMethod ZipFileHeader::getComprMethod() {
210 return ZipFileHeader_getComprMethod(this);
211}
212inline CspReader* ZipFileHeader::getReader() {
213 return ZipFileHeader_getReader(this);
214}
215inline U32 ZipFileHeader::getUncompressedSizeLittleEndian() {
216 return ZipFileHeader_getUncompressedSizeLittleEndian(this);
217}
218inline U32 ZipFileHeader::getCrc32LittleEndian() {
219 return ZipFileHeader_getCrc32LittleEndian(this);
220}
221inline U32 ZipFileHeader::getCompressedSize() {
222 return ZipFileHeader_getCompressedSize(this);
223}
224inline U32 ZipFileHeader::getUncompressedSize() {
225 return ZipFileHeader_getUncompressedSize(this);
226}
227inline U32 ZipFileHeader::getCrc32() {
228 return ZipFileHeader_getCrc32(this);
229}
230inline const char* ZipFileHeader::e2str(ZipErr e) {
231 return ZipFileHeader_e2str(e);
232}
233inline U16 ZipFileHeader::getVersionMade() {
234 return ZipFileHeader_getVersionMade(this);
235}
236inline U16 ZipFileHeader::getFlag() {
237 return ZipFileHeader_getFlag(this);
238}
239inline U32 ZipFileHeader::getDataOffset() {
240 return ZipFileHeader_getDataOffset(this);
241}
242inline U32 ZipFileHeader::getTime() {
243 return ZipFileHeader_getTime(this);
244}
245#endif
246
247#endif /* __DOXYGEN__ */
248
249
252typedef struct ZipFileInfo
253{
254 U32 crc32;
255 U32 dataOffset;
256 U32 uncompressedSize;
257 U32 compressedSize;
258 U32 time;
259 ZipComprMethod comprMethod;
260 U16 flag;
261 U8 *ef; /* AES encrypted ZIP file info */
262 U8 *AESef; /* AES encrypted ZIP file info */
264
265#if defined(B_LITTLE_ENDIAN)
266#define ZipFileInfo_makeLittleEndianU32(x) x
267#elif defined(B_BIG_ENDIAN)
268#define ZipFileInfo_makeLittleEndianU32(x) \
269 ((U32)((((U32)(x) & 0x000000ffU) << 24) | \
270 (((U32)(x) & 0x0000ff00U) << 8) | \
271 (((U32)(x) & 0x00ff0000U) >> 8) | \
272 (((U32)(x) & 0xff000000U) >> 24)))
273#else
274#error in config/make file, you must define one of B_LITTLE_ENDIAN or B_BIG_ENDIAN
275#endif
276
277#define ZipFileInfo_getCrc32LittleEndian(o) \
278 ZipFileInfo_makeLittleEndianU32((o)->crc32);
279#define ZipFileInfo_getUncompressedSizeLittleEndian(o) \
280 ZipFileInfo_makeLittleEndianU32((o)->uncompressedSize);
281
282
283#define ZipFileInfo_constructor(o, fileHeader, EfPtr) \
284do { \
285 (o)->crc32 = ZipFileHeader_getCrc32(fileHeader); \
286 (o)->dataOffset = ZipFileHeader_getDataOffset(fileHeader); \
287 (o)->uncompressedSize = ZipFileHeader_getUncompressedSize(fileHeader); \
288 (o)->compressedSize = ZipFileHeader_getCompressedSize(fileHeader); \
289 (o)->time = ZipFileHeader_getTime(fileHeader); \
290 (o)->comprMethod = ZipFileHeader_getComprMethod(fileHeader); \
291 (o)->flag = ZipFileHeader_getFlag(fileHeader); \
292 (o)->ef = EfPtr; \
293 (o)->AESef = (EfPtr + (ZipFileHeader_getAESef(fileHeader) - ZipFileHeader_getEf(fileHeader))); \
294}while(0)
295
296
297#ifndef __DOXYGEN__
298typedef struct
299{
300 U32 dataOffset;
301 U32 uncompressedSize;
302 U32 compressedSize;
303 ZipComprMethod comprMethod;
304} MiniZipFileInfo;
305#endif
306
307#define MiniZipFileInfo_constructor(o, fileHeader) \
308do { \
309 (o)->dataOffset = ZipFileHeader_getDataOffset(fileHeader); \
310 (o)->uncompressedSize = ZipFileHeader_getUncompressedSize(fileHeader); \
311 (o)->compressedSize = ZipFileHeader_getCompressedSize(fileHeader); \
312 (o)->comprMethod = ZipFileHeader_getComprMethod(fileHeader); \
313}while(0)
314
315
320typedef struct CentralDirIterator
321{
322#ifdef __cplusplus
324 CentralDirIterator(ZipContainer* container, U8* buf, U32 bufSize);
325 ZipErr getECode();
326 ZipFileHeader* getElement();
327 bool nextElement();
328 private:
329#endif
330 ZipFileHeader fileHeader;
331 U32 curFileHeaderOffs;
332 ZipErr err;
333 U16 entriesInCd;
334 U16 curEntry;
336
337#ifdef __cplusplus
338extern "C" {
339#endif
340#define CentralDirIterator_getECode(o) (o)->err
341BA_API void CentralDirIterator_constructor(CentralDirIterator* o,
342 struct ZipContainer* container);
343/* Re-entrant version,
344 * minimum size for buffer is 256
345 */
346BA_API void CentralDirIterator_constructorR(CentralDirIterator* o,
347 struct ZipContainer* container,
348 U8* buf, U32 bufSize);
349BA_API ZipFileHeader* CentralDirIterator_getElement(CentralDirIterator* o);
350BA_API BaBool CentralDirIterator_nextElement(CentralDirIterator* o);
351#ifdef __cplusplus
352}
353inline CentralDirIterator::CentralDirIterator(ZipContainer* container) {
354 CentralDirIterator_constructor(this, container);
355}
356inline CentralDirIterator::CentralDirIterator(
357 ZipContainer* container, U8* buf, U32 bufSize) {
358 CentralDirIterator_constructorR(this, container, buf, bufSize);
359}
360inline ZipErr CentralDirIterator::getECode() {
361 return CentralDirIterator_getECode(this);
362}
363inline ZipFileHeader* CentralDirIterator::getElement() {
364 return CentralDirIterator_getElement(this);
365}
366inline bool CentralDirIterator::nextElement() {
367 return CentralDirIterator_nextElement(this) ? true : false;
368}
369#endif
370
371
372
378typedef struct ZipContainer
379{
380#ifdef __cplusplus
381 ZipContainer(){}
382 void *operator new(size_t s) { return ::baMalloc(s); }
383 void operator delete(void* d) { if(d) ::baFree(d); }
384 void *operator new(size_t, void *place) { return place; }
385 void operator delete(void*, void *) { }
386
394 ZipContainer(ZipReader* reader, U8* buf, U32 bufSize);
395 ZipErr getECode();
396 private:
397#endif
398 ZipReader* reader;
399 U8* buf;
400 U32 bufSize;
401 U32 cdOffset;
402 ZipErr errCode;
403 U16 entriesInCd;
405
406#ifdef __cplusplus
407extern "C" {
408#endif
409BA_API void ZipContainer_constructor(ZipContainer* o,
410 ZipReader* reader,
411 U8* buf,
412 U32 bufSize);
413#define ZipContainer_getECode(o) (o)->errCode
414#ifdef __cplusplus
415}
416inline ZipContainer::ZipContainer(ZipReader* reader, U8* buf, U32 bufSize) {
417 ZipContainer_constructor(this,reader,buf,bufSize); }
418inline ZipErr ZipContainer::getECode() {
419 return ZipContainer_getECode(this); }
420#endif
421
422int initGZipHeader(struct ZipFileInfo* zfi, GzipHeader* gzipH);
423
424 /* end of IO */
426
427
428#endif
int(* CspReader_Read)(struct CspReader *o, void *data, U32 offset, U32 size, int blockStart)
Prototype for the CspReader callback function.
Definition: CspRunTm.h:107
void * baMalloc(size_t size)
Returns pointer to uninitialized newly-allocated space for an object of size "size",...
void baFree(void *p)
Deallocates space to which it points.
struct ZipContainer ZipContainer
A ZipContainer is a buffer used by a ZipIo when reading data from a ZipReader.
struct CentralDirIterator CentralDirIterator
Low level ZIP file central directory iterator.
struct ZipFileInfo ZipFileInfo
Low level ZIP file information used internally by the Zip File System.
Low level ZIP file central directory iterator.
Definition: ZipFileIterator.h:321
Abstract interface class for reading the "dat" file generated byHttpLink.
Definition: CspRunTm.h:119
A ZipContainer is a buffer used by a ZipIo when reading data from a ZipReader.
Definition: ZipFileIterator.h:379
Low level ZIP file information used internally by the Zip File System.
Definition: ZipFileIterator.h:253
Abstract interface class for reading a ZipFile.
Definition: ZipFileIterator.h:72