|
|
@ -1,5 +1,5 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2016, The PurpleI2P Project |
|
|
|
* Copyright (c) 2013-2017, The PurpleI2P Project |
|
|
|
* |
|
|
|
* |
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3 |
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3 |
|
|
|
* |
|
|
|
* |
|
|
@ -9,11 +9,13 @@ |
|
|
|
#include <inttypes.h> |
|
|
|
#include <inttypes.h> |
|
|
|
#include <string.h> /* memset */ |
|
|
|
#include <string.h> /* memset */ |
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
#include "Log.h" |
|
|
|
#include "Gzip.h" |
|
|
|
#include "Gzip.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace i2p { |
|
|
|
namespace i2p |
|
|
|
namespace data { |
|
|
|
{ |
|
|
|
|
|
|
|
namespace data |
|
|
|
|
|
|
|
{ |
|
|
|
const size_t GZIP_CHUNK_SIZE = 16384; |
|
|
|
const size_t GZIP_CHUNK_SIZE = 16384; |
|
|
|
|
|
|
|
|
|
|
|
GzipInflator::GzipInflator (): m_IsDirty (false) |
|
|
|
GzipInflator::GzipInflator (): m_IsDirty (false) |
|
|
@ -36,9 +38,10 @@ namespace data { |
|
|
|
m_Inflator.next_out = out; |
|
|
|
m_Inflator.next_out = out; |
|
|
|
m_Inflator.avail_out = outLen; |
|
|
|
m_Inflator.avail_out = outLen; |
|
|
|
int err; |
|
|
|
int err; |
|
|
|
if ((err = inflate (&m_Inflator, Z_NO_FLUSH)) == Z_STREAM_END) { |
|
|
|
if ((err = inflate (&m_Inflator, Z_NO_FLUSH)) == Z_STREAM_END) |
|
|
|
return outLen - m_Inflator.avail_out; |
|
|
|
return outLen - m_Inflator.avail_out; |
|
|
|
} |
|
|
|
// else
|
|
|
|
|
|
|
|
LogPrint (eLogError, "Gzip: Inflate error ", err); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -49,17 +52,20 @@ namespace data { |
|
|
|
m_Inflator.next_in = const_cast<uint8_t *>(in); |
|
|
|
m_Inflator.next_in = const_cast<uint8_t *>(in); |
|
|
|
m_Inflator.avail_in = inLen; |
|
|
|
m_Inflator.avail_in = inLen; |
|
|
|
int ret; |
|
|
|
int ret; |
|
|
|
do { |
|
|
|
do |
|
|
|
|
|
|
|
{ |
|
|
|
m_Inflator.next_out = out; |
|
|
|
m_Inflator.next_out = out; |
|
|
|
m_Inflator.avail_out = GZIP_CHUNK_SIZE; |
|
|
|
m_Inflator.avail_out = GZIP_CHUNK_SIZE; |
|
|
|
ret = inflate (&m_Inflator, Z_NO_FLUSH); |
|
|
|
ret = inflate (&m_Inflator, Z_NO_FLUSH); |
|
|
|
if (ret < 0) { |
|
|
|
if (ret < 0) |
|
|
|
|
|
|
|
{ |
|
|
|
inflateEnd (&m_Inflator); |
|
|
|
inflateEnd (&m_Inflator); |
|
|
|
os.setstate(std::ios_base::failbit); |
|
|
|
os.setstate(std::ios_base::failbit); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
os.write ((char *)out, GZIP_CHUNK_SIZE - m_Inflator.avail_out); |
|
|
|
os.write ((char *)out, GZIP_CHUNK_SIZE - m_Inflator.avail_out); |
|
|
|
} while (!m_Inflator.avail_out); // more data to read
|
|
|
|
} |
|
|
|
|
|
|
|
while (!m_Inflator.avail_out); // more data to read
|
|
|
|
delete[] out; |
|
|
|
delete[] out; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -99,9 +105,10 @@ namespace data { |
|
|
|
m_Deflator.next_out = out; |
|
|
|
m_Deflator.next_out = out; |
|
|
|
m_Deflator.avail_out = outLen; |
|
|
|
m_Deflator.avail_out = outLen; |
|
|
|
int err; |
|
|
|
int err; |
|
|
|
if ((err = deflate (&m_Deflator, Z_FINISH)) == Z_STREAM_END) { |
|
|
|
if ((err = deflate (&m_Deflator, Z_FINISH)) == Z_STREAM_END) |
|
|
|
return outLen - m_Deflator.avail_out; |
|
|
|
return outLen - m_Deflator.avail_out; |
|
|
|
} /* else */ |
|
|
|
// else
|
|
|
|
|
|
|
|
LogPrint (eLogError, "Gzip: Deflate error ", err); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} // data
|
|
|
|
} // data
|
|
|
|