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