more
This commit is contained in:
@@ -107,6 +107,7 @@ void Mainloop::Run()
|
||||
idx = 0;
|
||||
while(idx < res)
|
||||
{
|
||||
errno = 0;
|
||||
ev = &evs[idx++];
|
||||
if(ev->data.fd == sfd)
|
||||
{
|
||||
|
@@ -9,37 +9,20 @@ void LineReader::Data(const char *data, ssize_t l)
|
||||
{
|
||||
if (l <= 0)
|
||||
return;
|
||||
// process leftovers
|
||||
std::size_t idx = 0;
|
||||
std::size_t pos = 0;
|
||||
while (l-- > 0)
|
||||
m_line << m_leftover;
|
||||
m_leftover = "";
|
||||
m_line << std::string(data, l);
|
||||
|
||||
for(std::string line; std::getline(m_line, line); )
|
||||
{
|
||||
char c = data[idx++];
|
||||
if (c == '\n')
|
||||
{
|
||||
OnLine(data, pos);
|
||||
pos = 0;
|
||||
data += idx;
|
||||
}
|
||||
else if (c == '\r' && data[idx] == '\n')
|
||||
{
|
||||
OnLine(data, pos);
|
||||
data += idx + 1;
|
||||
pos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
|
||||
HandleLine(line);
|
||||
}
|
||||
if(m_line)
|
||||
m_leftover = m_line.str();
|
||||
m_line.clear();
|
||||
}
|
||||
|
||||
void LineReader::OnLine(const char *d, const size_t l)
|
||||
{
|
||||
std::string line;
|
||||
line += std::string(d, l);
|
||||
HandleLine(line);
|
||||
}
|
||||
|
||||
bool LineReader::ShouldClose() { return m_close; }
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ bool HashedCredDB::ProcessLine(const std::string &line)
|
||||
return Hash(m_passwd, salt) == cred;
|
||||
}
|
||||
|
||||
void HashedCredDB::HandleLine(const std::string &line)
|
||||
void HashedCredDB::HandleLine(const std::string line)
|
||||
{
|
||||
if (m_found)
|
||||
return;
|
||||
|
@@ -9,15 +9,15 @@
|
||||
|
||||
namespace nntpchan
|
||||
{
|
||||
NNTPServerHandler::NNTPServerHandler(const fs::path &storage)
|
||||
: LineReader(1024), m_article(nullptr), m_auth(nullptr), m_store(std::make_unique<ArticleStorage>(storage)),
|
||||
NNTPServerHandler::NNTPServerHandler(fs::path storage)
|
||||
: LineReader(1024), m_article(nullptr), m_auth(nullptr), m_store(storage),
|
||||
m_authed(false), m_state(eStateReadCommand)
|
||||
{
|
||||
}
|
||||
|
||||
NNTPServerHandler::~NNTPServerHandler() {}
|
||||
|
||||
void NNTPServerHandler::HandleLine(const std::string &line)
|
||||
void NNTPServerHandler::HandleLine(const std::string line)
|
||||
{
|
||||
if (m_state == eStateReadCommand)
|
||||
{
|
||||
@@ -51,6 +51,12 @@ void NNTPServerHandler::OnData(const char *data, ssize_t l)
|
||||
return;
|
||||
if (m_state == eStateStoreArticle)
|
||||
{
|
||||
std::cerr << "storing " << l << " bytes" << std::endl;
|
||||
if(strncmp(data, ".\r\n", l) == 0)
|
||||
{
|
||||
ArticleObtained();
|
||||
return;
|
||||
}
|
||||
const char *end = strstr(data, "\r\n.\r\n");
|
||||
if (end)
|
||||
{
|
||||
@@ -124,7 +130,7 @@ void NNTPServerHandler::HandleCommand(const std::deque<std::string> &command)
|
||||
if (cmdlen >= 2)
|
||||
{
|
||||
const std::string &msgid = command[1];
|
||||
if (IsValidMessageID(msgid) && m_store->Accept(msgid))
|
||||
if (IsValidMessageID(msgid) && m_store.Accept(msgid))
|
||||
{
|
||||
QueueLine("238 " + msgid);
|
||||
}
|
||||
@@ -139,9 +145,9 @@ void NNTPServerHandler::HandleCommand(const std::deque<std::string> &command)
|
||||
if (cmdlen >= 2)
|
||||
{
|
||||
const std::string &msgid = command[1];
|
||||
if (m_store->Accept(msgid))
|
||||
if (m_store.Accept(msgid))
|
||||
{
|
||||
m_article = m_store->OpenWrite(msgid);
|
||||
m_article = m_store.OpenWrite(msgid);
|
||||
}
|
||||
m_articleName = msgid;
|
||||
EnterState(eStateStoreArticle);
|
||||
|
@@ -20,6 +20,7 @@ void ArticleStorage::SetPath(const fs::path &fpath)
|
||||
fs::create_directories(basedir);
|
||||
assert(init_skiplist(posts_skiplist_dir));
|
||||
assert(init_skiplist(threads_skiplist_dir));
|
||||
errno = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +42,9 @@ bool ArticleStorage::Accept(const std::string &msgid) const
|
||||
if (!IsValidMessageID(msgid))
|
||||
return false;
|
||||
auto p = MessagePath(msgid);
|
||||
return !fs::exists(p);
|
||||
bool ret = !fs::exists(p);
|
||||
errno = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
fs::path ArticleStorage::MessagePath(const std::string &msgid) const { return basedir / msgid; }
|
||||
|
Reference in New Issue
Block a user