Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.

56 lines
1.1 KiB
C++
Raw Normal View History

2016-10-15 09:12:01 -04:00
#ifndef NNTPCHAN_STORAGE_HPP
#define NNTPCHAN_STORAGE_HPP
2017-05-03 13:33:04 -04:00
#include <fstream>
2016-10-15 09:12:01 -04:00
#include <string>
#include "message.hpp"
namespace nntpchan
{
class ArticleStorage
{
public:
ArticleStorage();
2016-10-15 12:37:59 -04:00
ArticleStorage(const std::string & fpath);
2016-10-15 09:12:01 -04:00
~ArticleStorage();
void SetPath(const std::string & fpath);
2017-05-03 13:33:04 -04:00
std::fstream * OpenWrite(const std::string & msgid);
std::fstream * OpenRead(const std::string & msgid);
2016-10-15 09:12:01 -04:00
/**
return true if we should accept a new message give its message id
*/
2017-05-03 13:33:04 -04:00
bool Accept(const std::string & msgid);
2016-10-15 09:12:01 -04:00
private:
2017-05-03 13:33:04 -04:00
template<typename Mode>
std::fstream * OpenMode(const std::string & msgid, const Mode & m)
{
if(IsValidMessageID(msgid))
{
std::fstream * f = new std::fstream;
f->open(MessagePath(msgid), m);
if(f->is_open())
return f;
delete f;
return nullptr;
}
else
return nullptr;
};
std::string MessagePath(const std::string & msgid);
2016-10-15 09:12:01 -04:00
static char GetPathSep();
2017-05-03 13:33:04 -04:00
2016-10-15 09:12:01 -04:00
std::string basedir;
2017-05-03 13:33:04 -04:00
2016-10-15 09:12:01 -04:00
};
}
#endif