blob: b79d7704b7186bcbe7bb07491eebe92f060d2562 [file] [log] [blame]
William Lallemand82fe75c2012-10-23 10:25:10 +02001/*
2 * include/types/compression.h
3 * This file defines everything related to compression.
4 *
5 * Copyright 2012 Exceliance, David Du Colombier <dducolombier@exceliance.fr>
6 William Lallemand <wlallemand@exceliance.fr>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation, version 2.1
11 * exclusively.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but 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 USA
21 */
22
23#ifndef _TYPES_COMP_H
24#define _TYPES_COMP_H
25
Willy Tarreau418b8c02015-03-29 03:32:06 +020026#if defined(USE_SLZ)
Willy Tarreaua5c51ac2015-10-13 16:45:21 +020027#ifdef USE_ZLIB
28#error "Cannot build with both USE_SLZ and USE_ZLIB at the same time."
29#endif
Willy Tarreau418b8c02015-03-29 03:32:06 +020030#include <slz.h>
31#elif defined(USE_ZLIB)
William Lallemand82fe75c2012-10-23 10:25:10 +020032#include <zlib.h>
Willy Tarreau418b8c02015-03-29 03:32:06 +020033#endif
William Lallemand08289f12012-10-31 11:19:18 +010034
William Lallemand82fe75c2012-10-23 10:25:10 +020035struct comp {
36 struct comp_algo *algos;
37 struct comp_type *types;
Willy Tarreau70737d12012-10-27 00:34:28 +020038 unsigned int offload;
William Lallemand82fe75c2012-10-23 10:25:10 +020039};
40
William Lallemand1c2d6222012-10-30 15:52:53 +010041struct comp_ctx {
Willy Tarreau418b8c02015-03-29 03:32:06 +020042#if defined(USE_SLZ)
43 struct slz_stream strm;
44 const void *direct_ptr; /* NULL or pointer to beginning of data */
45 int direct_len; /* length of direct_ptr if not NULL */
46 struct buffer *queued; /* if not NULL, data already queued */
47#elif defined(USE_ZLIB)
William Lallemand1c2d6222012-10-30 15:52:53 +010048 z_stream strm; /* zlib stream */
William Lallemand2b502472012-10-30 14:30:39 +010049 void *zlib_deflate_state;
50 void *zlib_window;
51 void *zlib_prev;
52 void *zlib_pending_buf;
53 void *zlib_head;
Willy Tarreau418b8c02015-03-29 03:32:06 +020054#endif
William Lallemandf3747832012-11-09 12:33:10 +010055 int cur_lvl;
William Lallemand1c2d6222012-10-30 15:52:53 +010056};
57
Willy Tarreau615105e2015-03-28 16:40:46 +010058/* Thanks to MSIE/IIS, the "deflate" name is ambigous, as according to the RFC
59 * it's a zlib-wrapped deflate stream, but MSIE only understands a raw deflate
60 * stream. For this reason some people prefer to emit a raw deflate stream on
61 * "deflate" and we'll need two algos for the same name, they are distinguished
62 * with the config name.
63 */
William Lallemand82fe75c2012-10-23 10:25:10 +020064struct comp_algo {
Willy Tarreau615105e2015-03-28 16:40:46 +010065 char *cfg_name; /* config name */
66 int cfg_name_len;
67
68 char *ua_name; /* name for the user-agent */
69 int ua_name_len;
70
William Lallemand8b52bb32012-11-16 18:06:41 +010071 int (*init)(struct comp_ctx **comp_ctx, int level);
William Lallemandbf3ae612012-11-19 12:35:37 +010072 int (*add_data)(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out);
Willy Tarreau9787efa2015-03-28 19:17:31 +010073 int (*flush)(struct comp_ctx *comp_ctx, struct buffer *out);
74 int (*finish)(struct comp_ctx *comp_ctx, struct buffer *out);
William Lallemand8b52bb32012-11-16 18:06:41 +010075 int (*end)(struct comp_ctx **comp_ctx);
William Lallemand82fe75c2012-10-23 10:25:10 +020076 struct comp_algo *next;
77};
78
William Lallemand82fe75c2012-10-23 10:25:10 +020079struct comp_type {
80 char *name;
81 int name_len;
82 struct comp_type *next;
83};
84
85
86#endif /* _TYPES_COMP_H */
87
88/*
89 * Local variables:
90 * c-indent-level: 8
91 * c-basic-offset: 8
92 * End:
93 */
94