~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to libclamav/nsis/nsis_zlib.h

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
ImportĀ upstreamĀ versionĀ 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* zlib.h -- interface of the 'zlib' general purpose compression library
2
 
  version 1.1.3, July 9th, 1998
3
 
 
4
 
  Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
5
 
 
6
 
  This software is provided 'as-is', without any express or implied
7
 
  warranty.  In no event will the authors be held liable for any damages
8
 
  arising from the use of this software.
9
 
 
10
 
  Permission is granted to anyone to use this software for any purpose,
11
 
  including commercial applications, and to alter it and redistribute it
12
 
  freely, subject to the following restrictions:
13
 
 
14
 
  1. The origin of this software must not be misrepresented; you must not
15
 
     claim that you wrote the original software. If you use this software
16
 
     in a product, an acknowledgment in the product documentation would be
17
 
     appreciated but is not required.
18
 
  2. Altered source versions must be plainly marked as such, and must not be
19
 
     misrepresented as being the original software.
20
 
  3. This notice may not be removed or altered from any source distribution.
21
 
 
22
 
  Jean-loup Gailly        Mark Adler
23
 
  jloup@gzip.org          madler@alumni.caltech.edu
24
 
 
25
 
 
26
 
*/
27
 
 
28
 
#ifndef _NSIS_ZLIB_H
29
 
#define _NSIS_ZLIB_H
30
 
 
31
 
#include "nsis_zconf.h"
32
 
#include "nsis_zutil.h"
33
 
 
34
 
#ifdef __cplusplus
35
 
