aboutsummaryrefslogtreecommitdiff
path: root/src/microspdy/compression.h
blob: ac37f1158d7fd8060b53b004535f9995793aad0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
    This file is part of libmicrospdy
    Copyright (C) 2012 Andrey Uzunov

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * @file compression.h
 * @brief  zlib handling functions
 * @author Andrey Uzunov
 */

#ifndef COMPRESSION_H
#define COMPRESSION_H

#include "platform.h"

/* size of buffers used by zlib on (de)compressing */
#define SPDYF_ZLIB_CHUNK 16384


/**
 * Initializes the zlib stream for compression. Must be called once
 * for a session on initialization.
 *
 * @param strm Zlib stream on which we work
 * @return SPDY_NO if zlib failed. SPDY_YES otherwise
 */		
int
SPDYF_zlib_deflate_init(z_stream *strm);


/**
 * Deinitializes the zlib stream for compression. Should be called once
 * for a session on cleaning up.
 *
 * @param strm Zlib stream on which we work
 */	
void
SPDYF_zlib_deflate_end(z_stream *strm);


/**
 * Compressing stream with zlib.
 *
 * @param strm Zlib stream on which we work
 * @param src stream of the data to be compressed
 * @param src_size size of the data
 * @param data_used the number of bytes from src_stream that were used
 * 					TODO do we need
 * @param dest the resulting compressed stream. Should be NULL. Must be
 * 					freed later manually.
 * @param dest_size size of the data after compression
 * @return SPDY_NO if malloc or zlib failed. SPDY_YES otherwise
 */
int
SPDYF_zlib_deflate(z_stream *strm,
					const void *src,
					size_t src_size,
					size_t *data_used,
					void **dest,
					size_t *dest_size);
     

/**
 * Initializes the zlib stream for decompression. Must be called once
 * for a session.
 *
 * @param strm Zlib stream on which we work
 * @return SPDY_NO if zlib failed. SPDY_YES otherwise
 */	                 
int
SPDYF_zlib_inflate_init(z_stream *strm);


/**
 * Deinitializes the zlib stream for decompression. Should be called once
 * for a session on cleaning up.
 *
 * @param strm Zlib stream on which we work
 */	
void
SPDYF_zlib_inflate_end(z_stream *strm);


/**
 * Decompressing stream with zlib.
 *
 * @param strm Zlib stream on which we work
 * @param src stream of the data to be decompressed
 * @param src_size size of the data
 * @param dest the resulting decompressed stream. Should be NULL. Must
 * 				be freed manually.
 * @param dest_size size of the data after decompression
 * @return SPDY_NO if malloc or zlib failed. SPDY_YES otherwise. If the
 * 			function fails, the SPDY session must be closed
 */
int
SPDYF_zlib_inflate(z_stream *strm,
					const void *src,
					size_t src_size,
					void **dest,
					size_t *dest_size);

#endif