2009-09-22 01:05:05 +02:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2009-09-22 01:05:05 +02:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2012-09-11 07:19:45 +02:00
|
|
|
* Copyright (c) 2008-2012, Tomasz Sowa
|
2009-09-22 01:05:05 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
#ifndef headerfile_winix_core_compress
|
|
|
|
#define headerfile_winix_core_compress
|
2009-10-08 19:59:10 +02:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <fcgiapp.h>
|
|
|
|
#include <zlib.h>
|
2012-09-11 07:19:45 +02:00
|
|
|
#include "requesttypes.h"
|
|
|
|
|
2009-10-08 19:59:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Compress
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Compress();
|
|
|
|
~Compress();
|
|
|
|
|
2011-04-02 02:10:16 +02:00
|
|
|
int Init(int compress_level_ = 6);
|
|
|
|
|
|
|
|
/*
|
|
|
|
encoding:
|
|
|
|
0 - raw deflate data with no zlib header or trailer, and will not compute an adler32 check value
|
|
|
|
(for Internet Explorer)
|
|
|
|
1 - deflate
|
|
|
|
2 - gzip
|
|
|
|
*/
|
|
|
|
int CompressAndPut(const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding = 2);
|
2012-09-11 07:19:45 +02:00
|
|
|
int Compressing(const BinaryPage & in, BinaryPage & out, int encoding = 2);
|
|
|
|
|
2009-10-08 19:59:10 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool AllocateMemory();
|
2011-04-02 02:10:16 +02:00
|
|
|
bool InitRawDeflate();
|
|
|
|
bool InitDeflate();
|
|
|
|
bool InitGzip();
|
|
|
|
|
|
|
|
int MakeCompress(z_stream & strm, const char * source, size_t source_len, FCGX_Stream * out_stream, int encoding);
|
2012-09-11 07:19:45 +02:00
|
|
|
int MakeCompress(z_stream & strm, const BinaryPage & page, BinaryPage & out, int encoding);
|
2011-04-02 02:10:16 +02:00
|
|
|
z_stream * SelectStream(int encoding);
|
|
|
|
void ResetStream(z_stream * pstrm, int encoding);
|
|
|
|
void PutLog(size_t source_len, int encoding);
|
2012-09-11 07:19:45 +02:00
|
|
|
void CopyToInputBuffer(BinaryPage::const_iterator & i, size_t len);
|
2009-10-08 19:59:10 +02:00
|
|
|
|
2011-04-02 02:10:16 +02:00
|
|
|
int compress_level;
|
2009-10-08 19:59:10 +02:00
|
|
|
size_t buffer_max_len;
|
2012-09-11 07:19:45 +02:00
|
|
|
|
|
|
|
// size of the last compressed page
|
|
|
|
size_t last_out_size;
|
|
|
|
|
|
|
|
char * buffer_in;
|
|
|
|
char * buffer_out;
|
2011-04-02 02:10:16 +02:00
|
|
|
z_stream strm_raw_deflate, strm_deflate, strm_gzip;
|
|
|
|
bool raw_deflate_inited, deflate_inited, gzip_inited;
|
2009-10-08 19:59:10 +02:00
|
|
|
bool ready_for_compress;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|