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.
nntpchan/contrib/backends/nntpchan-daemon/src/storage.cpp

60 lines
1.1 KiB
C++
Raw Normal View History

2016-10-15 18:12:01 +05:00
#include "storage.hpp"
#include <errno.h>
#include <sys/stat.h>
#include <sstream>
namespace nntpchan
{
ArticleStorage::ArticleStorage()
{
}
2016-10-15 21:37:59 +05:00
ArticleStorage::ArticleStorage(const std::string & fpath) {
SetPath(fpath);
}
2017-05-03 22:33:04 +05:00
2016-10-15 18:12:01 +05:00
ArticleStorage::~ArticleStorage()
{
}
void ArticleStorage::SetPath(const std::string & fpath)
{
basedir = fpath;
// quiet fail
// TODO: check for errors
mkdir(basedir.c_str(), 0700);
}
2017-05-03 22:33:04 +05:00
bool ArticleStorage::Accept(const std::string& msgid)
2016-10-15 18:12:01 +05:00
{
if (!IsValidMessageID(msgid)) return false;
2017-05-03 22:33:04 +05:00
auto s = MessagePath(msgid);
2016-10-15 18:12:01 +05:00
FILE * f = fopen(s.c_str(), "r");
if ( f == nullptr) return errno == ENOENT;
fclose(f);
return false;
}
2017-05-03 22:33:04 +05:00
std::string ArticleStorage::MessagePath(const std::string & msgid)
{
return basedir + GetPathSep() + msgid;
}
std::fstream * ArticleStorage::OpenRead(const std::string & msgid)
{
return OpenMode(msgid, std::ios::in);
}
std::fstream * ArticleStorage::OpenWrite(const std::string & msgid)
{
return OpenMode(msgid, std::ios::out);
}
2016-10-15 18:12:01 +05:00
char ArticleStorage::GetPathSep()
{
return '/';
}
2017-05-03 22:33:04 +05:00
2016-10-15 18:12:01 +05:00
}