2 * nghttp2 - HTTP/2 C Library
4 * Copyright (c) 2012 Tatsuhiro Tsujikawa
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "nghttp2_gzip.h"
29 int nghttp2_gzip_inflate_new(nghttp2_gzip **inflater_ptr) {
31 *inflater_ptr = malloc(sizeof(nghttp2_gzip));
32 if (*inflater_ptr == NULL) {
35 (*inflater_ptr)->finished = 0;
36 (*inflater_ptr)->zst.next_in = Z_NULL;
37 (*inflater_ptr)->zst.avail_in = 0;
38 (*inflater_ptr)->zst.zalloc = Z_NULL;
39 (*inflater_ptr)->zst.zfree = Z_NULL;
40 (*inflater_ptr)->zst.opaque = Z_NULL;
41 rv = inflateInit2(&(*inflater_ptr)->zst, 47);
49 void nghttp2_gzip_inflate_del(nghttp2_gzip *inflater) {
50 if (inflater != NULL) {
51 inflateEnd(&inflater->zst);
56 int nghttp2_gzip_inflate(nghttp2_gzip *inflater, uint8_t *out,
57 size_t *outlen_ptr, const uint8_t *in,
60 if (inflater->finished) {
63 inflater->zst.avail_in = (unsigned int)*inlen_ptr;
64 inflater->zst.next_in = (unsigned char *)in;
65 inflater->zst.avail_out = (unsigned int)*outlen_ptr;
66 inflater->zst.next_out = out;
68 rv = inflate(&inflater->zst, Z_NO_FLUSH);
70 *inlen_ptr -= inflater->zst.avail_in;
71 *outlen_ptr -= inflater->zst.avail_out;
74 inflater->finished = 1;
85 /* We need this for some compilers */
90 int nghttp2_gzip_inflate_finished(nghttp2_gzip *inflater) {
91 return inflater->finished;