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