~ubuntu-branches/debian/sid/clamav/sid

« back to all changes in this revision

Viewing changes to libclamav/libmspack-0.4alpha/mspack/mszip.h

  • Committer: Package Import Robot
  • Author(s): Andreas Cadhalpun, Andreas Cadhalpun, Sebastian Andrzej Siewior, Frans Spiesschaert
  • Date: 2014-10-15 06:50:20 UTC
  • mfrom: (1.3.13) (42.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20141015065020-0cpy1hdueggaw35s
Tags: 0.98.5~rc1+dfsg-1
[ Andreas Cadhalpun ]
* Import new upstream release candidate.
* Drop patches included upstream and update the others.
* Add 4 new symbols to libclamav6.symbols.
* Fix debian/copyright.
* Update lintian overrides.
* Update Standards-Version to 3.9.6 (no changes needed).
* Add Breaks and Replaces for old clamd package to clamdscan.
* Remove unnecessary shlibs:Depends from clamav-dbg.
* Add patches to support LLVM 3.5.

[ Sebastian Andrzej Siewior ]
* Add embedded copy of libmspack to be used as fallback, when libmspack-dev
  is not available.

[ Frans Spiesschaert ]
* Updated Dutch Debconf template translation (Closes: #763634)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of libmspack.
 
2
 * (C) 2003-2004 Stuart Caie.
 
3
 *
 
4
 * The deflate method was created by Phil Katz. MSZIP is equivalent to the
 
5
 * deflate method.
 
6
 *
 
7
 * libmspack is free software; you can redistribute it and/or modify it under
 
8
 * the terms of the GNU Lesser General Public License (LGPL) version 2.1
 
9
 *
 
10
 * For further details, see the file COPYING.LIB distributed with libmspack
 
11
 */
 
12
 
 
13
#ifndef MSPACK_MSZIP_H
 
14
#define MSPACK_MSZIP_H 1
 
15
 
 
16
#ifdef __cplusplus
 
17
extern "C" {
 
18
#endif
 
19
 
 
20
/* MSZIP (deflate) compression / (inflate) decompression definitions */
 
21
 
 
22
#define MSZIP_FRAME_SIZE          (32768) /* size of LZ history window */
 
23
#define MSZIP_LITERAL_MAXSYMBOLS  (288)   /* literal/length huffman tree */
 
24
#define MSZIP_LITERAL_TABLEBITS   (9)
 
25
#define MSZIP_DISTANCE_MAXSYMBOLS (32)    /* distance huffman tree */
 
26
#define MSZIP_DISTANCE_TABLEBITS  (6)
 
27
 
 
28
/* if there are less direct lookup entries than symbols, the longer
 
29
 * code pointers will be <= maxsymbols. This must not happen, or we
 
30
 * will decode entries badly */
 
31
#if (1 << MSZIP_LITERAL_TABLEBITS) < (MSZIP_LITERAL_MAXSYMBOLS * 2)
 
32
# define MSZIP_LITERAL_TABLESIZE (MSZIP_LITERAL_MAXSYMBOLS * 4)
 
33
#else
 
34
# define MSZIP_LITERAL_TABLESIZE ((1 << MSZIP_LITERAL_TABLEBITS) + \
 
35
                                  (MSZIP_LITERAL_MAXSYMBOLS * 2))
 
36
#endif
 
37
 
 
38
#if (1 << MSZIP_DISTANCE_TABLEBITS) < (MSZIP_DISTANCE_MAXSYMBOLS * 2)
 
39
# define MSZIP_DISTANCE_TABLESIZE (MSZIP_DISTANCE_MAXSYMBOLS * 4)
 
40
#else
 
41
# define MSZIP_DISTANCE_TABLESIZE ((1 << MSZIP_DISTANCE_TABLEBITS) + \
 
42
                                  (MSZIP_DISTANCE_MAXSYMBOLS * 2))
 
43
#endif
 
44
 
 
45
struct mszipd_stream {
 
46
  struct mspack_system *sys;            /* I/O routines          */
 
47
  struct mspack_file   *input;          /* input file handle     */
 
48
  struct mspack_file   *output;         /* output file handle    */
 
49
  unsigned int window_posn;             /* offset within window  */
 
50
 
 
51
  /* inflate() will call this whenever the window should be emptied. */
 
52
  int (*flush_window)(struct mszipd_stream *, unsigned int);
 
53
 
 
54
  int error, repair_mode, bytes_output;
 
55
 
 
56
  /* I/O buffering */
 
57
  unsigned char *inbuf, *i_ptr, *i_end, *o_ptr, *o_end, input_end;
 
58
  unsigned int bit_buffer, bits_left, inbuf_size;
 
59
 
 
60
 
 
61
  /* huffman code lengths */
 
62
  unsigned char  LITERAL_len[MSZIP_LITERAL_MAXSYMBOLS];
 
63
  unsigned char  DISTANCE_len[MSZIP_DISTANCE_MAXSYMBOLS];
 
64
 
 
65
  /* huffman decoding tables */
 
66
  unsigned short LITERAL_table [MSZIP_LITERAL_TABLESIZE];
 
67
  unsigned short DISTANCE_table[MSZIP_DISTANCE_TABLESIZE];
 
68
 
 
69
  /* 32kb history window */
 
70
  unsigned char window[MSZIP_FRAME_SIZE];
 
71
};
 
72
 
 
73
/* allocates MS-ZIP decompression stream for decoding the given stream.
 
74
 *
 
75
 * - uses system->alloc() to allocate memory
 
76
 *
 
77
 * - returns NULL if not enough memory
 
78
 *
 
79
 * - input_buffer_size is how many bytes to use as an input bitstream buffer
 
80
 *
 
81
 * - if repair_mode is non-zero, errors in decompression will be skipped
 
82
 *   and 'holes' left will be filled with zero bytes. This allows at least
 
83
 *   a partial recovery of erroneous data.
 
84
 */
 
85
extern struct mszipd_stream *mszipd_init(struct mspack_system *system,
 
86
                                        struct mspack_file *input,
 
87
                                        struct mspack_file *output,
 
88
                                        int input_buffer_size,
 
89
                                        int repair_mode);
 
90
 
 
91
/* decompresses, or decompresses more of, an MS-ZIP stream.
 
92
 *
 
93
 * - out_bytes of data will be decompressed and the function will return
 
94
 *   with an MSPACK_ERR_OK return code.
 
95
 *
 
96
 * - decompressing will stop as soon as out_bytes is reached. if the true
 
97
 *   amount of bytes decoded spills over that amount, they will be kept for
 
98
 *   a later invocation of mszipd_decompress().
 
99
 *
 
100
 * - the output bytes will be passed to the system->write() function given in
 
101
 *   mszipd_init(), using the output file handle given in mszipd_init(). More
 
102
 *   than one call may be made to system->write()
 
103
 *
 
104
 * - MS-ZIP will read input bytes as necessary using the system->read()
 
105
 *   function given in mszipd_init(), using the input file handle given in
 
106
 *   mszipd_init(). This will continue until system->read() returns 0 bytes,
 
107
 *   or an error.
 
108
 */
 
109
extern int mszipd_decompress(struct mszipd_stream *zip, off_t out_bytes);
 
110
 
 
111
/* decompresses an entire MS-ZIP stream in a KWAJ file. Acts very much
 
112
 * like mszipd_decompress(), but doesn't take an out_bytes parameter
 
113
 */
 
114
extern int mszipd_decompress_kwaj(struct mszipd_stream *zip);
 
115
 
 
116
/* frees all stream associated with an MS-ZIP data stream
 
117
 *
 
118
 * - calls system->free() using the system pointer given in mszipd_init()
 
119
 */
 
120
void mszipd_free(struct mszipd_stream *zip);
 
121
 
 
122
#ifdef __cplusplus
 
123
}
 
124
#endif
 
125
 
 
126
#endif