1 // This may look like C code, but it is really -*- C++ -*-
2
3 // ------------------------------------------------------------------
4 // The Goldware Library
5 // Copyright (C) 1990-1999 Odinn Sorensen
6 // Copyright (C) 1999-2000 Alexander S. Aganichev
7 // ------------------------------------------------------------------
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public
19 // License along with this program; if not, write to the Free
20 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 // MA 02111-1307, USA
22 // ------------------------------------------------------------------
23 // $Id: gmoarea.h,v 1.17 2008/01/20 14:45:52 stas_degteff Exp $
24 // ------------------------------------------------------------------
25 // Area structures and classes.
26 // ------------------------------------------------------------------
27
28
29 // ------------------------------------------------------------------
30
31 #ifndef __GMBAREA_H
32 #define __GMBAREA_H
33
34
35 // ------------------------------------------------------------------
36
37 #include <string>
38 #include <gstrbags.h>
39 #include <gutltag.h>
40 #include <glog.h>
41 #include <gedacfg.h>
42 #include <gmo_msg.h>
43
44
45 // ------------------------------------------------------------------
46 // Area base class
47
48 class gmo_area {
49
50 public:
51
52 // ----------------------------------------------------------------
53 // Config data
54
55 AreaCfgBase cfg;
56 GStrSet3 cfg2;
57
58
59 // ----------------------------------------------------------------
60 // Constructor and destructor
61
62 gmo_area();
63 virtual ~gmo_area();
64
65
66 // ----------------------------------------------------------------
67 // Data members
68
69 GTag* Msgn; // Message numbers
70 GTag* PMrk; // Personal mail marks
71
72 uint lastread; // Number of last message read
73 uint32_t lastreadentry; // Lastread message number at entry to area
74
75 int isopen; // NONZERO if open
76
77
78 // ----------------------------------------------------------------
79 // Access config data
80
areaid()81 int areaid() const { return cfg.areaid; }
groupid()82 int groupid() const { return cfg.groupid; }
type()83 uint type() const { return cfg.type; }
basetype()84 const std::string &basetype() const { return cfg.basetype; }
board()85 uint board() const { return cfg.board; }
aka()86 const ftn_addr& aka() const { return cfg.aka; }
originno()87 int originno() const { return cfg.originno; }
attr()88 Attr& attr() { return cfg.attr; }
ispacked()89 bool ispacked() const { return make_bool(cfg.attr.pkd()); }
packed(bool a)90 void packed(bool a) { cfg.attr.pkd(a); }
91
ascan()92 bool ascan() { return (bool)cfg.scan; }
ascanexcl()93 bool ascanexcl() { return (bool)cfg.scanexcl; }
ascanincl()94 bool ascanincl() { return (bool)cfg.scanincl; }
pmscan()95 bool pmscan() { return (bool)cfg.pmscan; }
pmscanexcl()96 bool pmscanexcl() { return (bool)cfg.pmscanexcl; }
pmscanincl()97 bool pmscanincl() { return (bool)cfg.pmscanincl; }
98
echoid()99 const char* echoid() const { return cfg2.Get1(); }
desc()100 const char* desc() const { return cfg2.Get2(); }
path()101 const char* path() const { return cfg2.Get3(); }
102
set_areaid(int a)103 void set_areaid(int a) { cfg.areaid = a; }
set_groupid(int g)104 void set_groupid(int g) { cfg.groupid = g; }
set_type(uint t)105 void set_type(uint t) { cfg.type = t; }
set_basetype(const char * m)106 void set_basetype(const char *m) { cfg.basetype = m; }
set_basetype(const std::string & m)107 void set_basetype(const std::string &m) { cfg.basetype = m; }
set_board(uint b)108 void set_board(uint b) { cfg.board = b; }
set_aka(ftn_addr & a)109 void set_aka(ftn_addr& a) { cfg.aka = a; }
set_originno(int o)110 void set_originno(int o) { cfg.originno = o; }
set_attr(Attr & a)111 void set_attr(Attr& a) { cfg.attr = a; }
set_origin(char * o)112 void set_origin(char* o) { std::string tmp = o; cfg.setorigin(tmp); }
113
set_scan(bool s)114 void set_scan(bool s) { cfg.scan = (byte)s; }
set_scanexcl(bool s)115 void set_scanexcl(bool s) { cfg.scanexcl = (byte)s; }
set_scanincl(bool s)116 void set_scanincl(bool s) { cfg.scanincl = (byte)s; }
set_pmscan(bool s)117 void set_pmscan(bool s) { cfg.pmscan = (byte)s; }
set_pmscanexcl(bool s)118 void set_pmscanexcl(bool s) { cfg.pmscanexcl = (byte)s; }
set_pmscanincl(bool s)119 void set_pmscanincl(bool s) { cfg.pmscanincl = (byte)s; }
120
set_echoid(const char * s)121 void set_echoid(const char* s) { cfg2.Change1(s); }
set_desc(const char * s)122 void set_desc(const char* s) { cfg2.Change2(s); }
set_path(const char * s)123 void set_path(const char* s) { cfg2.Change3(s); }
124
125
126 // ----------------------------------------------------------------
127 // Determine msgbase format
128
129 bool isseparator() const;
130
131
132 // ----------------------------------------------------------------
133 // Determine area features
134
issoftdelete()135 virtual bool issoftdelete() const { return false; }
havearrivedstamp()136 virtual bool havearrivedstamp() const { return true; }
havereceivedstamp()137 virtual bool havereceivedstamp() const { return true; }
requirehardterm()138 virtual bool requirehardterm() const { return false; }
requiresoftterm()139 virtual bool requiresoftterm() const { return false; }
140
141
142 // ----------------------------------------------------------------
143 // Determine area type
144
145 int isnet() const;
146 int isecho() const;
147 int islocal() const;
148 int isemail() const;
149 int isnewsgroup() const;
150 int isinternet() const;
151 int isqwk() const;
152 int issoup() const;
153
154
155 // ----------------------------------------------------------------
156 // Low-level messagebase member functions
157
158 virtual void open() = 0;
159 virtual void close() = 0;
160
161 virtual void suspend() = 0;
162 virtual void resume() = 0;
163
164 virtual void lock() = 0;
165 virtual void unlock() = 0;
166
167 virtual void scan() = 0;
168 virtual void scan_area() = 0;
169 virtual void scan_area_pm() = 0;
170
171 virtual int load_hdr(gmsg* msg) = 0;
172 virtual int load_msg(gmsg* msg) = 0;
173
174 virtual void save_hdr(int mode, gmsg* msg) = 0;
175 virtual void save_msg(int mode, gmsg* msg) = 0;
176
177 virtual void del_msg(gmsg* msg) = 0;
178
179 virtual void new_msgno(gmsg* msg) = 0;
180 virtual char* user_lookup(char* lookfor) = 0;
181 virtual int renumber() = 0;
182
183 virtual void update_timesread(gmsg* msg) = 0;
184
185 virtual Line* make_dump_msg(Line*& lin, gmsg* msg, char* lng_head) = 0;
186
set_highwater_mark()187 virtual void set_highwater_mark() { }
reset_highwater_mark()188 virtual void reset_highwater_mark() { }
189
190 protected:
191 Path realpath;
real_path()192 const char* real_path() const { return ispacked() ? realpath : path(); }
set_real_path(const char * newpath)193 void set_real_path(const char* newpath) { strxcpy(realpath, newpath, sizeof(Path)); }
194 };
195
196
197 // ------------------------------------------------------------------
198 // Inline implementations
199
isseparator()200 inline bool gmo_area::isseparator() const { return cfg.isseparator(); }
201
isnet()202 inline int gmo_area::isnet() const { return cfg.isnet(); }
isecho()203 inline int gmo_area::isecho() const { return cfg.isecho(); }
islocal()204 inline int gmo_area::islocal() const { return cfg.islocal(); }
isemail()205 inline int gmo_area::isemail() const { return cfg.isemail(); }
isnewsgroup()206 inline int gmo_area::isnewsgroup() const { return cfg.isnewsgroup(); }
isinternet()207 inline int gmo_area::isinternet() const { return cfg.isinternet(); }
isqwk()208 inline int gmo_area::isqwk() const { return cfg.isqwk(); }
issoup()209 inline int gmo_area::issoup() const { return cfg.issoup(); }
210
211
212 // ------------------------------------------------------------------
213
214 class SepArea : public gmo_area {
215
216 public:
217
SepArea()218 SepArea() { }
~SepArea()219 virtual ~SepArea() { }
220
221 // ----------------------------------------------------------------
222 // Messagebase member functions
223
open()224 void open() { }
close()225 void close() { }
226
suspend()227 void suspend() { }
resume()228 void resume() { }
229
lock()230 void lock() { }
unlock()231 void unlock() { }
232
scan()233 void scan() { }
scan_area()234 void scan_area() { }
scan_area_pm()235 void scan_area_pm() { }
236
load_hdr(gmsg *)237 int load_hdr(gmsg*) { return 0; }
load_msg(gmsg *)238 int load_msg(gmsg*) { return 0; }
239
save_hdr(int,gmsg *)240 void save_hdr(int, gmsg*) { }
save_msg(int,gmsg *)241 void save_msg(int, gmsg*) { }
242
del_msg(gmsg *)243 void del_msg(gmsg*) { }
244
new_msgno(gmsg *)245 void new_msgno(gmsg*) { }
user_lookup(char *)246 char* user_lookup(char*) { return NULL; }
renumber()247 int renumber() { return false; }
248
update_timesread(gmsg *)249 void update_timesread(gmsg*) { }
250
make_dump_msg(Line * &,gmsg *,char *)251 Line* make_dump_msg(Line*&, gmsg*, char*) { return NULL; }
252 };
253
254
255 // ------------------------------------------------------------------
256 // Personal mail
257
258 const int PM_STARTUP = 0x0001;
259 const int PM_ALLNAMES = 0x0002;
260 const int PM_LISTONLY = 0x0004;
261
262
263 // ------------------------------------------------------------------
264
265 extern glog* WideLog;
266 extern int WideDebug;
267 extern int WideCanLock;
268 extern const char** WideUsername;
269 extern int WideUsernames;
270 extern uint WideSharemode;
271 extern bool WideDispsoftcr; // DispsoftCR for current area
272 extern int WidePersonalmail;
273
274 // ------------------------------------------------------------------
275
276 bool PopupLocked(long __tries, int __isopen, const char* __file);
277 const char* Unpack(const char* archive);
278 void CleanUnpacked(const char* unpacked);
279
280 // ------------------------------------------------------------------
281 // SOFTCR management
282
283 // Detects SoftCR only if DispsoftCR is ON
issoftcr(char c)284 inline bool issoftcr(char c)
285 {
286 return not WideDispsoftcr and (c == SOFTCR);
287 }
288
289 // Skip spaces and SoftCRs (if DispsoftCR is ON)
spanspaces(const char * str)290 inline char *spanspaces(const char *str)
291 {
292 while ( (isspace(*str) and (*str != CR)) or issoftcr(*str) )
293 str++;
294 return (char *)str;
295 }
296
297 // Skip LineFeeds and SoftCRs (if DispsoftCR is ON)
spanfeeds(const char * str)298 inline char *spanfeeds(const char *str)
299 {
300 while ( (*str == LF) or issoftcr(*str) )
301 str++;
302 return (char *)str;
303 }
304
305
306 #endif
307
308 // ------------------------------------------------------------------
309
310