• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     This file is part of libmicrospdy
3     Copyright Copyright (C) 2012 Andrey Uzunov
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /**
20  * @file compression.h
21  * @brief  zlib handling functions
22  * @author Andrey Uzunov
23  */
24 
25 #ifndef COMPRESSION_H
26 #define COMPRESSION_H
27 
28 #include "platform.h"
29 
30 /* size of buffers used by zlib on (de)compressing */
31 #define SPDYF_ZLIB_CHUNK 16384
32 
33 
34 /**
35  * Initializes the zlib stream for compression. Must be called once
36  * for a session on initialization.
37  *
38  * @param strm Zlib stream on which we work
39  * @return SPDY_NO if zlib failed. SPDY_YES otherwise
40  */
41 int
42 SPDYF_zlib_deflate_init(z_stream *strm);
43 
44 
45 /**
46  * Deinitializes the zlib stream for compression. Should be called once
47  * for a session on cleaning up.
48  *
49  * @param strm Zlib stream on which we work
50  */
51 void
52 SPDYF_zlib_deflate_end(z_stream *strm);
53 
54 
55 /**
56  * Compressing stream with zlib.
57  *
58  * @param strm Zlib stream on which we work
59  * @param src stream of the data to be compressed
60  * @param src_size size of the data
61  * @param data_used the number of bytes from src_stream that were used
62  * 					TODO do we need
63  * @param dest the resulting compressed stream. Should be NULL. Must be
64  * 					freed later manually.
65  * @param dest_size size of the data after compression
66  * @return SPDY_NO if malloc or zlib failed. SPDY_YES otherwise
67  */
68 int
69 SPDYF_zlib_deflate(z_stream *strm,
70 					const void *src,
71 					size_t src_size,
72 					size_t *data_used,
73 					void **dest,
74 					size_t *dest_size);
75 
76 
77 /**
78  * Initializes the zlib stream for decompression. Must be called once
79  * for a session.
80  *
81  * @param strm Zlib stream on which we work
82  * @return SPDY_NO if zlib failed. SPDY_YES otherwise
83  */
84 int
85 SPDYF_zlib_inflate_init(z_stream *strm);
86 
87 
88 /**
89  * Deinitializes the zlib stream for decompression. Should be called once
90  * for a session on cleaning up.
91  *
92  * @param strm Zlib stream on which we work
93  */
94 void
95 SPDYF_zlib_inflate_end(z_stream *strm);
96 
97 
98 /**
99  * Decompressing stream with zlib.
100  *
101  * @param strm Zlib stream on which we work
102  * @param src stream of the data to be decompressed
103  * @param src_size size of the data
104  * @param dest the resulting decompressed stream. Should be NULL. Must
105  * 				be freed manually.
106  * @param dest_size size of the data after decompression
107  * @return SPDY_NO if malloc or zlib failed. SPDY_YES otherwise. If the
108  * 			function fails, the SPDY session must be closed
109  */
110 int
111 SPDYF_zlib_inflate(z_stream *strm,
112 					const void *src,
113 					size_t src_size,
114 					void **dest,
115 					size_t *dest_size);
116 
117 #endif
118