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