2017-05-03 18:15:06 +05:00
|
|
|
|
2016-10-15 18:12:01 +05:00
|
|
|
#include <cassert>
|
2018-05-03 20:47:20 +05:00
|
|
|
#include <cstring>
|
2016-10-15 18:12:01 +05:00
|
|
|
#include <iostream>
|
2017-10-17 19:29:56 +05:00
|
|
|
#include <nntpchan/net.hpp>
|
|
|
|
#include <nntpchan/nntp_auth.hpp>
|
|
|
|
#include <nntpchan/nntp_handler.hpp>
|
|
|
|
#include <nntpchan/nntp_server.hpp>
|
2016-10-15 18:12:01 +05:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
namespace nntpchan
|
|
|
|
{
|
2017-05-03 18:15:06 +05:00
|
|
|
|
2018-05-06 17:10:20 +05:00
|
|
|
NNTPServer::NNTPServer(ev::Loop *loop) : Server(loop), m_frontend(nullptr) {}
|
2016-10-15 18:12:01 +05:00
|
|
|
|
2017-10-17 19:29:56 +05:00
|
|
|
NNTPServer::~NNTPServer() {}
|
2016-10-18 17:17:40 +05:00
|
|
|
|
2018-05-03 20:47:20 +05:00
|
|
|
IServerConn *NNTPServer::CreateConn(int f)
|
2017-10-17 19:29:56 +05:00
|
|
|
{
|
|
|
|
CredDB_ptr creds;
|
2016-10-15 18:12:01 +05:00
|
|
|
|
2017-10-17 19:29:56 +05:00
|
|
|
std::ifstream i;
|
|
|
|
i.open(m_logindbpath);
|
|
|
|
if (i.is_open())
|
|
|
|
creds = std::make_shared<HashedFileDB>(m_logindbpath);
|
2017-05-03 17:09:23 +05:00
|
|
|
|
2017-10-17 19:29:56 +05:00
|
|
|
NNTPServerHandler *handler = new NNTPServerHandler(m_storagePath);
|
|
|
|
if (creds)
|
|
|
|
handler->SetAuth(creds);
|
2016-10-15 22:53:35 +05:00
|
|
|
|
2018-05-03 20:47:20 +05:00
|
|
|
return new NNTPServerConn(f, this, handler);
|
2017-10-17 19:29:56 +05:00
|
|
|
}
|
2016-10-18 17:17:40 +05:00
|
|
|
|
2017-10-17 19:29:56 +05:00
|
|
|
void NNTPServer::SetLoginDB(const std::string path) { m_logindbpath = path; }
|
2017-05-03 22:33:04 +05:00
|
|
|
|
2017-10-17 19:29:56 +05:00
|
|
|
void NNTPServer::SetStoragePath(const std::string &path) { m_storagePath = path; }
|
2017-05-03 22:33:04 +05:00
|
|
|
|
2017-10-17 19:29:56 +05:00
|
|
|
void NNTPServer::SetInstanceName(const std::string &name) { m_servername = name; }
|
2017-05-03 17:09:23 +05:00
|
|
|
|
2017-10-17 19:29:56 +05:00
|
|
|
void NNTPServer::SetFrontend(Frontend *f) { m_frontend.reset(f); }
|
2017-05-03 17:09:23 +05:00
|
|
|
|
2017-10-17 19:29:56 +05:00
|
|
|
std::string NNTPServer::InstanceName() const { return m_servername; }
|
2016-10-15 21:37:59 +05:00
|
|
|
|
2018-05-03 20:47:20 +05:00
|
|
|
void NNTPServer::OnAcceptError(int status) { std::cerr << "nntpserver::accept() " << strerror(status) << std::endl; }
|
2016-10-15 21:37:59 +05:00
|
|
|
|
2017-10-17 19:29:56 +05:00
|
|
|
void NNTPServerConn::Greet()
|
|
|
|
{
|
|
|
|
IConnHandler *handler = GetHandler();
|
|
|
|
handler->Greet();
|
|
|
|
}
|
2016-10-15 18:12:01 +05:00
|
|
|
}
|