1 /* 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 26 #if defined(USE_SLZ) 27 #ifdef USE_ZLIB 28 #error "Cannot build with both USE_SLZ and USE_ZLIB at the same time." 29 #endif 30 #include <slz.h> 31 #elif defined(USE_ZLIB) 32 #include <zlib.h> 33 #endif 34 35 #include <common/buffer.h> 36 37 struct comp { 38 struct comp_algo *algos; 39 struct comp_type *types; 40 unsigned int offload; 41 }; 42 43 struct comp_ctx { 44 #if defined(USE_SLZ) 45 struct slz_stream strm; 46 const void *direct_ptr; /* NULL or pointer to beginning of data */ 47 int direct_len; /* length of direct_ptr if not NULL */ 48 struct buffer queued; /* if not NULL, data already queued */ 49 #elif defined(USE_ZLIB) 50 z_stream strm; /* zlib stream */ 51 void *zlib_deflate_state; 52 void *zlib_window; 53 void *zlib_prev; 54 void *zlib_pending_buf; 55 void *zlib_head; 56 #endif 57 int cur_lvl; 58 }; 59 60 /* Thanks to MSIE/IIS, the "deflate" name is ambigous, as according to the RFC 61 * it's a zlib-wrapped deflate stream, but MSIE only understands a raw deflate 62 * stream. For this reason some people prefer to emit a raw deflate stream on 63 * "deflate" and we'll need two algos for the same name, they are distinguished 64 * with the config name. 65 */ 66 struct comp_algo { 67 char *cfg_name; /* config name */ 68 int cfg_name_len; 69 70 char *ua_name; /* name for the user-agent */ 71 int ua_name_len; 72 73 int (*init)(struct comp_ctx **comp_ctx, int level); 74 int (*add_data)(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out); 75 int (*flush)(struct comp_ctx *comp_ctx, struct buffer *out); 76 int (*finish)(struct comp_ctx *comp_ctx, struct buffer *out); 77 int (*end)(struct comp_ctx **comp_ctx); 78 struct comp_algo *next; 79 }; 80 81 struct comp_type { 82 char *name; 83 int name_len; 84 struct comp_type *next; 85 }; 86 87 88 #endif /* _TYPES_COMP_H */ 89 90 /* 91 * Local variables: 92 * c-indent-level: 8 93 * c-basic-offset: 8 94 * End: 95 */ 96 97