William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 1 | /* |
| 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 Tarreau | 3476364 | 2012-10-26 15:05:35 +0200 | [diff] [blame] | 15 | |
William Lallemand | 08289f1 | 2012-10-31 11:19:18 +0100 | [diff] [blame] | 16 | #ifdef USE_ZLIB |
Willy Tarreau | 3476364 | 2012-10-26 15:05:35 +0200 | [diff] [blame] | 17 | /* 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 Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 23 | #include <zlib.h> |
Willy Tarreau | 3476364 | 2012-10-26 15:05:35 +0200 | [diff] [blame] | 24 | #undef free_func |
William Lallemand | 08289f1 | 2012-10-31 11:19:18 +0100 | [diff] [blame] | 25 | #endif /* USE_ZLIB */ |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 26 | |
| 27 | #include <common/compat.h> |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 28 | #include <common/memory.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 29 | |
| 30 | #include <types/global.h> |
| 31 | #include <types/compression.h> |
| 32 | |
William Lallemand | 727db8b | 2013-04-20 17:33:20 +0200 | [diff] [blame] | 33 | #include <proto/acl.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 34 | #include <proto/compression.h> |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 35 | #include <proto/freq_ctr.h> |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 36 | #include <proto/proto_http.h> |
| 37 | |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 38 | |
| 39 | #ifdef USE_ZLIB |
| 40 | |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 41 | static void *alloc_zlib(void *opaque, unsigned int items, unsigned int size); |
| 42 | static void free_zlib(void *opaque, void *ptr); |
| 43 | |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 44 | /* zlib allocation */ |
| 45 | static struct pool_head *zlib_pool_deflate_state = NULL; |
| 46 | static struct pool_head *zlib_pool_window = NULL; |
| 47 | static struct pool_head *zlib_pool_prev = NULL; |
| 48 | static struct pool_head *zlib_pool_head = NULL; |
| 49 | static struct pool_head *zlib_pool_pending_buf = NULL; |
| 50 | |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 51 | long zlib_used_memory = 0; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 52 | |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 53 | #endif |
| 54 | |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 55 | unsigned int compress_min_idle = 0; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 56 | static struct pool_head *pool_comp_ctx = NULL; |
| 57 | |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 58 | |
Cyril Bonté | 6162c43 | 2012-11-10 19:27:47 +0100 | [diff] [blame] | 59 | const struct comp_algo comp_algos[] = |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 60 | { |
| 61 | { "identity", 8, identity_init, identity_add_data, identity_flush, identity_reset, identity_end }, |
| 62 | #ifdef USE_ZLIB |
| 63 | { "deflate", 7, deflate_init, deflate_add_data, deflate_flush, deflate_reset, deflate_end }, |
| 64 | { "gzip", 4, gzip_init, deflate_add_data, deflate_flush, deflate_reset, deflate_end }, |
| 65 | #endif /* USE_ZLIB */ |
| 66 | { NULL, 0, NULL , NULL, NULL, NULL, NULL } |
| 67 | }; |
| 68 | |
| 69 | /* |
| 70 | * Add a content-type in the configuration |
| 71 | */ |
| 72 | int comp_append_type(struct comp *comp, const char *type) |
| 73 | { |
| 74 | struct comp_type *comp_type; |
| 75 | |
| 76 | comp_type = calloc(1, sizeof(struct comp_type)); |
| 77 | comp_type->name_len = strlen(type); |
| 78 | comp_type->name = strdup(type); |
| 79 | comp_type->next = comp->types; |
| 80 | comp->types = comp_type; |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * Add an algorithm in the configuration |
| 86 | */ |
| 87 | int comp_append_algo(struct comp *comp, const char *algo) |
| 88 | { |
| 89 | struct comp_algo *comp_algo; |
| 90 | int i; |
| 91 | |
| 92 | for (i = 0; comp_algos[i].name; i++) { |
| 93 | if (!strcmp(algo, comp_algos[i].name)) { |
| 94 | comp_algo = calloc(1, sizeof(struct comp_algo)); |
| 95 | memmove(comp_algo, &comp_algos[i], sizeof(struct comp_algo)); |
| 96 | comp_algo->next = comp->algos; |
| 97 | comp->algos = comp_algo; |
| 98 | return 0; |
| 99 | } |
| 100 | } |
| 101 | return -1; |
| 102 | } |
| 103 | |
| 104 | /* emit the chunksize followed by a CRLF on the output and return the number of |
| 105 | * bytes written. Appends <add_crlf> additional CRLF after the first one. Chunk |
| 106 | * sizes are truncated to 6 hex digits (16 MB) and padded left. The caller is |
| 107 | * responsible for ensuring there is enough room left in the output buffer for |
| 108 | * the string (8 bytes * add_crlf*2). |
| 109 | */ |
| 110 | int http_emit_chunk_size(char *out, unsigned int chksz, int add_crlf) |
| 111 | { |
| 112 | int shift; |
| 113 | int pos = 0; |
| 114 | |
| 115 | for (shift = 20; shift >= 0; shift -= 4) |
| 116 | out[pos++] = hextab[(chksz >> shift) & 0xF]; |
| 117 | |
| 118 | do { |
| 119 | out[pos++] = '\r'; |
| 120 | out[pos++] = '\n'; |
| 121 | } while (--add_crlf >= 0); |
| 122 | |
| 123 | return pos; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Init HTTP compression |
| 128 | */ |
| 129 | int http_compression_buffer_init(struct session *s, struct buffer *in, struct buffer *out) |
| 130 | { |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 131 | int left; |
| 132 | |
| 133 | /* not enough space */ |
| 134 | if (in->size - buffer_len(in) < 40) |
| 135 | return -1; |
| 136 | |
Willy Tarreau | 7f2f8d5 | 2014-04-18 00:20:14 +0200 | [diff] [blame] | 137 | /* We start by copying the current buffer's pending outgoing data into |
| 138 | * a new temporary buffer that we initialize with a new empty chunk. |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 139 | */ |
Willy Tarreau | 474cf54 | 2014-11-24 10:54:47 +0100 | [diff] [blame] | 140 | b_reset(out); |
Willy Tarreau | 7f2f8d5 | 2014-04-18 00:20:14 +0200 | [diff] [blame] | 141 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 142 | if (in->o > 0) { |
| 143 | left = in->o - bo_contig_data(in); |
| 144 | memcpy(out->data, bo_ptr(in), bo_contig_data(in)); |
| 145 | out->p += bo_contig_data(in); |
| 146 | if (left > 0) { /* second part of the buffer */ |
| 147 | memcpy(out->p, in->data, left); |
| 148 | out->p += left; |
| 149 | } |
| 150 | out->o = in->o; |
| 151 | } |
| 152 | out->i += http_emit_chunk_size(out->p, 0, 0); |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * Add data to compress |
| 159 | */ |
| 160 | int http_compression_buffer_add_data(struct session *s, struct buffer *in, struct buffer *out) |
| 161 | { |
| 162 | struct http_msg *msg = &s->txn.rsp; |
William Lallemand | bf3ae61 | 2012-11-19 12:35:37 +0100 | [diff] [blame] | 163 | int consumed_data = 0; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 164 | int data_process_len; |
Willy Tarreau | 7f2f8d5 | 2014-04-18 00:20:14 +0200 | [diff] [blame] | 165 | int block1, block2; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 166 | |
| 167 | /* |
Willy Tarreau | 7f2f8d5 | 2014-04-18 00:20:14 +0200 | [diff] [blame] | 168 | * Temporarily skip already parsed data and chunks to jump to the |
| 169 | * actual data block. It is fixed before leaving. |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 170 | */ |
| 171 | b_adv(in, msg->next); |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 172 | |
| 173 | /* |
| 174 | * select the smallest size between the announced chunk size, the input |
Willy Tarreau | 7f2f8d5 | 2014-04-18 00:20:14 +0200 | [diff] [blame] | 175 | * data, and the available output buffer size. The compressors are |
| 176 | * assumed to be able to process all the bytes we pass to them at once. |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 177 | */ |
| 178 | data_process_len = MIN(in->i, msg->chunk_len); |
| 179 | data_process_len = MIN(out->size - buffer_len(out), data_process_len); |
| 180 | |
Willy Tarreau | 7f2f8d5 | 2014-04-18 00:20:14 +0200 | [diff] [blame] | 181 | block1 = data_process_len; |
| 182 | if (block1 > bi_contig_data(in)) |
| 183 | block1 = bi_contig_data(in); |
| 184 | block2 = data_process_len - block1; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 185 | |
Willy Tarreau | 7f2f8d5 | 2014-04-18 00:20:14 +0200 | [diff] [blame] | 186 | /* compressors return < 0 upon error or the amount of bytes read */ |
| 187 | consumed_data = s->comp_algo->add_data(s->comp_ctx, bi_ptr(in), block1, out); |
| 188 | if (consumed_data >= 0 && block2 > 0) { |
| 189 | consumed_data = s->comp_algo->add_data(s->comp_ctx, in->data, block2, out); |
| 190 | if (consumed_data >= 0) |
| 191 | consumed_data += block1; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 192 | } |
| 193 | |
Willy Tarreau | 7f2f8d5 | 2014-04-18 00:20:14 +0200 | [diff] [blame] | 194 | /* restore original buffer pointer */ |
| 195 | b_rew(in, msg->next); |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 196 | |
Willy Tarreau | 7f2f8d5 | 2014-04-18 00:20:14 +0200 | [diff] [blame] | 197 | if (consumed_data > 0) { |
| 198 | msg->next += consumed_data; |
| 199 | msg->chunk_len -= consumed_data; |
| 200 | } |
William Lallemand | bf3ae61 | 2012-11-19 12:35:37 +0100 | [diff] [blame] | 201 | return consumed_data; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /* |
| 205 | * Flush data in process, and write the header and footer of the chunk. Upon |
| 206 | * success, in and out buffers are swapped to avoid a copy. |
| 207 | */ |
| 208 | int http_compression_buffer_end(struct session *s, struct buffer **in, struct buffer **out, int end) |
| 209 | { |
Willy Tarreau | 3ca5448 | 2014-04-23 19:31:17 +0200 | [diff] [blame] | 210 | int to_forward; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 211 | int left; |
| 212 | struct http_msg *msg = &s->txn.rsp; |
| 213 | struct buffer *ib = *in, *ob = *out; |
William Lallemand | 08289f1 | 2012-10-31 11:19:18 +0100 | [diff] [blame] | 214 | |
| 215 | #ifdef USE_ZLIB |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 216 | int ret; |
| 217 | |
| 218 | /* flush data here */ |
| 219 | |
| 220 | if (end) |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 221 | ret = s->comp_algo->flush(s->comp_ctx, ob, Z_FINISH); /* end of data */ |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 222 | else |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 223 | ret = s->comp_algo->flush(s->comp_ctx, ob, Z_SYNC_FLUSH); /* end of buffer */ |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 224 | |
| 225 | if (ret < 0) |
| 226 | return -1; /* flush failed */ |
| 227 | |
William Lallemand | 08289f1 | 2012-10-31 11:19:18 +0100 | [diff] [blame] | 228 | #endif /* USE_ZLIB */ |
| 229 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 230 | if (ob->i > 8) { |
| 231 | /* more than a chunk size => some data were emitted */ |
| 232 | char *tail = ob->p + ob->i; |
| 233 | |
| 234 | /* write real size at the begining of the chunk, no need of wrapping */ |
| 235 | http_emit_chunk_size(ob->p, ob->i - 8, 0); |
| 236 | |
| 237 | /* chunked encoding requires CRLF after data */ |
| 238 | *tail++ = '\r'; |
| 239 | *tail++ = '\n'; |
| 240 | |
Willy Tarreau | 7f2f8d5 | 2014-04-18 00:20:14 +0200 | [diff] [blame] | 241 | /* At the end of data, we must write the empty chunk 0<CRLF>, |
| 242 | * and terminate the trailers section with a last <CRLF>. If |
| 243 | * we're forwarding a chunked-encoded response, we'll have a |
| 244 | * trailers section after the empty chunk which needs to be |
| 245 | * forwarded and which will provide the last CRLF. Otherwise |
| 246 | * we write it ourselves. |
| 247 | */ |
| 248 | if (msg->msg_state >= HTTP_MSG_TRAILERS) { |
| 249 | memcpy(tail, "0\r\n", 3); |
| 250 | tail += 3; |
| 251 | if (msg->msg_state >= HTTP_MSG_DONE) { |
| 252 | memcpy(tail, "\r\n", 2); |
| 253 | tail += 2; |
| 254 | } |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 255 | } |
| 256 | ob->i = tail - ob->p; |
| 257 | } else { |
| 258 | /* no data were sent, cancel the chunk size */ |
| 259 | ob->i = 0; |
| 260 | } |
| 261 | |
| 262 | to_forward = ob->i; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 263 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 264 | /* update input rate */ |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 265 | if (s->comp_ctx && s->comp_ctx->cur_lvl > 0) { |
Willy Tarreau | 3ca5448 | 2014-04-23 19:31:17 +0200 | [diff] [blame] | 266 | update_freq_ctr(&global.comp_bps_in, msg->next); |
| 267 | s->fe->fe_counters.comp_in += msg->next; |
| 268 | s->be->be_counters.comp_in += msg->next; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 269 | } else { |
Willy Tarreau | 3ca5448 | 2014-04-23 19:31:17 +0200 | [diff] [blame] | 270 | s->fe->fe_counters.comp_byp += msg->next; |
| 271 | s->be->be_counters.comp_byp += msg->next; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 272 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 273 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 274 | /* copy the remaining data in the tmp buffer. */ |
Willy Tarreau | 7f2f8d5 | 2014-04-18 00:20:14 +0200 | [diff] [blame] | 275 | b_adv(ib, msg->next); |
| 276 | msg->next = 0; |
| 277 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 278 | if (ib->i > 0) { |
| 279 | left = ib->i - bi_contig_data(ib); |
| 280 | memcpy(bi_end(ob), bi_ptr(ib), bi_contig_data(ib)); |
| 281 | ob->i += bi_contig_data(ib); |
| 282 | if (left > 0) { |
| 283 | memcpy(bi_end(ob), ib->data, left); |
| 284 | ob->i += left; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /* swap the buffers */ |
| 289 | *in = ob; |
| 290 | *out = ib; |
| 291 | |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 292 | if (s->comp_ctx && s->comp_ctx->cur_lvl > 0) { |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 293 | update_freq_ctr(&global.comp_bps_out, to_forward); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 294 | s->fe->fe_counters.comp_out += to_forward; |
| 295 | s->be->be_counters.comp_out += to_forward; |
| 296 | } |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 297 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 298 | /* forward the new chunk without remaining data */ |
| 299 | b_adv(ob, to_forward); |
| 300 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 301 | return to_forward; |
| 302 | } |
| 303 | |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 304 | /* |
| 305 | * Alloc the comp_ctx |
| 306 | */ |
| 307 | static inline int init_comp_ctx(struct comp_ctx **comp_ctx) |
| 308 | { |
| 309 | #ifdef USE_ZLIB |
| 310 | z_stream *strm; |
| 311 | |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 312 | if (global.maxzlibmem > 0 && (global.maxzlibmem - zlib_used_memory) < sizeof(struct comp_ctx)) |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 313 | return -1; |
| 314 | #endif |
| 315 | |
| 316 | if (unlikely(pool_comp_ctx == NULL)) |
| 317 | pool_comp_ctx = create_pool("comp_ctx", sizeof(struct comp_ctx), MEM_F_SHARED); |
| 318 | |
| 319 | *comp_ctx = pool_alloc2(pool_comp_ctx); |
| 320 | if (*comp_ctx == NULL) |
| 321 | return -1; |
| 322 | #ifdef USE_ZLIB |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 323 | zlib_used_memory += sizeof(struct comp_ctx); |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 324 | |
| 325 | strm = &(*comp_ctx)->strm; |
| 326 | strm->zalloc = alloc_zlib; |
| 327 | strm->zfree = free_zlib; |
| 328 | strm->opaque = *comp_ctx; |
| 329 | #endif |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Dealloc the comp_ctx |
| 335 | */ |
| 336 | static inline int deinit_comp_ctx(struct comp_ctx **comp_ctx) |
| 337 | { |
| 338 | if (!*comp_ctx) |
| 339 | return 0; |
| 340 | |
| 341 | pool_free2(pool_comp_ctx, *comp_ctx); |
| 342 | *comp_ctx = NULL; |
| 343 | |
| 344 | #ifdef USE_ZLIB |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 345 | zlib_used_memory -= sizeof(struct comp_ctx); |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 346 | #endif |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 347 | return 0; |
| 348 | } |
| 349 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 350 | |
| 351 | /**************************** |
| 352 | **** Identity algorithm **** |
| 353 | ****************************/ |
| 354 | |
| 355 | /* |
| 356 | * Init the identity algorithm |
| 357 | */ |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 358 | int identity_init(struct comp_ctx **comp_ctx, int level) |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 359 | { |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | /* |
| 364 | * Process data |
William Lallemand | bf3ae61 | 2012-11-19 12:35:37 +0100 | [diff] [blame] | 365 | * Return size of consumed data or -1 on error |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 366 | */ |
William Lallemand | bf3ae61 | 2012-11-19 12:35:37 +0100 | [diff] [blame] | 367 | int identity_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out) |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 368 | { |
William Lallemand | bf3ae61 | 2012-11-19 12:35:37 +0100 | [diff] [blame] | 369 | char *out_data = bi_end(out); |
| 370 | int out_len = out->size - buffer_len(out); |
| 371 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 372 | if (out_len < in_len) |
| 373 | return -1; |
| 374 | |
| 375 | memcpy(out_data, in_data, in_len); |
| 376 | |
William Lallemand | bf3ae61 | 2012-11-19 12:35:37 +0100 | [diff] [blame] | 377 | out->i += in_len; |
| 378 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 379 | return in_len; |
| 380 | } |
| 381 | |
William Lallemand | 1c2d622 | 2012-10-30 15:52:53 +0100 | [diff] [blame] | 382 | int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag) |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 383 | { |
| 384 | return 0; |
| 385 | } |
| 386 | |
William Lallemand | 1c2d622 | 2012-10-30 15:52:53 +0100 | [diff] [blame] | 387 | int identity_reset(struct comp_ctx *comp_ctx) |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 388 | { |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Deinit the algorithm |
| 394 | */ |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 395 | int identity_end(struct comp_ctx **comp_ctx) |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 396 | { |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | |
| 401 | #ifdef USE_ZLIB |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 402 | /* |
| 403 | * This is a tricky allocation function using the zlib. |
| 404 | * This is based on the allocation order in deflateInit2. |
| 405 | */ |
| 406 | static void *alloc_zlib(void *opaque, unsigned int items, unsigned int size) |
| 407 | { |
| 408 | struct comp_ctx *ctx = opaque; |
| 409 | static char round = 0; /* order in deflateInit2 */ |
| 410 | void *buf = NULL; |
Willy Tarreau | 4f31fc2 | 2014-12-24 18:07:55 +0100 | [diff] [blame] | 411 | struct pool_head *pool = NULL; |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 412 | |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 413 | if (global.maxzlibmem > 0 && (global.maxzlibmem - zlib_used_memory) < (long)(items * size)) |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 414 | goto end; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 415 | |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 416 | switch (round) { |
| 417 | case 0: |
| 418 | if (zlib_pool_deflate_state == NULL) |
| 419 | zlib_pool_deflate_state = create_pool("zlib_state", size * items, MEM_F_SHARED); |
Willy Tarreau | 4f31fc2 | 2014-12-24 18:07:55 +0100 | [diff] [blame] | 420 | pool = zlib_pool_deflate_state; |
| 421 | ctx->zlib_deflate_state = buf = pool_alloc2(pool); |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 422 | break; |
| 423 | |
| 424 | case 1: |
| 425 | if (zlib_pool_window == NULL) |
| 426 | zlib_pool_window = create_pool("zlib_window", size * items, MEM_F_SHARED); |
Willy Tarreau | 4f31fc2 | 2014-12-24 18:07:55 +0100 | [diff] [blame] | 427 | pool = zlib_pool_window; |
| 428 | ctx->zlib_window = buf = pool_alloc2(pool); |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 429 | break; |
| 430 | |
| 431 | case 2: |
| 432 | if (zlib_pool_prev == NULL) |
| 433 | zlib_pool_prev = create_pool("zlib_prev", size * items, MEM_F_SHARED); |
Willy Tarreau | 4f31fc2 | 2014-12-24 18:07:55 +0100 | [diff] [blame] | 434 | pool = zlib_pool_prev; |
| 435 | ctx->zlib_prev = buf = pool_alloc2(pool); |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 436 | break; |
| 437 | |
| 438 | case 3: |
| 439 | if (zlib_pool_head == NULL) |
| 440 | zlib_pool_head = create_pool("zlib_head", size * items, MEM_F_SHARED); |
Willy Tarreau | 4f31fc2 | 2014-12-24 18:07:55 +0100 | [diff] [blame] | 441 | pool = zlib_pool_head; |
| 442 | ctx->zlib_head = buf = pool_alloc2(pool); |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 443 | break; |
| 444 | |
| 445 | case 4: |
| 446 | if (zlib_pool_pending_buf == NULL) |
| 447 | zlib_pool_pending_buf = create_pool("zlib_pending_buf", size * items, MEM_F_SHARED); |
Willy Tarreau | 4f31fc2 | 2014-12-24 18:07:55 +0100 | [diff] [blame] | 448 | pool = zlib_pool_pending_buf; |
| 449 | ctx->zlib_pending_buf = buf = pool_alloc2(pool); |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 450 | break; |
| 451 | } |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 452 | if (buf != NULL) |
Willy Tarreau | 4f31fc2 | 2014-12-24 18:07:55 +0100 | [diff] [blame] | 453 | zlib_used_memory += pool->size; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 454 | |
| 455 | end: |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 456 | |
Willy Tarreau | 4690985 | 2012-11-15 14:57:56 +0100 | [diff] [blame] | 457 | /* deflateInit2() first allocates and checks the deflate_state, then if |
| 458 | * it succeeds, it allocates all other 4 areas at ones and checks them |
| 459 | * at the end. So we want to correctly count the rounds depending on when |
| 460 | * zlib is supposed to abort. |
| 461 | */ |
| 462 | if (buf || round) |
| 463 | round = (round + 1) % 5; |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 464 | return buf; |
| 465 | } |
| 466 | |
| 467 | static void free_zlib(void *opaque, void *ptr) |
| 468 | { |
| 469 | struct comp_ctx *ctx = opaque; |
Willy Tarreau | b1fbd05 | 2012-11-10 17:49:37 +0100 | [diff] [blame] | 470 | struct pool_head *pool = NULL; |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 471 | |
| 472 | if (ptr == ctx->zlib_window) |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 473 | pool = zlib_pool_window; |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 474 | else if (ptr == ctx->zlib_deflate_state) |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 475 | pool = zlib_pool_deflate_state; |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 476 | else if (ptr == ctx->zlib_prev) |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 477 | pool = zlib_pool_prev; |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 478 | else if (ptr == ctx->zlib_head) |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 479 | pool = zlib_pool_head; |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 480 | else if (ptr == ctx->zlib_pending_buf) |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 481 | pool = zlib_pool_pending_buf; |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 482 | |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 483 | pool_free2(pool, ptr); |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 484 | zlib_used_memory -= pool->size; |
William Lallemand | 2b50247 | 2012-10-30 14:30:39 +0100 | [diff] [blame] | 485 | } |
| 486 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 487 | /************************** |
| 488 | **** gzip algorithm **** |
| 489 | ***************************/ |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 490 | int gzip_init(struct comp_ctx **comp_ctx, int level) |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 491 | { |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 492 | z_stream *strm; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 493 | |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 494 | if (init_comp_ctx(comp_ctx) < 0) |
| 495 | return -1; |
William Lallemand | 9d5f548 | 2012-11-07 16:12:57 +0100 | [diff] [blame] | 496 | |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 497 | strm = &(*comp_ctx)->strm; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 498 | |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 499 | if (deflateInit2(strm, level, Z_DEFLATED, global.tune.zlibwindowsize + 16, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) { |
| 500 | deinit_comp_ctx(comp_ctx); |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 501 | return -1; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | (*comp_ctx)->cur_lvl = level; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | /************************** |
| 509 | **** Deflate algorithm **** |
| 510 | ***************************/ |
| 511 | |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 512 | int deflate_init(struct comp_ctx **comp_ctx, int level) |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 513 | { |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 514 | z_stream *strm; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 515 | |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 516 | if (init_comp_ctx(comp_ctx) < 0) |
| 517 | return -1; |
| 518 | |
| 519 | strm = &(*comp_ctx)->strm; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 520 | |
Willy Tarreau | c5599e7 | 2013-04-28 08:52:52 +0200 | [diff] [blame] | 521 | if (deflateInit2(strm, level, Z_DEFLATED, global.tune.zlibwindowsize, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) { |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 522 | deinit_comp_ctx(comp_ctx); |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 523 | return -1; |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | (*comp_ctx)->cur_lvl = level; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
William Lallemand | bf3ae61 | 2012-11-19 12:35:37 +0100 | [diff] [blame] | 531 | /* Return the size of consumed data or -1 */ |
| 532 | int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out) |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 533 | { |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 534 | int ret; |
William Lallemand | bf3ae61 | 2012-11-19 12:35:37 +0100 | [diff] [blame] | 535 | z_stream *strm = &comp_ctx->strm; |
| 536 | char *out_data = bi_end(out); |
| 537 | int out_len = out->size - buffer_len(out); |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 538 | |
| 539 | if (in_len <= 0) |
| 540 | return 0; |
| 541 | |
| 542 | |
| 543 | if (out_len <= 0) |
| 544 | return -1; |
| 545 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 546 | strm->next_in = (unsigned char *)in_data; |
| 547 | strm->avail_in = in_len; |
| 548 | strm->next_out = (unsigned char *)out_data; |
| 549 | strm->avail_out = out_len; |
| 550 | |
| 551 | ret = deflate(strm, Z_NO_FLUSH); |
| 552 | if (ret != Z_OK) |
| 553 | return -1; |
| 554 | |
| 555 | /* deflate update the available data out */ |
William Lallemand | bf3ae61 | 2012-11-19 12:35:37 +0100 | [diff] [blame] | 556 | out->i += out_len - strm->avail_out; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 557 | |
William Lallemand | bf3ae61 | 2012-11-19 12:35:37 +0100 | [diff] [blame] | 558 | return in_len - strm->avail_in; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 559 | } |
| 560 | |
William Lallemand | 1c2d622 | 2012-10-30 15:52:53 +0100 | [diff] [blame] | 561 | int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag) |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 562 | { |
| 563 | int ret; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 564 | int out_len = 0; |
William Lallemand | 1c2d622 | 2012-10-30 15:52:53 +0100 | [diff] [blame] | 565 | z_stream *strm = &comp_ctx->strm; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 566 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 567 | strm->next_out = (unsigned char *)bi_end(out); |
| 568 | strm->avail_out = out->size - buffer_len(out); |
| 569 | |
| 570 | ret = deflate(strm, flag); |
| 571 | if (ret != Z_OK && ret != Z_STREAM_END) |
| 572 | return -1; |
| 573 | |
| 574 | out_len = (out->size - buffer_len(out)) - strm->avail_out; |
| 575 | out->i += out_len; |
| 576 | |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 577 | /* compression limit */ |
| 578 | if ((global.comp_rate_lim > 0 && (read_freq_ctr(&global.comp_bps_out) > global.comp_rate_lim)) || /* rate */ |
| 579 | (idle_pct < compress_min_idle)) { /* idle */ |
| 580 | /* decrease level */ |
| 581 | if (comp_ctx->cur_lvl > 0) { |
| 582 | comp_ctx->cur_lvl--; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 583 | deflateParams(&comp_ctx->strm, comp_ctx->cur_lvl, Z_DEFAULT_STRATEGY); |
| 584 | } |
William Lallemand | 072a2bf | 2012-11-20 17:01:01 +0100 | [diff] [blame] | 585 | |
| 586 | } else if (comp_ctx->cur_lvl < global.tune.comp_maxlevel) { |
| 587 | /* increase level */ |
| 588 | comp_ctx->cur_lvl++ ; |
| 589 | deflateParams(&comp_ctx->strm, comp_ctx->cur_lvl, Z_DEFAULT_STRATEGY); |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 590 | } |
| 591 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 592 | return out_len; |
| 593 | } |
| 594 | |
William Lallemand | 1c2d622 | 2012-10-30 15:52:53 +0100 | [diff] [blame] | 595 | int deflate_reset(struct comp_ctx *comp_ctx) |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 596 | { |
William Lallemand | 1c2d622 | 2012-10-30 15:52:53 +0100 | [diff] [blame] | 597 | z_stream *strm = &comp_ctx->strm; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 598 | |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 599 | if (deflateReset(strm) == Z_OK) |
| 600 | return 0; |
| 601 | return -1; |
| 602 | } |
| 603 | |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 604 | int deflate_end(struct comp_ctx **comp_ctx) |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 605 | { |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 606 | z_stream *strm = &(*comp_ctx)->strm; |
| 607 | int ret; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 608 | |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 609 | ret = deflateEnd(strm); |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 610 | |
William Lallemand | 8b52bb3 | 2012-11-16 18:06:41 +0100 | [diff] [blame] | 611 | deinit_comp_ctx(comp_ctx); |
| 612 | |
| 613 | return ret; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | #endif /* USE_ZLIB */ |
| 617 | |
William Lallemand | 727db8b | 2013-04-20 17:33:20 +0200 | [diff] [blame] | 618 | /* boolean, returns true if compression is used (either gzip or deflate) in the response */ |
| 619 | static int |
| 620 | smp_fetch_res_comp(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame^] | 621 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
William Lallemand | 727db8b | 2013-04-20 17:33:20 +0200 | [diff] [blame] | 622 | { |
| 623 | smp->type = SMP_T_BOOL; |
| 624 | smp->data.uint = (l4->comp_algo != NULL); |
| 625 | return 1; |
| 626 | } |
| 627 | |
| 628 | /* string, returns algo */ |
| 629 | static int |
| 630 | smp_fetch_res_comp_algo(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame^] | 631 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
William Lallemand | 727db8b | 2013-04-20 17:33:20 +0200 | [diff] [blame] | 632 | { |
| 633 | if (!l4->comp_algo) |
| 634 | return 0; |
| 635 | |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 636 | smp->type = SMP_T_STR; |
| 637 | smp->flags = SMP_F_CONST; |
William Lallemand | 727db8b | 2013-04-20 17:33:20 +0200 | [diff] [blame] | 638 | smp->data.str.str = l4->comp_algo->name; |
| 639 | smp->data.str.len = l4->comp_algo->name_len; |
| 640 | return 1; |
| 641 | } |
| 642 | |
| 643 | /* Note: must not be declared <const> as its list will be overwritten */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 644 | static struct acl_kw_list acl_kws = {ILH, { |
Willy Tarreau | 7f6fa69 | 2013-04-23 19:39:43 +0200 | [diff] [blame] | 645 | { /* END */ }, |
William Lallemand | 727db8b | 2013-04-20 17:33:20 +0200 | [diff] [blame] | 646 | }}; |
| 647 | |
| 648 | /* Note: must not be declared <const> as its list will be overwritten */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 649 | static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { |
William Lallemand | 727db8b | 2013-04-20 17:33:20 +0200 | [diff] [blame] | 650 | { "res.comp", smp_fetch_res_comp, 0, NULL, SMP_T_BOOL, SMP_USE_HRSHP }, |
| 651 | { "res.comp_algo", smp_fetch_res_comp_algo, 0, NULL, SMP_T_STR, SMP_USE_HRSHP }, |
| 652 | { /* END */ }, |
| 653 | }}; |
| 654 | |
| 655 | __attribute__((constructor)) |
| 656 | static void __comp_fetch_init(void) |
| 657 | { |
| 658 | acl_register_keywords(&acl_kws); |
| 659 | sample_register_fetches(&sample_fetch_keywords); |
| 660 | } |