1168404Spjd/* inflate.h -- internal inflate state definition 2168404Spjd * Copyright (C) 1995-2004 Mark Adler 3168404Spjd * For conditions of distribution and use, see copyright notice in zlib.h 4168404Spjd */ 5168404Spjd 6168404Spjd#pragma ident "%Z%%M% %I% %E% SMI" 7168404Spjd 8168404Spjd/* WARNING: this file should *not* be used by applications. It is 9168404Spjd part of the implementation of the compression library and is 10168404Spjd subject to change. Applications should only use zlib.h. 11168404Spjd */ 12168404Spjd 13168404Spjd/* define NO_GZIP when compiling if you want to disable gzip header and 14168404Spjd trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 15168404Spjd the crc code when it is not needed. For shared libraries, gzip decoding 16168404Spjd should be left enabled. */ 17168404Spjd#ifndef NO_GZIP 18168404Spjd# define GUNZIP 19168404Spjd#endif 20168404Spjd 21168404Spjd/* Possible inflate modes between inflate() calls */ 22168404Spjdtypedef enum { 23168404Spjd HEAD, /* i: waiting for magic header */ 24168404Spjd FLAGS, /* i: waiting for method and flags (gzip) */ 25168404Spjd TIME, /* i: waiting for modification time (gzip) */ 26168404Spjd OS, /* i: waiting for extra flags and operating system (gzip) */ 27168404Spjd EXLEN, /* i: waiting for extra length (gzip) */ 28168404Spjd EXTRA, /* i: waiting for extra bytes (gzip) */ 29168404Spjd NAME, /* i: waiting for end of file name (gzip) */ 30168404Spjd COMMENT, /* i: waiting for end of comment (gzip) */ 31168404Spjd HCRC, /* i: waiting for header crc (gzip) */ 32168404Spjd DICTID, /* i: waiting for dictionary check value */ 33168404Spjd DICT, /* waiting for inflateSetDictionary() call */ 34168404Spjd TYPE, /* i: waiting for type bits, including last-flag bit */ 35168404Spjd TYPEDO, /* i: same, but skip check to exit inflate on new block */ 36168404Spjd STORED, /* i: waiting for stored size (length and complement) */ 37168404Spjd COPY, /* i/o: waiting for input or output to copy stored block */ 38168404Spjd TABLE, /* i: waiting for dynamic block table lengths */ 39168404Spjd LENLENS, /* i: waiting for code length code lengths */ 40168404Spjd CODELENS, /* i: waiting for length/lit and distance code lengths */ 41168404Spjd LEN, /* i: waiting for length/lit code */ 42168404Spjd LENEXT, /* i: waiting for length extra bits */ 43168404Spjd DIST, /* i: waiting for distance code */ 44168404Spjd DISTEXT, /* i: waiting for distance extra bits */ 45168404Spjd MATCH, /* o: waiting for output space to copy string */ 46168404Spjd LIT, /* o: waiting for output space to write literal */ 47168404Spjd CHECK, /* i: waiting for 32-bit check value */ 48168404Spjd LENGTH, /* i: waiting for 32-bit length (gzip) */ 49168404Spjd DONE, /* finished check, done -- remain here until reset */ 50168404Spjd BAD, /* got a data error -- remain here until reset */ 51168404Spjd MEM, /* got an inflate() memory error -- remain here until reset */ 52168404Spjd SYNC /* looking for synchronization bytes to restart inflate() */ 53168404Spjd} inflate_mode; 54168404Spjd 55168404Spjd/* 56168404Spjd State transitions between above modes - 57168404Spjd 58168404Spjd (most modes can go to the BAD or MEM mode -- not shown for clarity) 59168404Spjd 60168404Spjd Process header: 61168404Spjd HEAD -> (gzip) or (zlib) 62168404Spjd (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME 63168404Spjd NAME -> COMMENT -> HCRC -> TYPE 64168404Spjd (zlib) -> DICTID or TYPE 65168404Spjd DICTID -> DICT -> TYPE 66168404Spjd Read deflate blocks: 67168404Spjd TYPE -> STORED or TABLE or LEN or CHECK 68168404Spjd STORED -> COPY -> TYPE 69168404Spjd TABLE -> LENLENS -> CODELENS -> LEN 70168404Spjd Read deflate codes: 71168404Spjd LEN -> LENEXT or LIT or TYPE 72168404Spjd LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 73168404Spjd LIT -> LEN 74168404Spjd Process trailer: 75168404Spjd CHECK -> LENGTH -> DONE 76168404Spjd */ 77168404Spjd 78168404Spjd/* state maintained between inflate() calls. Approximately 7K bytes. */ 79168404Spjdstruct inflate_state { 80168404Spjd inflate_mode mode; /* current inflate mode */ 81168404Spjd int last; /* true if processing last block */ 82168404Spjd int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 83168404Spjd int havedict; /* true if dictionary provided */ 84168404Spjd int flags; /* gzip header method and flags (0 if zlib) */ 85168404Spjd unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 86168404Spjd unsigned long check; /* protected copy of check value */ 87168404Spjd unsigned long total; /* protected copy of output count */ 88168404Spjd gz_headerp head; /* where to save gzip header information */ 89168404Spjd /* sliding window */ 90168404Spjd unsigned wbits; /* log base 2 of requested window size */ 91168404Spjd unsigned wsize; /* window size or zero if not using window */ 92168404Spjd unsigned whave; /* valid bytes in the window */ 93168404Spjd unsigned write; /* window write index */ 94168404Spjd unsigned char FAR *window; /* allocated sliding window, if needed */ 95168404Spjd /* bit accumulator */ 96168404Spjd unsigned long hold; /* input bit accumulator */ 97168404Spjd unsigned bits; /* number of bits in "in" */ 98168404Spjd /* for string and stored block copying */ 99168404Spjd unsigned length; /* literal or length of data to copy */ 100168404Spjd unsigned offset; /* distance back to copy string from */ 101168404Spjd /* for table and code decoding */ 102168404Spjd unsigned extra; /* extra bits needed */ 103168404Spjd /* fixed and dynamic code tables */ 104168404Spjd code const FAR *lencode; /* starting table for length/literal codes */ 105168404Spjd code const FAR *distcode; /* starting table for distance codes */ 106168404Spjd unsigned lenbits; /* index bits for lencode */ 107168404Spjd unsigned distbits; /* index bits for distcode */ 108168404Spjd /* dynamic table building */ 109168404Spjd unsigned ncode; /* number of code length code lengths */ 110168404Spjd unsigned nlen; /* number of length code lengths */ 111168404Spjd unsigned ndist; /* number of distance code lengths */ 112168404Spjd unsigned have; /* number of code lengths in lens[] */ 113168404Spjd code FAR *next; /* next available space in codes[] */ 114168404Spjd unsigned short lens[320]; /* temporary storage for code lengths */ 115168404Spjd unsigned short work[288]; /* work area for code table building */ 116168404Spjd code codes[ENOUGH]; /* space for code tables */ 117168404Spjd}; 118