1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 * |
|
4 * This code is free software; you can redistribute it and/or modify it |
|
5 * under the terms of the GNU General Public License version 2 only, as |
|
6 * published by the Free Software Foundation. Oracle designates this |
|
7 * particular file as subject to the "Classpath" exception as provided |
|
8 * by Oracle in the LICENSE file that accompanied this code. |
|
9 * |
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
|
14 * accompanied this code). |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License version |
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 * |
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 * or visit www.oracle.com if you need additional information or have any |
|
22 * questions. |
|
23 */ |
|
24 |
|
25 /* inflate.h -- internal inflate state definition |
|
26 * Copyright (C) 1995-2004 Mark Adler |
|
27 * For conditions of distribution and use, see copyright notice in zlib.h |
|
28 */ |
|
29 |
|
30 /* WARNING: this file should *not* be used by applications. It is |
|
31 part of the implementation of the compression library and is |
|
32 subject to change. Applications should only use zlib.h. |
|
33 */ |
|
34 |
|
35 /* define NO_GZIP when compiling if you want to disable gzip header and |
|
36 trailer decoding by inflate(). NO_GZIP would be used to avoid linking in |
|
37 the crc code when it is not needed. For shared libraries, gzip decoding |
|
38 should be left enabled. */ |
|
39 #ifndef NO_GZIP |
|
40 # define GUNZIP |
|
41 #endif |
|
42 |
|
43 /* Possible inflate modes between inflate() calls */ |
|
44 typedef enum { |
|
45 HEAD, /* i: waiting for magic header */ |
|
46 FLAGS, /* i: waiting for method and flags (gzip) */ |
|
47 TIME, /* i: waiting for modification time (gzip) */ |
|
48 OS, /* i: waiting for extra flags and operating system (gzip) */ |
|
49 EXLEN, /* i: waiting for extra length (gzip) */ |
|
50 EXTRA, /* i: waiting for extra bytes (gzip) */ |
|
51 NAME, /* i: waiting for end of file name (gzip) */ |
|
52 COMMENT, /* i: waiting for end of comment (gzip) */ |
|
53 HCRC, /* i: waiting for header crc (gzip) */ |
|
54 DICTID, /* i: waiting for dictionary check value */ |
|
55 DICT, /* waiting for inflateSetDictionary() call */ |
|
56 TYPE, /* i: waiting for type bits, including last-flag bit */ |
|
57 TYPEDO, /* i: same, but skip check to exit inflate on new block */ |
|
58 STORED, /* i: waiting for stored size (length and complement) */ |
|
59 COPY, /* i/o: waiting for input or output to copy stored block */ |
|
60 TABLE, /* i: waiting for dynamic block table lengths */ |
|
61 LENLENS, /* i: waiting for code length code lengths */ |
|
62 CODELENS, /* i: waiting for length/lit and distance code lengths */ |
|
63 LEN, /* i: waiting for length/lit code */ |
|
64 LENEXT, /* i: waiting for length extra bits */ |
|
65 DIST, /* i: waiting for distance code */ |
|
66 DISTEXT, /* i: waiting for distance extra bits */ |
|
67 MATCH, /* o: waiting for output space to copy string */ |
|
68 LIT, /* o: waiting for output space to write literal */ |
|
69 CHECK, /* i: waiting for 32-bit check value */ |
|
70 LENGTH, /* i: waiting for 32-bit length (gzip) */ |
|
71 DONE, /* finished check, done -- remain here until reset */ |
|
72 BAD, /* got a data error -- remain here until reset */ |
|
73 MEM, /* got an inflate() memory error -- remain here until reset */ |
|
74 SYNC /* looking for synchronization bytes to restart inflate() */ |
|
75 } inflate_mode; |
|
76 |
|
77 /* |
|
78 State transitions between above modes - |
|
79 |
|
80 (most modes can go to the BAD or MEM mode -- not shown for clarity) |
|
81 |
|
82 Process header: |
|
83 HEAD -> (gzip) or (zlib) |
|
84 (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME |
|
85 NAME -> COMMENT -> HCRC -> TYPE |
|
86 (zlib) -> DICTID or TYPE |
|
87 DICTID -> DICT -> TYPE |
|
88 Read deflate blocks: |
|
89 TYPE -> STORED or TABLE or LEN or CHECK |
|
90 STORED -> COPY -> TYPE |
|
91 TABLE -> LENLENS -> CODELENS -> LEN |
|
92 Read deflate codes: |
|
93 LEN -> LENEXT or LIT or TYPE |
|
94 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN |
|
95 LIT -> LEN |
|
96 Process trailer: |
|
97 CHECK -> LENGTH -> DONE |
|
98 */ |
|
99 |
|
100 /* state maintained between inflate() calls. Approximately 7K bytes. */ |
|
101 struct inflate_state { |
|
102 inflate_mode mode; /* current inflate mode */ |
|
103 int last; /* true if processing last block */ |
|
104 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ |
|
105 int havedict; /* true if dictionary provided */ |
|
106 int flags; /* gzip header method and flags (0 if zlib) */ |
|
107 unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ |
|
108 unsigned long check; /* protected copy of check value */ |
|
109 unsigned long total; /* protected copy of output count */ |
|
110 gz_headerp head; /* where to save gzip header information */ |
|
111 /* sliding window */ |
|
112 unsigned wbits; /* log base 2 of requested window size */ |
|
113 unsigned wsize; /* window size or zero if not using window */ |
|
114 unsigned whave; /* valid bytes in the window */ |
|
115 unsigned write; /* window write index */ |
|
116 unsigned char FAR *window; /* allocated sliding window, if needed */ |
|
117 /* bit accumulator */ |
|
118 unsigned long hold; /* input bit accumulator */ |
|
119 unsigned bits; /* number of bits in "in" */ |
|
120 /* for string and stored block copying */ |
|
121 unsigned length; /* literal or length of data to copy */ |
|
122 unsigned offset; /* distance back to copy string from */ |
|
123 /* for table and code decoding */ |
|
124 unsigned extra; /* extra bits needed */ |
|
125 /* fixed and dynamic code tables */ |
|
126 code const FAR *lencode; /* starting table for length/literal codes */ |
|
127 code const FAR *distcode; /* starting table for distance codes */ |
|
128 unsigned lenbits; /* index bits for lencode */ |
|
129 unsigned distbits; /* index bits for distcode */ |
|
130 /* dynamic table building */ |
|
131 unsigned ncode; /* number of code length code lengths */ |
|
132 unsigned nlen; /* number of length code lengths */ |
|
133 unsigned ndist; /* number of distance code lengths */ |
|
134 unsigned have; /* number of code lengths in lens[] */ |
|
135 code FAR *next; /* next available space in codes[] */ |
|
136 unsigned short lens[320]; /* temporary storage for code lengths */ |
|
137 unsigned short work[288]; /* work area for code table building */ |
|
138 code codes[ENOUGH]; /* space for code tables */ |
|
139 }; |
|