1 /* 2 This file is part of the KDE libraries 3 SPDX-FileCopyrightText: 2002 Waldo Bastian <bastian@kde.org> 4 SPDX-FileCopyrightText: 2009 David Faure <faure@kde.org> 5 6 SPDX-License-Identifier: LGPL-2.0-only 7 */ 8 9 #ifndef _HTTPFILTER_H_ 10 #define _HTTPFILTER_H_ 11 12 class KFilterBase; 13 #include <QBuffer> 14 15 #include <QCryptographicHash> 16 #include <QObject> 17 18 #include <QLoggingCategory> Q_DECLARE_LOGGING_CATEGORY(KIO_HTTP_FILTER)19Q_DECLARE_LOGGING_CATEGORY(KIO_HTTP_FILTER) 20 21 class HTTPFilterBase : public QObject 22 { 23 Q_OBJECT 24 public: 25 HTTPFilterBase(); 26 ~HTTPFilterBase() override; 27 28 void chain(HTTPFilterBase *previous); 29 30 public Q_SLOTS: 31 virtual void slotInput(const QByteArray &d) = 0; 32 33 Q_SIGNALS: 34 void output(const QByteArray &d); 35 void error(const QString &); 36 37 protected: 38 HTTPFilterBase *last; 39 }; 40 41 class HTTPFilterChain : public HTTPFilterBase 42 { 43 Q_OBJECT 44 public: 45 HTTPFilterChain(); 46 47 void addFilter(HTTPFilterBase *filter); 48 49 public Q_SLOTS: 50 void slotInput(const QByteArray &d) override; 51 52 private: 53 HTTPFilterBase *first; 54 }; 55 56 class HTTPFilterMD5 : public HTTPFilterBase 57 { 58 Q_OBJECT 59 public: 60 HTTPFilterMD5(); 61 62 QString md5(); 63 64 public Q_SLOTS: 65 void slotInput(const QByteArray &d) override; 66 67 private: 68 QCryptographicHash context; 69 }; 70 71 class HTTPFilterGZip : public HTTPFilterBase 72 { 73 Q_OBJECT 74 public: 75 explicit HTTPFilterGZip(bool deflate = false /* for subclass HTTPFilterDeflate */); 76 ~HTTPFilterGZip() override; 77 78 public Q_SLOTS: 79 void slotInput(const QByteArray &d) override; 80 81 private: 82 bool m_deflateMode; 83 bool m_firstData; 84 bool m_finished; 85 KFilterBase *m_gzipFilter; 86 }; 87 88 class HTTPFilterDeflate : public HTTPFilterGZip 89 { 90 Q_OBJECT 91 public: 92 HTTPFilterDeflate(); 93 }; 94 95 #endif 96