/* inflate.h -- internal inflate state definition1* Copyright (C) 1995-2004 Mark Adler2* For conditions of distribution and use, see copyright notice in zlib.h3*/45/* WARNING: this file should *not* be used by applications. It is6part of the implementation of the compression library and is7subject to change. Applications should only use zlib.h.8*/910/* define NO_GZIP when compiling if you want to disable gzip header and11trailer decoding by inflate(). NO_GZIP would be used to avoid linking in12the crc code when it is not needed. For shared libraries, gzip decoding13should be left enabled. */14#ifndef NO_GZIP15# define GUNZIP16#endif1718/* Possible inflate modes between inflate() calls */19typedef enum {20HEAD, /* i: waiting for magic header */21FLAGS, /* i: waiting for method and flags (gzip) */22TIME, /* i: waiting for modification time (gzip) */23OS, /* i: waiting for extra flags and operating system (gzip) */24EXLEN, /* i: waiting for extra length (gzip) */25EXTRA, /* i: waiting for extra bytes (gzip) */26NAME, /* i: waiting for end of file name (gzip) */27COMMENT, /* i: waiting for end of comment (gzip) */28HCRC, /* i: waiting for header crc (gzip) */29DICTID, /* i: waiting for dictionary check value */30DICT, /* waiting for inflateSetDictionary() call */31TYPE, /* i: waiting for type bits, including last-flag bit */32TYPEDO, /* i: same, but skip check to exit inflate on new block */33STORED, /* i: waiting for stored size (length and complement) */34COPY, /* i/o: waiting for input or output to copy stored block */35TABLE, /* i: waiting for dynamic block table lengths */36LENLENS, /* i: waiting for code length code lengths */37CODELENS, /* i: waiting for length/lit and distance code lengths */38LEN, /* i: waiting for length/lit code */39LENEXT, /* i: waiting for length extra bits */40DIST, /* i: waiting for distance code */41DISTEXT, /* i: waiting for distance extra bits */42MATCH, /* o: waiting for output space to copy string */43LIT, /* o: waiting for output space to write literal */44CHECK, /* i: waiting for 32-bit check value */45LENGTH, /* i: waiting for 32-bit length (gzip) */46DONE, /* finished check, done -- remain here until reset */47BAD, /* got a data error -- remain here until reset */48MEM, /* got an inflate() memory error -- remain here until reset */49SYNC /* looking for synchronization bytes to restart inflate() */50} inflate_mode;5152/*53State transitions between above modes -5455(most modes can go to the BAD or MEM mode -- not shown for clarity)5657Process header:58HEAD -> (gzip) or (zlib)59(gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME60NAME -> COMMENT -> HCRC -> TYPE61(zlib) -> DICTID or TYPE62DICTID -> DICT -> TYPE63Read deflate blocks:64TYPE -> STORED or TABLE or LEN or CHECK65STORED -> COPY -> TYPE66TABLE -> LENLENS -> CODELENS -> LEN67Read deflate codes:68LEN -> LENEXT or LIT or TYPE69LENEXT -> DIST -> DISTEXT -> MATCH -> LEN70LIT -> LEN71Process trailer:72CHECK -> LENGTH -> DONE73*/7475/* state maintained between inflate() calls. Approximately 7K bytes. */76struct inflate_state {77inflate_mode mode; /* current inflate mode */78int last; /* true if processing last block */79int wrap; /* bit 0 true for zlib, bit 1 true for gzip */80int havedict; /* true if dictionary provided */81int flags; /* gzip header method and flags (0 if zlib) */82unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */83unsigned long check; /* protected copy of check value */84unsigned long total; /* protected copy of output count */85gz_headerp head; /* where to save gzip header information */86/* sliding window */87unsigned wbits; /* log base 2 of requested window size */88unsigned wsize; /* window size or zero if not using window */89unsigned whave; /* valid bytes in the window */90unsigned write; /* window write index */91unsigned char FAR *window; /* allocated sliding window, if needed */92/* bit accumulator */93unsigned long hold; /* input bit accumulator */94unsigned bits; /* number of bits in "in" */95/* for string and stored block copying */96unsigned length; /* literal or length of data to copy */97unsigned offset; /* distance back to copy string from */98/* for table and code decoding */99unsigned extra; /* extra bits needed */100/* fixed and dynamic code tables */101code const FAR *lencode; /* starting table for length/literal codes */102code const FAR *distcode; /* starting table for distance codes */103unsigned lenbits; /* index bits for lencode */104unsigned distbits; /* index bits for distcode */105/* dynamic table building */106unsigned ncode; /* number of code length code lengths */107unsigned nlen; /* number of length code lengths */108unsigned ndist; /* number of distance code lengths */109unsigned have; /* number of code lengths in lens[] */110code FAR *next; /* next available space in codes[] */111unsigned short lens[320]; /* temporary storage for code lengths */112unsigned short work[288]; /* work area for code table building */113code codes[ENOUGH]; /* space for code tables */114};115116117