Branch data Line data Source code
1 : : // $Id: ZIP.cc,v 1.1.4.2 2006/05/31 21:49:29 sommer Exp $
2 : : //
3 : : // See the file "COPYING" in the main distribution directory for copyright.
4 : :
5 : : #include "ZIP.h"
6 : :
7 : : #ifdef HAVE_LIBZ
8 : :
9 : 111 : ZIP_Analyzer::ZIP_Analyzer(Connection* conn, bool orig, Method arg_method)
10 : 111 : : TCP_SupportAnalyzer(AnalyzerTag::Zip, conn, orig)
11 : : {
12 : 111 : zip = 0;
13 : 111 : zip_status = Z_OK;
14 : 111 : method = arg_method;
15 : :
16 : 111 : zip = new z_stream;
17 : 111 : zip->zalloc = 0;
18 : 111 : zip->zfree = 0;
19 : 111 : zip->opaque = 0;
20 : 111 : zip->next_out = 0;
21 : 111 : zip->avail_out = 0;
22 : 111 : zip->next_in = 0;
23 : 111 : zip->avail_in = 0;
24 : :
25 : : // "15" here means maximum compression. "32" is a gross overload
26 : : // hack that means "check it for whether it's a gzip file". Sheesh.
27 : 111 : zip_status = inflateInit2(zip, 15 + 32);
28 [ - + # # ]: 111 : if ( zip_status != Z_OK )
29 : : {
30 : 0 : Weird("inflate_init_failed");
31 : 0 : delete zip;
32 : 0 : zip = 0;
33 : : }
34 : 111 : }
35 : :
36 : 111 : ZIP_Analyzer::~ZIP_Analyzer()
37 : : {
38 : 111 : delete zip;
39 [ + - ][ # # ]: 111 : }
[ # # ]
40 : :
41 : 111 : void ZIP_Analyzer::Done()
42 : : {
43 : 111 : Analyzer::Done();
44 : :
45 [ + + ]: 111 : if ( zip )
46 : 5 : inflateEnd(zip);
47 : 111 : }
48 : :
49 : 676 : void ZIP_Analyzer::DeliverStream(int len, const u_char* data, bool orig)
50 : : {
51 : 676 : TCP_SupportAnalyzer::DeliverStream(len, data, orig);
52 : :
53 [ + - + + ]: 676 : if ( ! len || zip_status != Z_OK )
54 : 676 : return;
55 : :
56 : : static unsigned int unzip_size = 4096;
57 : 625 : Bytef unzipbuf[unzip_size];
58 : :
59 : 625 : zip->next_in = (Bytef*) data;
60 : 625 : zip->avail_in = len;
61 : :
62 [ + + ][ + + ]: 955 : do
63 : : {
64 : 904 : zip->next_out = unzipbuf;
65 : 904 : zip->avail_out = unzip_size;
66 : :
67 : 904 : zip_status = inflate(zip, Z_SYNC_FLUSH);
68 : :
69 [ + + + + ]: 904 : if ( zip_status != Z_STREAM_END &&
[ + - ]
70 : : zip_status != Z_OK &&
71 : : zip_status != Z_BUF_ERROR )
72 : : {
73 : 4 : Weird("inflate_failed");
74 : 4 : inflateEnd(zip);
75 : 4 : break;
76 : : }
77 : :
78 : 900 : int have = unzip_size - zip->avail_out;
79 [ + + ]: 900 : if ( have )
80 : 888 : ForwardStream(have, unzipbuf, IsOrig());
81 : :
82 [ + + ]: 900 : if ( zip_status == Z_STREAM_END )
83 : : {
84 : 106 : inflateEnd(zip);
85 : 106 : delete zip;
86 : 106 : zip = 0;
87 : 106 : break;
88 : : }
89 : :
90 : 794 : zip_status = Z_OK;
91 : : }
92 : : while ( zip->avail_out == 0 );
93 [ + - ][ + - ]: 6 : }
94 : 3 : #endif
|