extern "C" {
36
 
#endif
37
 
 
38
 
 
39
 
typedef struct inflate_huft_s FAR inflate_huft;
40
 
 
41
 
 
42
 
 
43
 
typedef enum {        /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
44
 
      CODES_START,    /* x: set up for LEN */
45
 
      CODES_LEN,      /* i: get length/literal/eob next */
46
 
      CODES_LENEXT,   /* i: getting length extra (have base) */
47
 
      CODES_DIST,     /* i: get distance next */
48
 
      CODES_DISTEXT,  /* i: getting distance extra */
49
 
      CODES_COPY,     /* o: copying bytes in window, waiting for space */
50
 
      CODES_LIT,      /* o: got literal, waiting for output space */
51
 
      CODES_WASH,     /* o: got eob, possibly still output waiting */
52
 
      /* CODES_END,      x: got eob and all data flushed */
53
 
      /* CODES_BADCODE,  x: got error */
54
 
 
55
 
      TYPE,     /* get type bits (3, including end bit) */
56
 
      LENS,     /* get lengths for stored */
57
 
      STORED,   /* processing stored block */
58
 
      TABLE,    /* get table lengths */
59
 
      BTREE,    /* get bit lengths tree for a dynamic block */
60
 
      DTREE,    /* get length, distance trees for a dynamic block */
61
 
      CODES,    /* processing fixed or dynamic block */
62
 
      DRY,      /* output remaining window bytes */
63
 
      DONE,     /* finished last block, done */
64
 
      NZ_BAD       /* got a data error--stuck here */
65
 
} inflate_mode;
66
 
 
67
 
/* inflate codes private state */
68
 
struct inflate_codes_state {
69
 
 
70
 
  /* mode */
71
 
  /* inflate_mode mode;      current inflate_codes mode */
72
 
 
73
 
  /* mode dependent information */
74
 
  uInt len;
75
 
  union {
76
 
    struct {
77
 
      inflate_huft *tree;       /* pointer into tree */
78
 
      uInt need;                /* bits needed */
79
 
    } code;             /* if LEN or DIST, where in tree */
80
 
    uInt lit;           /* if LIT, literal */
81
 
    struct {
82
 
      uInt get;                 /* bits to get for extra */
83
 
      uInt dist;                /* distance back to copy from */
84
 
    } copy;             /* if EXT or COPY, where and how much */
85
 
  } sub;                /* submode */
86
 
 
87
 
  /* mode independent information */
88
 
  Byte lbits;           /* ltree bits decoded per branch */
89
 
  Byte dbits;           /* dtree bits decoder per branch */
90
 
  inflate_huft *ltree;          /* literal/length/eob tree */
91
 
  inflate_huft *dtree;          /* distance tree */
92
 
 
93
 
};
94
 
 
95
 
struct inflate_huft_s {
96
 
  union {
97
 
    struct {
98
 
      Byte Exop;        /* number of extra bits or operation */
99
 
      Byte Bits;        /* number of bits in this code or subcode */
100
 
    } what;
101
 
  } word;
102
 
  unsigned short base;            /* literal, length base, distance base,
103
 
                           or table offset */
104
 
};
105
 
 
106
 
#define MANY 1440
107
 
 
108
 
typedef struct inflate_codes_state inflate_codes_statef;
109
 
 
110
 
#define FIXEDH 544      /* number of hufts used by fixed tables */
111
 
 
112
 
struct z_stuff {
113
 
  char fixed_built;
114
 
  inflate_huft fixed_mem[FIXEDH];
115
 
  uInt fixed_bl;
116
 
  uInt fixed_bd;
117
 
  inflate_huft *fixed_tl;
118
 
  inflate_huft *fixed_td;
119
 
  uIntf v[288];
120
 
  uIntf lc[288];
121
 
};
122
 
 
123
 
struct inflate_blocks_state {
124
 
  /* acab */
125
 
  struct z_stuff zs;
126
 
 
127
 
  /* mode */
128
 
  inflate_mode  mode;    /* current inflate_block mode */
129
 
 
130
 
  /* mode dependent information */
131
 
  union {
132
 
    uInt left;          /* if STORED, bytes left to copy */
133
 
    struct {
134
 
      uInt table;               /* table lengths (14 bits) */
135
 
      uInt index;               /* index into blens (or border) */
136
 
      uIntf t_blens[258+31+31];             /* bit lengths of codes */
137
 
      uInt bb;                  /* bit length tree depth */
138
 
      inflate_huft *tb;         /* bit length decoding tree */
139
 
    } trees;            /* if DTREE, decoding info for trees */
140
 
    struct {
141
 
      inflate_codes_statef t_codes;
142
 
    } decode;           /* if CODES, current state */
143
 
  } sub;                /* submode */
144
 
 
145
 
  uInt last;            /* DRY if this block is the last block, TYPE otherwise */
146
 
 
147
 
  /* mode independent information */
148
 
  uInt bitk;            /* bits in bit buffer */
149
 
  uLong bitb;           /* bit buffer */
150
 
  inflate_huft hufts[MANY];  /* single malloc for tree space */
151
 
  Bytef window[1 << MAX_WBITS];        /* sliding window */
152
 
  Bytef *end;           /* one byte after sliding window */
153
 
  Bytef *read;          /* window read pointer */
154
 
  Bytef *write;         /* window write pointer */
155
 
  uLong check;          /* check on output */
156
 
 
157
 
};
158
 
 
159
 
typedef struct nsis_z_stream_s {
160
 
    Bytef    *next_in;  /* next input byte */
161
 
    uInt     avail_in;  /* number of bytes available at next_in */
162
 
    uLong    total_in;  /* total nb of input bytes read so far */
163
 
 
164
 
    Bytef    *next_out; /* next output byte should be put there */
165
 
    uInt     avail_out; /* remaining free space at next_out */
166
 
 
167
 
    /* char     *msg;      last error message, NULL if no error */
168
 
    /* struct internal_state FAR *state; not visible by applications */
169
 
    struct inflate_blocks_state blocks;
170
 
 
171
 
} nsis_z_stream;
172
 
 
173
 
typedef nsis_z_stream FAR *nsis_z_streamp;
174
 
 
175
 
 
176
 
#define Z_NO_FLUSH      0
177
 
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
178
 
#define Z_SYNC_FLUSH    2
179
 
#define Z_FULL_FLUSH    3
180
 
#define Z_FINISH        4
181
 
/* Allowed flush values; see deflate() below for details */
182
 
 
183
 
#define Z_OK            0
184
 
#define Z_STREAM_END    1
185
 
#define Z_NEED_DICT     2
186
 
#define Z_ERRNO        (-1)
187
 
 
188
 
/* EXEHEAD doesn't need a specific return code, just < 0 */
189
 
#define Z_STREAM_ERROR (-2)
190
 
#define Z_DATA_ERROR   (-3)
191
 
#define Z_MEM_ERROR    (-4)
192
 
#define Z_BUF_ERROR    (-5)
193
 
#define Z_VERSION_ERROR (-6)
194
 
 
195
 
/* Return codes for the compression/decompression functions. Negative
196
 
 * values are errors, positive values are used for special but normal events.
197
 
 */
198
 
 
199
 
#define Z_NO_COMPRESSION         0
200
 
#define Z_BEST_SPEED             1
201
 
#define Z_BEST_COMPRESSION       9
202
 
#define Z_DEFAULT_COMPRESSION  (-1)
203
 
/* compression levels */
204
 
 
205
 
#define Z_FILTERED            1
206
 
#define Z_HUFFMAN_ONLY        2
207
 
#define Z_DEFAULT_STRATEGY    0
208
 
/* compression strategy; see deflateInit2() below for details */
209
 
 
210
 
/* Possible values of the data_type field */
211
 
 
212
 
#define Z_DEFLATED   8
213
 
/* The deflate compression method (the only one supported in this version) */
214
 
 
215
 
#define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
216
 
 
217
 
 
218
 
#define nsis_inflateInit(z) \
219
 
{ \
220
 
 (z)->blocks.zs.fixed_built = 0; \
221
 
 (z)->blocks.zs.fixed_bl = 9;     \
222
 
 (z)->blocks.zs.fixed_bd = 5;     \
223
 
 inflateReset(z);         \
224
 
}
225
 
int ZEXPORT nsis_inflate(nsis_z_streamp z);
226
 
#define inflateReset(z) \
227
 
{ \
228
 
  (z)->blocks.mode = TYPE; \
229
 
  (z)->blocks.bitk = (z)->blocks.bitb = 0; \
230
 
  (z)->blocks.read = (z)->blocks.write = (z)->blocks.window; \
231
 
  (z)->blocks.end = (z)->blocks.window + (1 << DEF_WBITS); \
232
 
}
233
 
 
234
 
#ifdef __cplusplus
235
 
}
236
 
#endif
237
 
 
238
 
#endif /* _ZLIB_H */