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