123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- //
- // "$Id: Server.H 153 2009-04-13 01:29:07Z mike $"
- //
- // Server class definitions for newsd.
- //
- // Copyright 2003-2009 Michael Sweet
- // Copyright 2002 Greg Ercolano
- //
- // This program is free software; you can redistribute it and/or modify
- // it under the terms of the GNU General Public Licensse as published by
- // the Free Software Foundation; either version 2 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program; if not, write to the Free Software
- // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- //
- #ifndef _Server_H_
- # define _Server_H_
- # include "everything.H"
- # include "Group.H"
- # include "Article.H"
- enum NNTPStatus //// NNTP status codes
- {
- NNTP_HELP = 100, // Help text follows (multi-line)
- NNTP_CAPABILITIES = 101, // Capability list follows (multi-line)
- NNTP_DATE = 111, // Server date and time
- NNTP_POSTING_ALLOWED = 200, // Posting allowed (initial, MODE READER)
- NNTP_POSTING_NOT_ALLOWED = 201, // Posting not allowed (initial, MODE READER)
- NNTP_QUIT = 205, // Connection closing
- NNTP_GROUP = 211, // Group successfully selected
- NNTP_LIST = 215, // Information follows (multi-line)
- NNTP_ARTICLE = 220, // Article data follows (multi-line)
- NNTP_HEAD = 221, // Article headers follow (multi-line)
- NNTP_BODY = 222, // Article body follows (multi-line)
- NNTP_ARTICLE_FOUND = 223, // Article found (LAST, NEXT, STAT)
- NNTP_OVER = 224, // Overview information follows (multi-line)
- NNTP_HDR = 225, // Headers follow (multi-line)
- NNTP_NEWNEWS = 230, // List of new articles follows (multi-line)
- NNTP_NEWGROUPS = 231, // List of new newsgroups follows (multi-line)
- NNTP_IHAVE = 235, // Article transferred OK (second stage)
- NNTP_POST = 240, // Article received OK (second stage)
- NNTP_AUTHINFO_ACCEPTED = 281, // Authentication accepted
- NNTP_AUTHINFO_ACCEPTED_INFO = 283, // Authentication accepted (with success data)
- NNTP_IHAVE_CONTINUE = 335, // Send article to be transferred
- NNTP_POST_CONTINUE = 340, // Send article to be posted
- NNTP_AUTHINFO_SIMPLE = 350, // Continue with authorization sequence
- NNTP_AUTHINFO_PASSWORD = 381, // Password required
- NNTP_STARTTLS = 382, // Continue with TLS negotiation
- NNTP_UNAVAILABLE = 400, // Service not available or no longer available
- NNTP_WRONG_MODE = 401, // The server is in the wrong mode
- NNTP_INTERNAL_ERROR = 403, // Internal fault or problem preventing action being taken
- NNTP_GROUP_NOT_FOUND = 411, // No such newsgroup (GROUP, LISTGROUP)
- NNTP_GROUP_NOT_SELECTED = 412, // No newsgroup selected (ARTICLE, BODY, GROUP, HDR, HEAD, LAST, LISTGROUP, NEXT, OVER, STAT)
- NNTP_NO_CURRENT_ARTICLE = 420, // Current article number is invalid (ARTICLE, BODY, HDR, HEAD, LAST, NEXT, OVER, STAT)
- NNTP_NO_NEXT_ARTICLE = 421, // No next article in this group (NEXT)
- NNTP_NO_LAST_ARTICLE = 422, // No previous article in this group (LAST)
- NNTP_BAD_ARTICLE_NUMBER = 423, // No article with that number or in that range (ARTICLE, BODY, HDR, HEAD, OVER, STAT)
- NNTP_BAD_MESSAGE_ID = 430, // No article with that message-id (ARTICLE, BODY, HDR, HEAD, OVER, STAT)
- NNTP_IHAVE_NOT_WANTED = 435, // Article not wanted
- NNTP_IHAVE_NOT_POSSIBLE = 436, // Transfer not possible; try again later
- NNTP_IHAVE_REJECTED = 437, // Transfer rejected; do not retry
- NNTP_POST_NOT_ALLOWED = 440, // Posting not allowed
- NNTP_POST_FAILED = 441, // Posting failed
- NNTP_AUTHINFO_REQUIRED = 480, // Authentication required
- NNTP_AUTHINFO_REJECTED = 481, // Authentication rejected
- NNTP_AUTHINFO_ERROR = 482, // Authentication error
- NTTP_PRIVACY = 483, // Command unavailable until suitable privacy has been arranged
- NNTP_UNKNOWN_COMMAND = 500, // Unknown command
- NNTP_SYNTAX_ERROR = 501, // Syntax error in command
- NNTP_NO_PERMISSION = 502, // No permission (initial, AUTHINFO, MODE READER)
- NNTP_NOT_SUPPORTED = 503, // Feature not supported
- NNTP_BASE64_ERROR = 504, // Error in base64-encoding [RFC4648] of an argument
- NNTP_STARTTLS_ERROR = 580 // Cannot initiate TLS negotiation
- };
- class Listener //// Listener
- {
- // Instance data
- int sock; // Listener socket
- // Class global data
- static int alloc_polldata, // Allocated pollfd elements
- num_polldata; // Active pollfd elements
- static struct pollfd *polldata; // pollfd elements
- public:
- Listener(const char *hostport);
- ~Listener();
- static int StartServers();
- };
- class Server
- {
- // Server-specific data...
- int sock, // listener socket (accept())
- msgsock; // transaction socket (read/write)
- char *buf; // line buffer (internal)
- struct sockaddr_in sin;
- Group group; // current group
- Article article; // current article
- string errmsg;
- public:
- Server()
- {
- sock = msgsock = -1;
- buf = (char*)malloc(LINE_LEN);
- }
- ~Server()
- {
- if ( msgsock != -1 )
- { close(msgsock); msgsock = -1; }
- if ( sock != -1 )
- { close(sock); sock = -1; }
- if ( buf )
- { free(buf); buf = 0; }
- }
- const char *Errmsg() { return(errmsg.c_str()); }
- int MsgSock() { return(msgsock); }
- int Sock() { return(sock); }
- const char *GetRemoteIPStr()
- { return(inet_ntoa(sin.sin_addr)); }
- int Send(const char *msg);
- int IsAllowed(int op);
- int ValidGroup(const char *groupname);
- int NewGroup(const char *the_group);
- // TCP CONNECTIONS
- int Listen();
- int Accept();
- int CommandLoop(const char *overview[]);
- };
- #endif // !_Server_H_
- //
- // End of "$Id: Server.H 153 2009-04-13 01:29:07Z mike $".
- //
|