Revert "more c++ stuff probably broken"
This reverts commit 5ea8b1b245.
			
			
This commit is contained in:
		| @@ -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<HashType t> | ||||
|   struct Hasher | ||||
|   { | ||||
|     typedef std::function<void(uint8_t *, size_t)> DigestVisitor; | ||||
|  | ||||
|     Hasher(); | ||||
|     ~Hasher(); | ||||
|     void Update(const char * data, size_t sz); | ||||
|     void Final(DigestVisitor v); | ||||
|   }; | ||||
|  | ||||
|   /** global crypto initializer */ | ||||
|   struct Crypto | ||||
|   { | ||||
|   | ||||
| @@ -1,58 +0,0 @@ | ||||
| #include "io.hpp" | ||||
|  | ||||
| namespace nntpchan | ||||
| { | ||||
|   namespace io | ||||
|   { | ||||
|  | ||||
|     template<class CharT = char> | ||||
|     struct MultiWriter : public std::basic_streambuf<CharT> , public std::basic_ostream<CharT> | ||||
|     { | ||||
|       using Base = std::basic_streambuf<CharT>; | ||||
|       using char_type = typename Base::char_type; | ||||
|       using int_type = typename Base::int_type; | ||||
|  | ||||
|       std::vector<std::basic_ostream<CharT> *> 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<CharT> * wr) | ||||
|       { | ||||
|         writers.push_back(wr); | ||||
|       } | ||||
|  | ||||
|       virtual ~MultiWriter() | ||||
|       { | ||||
|         for(const auto & itr : writers) | ||||
|           delete itr; | ||||
|       } | ||||
|  | ||||
|     }; | ||||
|  | ||||
|  | ||||
|     std::basic_ostream<char> * multiWriter(const std::vector<std::basic_ostream<char> *> & writers) | ||||
|     { | ||||
|       MultiWriter<char> * wr = new MultiWriter<char>; | ||||
|       for(auto & itr : writers) | ||||
|         wr->AddWriter(itr); | ||||
|       return wr; | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @@ -1,34 +0,0 @@ | ||||
| #ifndef NNTPCHAN_IO_HPP | ||||
| #define NNTPCHAN_IO_HPP | ||||
| #include <iostream> | ||||
| #include <vector> | ||||
|  | ||||
|  | ||||
| namespace nntpchan | ||||
| { | ||||
|   namespace io | ||||
|   { | ||||
|     template<size_t bufferSize> | ||||
|     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<char> * multiWriter(const std::vector<std::basic_ostream<char> *> & writers); | ||||
|     std::basic_istream<char> * teeReader(std::basic_istream<char> * i, std::basic_ostream<char> * o); | ||||
|   } | ||||
| } | ||||
|  | ||||
| #endif | ||||
| @@ -1,26 +1,33 @@ | ||||
| #ifndef NNTPCHAN_MESSAGE_HPP | ||||
| #define NNTPCHAN_MESSAGE_HPP | ||||
|  | ||||
| #include <functional> | ||||
| #include <string> | ||||
| #include <vector> | ||||
| #include <map> | ||||
| #include <functional> | ||||
|  | ||||
| namespace nntpchan | ||||
| { | ||||
|   bool IsValidMessageID(const std::string & msgid); | ||||
|  | ||||
|   namespace mime | ||||
|   { | ||||
|     typedef std::function<bool(std::string, std::string)> HeaderValueVisitor; | ||||
|   typedef std::pair<std::string, std::string> MessageHeader; | ||||
|  | ||||
|     struct PartHeader | ||||
|     { | ||||
|       std::string boundary; | ||||
|       std::map<std::string, std::string> values; | ||||
|   typedef std::map<std::string, std::string> MIMEPartHeader; | ||||
|  | ||||
|     }; | ||||
|   typedef std::function<bool(const MessageHeader &)> MessageHeaderFilter; | ||||
|  | ||||
|   typedef std::function<bool(const MIMEPartHeader &)> 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); | ||||
|  | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -1,26 +0,0 @@ | ||||
| #ifndef NNTP_FILTER_HPP | ||||
| #define NNTP_FILTER_HPP | ||||
|  | ||||
| #include <iostream> | ||||
| #include <crypto.hpp> | ||||
|  | ||||
| namespace nntpchan | ||||
| { | ||||
|  | ||||
|   template<class CharT> | ||||
|   struct MessageFilter : public std::basic_ostream<CharT> | ||||
|   { | ||||
|     using Base = std::basic_streambuf<CharT>; | ||||
|     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 | ||||
| @@ -1,7 +1,5 @@ | ||||
| #include "nntp_handler.hpp" | ||||
| #include "io.hpp" | ||||
| #include "message.hpp" | ||||
|  | ||||
| #include <algorithm> | ||||
| #include <cctype> | ||||
| #include <cstring> | ||||
| @@ -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); | ||||
|   | ||||
| @@ -4,7 +4,6 @@ | ||||
| #include <string> | ||||
| #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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user