From f460ad667c0c5de742d1d2e7f0c7b4d84fc0ccf3 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 19 Mar 2024 07:51:34 +0100 Subject: [PATCH] files --- .../src/3rd-party/qcompressor/qcompressor.cpp | 196 ++++++++++++++++++ .../src/3rd-party/qcompressor/qcompressor.h | 17 ++ src/librssguard/miscellaneous/application.cpp | 2 - src/librssguard/miscellaneous/feedreader.cpp | 1 + 4 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 src/librssguard-standard/src/3rd-party/qcompressor/qcompressor.cpp create mode 100644 src/librssguard-standard/src/3rd-party/qcompressor/qcompressor.h diff --git a/src/librssguard-standard/src/3rd-party/qcompressor/qcompressor.cpp b/src/librssguard-standard/src/3rd-party/qcompressor/qcompressor.cpp new file mode 100644 index 000000000..458258864 --- /dev/null +++ b/src/librssguard-standard/src/3rd-party/qcompressor/qcompressor.cpp @@ -0,0 +1,196 @@ +#include "qcompressor.h" + +/** + * @brief Compresses the given buffer using the standard GZIP algorithm + * @param input The buffer to be compressed + * @param output The result of the compression + * @param level The compression level to be used (@c 0 = no compression, @c 9 = max, @c -1 = default) + * @return @c true if the compression was successful, @c false otherwise + */ +bool QCompressor::gzipCompress(QByteArray input, QByteArray &output, int level) +{ + // Prepare output + output.clear(); + + // Is there something to do? + if(input.length()) + { + // Declare vars + int flush = 0; + + // Prepare deflater status + z_stream strm; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + strm.avail_in = 0; + strm.next_in = Z_NULL; + + // Initialize deflater + int ret = deflateInit2(&strm, qMax(-1, qMin(9, level)), Z_DEFLATED, GZIP_WINDOWS_BIT, 8, Z_DEFAULT_STRATEGY); + + if (ret != Z_OK) + return(false); + + // Prepare output + output.clear(); + + // Extract pointer to input data + char *input_data = input.data(); + int input_data_left = input.length(); + + // Compress data until available + do { + // Determine current chunk size + int chunk_size = qMin(GZIP_CHUNK_SIZE, input_data_left); + + // Set deflater references + strm.next_in = (unsigned char*)input_data; + strm.avail_in = chunk_size; + + // Update interval variables + input_data += chunk_size; + input_data_left -= chunk_size; + + // Determine if it is the last chunk + flush = (input_data_left <= 0 ? Z_FINISH : Z_NO_FLUSH); + + // Deflate chunk and cumulate output + do { + + // Declare vars + char out[GZIP_CHUNK_SIZE]; + + // Set deflater references + strm.next_out = (unsigned char*)out; + strm.avail_out = GZIP_CHUNK_SIZE; + + // Try to deflate chunk + ret = deflate(&strm, flush); + + // Check errors + if(ret == Z_STREAM_ERROR) + { + // Clean-up + deflateEnd(&strm); + + // Return + return(false); + } + + // Determine compressed size + int have = (GZIP_CHUNK_SIZE - strm.avail_out); + + // Cumulate result + if(have > 0) + output.append((char*)out, have); + + } while (strm.avail_out == 0); + + } while (flush != Z_FINISH); + + // Clean-up + (void)deflateEnd(&strm); + + // Return + return(ret == Z_STREAM_END); + } + else + return(true); +} + +/** + * @brief Decompresses the given buffer using the standard GZIP algorithm + * @param input The buffer to be decompressed + * @param output The result of the decompression + * @return @c true if the decompression was successfull, @c false otherwise + */ +bool QCompressor::gzipDecompress(QByteArray input, QByteArray &output) +{ + // Prepare output + output.clear(); + + // Is there something to do? + if(input.length() > 0) + { + // Prepare inflater status + z_stream strm; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + strm.avail_in = 0; + strm.next_in = Z_NULL; + + // Initialize inflater + int ret = inflateInit2(&strm, GZIP_WINDOWS_BIT); + + if (ret != Z_OK) + return(false); + + // Extract pointer to input data + char *input_data = input.data(); + int input_data_left = input.length(); + + // Decompress data until available + do { + // Determine current chunk size + int chunk_size = qMin(GZIP_CHUNK_SIZE, input_data_left); + + // Check for termination + if(chunk_size <= 0) + break; + + // Set inflater references + strm.next_in = (unsigned char*)input_data; + strm.avail_in = chunk_size; + + // Update interval variables + input_data += chunk_size; + input_data_left -= chunk_size; + + // Inflate chunk and cumulate output + do { + + // Declare vars + char out[GZIP_CHUNK_SIZE]; + + // Set inflater references + strm.next_out = (unsigned char*)out; + strm.avail_out = GZIP_CHUNK_SIZE; + + // Try to inflate chunk + ret = inflate(&strm, Z_NO_FLUSH); + + switch (ret) { + case Z_NEED_DICT: + ret = Z_DATA_ERROR; + case Z_DATA_ERROR: + case Z_MEM_ERROR: + case Z_STREAM_ERROR: + // Clean-up + inflateEnd(&strm); + + // Return + return(false); + } + + // Determine decompressed size + int have = (GZIP_CHUNK_SIZE - strm.avail_out); + + // Cumulate result + if(have > 0) + output.append((char*)out, have); + + } while (strm.avail_out == 0); + + } while (ret != Z_STREAM_END); + + // Clean-up + inflateEnd(&strm); + + // Return + return (ret == Z_STREAM_END); + } + else + return(true); +} \ No newline at end of file diff --git a/src/librssguard-standard/src/3rd-party/qcompressor/qcompressor.h b/src/librssguard-standard/src/3rd-party/qcompressor/qcompressor.h new file mode 100644 index 000000000..a620eddfc --- /dev/null +++ b/src/librssguard-standard/src/3rd-party/qcompressor/qcompressor.h @@ -0,0 +1,17 @@ +#ifndef QCOMPRESSOR_H +#define QCOMPRESSOR_H + +#include +#include + +#define GZIP_WINDOWS_BIT 15 + 16 +#define GZIP_CHUNK_SIZE 32 * 1024 + +class QCompressor +{ +public: + static bool gzipCompress(QByteArray input, QByteArray &output, int level = -1); + static bool gzipDecompress(QByteArray input, QByteArray &output); +}; + +#endif // QCOMPRESSOR_H diff --git a/src/librssguard/miscellaneous/application.cpp b/src/librssguard/miscellaneous/application.cpp index d36269367..954f89c15 100644 --- a/src/librssguard/miscellaneous/application.cpp +++ b/src/librssguard/miscellaneous/application.cpp @@ -300,8 +300,6 @@ void Application::performLogging(QtMsgType type, const QMessageLogContext& conte if (!s_disableDebug) { std::cerr << console_message.toStdString() << std::endl; - - std::cerr << QDir::currentPath().toStdString() << std::endl; } if (!s_customLogFile.isEmpty()) { diff --git a/src/librssguard/miscellaneous/feedreader.cpp b/src/librssguard/miscellaneous/feedreader.cpp index cdb286f68..d481861d8 100644 --- a/src/librssguard/miscellaneous/feedreader.cpp +++ b/src/librssguard/miscellaneous/feedreader.cpp @@ -56,6 +56,7 @@ FeedReader::~FeedReader() { for (ServiceEntryPoint* service : m_feedServices) { if (!service->isDynamicallyLoaded()) { qDebugNN << LOGSEC_CORE << "Deleting service" << QUOTE_W_SPACE_DOT(service->code()); + delete service; } else { qDebugNN << LOGSEC_CORE << "Service" << QUOTE_W_SPACE(service->code()) << "will be deleted by runtime.";