From 51e0763faff53269392e9d6a62537e0c5815d072 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 4 Aug 2017 10:43:49 -0400 Subject: [PATCH] Revert "more c++ stuff probably broken" This reverts commit 5ea8b1b245af5863c3c94b638d321af0a6bc5dab. --- .../backends/nntpchan-daemon/src/crypto.hpp | 19 ------ contrib/backends/nntpchan-daemon/src/io.cpp | 58 ------------------- contrib/backends/nntpchan-daemon/src/io.hpp | 34 ----------- .../backends/nntpchan-daemon/src/message.hpp | 27 +++++---- .../nntpchan-daemon/src/nntp_filter.hpp | 26 --------- .../nntpchan-daemon/src/nntp_handler.cpp | 6 +- .../nntpchan-daemon/src/nntp_handler.hpp | 2 - 7 files changed, 18 insertions(+), 154 deletions(-) delete mode 100644 contrib/backends/nntpchan-daemon/src/io.cpp delete mode 100644 contrib/backends/nntpchan-daemon/src/io.hpp delete mode 100644 contrib/backends/nntpchan-daemon/src/nntp_filter.hpp diff --git a/contrib/backends/nntpchan-daemon/src/crypto.hpp b/contrib/backends/nntpchan-daemon/src/crypto.hpp index 3f8bd04..c563566 100644 --- a/contrib/backends/nntpchan-daemon/src/crypto.hpp +++ b/contrib/backends/nntpchan-daemon/src/crypto.hpp @@ -10,25 +10,6 @@ namespace nntpchan void SHA512(const uint8_t * d, std::size_t l, SHA512Digest & h); - enum HashType - { - eHashTypeSHA1, - eHashTypeSHA256, - eHashTypeSHA512, - eHashTypeBLAKE2B - }; - - template - struct Hasher - { - typedef std::function DigestVisitor; - - Hasher(); - ~Hasher(); - void Update(const char * data, size_t sz); - void Final(DigestVisitor v); - }; - /** global crypto initializer */ struct Crypto { diff --git a/contrib/backends/nntpchan-daemon/src/io.cpp b/contrib/backends/nntpchan-daemon/src/io.cpp deleted file mode 100644 index a8099de..0000000 --- a/contrib/backends/nntpchan-daemon/src/io.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "io.hpp" - -namespace nntpchan -{ - namespace io - { - - template - struct MultiWriter : public std::basic_streambuf , public std::basic_ostream - { - using Base = std::basic_streambuf; - using char_type = typename Base::char_type; - using int_type = typename Base::int_type; - - std::vector *> writers; - - int_type overflow(int_type ch) - { - return Base::overflow(ch); - } - - virtual std::streamsize xputn(const char_type * data, std::streamsize sz) - { - for(const auto & itr : writers) - itr->write(data, sz); - return sz; - } - - virtual int sync() - { - for(const auto & itr : writers) - itr->flush(); - return 0; - } - - void AddWriter(std::basic_ostream * wr) - { - writers.push_back(wr); - } - - virtual ~MultiWriter() - { - for(const auto & itr : writers) - delete itr; - } - - }; - - - std::basic_ostream * multiWriter(const std::vector *> & writers) - { - MultiWriter * wr = new MultiWriter; - for(auto & itr : writers) - wr->AddWriter(itr); - return wr; - } - } -} diff --git a/contrib/backends/nntpchan-daemon/src/io.hpp b/contrib/backends/nntpchan-daemon/src/io.hpp deleted file mode 100644 index b36ef9a..0000000 --- a/contrib/backends/nntpchan-daemon/src/io.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef NNTPCHAN_IO_HPP -#define NNTPCHAN_IO_HPP -#include -#include - - -namespace nntpchan -{ - namespace io - { - template - ssize_t copy(std::ostream * dst, std::istream * src) - { - char buff[bufferSize]; - ssize_t n = 0; - while(!src->eof() && src->good()) - { - std::streamsize sz; - src->read(buff, bufferSize); - sz = src->gcount(); - n += sz; - dst->write(buff, sz); - if(!dst->good()) - break; - } - return n; - } - - std::basic_ostream * multiWriter(const std::vector *> & writers); - std::basic_istream * teeReader(std::basic_istream * i, std::basic_ostream * o); - } -} - -#endif diff --git a/contrib/backends/nntpchan-daemon/src/message.hpp b/contrib/backends/nntpchan-daemon/src/message.hpp index 8e018ea..d9aa49b 100644 --- a/contrib/backends/nntpchan-daemon/src/message.hpp +++ b/contrib/backends/nntpchan-daemon/src/message.hpp @@ -1,26 +1,33 @@ #ifndef NNTPCHAN_MESSAGE_HPP #define NNTPCHAN_MESSAGE_HPP -#include #include #include +#include +#include namespace nntpchan { bool IsValidMessageID(const std::string & msgid); - namespace mime - { - typedef std::function HeaderValueVisitor; + typedef std::pair MessageHeader; - struct PartHeader - { - std::string boundary; - std::map values; + typedef std::map MIMEPartHeader; - }; + typedef std::function MessageHeaderFilter; + + typedef std::function MIMEPartFilter; + + /** + read MIME message from i, + filter each header with h, + filter each part with p, + store result in o + + return true if we read the whole message, return false if there is remaining + */ + bool StoreMIMEMessage(std::istream & i, MessageHeaderFilter h, MIMEPartHeader p, std::ostream & o); - } } diff --git a/contrib/backends/nntpchan-daemon/src/nntp_filter.hpp b/contrib/backends/nntpchan-daemon/src/nntp_filter.hpp deleted file mode 100644 index fb0a389..0000000 --- a/contrib/backends/nntpchan-daemon/src/nntp_filter.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef NNTP_FILTER_HPP -#define NNTP_FILTER_HPP - -#include -#include - -namespace nntpchan -{ - - template - struct MessageFilter : public std::basic_ostream - { - using Base = std::basic_streambuf; - using char_type = Base::char_type; - using int_type = Base::int_type; - - virtual int_type overflow(int_type ch); - protected: - virtual void xsputn(const char_type * data, std::streamsize sz); - - - - }; -} - -#endif diff --git a/contrib/backends/nntpchan-daemon/src/nntp_handler.cpp b/contrib/backends/nntpchan-daemon/src/nntp_handler.cpp index c86ccdb..327cd49 100644 --- a/contrib/backends/nntpchan-daemon/src/nntp_handler.cpp +++ b/contrib/backends/nntpchan-daemon/src/nntp_handler.cpp @@ -1,7 +1,5 @@ #include "nntp_handler.hpp" -#include "io.hpp" #include "message.hpp" - #include #include #include @@ -127,9 +125,7 @@ namespace nntpchan const std::string & msgid = command[1]; if(m_store.Accept(msgid)) { - std::ostream * file = m_store.OpenWrite(msgid); - m_filter = new MessageFilter(msgid); - m_article = nntpchan::io::multiWriter({file, m_filter}); + m_article = m_store.OpenWrite(msgid); } m_articleName = msgid; EnterState(eStateStoreArticle); diff --git a/contrib/backends/nntpchan-daemon/src/nntp_handler.hpp b/contrib/backends/nntpchan-daemon/src/nntp_handler.hpp index 0a109e1..64d708d 100644 --- a/contrib/backends/nntpchan-daemon/src/nntp_handler.hpp +++ b/contrib/backends/nntpchan-daemon/src/nntp_handler.hpp @@ -4,7 +4,6 @@ #include #include "line.hpp" #include "nntp_auth.hpp" -#include "nntp_filter.hpp" #include "storage.hpp" namespace nntpchan @@ -51,7 +50,6 @@ namespace nntpchan private: std::string m_articleName; std::fstream * m_article; - MessageFilter * m_filter; NNTPCredentialDB * m_auth; ArticleStorage m_store; std::string m_mode;