1*3886Sahl /* inflate.h -- internal inflate state definition 2*3886Sahl * Copyright (C) 1995-2004 Mark Adler 3*3886Sahl * For conditions of distribution and use, see copyright notice in zlib.h 4*3886Sahl */ 5*3886Sahl 6*3886Sahl #pragma ident "%Z%%M% %I% %E% SMI" 7*3886Sahl 8*3886Sahl /* WARNING: this file should *not* be used by applications. It is 9*3886Sahl part of the implementation of the compression library and is 10*3886Sahl subject to change. Applications should only use zlib.h. 11*3886Sahl */ 12*3886Sahl 13*3886Sahl /* define NO_GZIP when compiling if you want to disable gzip header and 14*3886Sahl trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 15*3886Sahl the crc code when it is not needed. For shared libraries, gzip decoding 16*3886Sahl should be left enabled. */ 17*3886Sahl #ifndef NO_GZIP 18*3886Sahl # define GUNZIP 19*3886Sahl #endif 20*3886Sahl 21*3886Sahl /* Possible inflate modes between inflate() calls */ 22*3886Sahl typedef enum { 23*3886Sahl HEAD, /* i: waiting for magic header */ 24*3886Sahl FLAGS, /* i: waiting for method and flags (gzip) */ 25*3886Sahl TIME, /* i: waiting for modification time (gzip) */ 26*3886Sahl OS, /* i: waiting for extra flags and operating system (gzip) */ 27*3886Sahl EXLEN, /* i: waiting for extra length (gzip) */ 28*3886Sahl EXTRA, /* i: waiting for extra bytes (gzip) */ 29*3886Sahl NAME, /* i: waiting for end of file name (gzip) */ 30*3886Sahl COMMENT, /* i: waiting for end of comment (gzip) */ 31*3886Sahl HCRC, /* i: waiting for header crc (gzip) */ 32*3886Sahl DICTID, /* i: waiting for dictionary check value */ 33*3886Sahl DICT, /* waiting for inflateSetDictionary() call */ 34*3886Sahl TYPE, /* i: waiting for type bits, including last-flag bit */ 35*3886Sahl TYPEDO, /* i: same, but skip check to exit inflate on new block */ 36*3886Sahl STORED, /* i: waiting for stored size (length and complement) */ 37*3886Sahl COPY, /* i/o: waiting for input or output to copy stored block */ 38*3886Sahl TABLE, /* i: waiting for dynamic block table lengths */ 39*3886Sahl LENLENS, /* i: waiting for code length code lengths */ 40*3886Sahl CODELENS, /* i: waiting for length/lit and distance code lengths */ 41*3886Sahl LEN, /* i: waiting for length/lit code */ 42*3886Sahl LENEXT, /* i: waiting for length extra bits */ 43*3886Sahl DIST, /* i: waiting for distance code */ 44*3886Sahl DISTEXT, /* i: waiting for distance extra bits */ 45*3886Sahl MATCH, /* o: waiting for output space to copy string */ 46*3886Sahl LIT, /* o: waiting for output space to write literal */ 47*3886Sahl CHECK, /* i: waiting for 32-bit check value */ 48*3886Sahl LENGTH, /* i: waiting for 32-bit length (gzip) */ 49*3886Sahl DONE, /* finished check, done -- remain here until reset */ 50*3886Sahl BAD, /* got a data error -- remain here until reset */ 51*3886Sahl MEM, /* got an inflate() memory error -- remain here until reset */ 52*3886Sahl SYNC /* looking for synchronization bytes to restart inflate() */ 53*3886Sahl } inflate_mode; 54*3886Sahl 55*3886Sahl /* 56*3886Sahl State transitions between above modes - 57*3886Sahl 58*3886Sahl (most modes can go to the BAD or MEM mode -- not shown for clarity) 59*3886Sahl 60*3886Sahl Process header: 61*3886Sahl HEAD -> (gzip) or (zlib) 62*3886Sahl (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME 63*3886Sahl NAME -> COMMENT -> HCRC -> TYPE 64*3886Sahl (zlib) -> DICTID or TYPE 65*3886Sahl DICTID -> DICT -> TYPE 66*3886Sahl Read deflate blocks: 67*3886Sahl TYPE -> STORED or TABLE or LEN or CHECK 68*3886Sahl STORED -> COPY -> TYPE 69*3886Sahl TABLE -> LENLENS -> CODELENS -> LEN 70*3886Sahl Read deflate codes: 71*3886Sahl LEN -> LENEXT or LIT or TYPE 72*3886Sahl LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 73*3886Sahl LIT -> LEN 74*3886Sahl Process trailer: 75*3886Sahl CHECK -> LENGTH -> DONE 76*3886Sahl */ 77*3886Sahl 78*3886Sahl /* state maintained between inflate() calls. Approximately 7K bytes. */ 79*3886Sahl struct inflate_state { 80*3886Sahl inflate_mode mode; /* current inflate mode */ 81*3886Sahl int last; /* true if processing last block */ 82*3886Sahl int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 83*3886Sahl int havedict; /* true if dictionary provided */ 84*3886Sahl int flags; /* gzip header method and flags (0 if zlib) */ 85*3886Sahl unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 86*3886Sahl unsigned long check; /* protected copy of check value */ 87*3886Sahl unsigned long total; /* protected copy of output count */ 88*3886Sahl gz_headerp head; /* where to save gzip header information */ 89*3886Sahl /* sliding window */ 90*3886Sahl unsigned wbits; /* log base 2 of requested window size */ 91*3886Sahl unsigned wsize; /* window size or zero if not using window */ 92*3886Sahl unsigned whave; /* valid bytes in the window */ 93*3886Sahl unsigned write; /* window write index */ 94*3886Sahl unsigned char FAR *window; /* allocated sliding window, if needed */ 95*3886Sahl /* bit accumulator */ 96*3886Sahl unsigned long hold; /* input bit accumulator */ 97*3886Sahl unsigned bits; /* number of bits in "in" */ 98*3886Sahl /* for string and stored block copying */ 99*3886Sahl unsigned length; /* literal or length of data to copy */ 100*3886Sahl unsigned offset; /* distance back to copy string from */ 101*3886Sahl /* for table and code decoding */ 102*3886Sahl unsigned extra; /* extra bits needed */ 103*3886Sahl /* fixed and dynamic code tables */ 104*3886Sahl code const FAR *lencode; /* starting table for length/literal codes */ 105*3886Sahl code const FAR *distcode; /* starting table for distance codes */ 106*3886Sahl unsigned lenbits; /* index bits for lencode */ 107*3886Sahl unsigned distbits; /* index bits for distcode */ 108*3886Sahl /* dynamic table building */ 109*3886Sahl unsigned ncode; /* number of code length code lengths */ 110*3886Sahl unsigned nlen; /* number of length code lengths */ 111*3886Sahl unsigned ndist; /* number of distance code lengths */ 112*3886Sahl unsigned have; /* number of code lengths in lens[] */ 113*3886Sahl code FAR *next; /* next available space in codes[] */ 114*3886Sahl unsigned short lens[320]; /* temporary storage for code lengths */ 115*3886Sahl unsigned short work[288]; /* work area for code table building */ 116*3886Sahl code codes[ENOUGH]; /* space for code tables */ 117*3886Sahl }; 118