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