2016-10-15 18:12:01 +05:00
|
|
|
#ifndef NNTPCHAN_NNTP_SERVER_HPP
|
|
|
|
#define NNTPCHAN_NNTP_SERVER_HPP
|
|
|
|
#include <uv.h>
|
|
|
|
#include <string>
|
2016-10-15 21:37:59 +05:00
|
|
|
#include <deque>
|
2016-10-15 18:12:01 +05:00
|
|
|
#include "storage.hpp"
|
2016-10-18 17:17:40 +05:00
|
|
|
#include "frontend.hpp"
|
2016-10-15 21:37:59 +05:00
|
|
|
#include "nntp_auth.hpp"
|
|
|
|
#include "nntp_handler.hpp"
|
2016-10-15 18:12:01 +05:00
|
|
|
|
|
|
|
namespace nntpchan
|
|
|
|
{
|
2016-10-15 21:37:59 +05:00
|
|
|
|
2016-10-15 18:12:01 +05:00
|
|
|
class NNTPServerConn;
|
|
|
|
|
|
|
|
class NNTPServer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NNTPServer(uv_loop_t * loop);
|
|
|
|
~NNTPServer();
|
|
|
|
|
|
|
|
void Bind(const std::string & addr);
|
|
|
|
|
|
|
|
void OnAccept(uv_stream_t * s, int status);
|
|
|
|
|
|
|
|
void SetStoragePath(const std::string & path);
|
2016-10-15 22:53:35 +05:00
|
|
|
|
|
|
|
void SetLoginDB(const std::string path);
|
2016-10-18 17:17:40 +05:00
|
|
|
|
|
|
|
void SetFrontend(Frontend * f);
|
|
|
|
|
|
|
|
void Close();
|
2016-10-15 18:12:01 +05:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
operator uv_handle_t * () { return (uv_handle_t*) &m_server; }
|
|
|
|
operator uv_tcp_t * () { return &m_server; }
|
|
|
|
operator uv_stream_t * () { return (uv_stream_t *) &m_server; }
|
|
|
|
|
|
|
|
uv_tcp_t m_server;
|
|
|
|
uv_loop_t * m_loop;
|
|
|
|
|
2016-10-15 21:37:59 +05:00
|
|
|
std::deque<NNTPServerConn *> m_conns;
|
2016-10-15 18:12:01 +05:00
|
|
|
|
2016-10-15 22:53:35 +05:00
|
|
|
std::string m_logindbpath;
|
2016-10-15 18:12:01 +05:00
|
|
|
std::string m_storagePath;
|
2016-10-18 17:17:40 +05:00
|
|
|
|
|
|
|
Frontend * m_frontend;
|
2016-10-15 18:12:01 +05:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class NNTPServerConn
|
|
|
|
{
|
|
|
|
public:
|
2016-10-15 22:53:35 +05:00
|
|
|
NNTPServerConn(uv_loop_t * l, uv_stream_t * s, const std::string & storage, NNTPCredentialDB * creds);
|
2016-10-15 21:37:59 +05:00
|
|
|
/** @brief close connection, this connection cannot be used after calling this */
|
2016-10-15 18:12:01 +05:00
|
|
|
void Close();
|
|
|
|
|
2016-10-15 21:37:59 +05:00
|
|
|
/** @brief send next queued reply */
|
2016-10-15 18:12:01 +05:00
|
|
|
void SendNextReply();
|
2016-10-15 21:37:59 +05:00
|
|
|
|
|
|
|
void Greet();
|
2016-10-15 18:12:01 +05:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void SendString(const std::string & line);
|
|
|
|
|
|
|
|
|
|
|
|
operator uv_stream_t * () { return (uv_stream_t *) &m_conn; }
|
|
|
|
|
|
|
|
uv_tcp_t m_conn;
|
|
|
|
|
|
|
|
NNTPServerHandler m_handler;
|
2016-10-15 21:37:59 +05:00
|
|
|
|
|
|
|
char m_readbuff[1028];
|
2016-10-15 18:12:01 +05:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|