Chris@43: /* inflate.h -- internal inflate state definition Chris@43: * Copyright (C) 1995-2009 Mark Adler Chris@43: * For conditions of distribution and use, see copyright notice in zlib.h Chris@43: */ Chris@43: Chris@43: /* WARNING: this file should *not* be used by applications. It is Chris@43: part of the implementation of the compression library and is Chris@43: subject to change. Applications should only use zlib.h. Chris@43: */ Chris@43: Chris@43: /* define NO_GZIP when compiling if you want to disable gzip header and Chris@43: trailer decoding by inflate(). NO_GZIP would be used to avoid linking in Chris@43: the crc code when it is not needed. For shared libraries, gzip decoding Chris@43: should be left enabled. */ Chris@43: #ifndef NO_GZIP Chris@43: # define GUNZIP Chris@43: #endif Chris@43: Chris@43: /* Possible inflate modes between inflate() calls */ Chris@43: typedef enum { Chris@43: HEAD, /* i: waiting for magic header */ Chris@43: FLAGS, /* i: waiting for method and flags (gzip) */ Chris@43: TIME, /* i: waiting for modification time (gzip) */ Chris@43: OS, /* i: waiting for extra flags and operating system (gzip) */ Chris@43: EXLEN, /* i: waiting for extra length (gzip) */ Chris@43: EXTRA, /* i: waiting for extra bytes (gzip) */ Chris@43: NAME, /* i: waiting for end of file name (gzip) */ Chris@43: COMMENT, /* i: waiting for end of comment (gzip) */ Chris@43: HCRC, /* i: waiting for header crc (gzip) */ Chris@43: DICTID, /* i: waiting for dictionary check value */ Chris@43: DICT, /* waiting for inflateSetDictionary() call */ Chris@43: TYPE, /* i: waiting for type bits, including last-flag bit */ Chris@43: TYPEDO, /* i: same, but skip check to exit inflate on new block */ Chris@43: STORED, /* i: waiting for stored size (length and complement) */ Chris@43: COPY_, /* i/o: same as COPY below, but only first time in */ Chris@43: COPY, /* i/o: waiting for input or output to copy stored block */ Chris@43: TABLE, /* i: waiting for dynamic block table lengths */ Chris@43: LENLENS, /* i: waiting for code length code lengths */ Chris@43: CODELENS, /* i: waiting for length/lit and distance code lengths */ Chris@43: LEN_, /* i: same as LEN below, but only first time in */ Chris@43: LEN, /* i: waiting for length/lit/eob code */ Chris@43: LENEXT, /* i: waiting for length extra bits */ Chris@43: DIST, /* i: waiting for distance code */ Chris@43: DISTEXT, /* i: waiting for distance extra bits */ Chris@43: MATCH, /* o: waiting for output space to copy string */ Chris@43: LIT, /* o: waiting for output space to write literal */ Chris@43: CHECK, /* i: waiting for 32-bit check value */ Chris@43: LENGTH, /* i: waiting for 32-bit length (gzip) */ Chris@43: DONE, /* finished check, done -- remain here until reset */ Chris@43: BAD, /* got a data error -- remain here until reset */ Chris@43: MEM, /* got an inflate() memory error -- remain here until reset */ Chris@43: SYNC /* looking for synchronization bytes to restart inflate() */ Chris@43: } inflate_mode; Chris@43: Chris@43: /* Chris@43: State transitions between above modes - Chris@43: Chris@43: (most modes can go to BAD or MEM on error -- not shown for clarity) Chris@43: Chris@43: Process header: Chris@43: HEAD -> (gzip) or (zlib) or (raw) Chris@43: (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> Chris@43: HCRC -> TYPE Chris@43: (zlib) -> DICTID or TYPE Chris@43: DICTID -> DICT -> TYPE Chris@43: (raw) -> TYPEDO Chris@43: Read deflate blocks: Chris@43: TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK Chris@43: STORED -> COPY_ -> COPY -> TYPE Chris@43: TABLE -> LENLENS -> CODELENS -> LEN_ Chris@43: LEN_ -> LEN Chris@43: Read deflate codes in fixed or dynamic block: Chris@43: LEN -> LENEXT or LIT or TYPE Chris@43: LENEXT -> DIST -> DISTEXT -> MATCH -> LEN Chris@43: LIT -> LEN Chris@43: Process trailer: Chris@43: CHECK -> LENGTH -> DONE Chris@43: */ Chris@43: Chris@43: /* state maintained between inflate() calls. Approximately 10K bytes. */ Chris@43: struct inflate_state { Chris@43: inflate_mode mode; /* current inflate mode */ Chris@43: int last; /* true if processing last block */ Chris@43: int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ Chris@43: int havedict; /* true if dictionary provided */ Chris@43: int flags; /* gzip header method and flags (0 if zlib) */ Chris@43: unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ Chris@43: unsigned long check; /* protected copy of check value */ Chris@43: unsigned long total; /* protected copy of output count */ Chris@43: gz_headerp head; /* where to save gzip header information */ Chris@43: /* sliding window */ Chris@43: unsigned wbits; /* log base 2 of requested window size */ Chris@43: unsigned wsize; /* window size or zero if not using window */ Chris@43: unsigned whave; /* valid bytes in the window */ Chris@43: unsigned wnext; /* window write index */ Chris@43: unsigned char FAR *window; /* allocated sliding window, if needed */ Chris@43: /* bit accumulator */ Chris@43: unsigned long hold; /* input bit accumulator */ Chris@43: unsigned bits; /* number of bits in "in" */ Chris@43: /* for string and stored block copying */ Chris@43: unsigned length; /* literal or length of data to copy */ Chris@43: unsigned offset; /* distance back to copy string from */ Chris@43: /* for table and code decoding */ Chris@43: unsigned extra; /* extra bits needed */ Chris@43: /* fixed and dynamic code tables */ Chris@43: code const FAR *lencode; /* starting table for length/literal codes */ Chris@43: code const FAR *distcode; /* starting table for distance codes */ Chris@43: unsigned lenbits; /* index bits for lencode */ Chris@43: unsigned distbits; /* index bits for distcode */ Chris@43: /* dynamic table building */ Chris@43: unsigned ncode; /* number of code length code lengths */ Chris@43: unsigned nlen; /* number of length code lengths */ Chris@43: unsigned ndist; /* number of distance code lengths */ Chris@43: unsigned have; /* number of code lengths in lens[] */ Chris@43: code FAR *next; /* next available space in codes[] */ Chris@43: unsigned short lens[320]; /* temporary storage for code lengths */ Chris@43: unsigned short work[288]; /* work area for code table building */ Chris@43: code codes[ENOUGH]; /* space for code tables */ Chris@43: int sane; /* if false, allow invalid distance too far */ Chris@43: int back; /* bits back of last unprocessed length/lit */ Chris@43: unsigned was; /* initial length of match */ Chris@43: };