/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#ifdef HAVE_ZLIB
#include "crc32.h"
#include "istream-private.h"
#include "istream-zlib.h"
#include <zlib.h>
struct zlib_istream {
};
bool close_parent)
{
}
if (close_parent)
}
{
"zlib.read(%s): %s at %"PRIuUOFF_T,
if (zstream->log_errors)
}
{
const unsigned char *data;
int ret;
}
if (ret == -2) {
ret = -1;
}
return ret;
}
if (size < GZ_HEADER_MIN_SIZE)
return 0;
/* missing gzip magic header */
return -1;
}
return 0;
pos += 2;
return 0;
pos += fextra_size;
}
do {
return 0;
}
do {
return 0;
}
return 0;
pos += 2;
}
return 1;
}
{
const unsigned char *data;
int ret;
}
return ret;
}
if (size < GZ_TRAILER_SIZE)
return 0;
return -1;
}
return 1;
}
{
const unsigned char *data;
int ret;
if (!zstream->trailer_read) {
do {
if (ret <= 0)
return ret;
}
return -1;
}
}
if (zstream->starting_concated_output) {
/* make sure there actually is something in parent stream.
we don't want to reset the stream unless we actually see
some concated output. */
if (ret <= 0) {
if (ret == 0)
return 0;
}
return -1;
}
/* gzip file with concatenated content */
}
if (!zstream->header_read) {
do {
if (ret <= 0)
return ret;
}
/* we're here because we seeked back within the read buffer. */
if (zstream->trailer_read) {
}
return ret;
}
return -2; /* buffer full */
} else {
/* try to avoid compressing, so we can quickly seek backwards */
return -2; /* buffer full */
}
} else {
}
return -1;
}
if (size == 0) {
/* no more input */
return 0;
}
out_size);
switch (ret) {
case Z_OK:
break;
case Z_NEED_DICT:
return -1;
case Z_DATA_ERROR:
return -1;
case Z_MEM_ERROR:
case Z_STREAM_END:
if (!zstream->trailer_read) {
/* try to read and verify the trailer, we might not
be called again. */
if (i_stream_zlib_read_trailer(zstream) < 0)
return -1;
}
break;
default:
}
if (out_size == 0) {
/* read more input */
return i_stream_zlib_read(stream);
}
return out_size;
}
{
int ret;
switch (ret) {
case Z_OK:
break;
case Z_MEM_ERROR:
case Z_VERSION_ERROR:
i_fatal("Wrong zlib library version (broken compilation)");
case Z_STREAM_ERROR:
i_fatal("zlib: Invalid parameters");
default:
}
}
{
}
static void
{
if (v_offset < start_offset) {
/* have to seek backwards */
start_offset = 0;
}
/* seeking backwards within what's already cached */
} else {
/* read and cache forward */
do {
v_offset -
ret = -1;
break;
}
/* some failure, we've broken it */
i_error("zlib_istream.seek(%s) failed: %s",
} else {
/* unexpected EOF. allow it since we may just
want to check if there's anything.. */
}
}
}
if (mark)
}
static int
{
return -1;
}
/* when exact=FALSE always return the parent stat's size, even if we
know the exact value. this is necessary because otherwise e.g. mbox
code can see two different values and think that a compressed mbox
file keeps changing. */
if (!exact)
return 0;
do {
return -1;
}
return 0;
}
{
/* a compressed file doesn't change unexpectedly,
don't clear our caches unnecessarily */
return;
}
}
}
static struct istream *
{
i_stream_get_fd(input), 0);
}
{
}
{
}
#endif