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