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