1 #ifndef _nntpconnection_
\r
2 #define _nntpconnection_
\r
4 #include "../threadwrapper/cancelablerunnable.h"
\r
5 #include "../socketdefines.h"
\r
6 #include "../ilogger.h"
\r
7 #include "../message.h"
\r
8 #include "../localidentity.h"
\r
9 #include "../ithreaddatabase.h"
\r
17 #include <sys/socket.h>
\r
18 #include <sys/select.h>
\r
19 #include <sys/types.h>
\r
21 #include <netinet/in.h>
\r
22 #include <arpa/inet.h>
\r
25 class NNTPConnection:public CancelableRunnable,public ILogger,public IThreadDatabase
\r
28 NNTPConnection(SOCKET sock);
\r
32 const bool Disconnected() { return m_socket==INVALID_SOCKET; }
\r
38 typedef enum ClientMode
\r
45 std::string m_command;
\r
46 std::vector<std::string> m_arguments;
\r
50 ClientStatus(SQLite3DB::DB *db):m_authuser(db) {}
\r
57 LocalIdentity m_authuser; // -1 if user not authenticated, otherwise id of user from tblLocalIdentity
\r
58 bool m_authenticated;
\r
61 void SendBuffered(const std::string &data);
\r
62 void SendBufferedLine(const std::string &data) { SendBuffered(data+"\r\n"); }
\r
63 void SocketSend(); // immediately send buffered data - will block if send if no ready
\r
64 void SocketReceive(); // immediately recv data on socket - will block if no data is waiting
\r
65 void HandleReceivedData();
\r
66 std::vector<char>::iterator Find(std::vector<char> &buffer, const std::string &val);
\r
67 const bool HandleCommand(const NNTPCommand &command);
\r
68 void HandlePostedMessage(const std::string &message);
\r
70 void SendArticleParts(const NNTPCommand &command);
\r
71 void SendArticleOverInfo(Message &message);
\r
73 // various NNTP commands to handle
\r
74 const bool HandleQuitCommand(const NNTPCommand &command);
\r
75 const bool HandleModeCommand(const NNTPCommand &command);
\r
76 const bool HandleCapabilitiesCommand(const NNTPCommand &command);
\r
77 const bool HandleHelpCommand(const NNTPCommand &command);
\r
78 const bool HandleDateCommand(const NNTPCommand &command);
\r
79 const bool HandleListCommand(const NNTPCommand &command);
\r
80 const bool HandleGroupCommand(const NNTPCommand &command);
\r
81 const bool HandleListGroupCommand(const NNTPCommand &command);
\r
82 const bool HandleNextCommand(const NNTPCommand &command);
\r
83 const bool HandleLastCommand(const NNTPCommand &command);
\r
84 const bool HandleArticleCommand(const NNTPCommand &command);
\r
85 const bool HandleHeadCommand(const NNTPCommand &command);
\r
86 const bool HandleBodyCommand(const NNTPCommand &command);
\r
87 const bool HandleStatCommand(const NNTPCommand &command);
\r
88 const bool HandleNewGroupsCommand(const NNTPCommand &command);
\r
89 const bool HandlePostCommand(const NNTPCommand &command);
\r
90 const bool HandleOverCommand(const NNTPCommand &command);
\r
91 const bool HandleAuthInfoCommand(const NNTPCommand &command);
\r
92 const bool HandleGetTrustCommand(const NNTPCommand &command);
\r
93 const bool HandleSetTrustCommand(const NNTPCommand &command);
\r
94 const bool HandleGetTrustListCommand(const NNTPCommand &command);
\r
97 ClientStatus m_status;
\r
98 std::vector<char> m_sendbuffer;
\r
99 std::vector<char> m_receivebuffer;
\r
100 std::vector<char> m_tempbuffer;
\r
104 #endif // _nntpconnection_
\r