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