blob: 72c9996b931acd0d21405c395d09e732692ca359 [file] [log] [blame]
William Lallemand82fe75c2012-10-23 10:25:10 +02001/*
2 * HTTP compression.
3 *
4 * Copyright 2012 Exceliance, David Du Colombier <dducolombier@exceliance.fr>
5 * William Lallemand <wlallemand@exceliance.fr>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
14#include <stdio.h>
Willy Tarreau34763642012-10-26 15:05:35 +020015
William Lallemand08289f12012-10-31 11:19:18 +010016#ifdef USE_ZLIB
Willy Tarreau34763642012-10-26 15:05:35 +020017/* Note: the crappy zlib and openssl libs both define the "free_func" type.
18 * That's a very clever idea to use such a generic name in general purpose
19 * libraries, really... The zlib one is easier to redefine than openssl's,
20 * so let's only fix this one.
21 */
22#define free_func zlib_free_func
William Lallemand82fe75c2012-10-23 10:25:10 +020023#include <zlib.h>
Willy Tarreau34763642012-10-26 15:05:35 +020024#undef free_func
William Lallemand08289f12012-10-31 11:19:18 +010025#endif /* USE_ZLIB */
William Lallemand82fe75c2012-10-23 10:25:10 +020026
27#include <common/compat.h>
William Lallemand2b502472012-10-30 14:30:39 +010028#include <common/memory.h>
William Lallemand82fe75c2012-10-23 10:25:10 +020029
30#include <types/global.h>
31#include <types/compression.h>
32
33#include <proto/compression.h>
William Lallemandd85f9172012-11-09 17:05:39 +010034#include <proto/freq_ctr.h>
William Lallemand82fe75c2012-10-23 10:25:10 +020035#include <proto/proto_http.h>
36
William Lallemand2b502472012-10-30 14:30:39 +010037
38#ifdef USE_ZLIB
39
40/* zlib allocation */
41static struct pool_head *zlib_pool_deflate_state = NULL;
42static struct pool_head *zlib_pool_window = NULL;
43static struct pool_head *zlib_pool_prev = NULL;
44static struct pool_head *zlib_pool_head = NULL;
45static struct pool_head *zlib_pool_pending_buf = NULL;
46
William Lallemand9d5f5482012-11-07 16:12:57 +010047static long long zlib_memory_available = -1;
48
49
William Lallemand2b502472012-10-30 14:30:39 +010050#endif
51
52
Cyril Bonté6162c432012-11-10 19:27:47 +010053const struct comp_algo comp_algos[] =
William Lallemand82fe75c2012-10-23 10:25:10 +020054{
55 { "identity", 8, identity_init, identity_add_data, identity_flush, identity_reset, identity_end },
56#ifdef USE_ZLIB
57 { "deflate", 7, deflate_init, deflate_add_data, deflate_flush, deflate_reset, deflate_end },
58 { "gzip", 4, gzip_init, deflate_add_data, deflate_flush, deflate_reset, deflate_end },
59#endif /* USE_ZLIB */
60 { NULL, 0, NULL , NULL, NULL, NULL, NULL }
61};
62
63/*
64 * Add a content-type in the configuration
65 */
66int comp_append_type(struct comp *comp, const char *type)
67{
68 struct comp_type *comp_type;
69
70 comp_type = calloc(1, sizeof(struct comp_type));
71 comp_type->name_len = strlen(type);
72 comp_type->name = strdup(type);
73 comp_type->next = comp->types;
74 comp->types = comp_type;
75 return 0;
76}
77
78/*
79 * Add an algorithm in the configuration
80 */
81int comp_append_algo(struct comp *comp, const char *algo)
82{
83 struct comp_algo *comp_algo;
84 int i;
85
86 for (i = 0; comp_algos[i].name; i++) {
87 if (!strcmp(algo, comp_algos[i].name)) {
88 comp_algo = calloc(1, sizeof(struct comp_algo));
89 memmove(comp_algo, &comp_algos[i], sizeof(struct comp_algo));
90 comp_algo->next = comp->algos;
91 comp->algos = comp_algo;
92 return 0;
93 }
94 }
95 return -1;
96}
97
98/* emit the chunksize followed by a CRLF on the output and return the number of
99 * bytes written. Appends <add_crlf> additional CRLF after the first one. Chunk
100 * sizes are truncated to 6 hex digits (16 MB) and padded left. The caller is
101 * responsible for ensuring there is enough room left in the output buffer for
102 * the string (8 bytes * add_crlf*2).
103 */
104int http_emit_chunk_size(char *out, unsigned int chksz, int add_crlf)
105{
106 int shift;
107 int pos = 0;
108
109 for (shift = 20; shift >= 0; shift -= 4)
110 out[pos++] = hextab[(chksz >> shift) & 0xF];
111
112 do {
113 out[pos++] = '\r';
114 out[pos++] = '\n';
115 } while (--add_crlf >= 0);
116
117 return pos;
118}
119
120/*
121 * Init HTTP compression
122 */
123int http_compression_buffer_init(struct session *s, struct buffer *in, struct buffer *out)
124{
125 struct http_msg *msg = &s->txn.rsp;
126 int left;
127
128 /* not enough space */
129 if (in->size - buffer_len(in) < 40)
130 return -1;
131
132 /*
133 * Skip data, we don't need them in the new buffer. They are results
134 * of CHUNK_CRLF and CHUNK_SIZE parsing.
135 */
136 b_adv(in, msg->next);
137 msg->next = 0;
138 msg->sov = 0;
139 msg->sol = 0;
140
141 out->size = global.tune.bufsize;
142 out->i = 0;
143 out->o = 0;
144 out->p = out->data;
145 /* copy output data */
146 if (in->o > 0) {
147 left = in->o - bo_contig_data(in);
148 memcpy(out->data, bo_ptr(in), bo_contig_data(in));
149 out->p += bo_contig_data(in);
150 if (left > 0) { /* second part of the buffer */
151 memcpy(out->p, in->data, left);
152 out->p += left;
153 }
154 out->o = in->o;
155 }
156 out->i += http_emit_chunk_size(out->p, 0, 0);
157
158 return 0;
159}
160
161/*
162 * Add data to compress
163 */
164int http_compression_buffer_add_data(struct session *s, struct buffer *in, struct buffer *out)
165{
166 struct http_msg *msg = &s->txn.rsp;
William Lallemandbf3ae612012-11-19 12:35:37 +0100167 int consumed_data = 0;
William Lallemand82fe75c2012-10-23 10:25:10 +0200168 int data_process_len;
169 int left;
170 int ret;
171
172 /*
173 * Skip data, we don't need them in the new buffer. They are results
174 * of CHUNK_CRLF and CHUNK_SIZE parsing.
175 */
176 b_adv(in, msg->next);
177 msg->next = 0;
178 msg->sov = 0;
179 msg->sol = 0;
180
181 /*
182 * select the smallest size between the announced chunk size, the input
183 * data, and the available output buffer size
184 */
185 data_process_len = MIN(in->i, msg->chunk_len);
186 data_process_len = MIN(out->size - buffer_len(out), data_process_len);
187
188 left = data_process_len - bi_contig_data(in);
189 if (left <= 0) {
William Lallemandbf3ae612012-11-19 12:35:37 +0100190 consumed_data += ret = s->comp_algo->add_data(&s->comp_ctx, bi_ptr(in), data_process_len, out);
William Lallemand82fe75c2012-10-23 10:25:10 +0200191 if (ret < 0)
192 return -1;
William Lallemand82fe75c2012-10-23 10:25:10 +0200193
194 } else {
William Lallemandbf3ae612012-11-19 12:35:37 +0100195 consumed_data += ret = s->comp_algo->add_data(&s->comp_ctx, bi_ptr(in), bi_contig_data(in), out);
William Lallemand82fe75c2012-10-23 10:25:10 +0200196 if (ret < 0)
197 return -1;
William Lallemandbf3ae612012-11-19 12:35:37 +0100198 consumed_data += ret = s->comp_algo->add_data(&s->comp_ctx, in->data, left, out);
William Lallemand82fe75c2012-10-23 10:25:10 +0200199 if (ret < 0)
200 return -1;
William Lallemand82fe75c2012-10-23 10:25:10 +0200201 }
202
203 b_adv(in, data_process_len);
204 msg->chunk_len -= data_process_len;
205
William Lallemandbf3ae612012-11-19 12:35:37 +0100206 return consumed_data;
William Lallemand82fe75c2012-10-23 10:25:10 +0200207}
208
209/*
210 * Flush data in process, and write the header and footer of the chunk. Upon
211 * success, in and out buffers are swapped to avoid a copy.
212 */
213int http_compression_buffer_end(struct session *s, struct buffer **in, struct buffer **out, int end)
214{
215 int to_forward;
216 int left;
217 struct http_msg *msg = &s->txn.rsp;
218 struct buffer *ib = *in, *ob = *out;
William Lallemand08289f12012-10-31 11:19:18 +0100219
220#ifdef USE_ZLIB
William Lallemand82fe75c2012-10-23 10:25:10 +0200221 int ret;
222
223 /* flush data here */
224
225 if (end)
226 ret = s->comp_algo->flush(&s->comp_ctx, ob, Z_FINISH); /* end of data */
227 else
228 ret = s->comp_algo->flush(&s->comp_ctx, ob, Z_SYNC_FLUSH); /* end of buffer */
229
230 if (ret < 0)
231 return -1; /* flush failed */
232
William Lallemand08289f12012-10-31 11:19:18 +0100233#endif /* USE_ZLIB */
234
William Lallemand82fe75c2012-10-23 10:25:10 +0200235 if (ob->i > 8) {
236 /* more than a chunk size => some data were emitted */
237 char *tail = ob->p + ob->i;
238
239 /* write real size at the begining of the chunk, no need of wrapping */
240 http_emit_chunk_size(ob->p, ob->i - 8, 0);
241
242 /* chunked encoding requires CRLF after data */
243 *tail++ = '\r';
244 *tail++ = '\n';
245
246 if (!(msg->flags & HTTP_MSGF_TE_CHNK) && msg->chunk_len == 0) {
247 /* End of data, 0<CRLF><CRLF> is needed but we're not
248 * in chunked mode on input so we must add it ourselves.
249 */
250 memcpy(tail, "0\r\n\r\n", 5);
251 tail += 5;
252 }
253 ob->i = tail - ob->p;
254 } else {
255 /* no data were sent, cancel the chunk size */
256 ob->i = 0;
257 }
258
259 to_forward = ob->i;
260
William Lallemandd85f9172012-11-09 17:05:39 +0100261 /* update input rate */
262 if (s->comp_ctx.cur_lvl > 0)
263 update_freq_ctr(&global.comp_bps_in, ib->o - ob->o);
264
William Lallemand82fe75c2012-10-23 10:25:10 +0200265 /* copy the remaining data in the tmp buffer. */
266 if (ib->i > 0) {
267 left = ib->i - bi_contig_data(ib);
268 memcpy(bi_end(ob), bi_ptr(ib), bi_contig_data(ib));
269 ob->i += bi_contig_data(ib);
270 if (left > 0) {
271 memcpy(bi_end(ob), ib->data, left);
272 ob->i += left;
273 }
274 }
275
276 /* swap the buffers */
277 *in = ob;
278 *out = ib;
279
William Lallemandd85f9172012-11-09 17:05:39 +0100280 if (s->comp_ctx.cur_lvl > 0)
281 update_freq_ctr(&global.comp_bps_out, to_forward);
282
William Lallemand82fe75c2012-10-23 10:25:10 +0200283 /* forward the new chunk without remaining data */
284 b_adv(ob, to_forward);
285
286 /* if there are data between p and next, there are trailers, must forward them */
287 b_adv(ob, msg->next);
288 msg->next = 0;
289
290 return to_forward;
291}
292
293
294/****************************
295 **** Identity algorithm ****
296 ****************************/
297
298/*
299 * Init the identity algorithm
300 */
William Lallemand1c2d6222012-10-30 15:52:53 +0100301int identity_init(struct comp_ctx *comp_ctx, int level)
William Lallemand82fe75c2012-10-23 10:25:10 +0200302{
303 return 0;
304}
305
306/*
307 * Process data
William Lallemandbf3ae612012-11-19 12:35:37 +0100308 * Return size of consumed data or -1 on error
William Lallemand82fe75c2012-10-23 10:25:10 +0200309 */
William Lallemandbf3ae612012-11-19 12:35:37 +0100310int identity_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out)
William Lallemand82fe75c2012-10-23 10:25:10 +0200311{
William Lallemandbf3ae612012-11-19 12:35:37 +0100312 char *out_data = bi_end(out);
313 int out_len = out->size - buffer_len(out);
314
William Lallemand82fe75c2012-10-23 10:25:10 +0200315 if (out_len < in_len)
316 return -1;
317
318 memcpy(out_data, in_data, in_len);
319
William Lallemandbf3ae612012-11-19 12:35:37 +0100320 out->i += in_len;
321
William Lallemand82fe75c2012-10-23 10:25:10 +0200322 return in_len;
323}
324
William Lallemand1c2d6222012-10-30 15:52:53 +0100325int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag)
William Lallemand82fe75c2012-10-23 10:25:10 +0200326{
327 return 0;
328}
329
330
William Lallemand1c2d6222012-10-30 15:52:53 +0100331int identity_reset(struct comp_ctx *comp_ctx)
William Lallemand82fe75c2012-10-23 10:25:10 +0200332{
333 return 0;
334}
335
336/*
337 * Deinit the algorithm
338 */
William Lallemand1c2d6222012-10-30 15:52:53 +0100339int identity_end(struct comp_ctx *comp_ctx)
William Lallemand82fe75c2012-10-23 10:25:10 +0200340{
341 return 0;
342}
343
344
345#ifdef USE_ZLIB
William Lallemand2b502472012-10-30 14:30:39 +0100346/*
347 * This is a tricky allocation function using the zlib.
348 * This is based on the allocation order in deflateInit2.
349 */
350static void *alloc_zlib(void *opaque, unsigned int items, unsigned int size)
351{
352 struct comp_ctx *ctx = opaque;
353 static char round = 0; /* order in deflateInit2 */
354 void *buf = NULL;
355
William Lallemand9d5f5482012-11-07 16:12:57 +0100356 if (global.maxzlibmem > 0 && zlib_memory_available < items * size){
357 buf = NULL;
358 goto end;
359 }
360
William Lallemand2b502472012-10-30 14:30:39 +0100361 switch (round) {
362 case 0:
363 if (zlib_pool_deflate_state == NULL)
364 zlib_pool_deflate_state = create_pool("zlib_state", size * items, MEM_F_SHARED);
365 ctx->zlib_deflate_state = buf = pool_alloc2(zlib_pool_deflate_state);
366 break;
367
368 case 1:
369 if (zlib_pool_window == NULL)
370 zlib_pool_window = create_pool("zlib_window", size * items, MEM_F_SHARED);
371 ctx->zlib_window = buf = pool_alloc2(zlib_pool_window);
372 break;
373
374 case 2:
375 if (zlib_pool_prev == NULL)
376 zlib_pool_prev = create_pool("zlib_prev", size * items, MEM_F_SHARED);
377 ctx->zlib_prev = buf = pool_alloc2(zlib_pool_prev);
378 break;
379
380 case 3:
381 if (zlib_pool_head == NULL)
382 zlib_pool_head = create_pool("zlib_head", size * items, MEM_F_SHARED);
383 ctx->zlib_head = buf = pool_alloc2(zlib_pool_head);
384 break;
385
386 case 4:
387 if (zlib_pool_pending_buf == NULL)
388 zlib_pool_pending_buf = create_pool("zlib_pending_buf", size * items, MEM_F_SHARED);
389 ctx->zlib_pending_buf = buf = pool_alloc2(zlib_pool_pending_buf);
390 break;
391 }
William Lallemand9d5f5482012-11-07 16:12:57 +0100392 if (buf != NULL && global.maxzlibmem > 0)
393 zlib_memory_available -= items * size;
394
395end:
William Lallemand2b502472012-10-30 14:30:39 +0100396
Willy Tarreau46909852012-11-15 14:57:56 +0100397 /* deflateInit2() first allocates and checks the deflate_state, then if
398 * it succeeds, it allocates all other 4 areas at ones and checks them
399 * at the end. So we want to correctly count the rounds depending on when
400 * zlib is supposed to abort.
401 */
402 if (buf || round)
403 round = (round + 1) % 5;
William Lallemand2b502472012-10-30 14:30:39 +0100404 return buf;
405}
406
407static void free_zlib(void *opaque, void *ptr)
408{
409 struct comp_ctx *ctx = opaque;
Willy Tarreaub1fbd052012-11-10 17:49:37 +0100410 struct pool_head *pool = NULL;
William Lallemand2b502472012-10-30 14:30:39 +0100411
412 if (ptr == ctx->zlib_window)
William Lallemand9d5f5482012-11-07 16:12:57 +0100413 pool = zlib_pool_window;
William Lallemand2b502472012-10-30 14:30:39 +0100414 else if (ptr == ctx->zlib_deflate_state)
William Lallemand9d5f5482012-11-07 16:12:57 +0100415 pool = zlib_pool_deflate_state;
William Lallemand2b502472012-10-30 14:30:39 +0100416 else if (ptr == ctx->zlib_prev)
William Lallemand9d5f5482012-11-07 16:12:57 +0100417 pool = zlib_pool_prev;
William Lallemand2b502472012-10-30 14:30:39 +0100418 else if (ptr == ctx->zlib_head)
William Lallemand9d5f5482012-11-07 16:12:57 +0100419 pool = zlib_pool_head;
William Lallemand2b502472012-10-30 14:30:39 +0100420 else if (ptr == ctx->zlib_pending_buf)
William Lallemand9d5f5482012-11-07 16:12:57 +0100421 pool = zlib_pool_pending_buf;
William Lallemand2b502472012-10-30 14:30:39 +0100422
William Lallemand9d5f5482012-11-07 16:12:57 +0100423 pool_free2(pool, ptr);
424 if (global.maxzlibmem > 0)
425 zlib_memory_available += pool->size;
William Lallemand2b502472012-10-30 14:30:39 +0100426}
427
William Lallemand82fe75c2012-10-23 10:25:10 +0200428
429/**************************
430**** gzip algorithm ****
431***************************/
William Lallemand1c2d6222012-10-30 15:52:53 +0100432int gzip_init(struct comp_ctx *comp_ctx, int level)
William Lallemand82fe75c2012-10-23 10:25:10 +0200433{
William Lallemand1c2d6222012-10-30 15:52:53 +0100434 z_stream *strm = &comp_ctx->strm;
William Lallemand82fe75c2012-10-23 10:25:10 +0200435
William Lallemand9d5f5482012-11-07 16:12:57 +0100436 if (global.maxzlibmem > 0 && zlib_memory_available < 0)
437 zlib_memory_available = global.maxzlibmem * 1024 * 1024; /* Megabytes to bytes */
438
William Lallemand2b502472012-10-30 14:30:39 +0100439 strm->zalloc = alloc_zlib;
440 strm->zfree = free_zlib;
441 strm->opaque = comp_ctx;
William Lallemand82fe75c2012-10-23 10:25:10 +0200442
William Lallemanda509e4c2012-11-07 16:54:34 +0100443 if (deflateInit2(&comp_ctx->strm, level, Z_DEFLATED, global.tune.zlibwindowsize + 16, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK)
William Lallemand82fe75c2012-10-23 10:25:10 +0200444 return -1;
445
446 return 0;
447}
448/**************************
449**** Deflate algorithm ****
450***************************/
451
William Lallemand1c2d6222012-10-30 15:52:53 +0100452int deflate_init(struct comp_ctx *comp_ctx, int level)
William Lallemand82fe75c2012-10-23 10:25:10 +0200453{
William Lallemand1c2d6222012-10-30 15:52:53 +0100454 z_stream *strm = &comp_ctx->strm;
William Lallemand82fe75c2012-10-23 10:25:10 +0200455
William Lallemand2b502472012-10-30 14:30:39 +0100456 strm->zalloc = alloc_zlib;
457 strm->zfree = free_zlib;
458 strm->opaque = comp_ctx;
William Lallemand82fe75c2012-10-23 10:25:10 +0200459
William Lallemand1c2d6222012-10-30 15:52:53 +0100460 if (deflateInit(&comp_ctx->strm, level) != Z_OK)
William Lallemand82fe75c2012-10-23 10:25:10 +0200461 return -1;
462
463 return 0;
464}
465
William Lallemandbf3ae612012-11-19 12:35:37 +0100466/* Return the size of consumed data or -1 */
467int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out)
William Lallemand82fe75c2012-10-23 10:25:10 +0200468{
William Lallemand82fe75c2012-10-23 10:25:10 +0200469 int ret;
William Lallemandbf3ae612012-11-19 12:35:37 +0100470 z_stream *strm = &comp_ctx->strm;
471 char *out_data = bi_end(out);
472 int out_len = out->size - buffer_len(out);
William Lallemand82fe75c2012-10-23 10:25:10 +0200473
474 if (in_len <= 0)
475 return 0;
476
477
478 if (out_len <= 0)
479 return -1;
480
William Lallemand82fe75c2012-10-23 10:25:10 +0200481 strm->next_in = (unsigned char *)in_data;
482 strm->avail_in = in_len;
483 strm->next_out = (unsigned char *)out_data;
484 strm->avail_out = out_len;
485
486 ret = deflate(strm, Z_NO_FLUSH);
487 if (ret != Z_OK)
488 return -1;
489
490 /* deflate update the available data out */
William Lallemandbf3ae612012-11-19 12:35:37 +0100491 out->i += out_len - strm->avail_out;
William Lallemand82fe75c2012-10-23 10:25:10 +0200492
William Lallemandbf3ae612012-11-19 12:35:37 +0100493 return in_len - strm->avail_in;
William Lallemand82fe75c2012-10-23 10:25:10 +0200494}
495
William Lallemand1c2d6222012-10-30 15:52:53 +0100496int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag)
William Lallemand82fe75c2012-10-23 10:25:10 +0200497{
498 int ret;
William Lallemand82fe75c2012-10-23 10:25:10 +0200499 int out_len = 0;
William Lallemand1c2d6222012-10-30 15:52:53 +0100500 z_stream *strm = &comp_ctx->strm;
William Lallemand82fe75c2012-10-23 10:25:10 +0200501
William Lallemand82fe75c2012-10-23 10:25:10 +0200502 strm->next_out = (unsigned char *)bi_end(out);
503 strm->avail_out = out->size - buffer_len(out);
504
505 ret = deflate(strm, flag);
506 if (ret != Z_OK && ret != Z_STREAM_END)
507 return -1;
508
509 out_len = (out->size - buffer_len(out)) - strm->avail_out;
510 out->i += out_len;
511
William Lallemandd85f9172012-11-09 17:05:39 +0100512 /* compression rate limit */
513 if (global.comp_rate_lim > 0) {
514
515 if (read_freq_ctr(&global.comp_bps_out) > global.comp_rate_lim) {
516 /* decrease level */
517 if (comp_ctx->cur_lvl > 0) {
518 comp_ctx->cur_lvl--;
519 deflateParams(&comp_ctx->strm, comp_ctx->cur_lvl, Z_DEFAULT_STRATEGY);
520 }
521
522 } else if (comp_ctx->cur_lvl < global.comp_rate_lim) {
523 /* increase level */
524 comp_ctx->cur_lvl++ ;
525 deflateParams(&comp_ctx->strm, comp_ctx->cur_lvl, Z_DEFAULT_STRATEGY);
526 }
527 }
528
William Lallemand82fe75c2012-10-23 10:25:10 +0200529 return out_len;
530}
531
William Lallemand1c2d6222012-10-30 15:52:53 +0100532int deflate_reset(struct comp_ctx *comp_ctx)
William Lallemand82fe75c2012-10-23 10:25:10 +0200533{
William Lallemand1c2d6222012-10-30 15:52:53 +0100534 z_stream *strm = &comp_ctx->strm;
William Lallemand82fe75c2012-10-23 10:25:10 +0200535
William Lallemand82fe75c2012-10-23 10:25:10 +0200536 if (deflateReset(strm) == Z_OK)
537 return 0;
538 return -1;
539}
540
William Lallemand1c2d6222012-10-30 15:52:53 +0100541int deflate_end(struct comp_ctx *comp_ctx)
William Lallemand82fe75c2012-10-23 10:25:10 +0200542{
William Lallemand1c2d6222012-10-30 15:52:53 +0100543 z_stream *strm = &comp_ctx->strm;
William Lallemand82fe75c2012-10-23 10:25:10 +0200544
William Lallemand9d5f5482012-11-07 16:12:57 +0100545 if (deflateEnd(strm) != Z_OK)
546 return -1;
William Lallemand82fe75c2012-10-23 10:25:10 +0200547
William Lallemand9d5f5482012-11-07 16:12:57 +0100548 return 0;
William Lallemand82fe75c2012-10-23 10:25:10 +0200549}
550
551#endif /* USE_ZLIB */
552