~ubuntu-branches/ubuntu/trusty/clamav/trusty-proposed

« back to all changes in this revision

Viewing changes to libclamav/mspack/qtm.h

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2005-09-19 09:05:59 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050919090559-hikpqduq8yx5qxo2
Tags: 0.87-1
* New upstream version
  - Fixes CAN-2005-2920 and CAN-2005-2919 (closes: #328660)
* New logcheck line for clamav-daemon (closes: #323132)
* relibtoolize and apply kfreebsd patch (closes: #327707)
* Make sure init.d script starts freshclam up again after upgrade when run
  from if-up.d (closes: #328912)

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 Quantum method was created by David Stafford, adapted by Microsoft
 
5
 * Corporation.
 
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_QTM_H
 
14
#define MSPACK_QTM_H 1
 
15
 
 
16
/* Quantum compression / decompression definitions */
 
17
 
 
18
#define QTM_FRAME_SIZE (32768)
 
19
 
 
20
struct qtmd_modelsym {
 
21
  unsigned short sym, cumfreq;
 
22
};
 
23
 
 
24
struct qtmd_model {
 
25
  int shiftsleft, entries;
 
26
  struct qtmd_modelsym *syms;
 
27
};
 
28
 
 
29
struct qtmd_stream {
 
30
  struct mspack_system *sys;      /* I/O routines                            */
 
31
  struct mspack_file   *input;    /* input file handle                       */
 
32
  struct mspack_file   *output;   /* output file handle                      */
 
33
 
 
34
  unsigned char *window;          /* decoding window                         */
 
35
  unsigned int window_size;       /* window size                             */
 
36
  unsigned int window_posn;       /* decompression offset within window      */
 
37
  unsigned int frame_start;       /* start of current frame within window    */
 
38
 
 
39
  unsigned short H, L, C;         /* high/low/current: arith coding state    */
 
40
  unsigned char header_read;      /* have we started decoding a new frame?   */
 
41
 
 
42
  int error;
 
43
 
 
44
  /* I/O buffers */
 
45
  unsigned char *inbuf, *i_ptr, *i_end, *o_ptr, *o_end;
 
46
  unsigned int  bit_buffer, inbuf_size;
 
47
  unsigned char bits_left;
 
48
 
 
49
  /* four literal models, each representing 64 symbols
 
50
   * model0 for literals from   0 to  63 (selector = 0)
 
51
   * model1 for literals from  64 to 127 (selector = 1)
 
52
   * model2 for literals from 128 to 191 (selector = 2)
 
53
   * model3 for literals from 129 to 255 (selector = 3) */
 
54
  struct qtmd_model model0, model1, model2, model3;
 
55
 
 
56
  /* three match models.
 
57
   * model4 for match with fixed length of 3 bytes
 
58
   * model5 for match with fixed length of 4 bytes
 
59
   * model6 for variable length match, encoded with model6len model */
 
60
  struct qtmd_model model4, model5, model6, model6len;
 
61
 
 
62
  /* selector model. 0-6 to say literal (0,1,2,3) or match (4,5,6) */
 
63
  struct qtmd_model model7;
 
64
 
 
65
  /* symbol arrays for all models */
 
66
  struct qtmd_modelsym m0sym[64 + 1];
 
67
  struct qtmd_modelsym m1sym[64 + 1];
 
68
  struct qtmd_modelsym m2sym[64 + 1];
 
69
  struct qtmd_modelsym m3sym[64 + 1];
 
70
  struct qtmd_modelsym m4sym[24 + 1];
 
71
  struct qtmd_modelsym m5sym[36 + 1];
 
72
  struct qtmd_modelsym m6sym[42 + 1], m6lsym[27 + 1];
 
73
  struct qtmd_modelsym m7sym[7 + 1];
 
74
};
 
75
 
 
76
/* allocates Quantum decompression state for decoding the given stream.
 
77
 *
 
78
 * - returns NULL if window_bits is outwith the range 10 to 21 (inclusive).
 
79
 *
 
80
 * - uses system->alloc() to allocate memory
 
81
 *
 
82
 * - returns NULL if not enough memory
 
83
 *
 
84
 * - window_bits is the size of the Quantum window, from 1Kb (10) to 2Mb (21).
 
85
 *
 
86
 * - input_buffer_size is the number of bytes to use to store bitstream data.
 
87
 */
 
88
extern struct qtmd_stream *qtmd_init(struct mspack_system *system,
 
89
                                     struct mspack_file *input,
 
90
                                     struct mspack_file *output,
 
91
                                     int window_bits,
 
92
                                     int input_buffer_size);
 
93
 
 
94
/* decompresses, or decompresses more of, a Quantum stream.
 
95
 *
 
96
 * - out_bytes of data will be decompressed and the function will return
 
97
 *   with an MSPACK_ERR_OK return code.
 
98
 *
 
99
 * - decompressing will stop as soon as out_bytes is reached. if the true
 
100
 *   amount of bytes decoded spills over that amount, they will be kept for
 
101
 *   a later invocation of qtmd_decompress().
 
102
 *
 
103
 * - the output bytes will be passed to the system->write() function given in
 
104
 *   qtmd_init(), using the output file handle given in qtmd_init(). More
 
105
 *   than one call may be made to system->write()
 
106
 *
 
107
 * - Quantum will read input bytes as necessary using the system->read()
 
108
 *   function given in qtmd_init(), using the input file handle given in
 
109
 *   qtmd_init(). This will continue until system->read() returns 0 bytes,
 
110
 *   or an error.
 
111
 */
 
112
extern int qtmd_decompress(struct qtmd_stream *qtm, off_t out_bytes);
 
113
 
 
114
/* frees all state associated with a Quantum data stream
 
115
 *
 
116
 * - calls system->free() using the system pointer given in qtmd_init()
 
117
 */
 
118
void qtmd_free(struct qtmd_stream *qtm);
 
119
 
 
120
#endif