Server.H 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // "$Id: Server.H 153 2009-04-13 01:29:07Z mike $"
  3. //
  4. // Server class definitions for newsd.
  5. //
  6. // Copyright 2003-2009 Michael Sweet
  7. // Copyright 2002 Greg Ercolano
  8. //
  9. // This program is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public Licensse as published by
  11. // the Free Software Foundation; either version 2 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. //
  23. #ifndef _Server_H_
  24. # define _Server_H_
  25. # include "everything.H"
  26. # include "Group.H"
  27. # include "Article.H"
  28. enum NNTPStatus //// NNTP status codes
  29. {
  30. NNTP_HELP = 100, // Help text follows (multi-line)
  31. NNTP_CAPABILITIES = 101, // Capability list follows (multi-line)
  32. NNTP_DATE = 111, // Server date and time
  33. NNTP_POSTING_ALLOWED = 200, // Posting allowed (initial, MODE READER)
  34. NNTP_POSTING_NOT_ALLOWED = 201, // Posting not allowed (initial, MODE READER)
  35. NNTP_QUIT = 205, // Connection closing
  36. NNTP_GROUP = 211, // Group successfully selected
  37. NNTP_LIST = 215, // Information follows (multi-line)
  38. NNTP_ARTICLE = 220, // Article data follows (multi-line)
  39. NNTP_HEAD = 221, // Article headers follow (multi-line)
  40. NNTP_BODY = 222, // Article body follows (multi-line)
  41. NNTP_ARTICLE_FOUND = 223, // Article found (LAST, NEXT, STAT)
  42. NNTP_OVER = 224, // Overview information follows (multi-line)
  43. NNTP_HDR = 225, // Headers follow (multi-line)
  44. NNTP_NEWNEWS = 230, // List of new articles follows (multi-line)
  45. NNTP_NEWGROUPS = 231, // List of new newsgroups follows (multi-line)
  46. NNTP_IHAVE = 235, // Article transferred OK (second stage)
  47. NNTP_POST = 240, // Article received OK (second stage)
  48. NNTP_AUTHINFO_ACCEPTED = 281, // Authentication accepted
  49. NNTP_AUTHINFO_ACCEPTED_INFO = 283, // Authentication accepted (with success data)
  50. NNTP_IHAVE_CONTINUE = 335, // Send article to be transferred
  51. NNTP_POST_CONTINUE = 340, // Send article to be posted
  52. NNTP_AUTHINFO_SIMPLE = 350, // Continue with authorization sequence
  53. NNTP_AUTHINFO_PASSWORD = 381, // Password required
  54. NNTP_STARTTLS = 382, // Continue with TLS negotiation
  55. NNTP_UNAVAILABLE = 400, // Service not available or no longer available
  56. NNTP_WRONG_MODE = 401, // The server is in the wrong mode
  57. NNTP_INTERNAL_ERROR = 403, // Internal fault or problem preventing action being taken
  58. NNTP_GROUP_NOT_FOUND = 411, // No such newsgroup (GROUP, LISTGROUP)
  59. NNTP_GROUP_NOT_SELECTED = 412, // No newsgroup selected (ARTICLE, BODY, GROUP, HDR, HEAD, LAST, LISTGROUP, NEXT, OVER, STAT)
  60. NNTP_NO_CURRENT_ARTICLE = 420, // Current article number is invalid (ARTICLE, BODY, HDR, HEAD, LAST, NEXT, OVER, STAT)
  61. NNTP_NO_NEXT_ARTICLE = 421, // No next article in this group (NEXT)
  62. NNTP_NO_LAST_ARTICLE = 422, // No previous article in this group (LAST)
  63. NNTP_BAD_ARTICLE_NUMBER = 423, // No article with that number or in that range (ARTICLE, BODY, HDR, HEAD, OVER, STAT)
  64. NNTP_BAD_MESSAGE_ID = 430, // No article with that message-id (ARTICLE, BODY, HDR, HEAD, OVER, STAT)
  65. NNTP_IHAVE_NOT_WANTED = 435, // Article not wanted
  66. NNTP_IHAVE_NOT_POSSIBLE = 436, // Transfer not possible; try again later
  67. NNTP_IHAVE_REJECTED = 437, // Transfer rejected; do not retry
  68. NNTP_POST_NOT_ALLOWED = 440, // Posting not allowed
  69. NNTP_POST_FAILED = 441, // Posting failed
  70. NNTP_AUTHINFO_REQUIRED = 480, // Authentication required
  71. NNTP_AUTHINFO_REJECTED = 481, // Authentication rejected
  72. NNTP_AUTHINFO_ERROR = 482, // Authentication error
  73. NTTP_PRIVACY = 483, // Command unavailable until suitable privacy has been arranged
  74. NNTP_UNKNOWN_COMMAND = 500, // Unknown command
  75. NNTP_SYNTAX_ERROR = 501, // Syntax error in command
  76. NNTP_NO_PERMISSION = 502, // No permission (initial, AUTHINFO, MODE READER)
  77. NNTP_NOT_SUPPORTED = 503, // Feature not supported
  78. NNTP_BASE64_ERROR = 504, // Error in base64-encoding [RFC4648] of an argument
  79. NNTP_STARTTLS_ERROR = 580 // Cannot initiate TLS negotiation
  80. };
  81. class Listener //// Listener
  82. {
  83. // Instance data
  84. int sock; // Listener socket
  85. // Class global data
  86. static int alloc_polldata, // Allocated pollfd elements
  87. num_polldata; // Active pollfd elements
  88. static struct pollfd *polldata; // pollfd elements
  89. public:
  90. Listener(const char *hostport);
  91. ~Listener();
  92. static int StartServers();
  93. };
  94. class Server
  95. {
  96. // Server-specific data...
  97. int sock, // listener socket (accept())
  98. msgsock; // transaction socket (read/write)
  99. char *buf; // line buffer (internal)
  100. struct sockaddr_in sin;
  101. Group group; // current group
  102. Article article; // current article
  103. string errmsg;
  104. public:
  105. Server()
  106. {
  107. sock = msgsock = -1;
  108. buf = (char*)malloc(LINE_LEN);
  109. }
  110. ~Server()
  111. {
  112. if ( msgsock != -1 )
  113. { close(msgsock); msgsock = -1; }
  114. if ( sock != -1 )
  115. { close(sock); sock = -1; }
  116. if ( buf )
  117. { free(buf); buf = 0; }
  118. }
  119. const char *Errmsg() { return(errmsg.c_str()); }
  120. int MsgSock() { return(msgsock); }
  121. int Sock() { return(sock); }
  122. const char *GetRemoteIPStr()
  123. { return(inet_ntoa(sin.sin_addr)); }
  124. int Send(const char *msg);
  125. int IsAllowed(int op);
  126. int ValidGroup(const char *groupname);
  127. int NewGroup(const char *the_group);
  128. // TCP CONNECTIONS
  129. int Listen();
  130. int Accept();
  131. int CommandLoop(const char *overview[]);
  132. };
  133. #endif // !_Server_H_
  134. //
  135. // End of "$Id: Server.H 153 2009-04-13 01:29:07Z mike $".
  136. //