2016-10-15 21:37:59 +05:00
|
|
|
#ifndef NNTPCHAN_NNTP_HANDLER_HPP
|
|
|
|
#define NNTPCHAN_NNTP_HANDLER_HPP
|
|
|
|
#include <deque>
|
|
|
|
#include <string>
|
|
|
|
#include "line.hpp"
|
2016-10-15 22:53:35 +05:00
|
|
|
#include "nntp_auth.hpp"
|
2016-10-15 21:37:59 +05:00
|
|
|
#include "storage.hpp"
|
|
|
|
|
|
|
|
namespace nntpchan
|
|
|
|
{
|
2017-05-03 18:15:06 +05:00
|
|
|
class NNTPServerHandler : public LineReader, public IConnHandler
|
2016-10-15 21:37:59 +05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NNTPServerHandler(const std::string & storage);
|
2016-10-15 22:53:35 +05:00
|
|
|
~NNTPServerHandler();
|
2017-05-03 18:15:06 +05:00
|
|
|
|
|
|
|
virtual bool ShouldClose();
|
|
|
|
|
2016-10-15 22:53:35 +05:00
|
|
|
void SetAuth(NNTPCredentialDB * creds);
|
|
|
|
|
2017-05-03 18:44:42 +05:00
|
|
|
virtual void OnData(const char *, ssize_t);
|
|
|
|
|
2016-10-15 22:53:35 +05:00
|
|
|
void Greet();
|
2017-05-03 18:15:06 +05:00
|
|
|
|
2016-10-15 21:37:59 +05:00
|
|
|
protected:
|
|
|
|
void HandleLine(const std::string & line);
|
|
|
|
void HandleCommand(const std::deque<std::string> & command);
|
|
|
|
private:
|
2017-05-03 18:15:06 +05:00
|
|
|
|
2016-10-15 21:37:59 +05:00
|
|
|
enum State {
|
|
|
|
eStateReadCommand,
|
|
|
|
eStateStoreArticle,
|
|
|
|
eStateQuit
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2017-05-03 22:33:04 +05:00
|
|
|
|
|
|
|
void EnterState(State st);
|
|
|
|
|
|
|
|
void ArticleObtained();
|
|
|
|
|
2016-10-15 21:37:59 +05:00
|
|
|
// handle quit command, this queues a reply
|
|
|
|
void Quit();
|
|
|
|
|
|
|
|
// switch nntp modes, this queues a reply
|
|
|
|
void SwitchMode(const std::string & mode);
|
2016-10-15 22:53:35 +05:00
|
|
|
|
|
|
|
bool PostingAllowed();
|
2017-05-03 18:15:06 +05:00
|
|
|
|
2016-10-15 21:37:59 +05:00
|
|
|
private:
|
2017-05-03 22:33:04 +05:00
|
|
|
std::string m_articleName;
|
|
|
|
std::fstream * m_article;
|
2016-10-15 22:53:35 +05:00
|
|
|
NNTPCredentialDB * m_auth;
|
2016-10-15 21:37:59 +05:00
|
|
|
ArticleStorage m_store;
|
|
|
|
std::string m_mode;
|
|
|
|
bool m_authed;
|
|
|
|
State m_state;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|