aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/https/tls/gnutls_compress_int.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2008-11-18 08:20:26 +0000
committerChristian Grothoff <christian@grothoff.org>2008-11-18 08:20:26 +0000
commite5295880b97c77d225cc1ab284bcc98e954195aa (patch)
tree20fbc1f0afb1d8af92f7355560bd5dda988f1c53 /src/daemon/https/tls/gnutls_compress_int.c
parent7474a036d785d5c4f2e1c75410ebbbfee16ff168 (diff)
downloadlibmicrohttpd-e5295880b97c77d225cc1ab284bcc98e954195aa.tar.gz
libmicrohttpd-e5295880b97c77d225cc1ab284bcc98e954195aa.zip
removing broken code for compress and useless -- equally broken -- options
Diffstat (limited to 'src/daemon/https/tls/gnutls_compress_int.c')
-rw-r--r--src/daemon/https/tls/gnutls_compress_int.c296
1 files changed, 0 insertions, 296 deletions
diff --git a/src/daemon/https/tls/gnutls_compress_int.c b/src/daemon/https/tls/gnutls_compress_int.c
deleted file mode 100644
index da17b892..00000000
--- a/src/daemon/https/tls/gnutls_compress_int.c
+++ /dev/null
@@ -1,296 +0,0 @@
1/*
2 * Copyright (C) 2000, 2002, 2003, 2004, 2005, 2007 Free Software Foundation
3 *
4 * Author: Nikos Mavrogiannopoulos
5 *
6 * This file is part of GNUTLS.
7 *
8 * The GNUTLS library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 * USA
22 *
23 */
24
25#include <gnutls_int.h>
26#include <gnutls_compress.h>
27#include <gnutls_algorithms.h>
28#include "gnutls_errors.h"
29
30/* The flag d is the direction (compress, decompress). Non zero is
31 * decompress.
32 */
33comp_hd_t
34MHD_gtls_comp_init (enum MHD_GNUTLS_CompressionMethod method, int d)
35{
36 comp_hd_t ret;
37
38 ret = MHD_gnutls_malloc (sizeof (struct comp_hd_t_STRUCT));
39 if (ret == NULL)
40 {
41 MHD_gnutls_assert ();
42 return NULL;
43 }
44
45 ret->algo = method;
46 ret->handle = NULL;
47
48 switch (method)
49 {
50#ifdef HAVE_LIBZ
51 case MHD_GNUTLS_COMP_DEFLATE:
52 {
53 int window_bits, mem_level;
54 int comp_level;
55 int err;
56 z_stream *zhandle;
57
58 window_bits = MHD_gtls_compression_get_wbits (method);
59 mem_level = MHD_gtls_compression_get_mem_level (method);
60 comp_level = MHD_gtls_compression_get_comp_level (method);
61
62 ret->handle = MHD_gnutls_malloc (sizeof (z_stream));
63 if (ret->handle == NULL)
64 {
65 MHD_gnutls_assert ();
66 goto cleanup_ret;
67 }
68
69 zhandle = ret->handle;
70
71 zhandle->zalloc = (alloc_func) 0;
72 zhandle->zfree = (free_func) 0;
73 zhandle->opaque = (voidpf) 0;
74
75 if (d)
76 err = inflateInit2 (zhandle, window_bits);
77 else
78 err = deflateInit2 (zhandle,
79 comp_level, Z_DEFLATED,
80 window_bits, mem_level, Z_DEFAULT_STRATEGY);
81 if (err != Z_OK)
82 {
83 MHD_gnutls_assert ();
84 MHD_gnutls_free (ret->handle);
85 goto cleanup_ret;
86 }
87 break;
88 }
89#endif
90 case MHD_GNUTLS_COMP_NULL:
91 break;
92 default:
93 /* not supported! */
94 goto cleanup_ret;
95 }
96 return ret;
97
98cleanup_ret:
99 MHD_gnutls_free (ret);
100 return NULL;
101}
102
103/* The flag d is the direction (compress, decompress). Non zero is
104 * decompress.
105 */
106void
107MHD_gtls_comp_deinit (comp_hd_t handle, int d)
108{
109 if (handle != NULL)
110 {
111 switch (handle->algo)
112 {
113#ifdef HAVE_LIBZ
114 int err;
115 case MHD_GNUTLS_COMP_DEFLATE:
116 if (d)
117 err = inflateEnd (handle->handle);
118 else
119 err = deflateEnd (handle->handle);
120 break;
121#endif
122 default:
123 break;
124 }
125 MHD_gnutls_free (handle->handle);
126 MHD_gnutls_free (handle);
127
128 }
129}
130
131/* These functions are memory consuming
132 */
133
134int
135MHD_gtls_compress (comp_hd_t handle, const opaque * plain,
136 size_t plain_size, opaque ** compressed,
137 size_t max_comp_size)
138{
139 int compressed_size = GNUTLS_E_COMPRESSION_FAILED;
140
141 /* NULL compression is not handled here
142 */
143 if (handle == NULL)
144 {
145 MHD_gnutls_assert ();
146 return GNUTLS_E_INTERNAL_ERROR;
147 }
148
149 switch (handle->algo)
150 {
151
152#ifdef HAVE_LIBZ
153 case MHD_GNUTLS_COMP_DEFLATE:
154 {
155 uLongf size;
156 z_stream *zhandle;
157 int err;
158
159 size = (plain_size + plain_size) + 10;
160 *compressed = MHD_gnutls_malloc (size);
161 if (*compressed == NULL)
162 {
163 MHD_gnutls_assert ();
164 return GNUTLS_E_MEMORY_ERROR;
165 }
166
167 zhandle = handle->handle;
168
169 zhandle->next_in = (Bytef *) plain;
170 zhandle->avail_in = plain_size;
171 zhandle->next_out = (Bytef *) * compressed;
172 zhandle->avail_out = size;
173
174 err = deflate (zhandle, Z_SYNC_FLUSH);
175
176 if (err != Z_OK || zhandle->avail_in != 0)
177 {
178 MHD_gnutls_assert ();
179 MHD_gnutls_free (*compressed);
180 *compressed = NULL;
181 return GNUTLS_E_COMPRESSION_FAILED;
182 }
183
184 compressed_size = size - zhandle->avail_out;
185 break;
186 }
187#endif
188 default:
189 MHD_gnutls_assert ();
190 return GNUTLS_E_INTERNAL_ERROR;
191 } /* switch */
192
193 if ((size_t) compressed_size > max_comp_size)
194 {
195 MHD_gnutls_free (*compressed);
196 *compressed = NULL;
197 return GNUTLS_E_COMPRESSION_FAILED;
198 }
199
200 return compressed_size;
201}
202
203
204
205int
206MHD_gtls_decompress (comp_hd_t handle, opaque * compressed,
207 size_t compressed_size, opaque ** plain,
208 size_t max_record_size)
209{
210 int plain_size = GNUTLS_E_DECOMPRESSION_FAILED;
211
212 if (compressed_size > max_record_size + EXTRA_COMP_SIZE)
213 {
214 MHD_gnutls_assert ();
215 return GNUTLS_E_DECOMPRESSION_FAILED;
216 }
217
218 /* NULL compression is not handled here
219 */
220
221 if (handle == NULL)
222 {
223 MHD_gnutls_assert ();
224 return GNUTLS_E_INTERNAL_ERROR;
225 }
226
227 switch (handle->algo)
228 {
229#ifdef HAVE_LIBZ
230 case MHD_GNUTLS_COMP_DEFLATE:
231 {
232 int err;
233 uLongf out_size;
234 z_stream *zhandle;
235 unsigned int cur_pos;
236
237 *plain = NULL;
238 out_size = compressed_size + compressed_size;
239 plain_size = 0;
240
241 zhandle = handle->handle;
242
243 zhandle->next_in = (Bytef *) compressed;
244 zhandle->avail_in = compressed_size;
245
246 cur_pos = 0;
247
248 do
249 {
250 out_size += 512;
251 *plain = MHD_gtls_realloc_fast (*plain, out_size);
252 if (*plain == NULL)
253 {
254 MHD_gnutls_assert ();
255 return GNUTLS_E_MEMORY_ERROR;
256 }
257
258 zhandle->next_out = (Bytef *) (*plain + cur_pos);
259 zhandle->avail_out = out_size - cur_pos;
260
261 err = inflate (zhandle, Z_SYNC_FLUSH);
262
263 cur_pos = out_size - zhandle->avail_out;
264
265 }
266 while ((err == Z_BUF_ERROR && zhandle->avail_out == 0
267 && out_size < max_record_size)
268 || (err == Z_OK && zhandle->avail_in != 0));
269
270 if (err != Z_OK)
271 {
272 MHD_gnutls_assert ();
273 MHD_gnutls_free (*plain);
274 *plain = NULL;
275 return GNUTLS_E_DECOMPRESSION_FAILED;
276 }
277
278 plain_size = out_size - zhandle->avail_out;
279 break;
280 }
281#endif
282 default:
283 MHD_gnutls_assert ();
284 return GNUTLS_E_INTERNAL_ERROR;
285 } /* switch */
286
287 if ((size_t) plain_size > max_record_size)
288 {
289 MHD_gnutls_assert ();
290 MHD_gnutls_free (*plain);
291 *plain = NULL;
292 return GNUTLS_E_DECOMPRESSION_FAILED;
293 }
294
295 return plain_size;
296}