Group.H 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // Group.H -- Manage newsgroup groups
  3. //
  4. // Copyright 2003 Michael Sweet
  5. // Copyright 2002 Greg Ercolano
  6. //
  7. // This program is free software; you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public Licensse as published by
  9. // the Free Software Foundation; either version 2 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program; if not, write to the Free Software
  19. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. //
  21. #ifndef GROUP_H
  22. #define GROUP_H
  23. #include "everything.H"
  24. class Group
  25. {
  26. // ".info" FILE DATA
  27. unsigned long start, end, total; // start/end/total articles
  28. // ".config" FILE DATA
  29. string desc; // group description
  30. string creator; // group creator email
  31. string name; // group name
  32. string ccpost; // email address to cc all postings to
  33. string replyto; // optional replyto address
  34. string voidemail; // bit bucket
  35. int postok, // allow posting to this group
  36. postlimit; // posting line limit
  37. string dirname; // directory name
  38. time_t ctime; // creation time
  39. int valid; // is group valid? 0=invalid
  40. string errmsg; // error message
  41. char datebuf[80]; // RFC822 date buffer
  42. // GENERAL LOCKING
  43. // Write lock whenever posting or saving info file.
  44. // Read lock before accessing info file.
  45. //
  46. int WriteLock();
  47. int ReadLock();
  48. void Unlock(int fd);
  49. int WriteString(FILE *fp, const char *buf);
  50. int BuildInfo(int dolock = 1);
  51. int LoadInfo(int dolock = 1);
  52. int SaveInfo(int dolock = 1);
  53. int LoadConfig(int dolock = 1);
  54. int SaveConfig();
  55. void ReorderHeader(const char*overview[], vector<string>& head);
  56. const char *DateRFC822();
  57. void _Copy(const Group&o)
  58. {
  59. start = o.start;
  60. end = o.end;
  61. total = o.total;
  62. desc = o.desc;
  63. creator = o.creator;
  64. name = o.name;
  65. ccpost = o.ccpost;
  66. replyto = o.replyto;
  67. voidemail = o.voidemail;
  68. postok = o.postok;
  69. postlimit = o.postlimit;
  70. ctime = o.ctime;
  71. valid = o.valid;
  72. }
  73. public:
  74. Group()
  75. {
  76. start = end = total = 0;
  77. desc = "";
  78. creator = "news";
  79. name = "";
  80. ccpost = "-";
  81. replyto = "-";
  82. voidemail = "root";
  83. postok = 0;
  84. postlimit = 0;
  85. ctime = 0;
  86. valid = 0;
  87. }
  88. ~Group()
  89. { }
  90. Group(const Group&o)
  91. {
  92. _Copy(o);
  93. }
  94. Group& operator=(const Group&o)
  95. {
  96. _Copy(o);
  97. return(*this);
  98. }
  99. // ACCESSORS
  100. unsigned long Start() { return(start); }
  101. unsigned long End() { return(end); }
  102. unsigned long Total() { return(total); }
  103. int PostOK() { return(postok); }
  104. int PostLimit() { return(postlimit); }
  105. long Ctime() { return(ctime); }
  106. int IsValid() { return(valid); }
  107. int IsCCPost() { return(ccpost == "-" ? 0 : 1); }
  108. int IsReplyTo() { return(replyto == "-" ? 0 : 1); }
  109. const char *Description() { return(desc.c_str()); }
  110. const char *Creator() { return(creator.c_str()); }
  111. const char *Name() { return(name.c_str()); }
  112. const char *CCPost() { return(ccpost.c_str()); }
  113. const char *ReplyTo() { return(replyto.c_str()); }
  114. const char *VoidEmail() { return(voidemail.c_str()); }
  115. const char *Errmsg() { return(errmsg.c_str()); }
  116. void Start(unsigned long val) { start = val; }
  117. void End(unsigned long val) { end = val; }
  118. void Total(unsigned long val) { total = val; }
  119. void Name(const char*val) { name = val; }
  120. int Load(const char *group, int dolock = 1);
  121. int WriteInfo(int fd);
  122. int FindArticleByMessageID(const char *find_messageid,
  123. unsigned long &articlenum);
  124. int Post(const char*overview[], vector<string> &head,
  125. vector<string> &body, const char *remoteip_str, bool force=false);
  126. const char *Dirname();
  127. int NewGroup();
  128. int ParseArticle(string &msg, vector<string>&head, vector<string>&body);
  129. void UpdatePath(vector<string>&head);
  130. int IsValidGroup();
  131. };
  132. #endif /*!GROUP_H*/