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