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 // ------------------------------------------------------------------
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library 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 GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this program; if not, write to the Free
19 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 // MA 02111-1307, USA
21 // ------------------------------------------------------------------
22 // $Id: gxgecho.cpp,v 1.7 2006/01/20 11:55:12 stas_degteff Exp $
23 // ------------------------------------------------------------------
24 // Read areas from GEcho
25 // ------------------------------------------------------------------
26
27 #include <cstdlib>
28 #include <gmemdbg.h>
29 #include <gstrall.h>
30 #if defined(__GOLD_GUI__)
31 #include <gvidall.h>
32 #include <gvidgui.h>
33 #endif
34 #undef GCFG_NOGECHO
35 #include <gedacfg.h>
36
37 #if defined(ADDRESS)
38 #undef ADDRESS
39 #endif
40
41 #include <gs_ge120.h>
42
43
44 // ------------------------------------------------------------------
45 // Read GEcho AREAFILE.GE and SETUP.GE
46
ReadGEcho(char * tag)47 void gareafile::ReadGEcho(char* tag) {
48
49 FILE* fp;
50 char* ptr;
51 char* ptr2;
52 AreaCfg aa;
53 int n;
54 word sysrev;
55 AREAFILE_GE* area;
56 AREAFILE_HDR ahdr;
57 SETUP_GE* gesetup;
58 Path gepath, file;
59 char options[80], abuf[40];
60
61 *gepath = NUL;
62
63 strcpy(options, tag);
64 ptr = strtok(tag, " \t");
65 while(ptr) {
66 if(*ptr != '-') {
67 AddBackslash(strcpy(gepath, ptr));
68 break;
69 }
70 ptr = strtok(NULL, " \t");
71 }
72 if(*gepath == NUL) {
73 ptr = getenv("GE");
74 if(ptr) {
75 ptr = strcpy(gepath, ptr);
76 ptr2 = strchr(ptr, ' ');
77 if(ptr2)
78 *ptr2 = NUL;
79 AddBackslash(gepath);
80 }
81 }
82 if(*gepath == NUL)
83 strcpy(gepath, areapath);
84
85 MakePathname(file, gepath, "setup.ge");
86
87 gesetup = (SETUP_GE*)throw_calloc(1, sizeof(SETUP_GE));
88 if(gesetup) {
89
90 fp = fsopen(file, "rb", sharemode);
91 if (fp)
92 {
93 if (not quiet)
94 STD_PRINTNL("* Reading " << file);
95
96 fread(&sysrev, sizeof(word), 1, fp);
97 rewind(fp);
98
99 if(sysrev == GE_THISREV) {
100
101 fread(gesetup, sizeof(SETUP_GE), 1, fp);
102 fclose(fp);
103
104 int ge_version = (gesetup->version_major * 100) + gesetup->version_minor;
105
106 //for(n=0; n<USERS; n++)
107 //CfgUsername(gesetup->username[n]);
108
109 CfgHudsonpath(gesetup->hmbpath);
110 CfgJampath(gesetup->jampath);
111
112 const char *_fidomsgtype = fidomsgtype;
113
114 if(ge_version >= 102)
115 {
116 _fidomsgtype = (gesetup->extraoptions & OPUSDATES) ? "OPUS" : "FTS1";
117 if((streql(_fidomsgtype, "FTS1")) and (streql(fidomsgtype, "OPUS")))
118 {
119 STD_PRINTNL("* Warning - FTS-1 format is used for *.MSG. For better compatibility set this");
120 STD_PRINTNL("* in GSETUP: Miscellanous->GEcho Options->MSG compatibilty = Opus (not Fido).");
121 STD_PRINTNL("* To disable this warning, set FIDOMSGTYPE FTS1 in your GoldED setup.");
122 }
123 }
124
125 int _AKAS = AKAS;
126 ftn_addr* _aka = (ftn_addr*)gesetup->aka;
127 if(ge_version < 110) {
128 _aka = (ftn_addr*)gesetup->oldaka;
129 _AKAS = OLDAKAS;
130 }
131
132 // Old netmail board (no longer in use by GEcho, but just in case...)
133 if(gesetup->oldnetmailboard and gesetup->oldnetmailboard < 201) {
134 aa.reset();
135 aa.basetype = "HUDSON";
136 aa.type = GMB_NET;
137 aa.attr = attribsnet;
138 aa.aka = _aka[0];
139 aa.board = gesetup->oldnetmailboard;
140 aa.setdesc("GEcho Netmail (HMB)");
141 aa.setautoid("NETMAIL");
142 AddNewArea(aa);
143 }
144 else if(not strblank(gesetup->mailpath)) {
145 aa.reset();
146 aa.basetype = _fidomsgtype;
147 aa.type = GMB_NET;
148 aa.attr = attribsnet;
149 aa.aka = _aka[0];
150 aa.setpath(gesetup->mailpath);
151 aa.setdesc("GEcho Netmail");
152 aa.setautoid("NETMAIL");
153 AddNewArea(aa);
154 }
155
156 // Bad msgs
157 uint _badboard = (ge_version >= 110) ? gesetup->badarea : gesetup->oldbadboard;
158 if(_badboard and _badboard < 201) {
159 aa.reset();
160 aa.basetype = "HUDSON";
161 aa.type = GMB_ECHO;
162 aa.attr = attribsecho;
163 aa.board = _badboard;
164 aa.aka = _aka[0];
165 aa.setdesc("GEcho Bad Msgs (HMB)");
166 aa.setautoid("ECHO_BAD");
167 AddNewArea(aa);
168 }
169 else if(not strblank(gesetup->badecho_path)) {
170 aa.reset();
171 aa.basetype = _fidomsgtype;
172 aa.type = GMB_ECHO;
173 aa.attr = attribsecho;
174 aa.aka = _aka[0];
175 aa.setpath(gesetup->badecho_path);
176 aa.setdesc("GEcho Bad Msgs");
177 aa.setautoid("ECHO_BAD");
178 AddNewArea(aa);
179 }
180
181 // Dupe msgs
182 if(ge_version < 120) {
183 //uint _dupboard = (ge_version >= 110) ? gesetup->duparea : gesetup->olddupboard;
184 uint _dupboard = (ge_version >= 110) ? gesetup->reserved5 : gesetup->olddupboard;
185 if(_dupboard and _dupboard < 201) {
186 aa.reset();
187 aa.basetype = "HUDSON";
188 aa.type = GMB_ECHO;
189 aa.attr = attribsecho;
190 aa.board = _dupboard;
191 aa.aka = _aka[0];
192 aa.setdesc("GEcho Dupe Msgs (HMB)");
193 aa.setautoid("ECHO_DUPES");
194 AddNewArea(aa);
195 }
196 }
197
198 // Recovery
199 if(gesetup->recoveryboard and gesetup->recoveryboard < 201) {
200 aa.reset();
201 aa.basetype = "HUDSON";
202 aa.type = GMB_ECHO;
203 aa.attr = attribsecho;
204 aa.board = gesetup->recoveryboard;
205 aa.aka = _aka[0];
206 aa.setdesc("GEcho Recovered Msgs (HMB)");
207 aa.setautoid("ECHO_RECOVERED");
208 AddNewArea(aa);
209 }
210
211 // Received msgs
212 uint _rcvdboard = (ge_version >= 110) ? gesetup->rcvdarea : gesetup->oldrcvdboard;
213 if(_rcvdboard and _rcvdboard < 201) {
214 aa.reset();
215 aa.basetype = "HUDSON";
216 aa.type = GMB_ECHO;
217 aa.attr = attribsecho;
218 aa.board = _rcvdboard;
219 aa.aka = _aka[0];
220 aa.setdesc("GEcho Received Netmail (HMB)");
221 aa.setautoid("NET_RECEIVED");
222 AddNewArea(aa);
223 }
224 else if(not strblank(gesetup->rcvdmailpath)) {
225 aa.reset();
226 aa.basetype = _fidomsgtype;
227 aa.type = GMB_NET;
228 aa.attr = attribsnet;
229 aa.aka = _aka[0];
230 aa.setpath(gesetup->rcvdmailpath);
231 aa.setdesc("GEcho Received Netmail");
232 aa.setautoid("NET_RECEIVED");
233 AddNewArea(aa);
234 }
235
236 // Sent msgs
237 uint _sentboard = (ge_version >= 110) ? gesetup->sentarea : gesetup->oldsentboard;
238 if(gesetup->oldsentboard and gesetup->oldsentboard < 201) {
239 aa.reset();
240 aa.basetype = "HUDSON";
241 aa.type = GMB_ECHO;
242 aa.attr = attribsecho;
243 aa.board = _sentboard;
244 aa.aka = _aka[0];
245 aa.setdesc("GEcho Sent Netmail (HMB)");
246 aa.setautoid("NET_SENT");
247 AddNewArea(aa);
248 }
249 else if(not strblank(gesetup->sentmailpath)) {
250 aa.reset();
251 aa.basetype = _fidomsgtype;
252 aa.type = GMB_NET;
253 aa.attr = attribsnet;
254 aa.aka = _aka[0];
255 aa.setpath(gesetup->sentmailpath);
256 aa.setdesc("GEcho Sent Netmail");
257 aa.setautoid("NET_SENT");
258 AddNewArea(aa);
259 }
260
261 // Personal mail boards
262 for(n=0; n<USERS; n++) {
263 int u = USERS - n - 1;
264 uint _persmailboard = (ge_version >= 110) ? gesetup->persmailarea[u] : gesetup->oldpersmailboard[u];
265 if(_persmailboard and _persmailboard < 201) {
266 aa.reset();
267 aa.basetype = "HUDSON";
268 aa.type = GMB_ECHO;
269 aa.attr = attribsecho;
270 aa.aka = _aka[0];
271 aa.board = _persmailboard;
272 Desc desc;
273 sprintf(desc, "GEcho PM for %s", gesetup->username[u]);
274 aa.setdesc(desc);
275 sprintf(desc, "ECHO_PM%u", u);
276 aa.setautoid(desc);
277 AddNewArea(aa);
278 }
279 }
280
281 // Personal mail
282 if(not strblank(gesetup->persmail_path)) {
283 aa.reset();
284 aa.basetype = _fidomsgtype;
285 aa.type = GMB_ECHO;
286 aa.attr = attribsecho;
287 aa.aka = _aka[0];
288 aa.setpath(gesetup->persmail_path);
289 aa.setdesc("GEcho Personal Mail");
290 aa.setautoid("ECHO_PERSONAL");
291 AddNewArea(aa);
292 }
293
294 // User netmail boards
295 for(n=0; n<USERS; n++) {
296 int u = USERS - n - 1;
297 uint _userboard = (ge_version >= 110) ? gesetup->userarea[u] : gesetup->olduserboard[u];
298 if(_userboard and _userboard < 201) {
299 aa.reset();
300 aa.basetype = "HUDSON";
301 aa.type = GMB_NET;
302 aa.attr = attribsnet;
303 aa.aka = _aka[0];
304 aa.board = _userboard;
305 Desc desc;
306 sprintf(desc, "GEcho Netmail for %s", gesetup->username[u]);
307 aa.setdesc(desc);
308 sprintf(desc, "NET_USER%u", u);
309 aa.setautoid(desc);
310 AddNewArea(aa);
311 }
312 }
313
314 // AKA net areas
315 for(n=0; n<_AKAS; n++) {
316 int a = _AKAS - n - 1;
317 uint _akaboard = (ge_version >= 110) ? gesetup->akaarea[a] : gesetup->oldakaboard[a];
318 if(_aka[a].net and _akaboard and _akaboard < 201) {
319 aa.reset();
320 aa.basetype = "HUDSON";
321 aa.type = GMB_NET;
322 aa.attr = attribsnet;
323 aa.aka = _aka[a];
324 aa.board = _akaboard;
325 Desc desc;
326 sprintf(desc, "GEcho Netmail, %s", _aka[a].make_string(abuf));
327 aa.setdesc(desc);
328 sprintf(desc, "NET_AKA%u", a);
329 aa.setautoid(desc);
330 AddNewArea(aa);
331 }
332 }
333
334 // --------------------------------------------------------------
335
336 MakePathname(file, gepath, "areafile.ge");
337
338 fp = fsopen(file, "rb", sharemode);
339 if (fp)
340 {
341 setvbuf(fp, NULL, _IOFBF, 8192);
342
343 if (not quiet)
344 STD_PRINTNL("* Reading " << file);
345
346 fread(&ahdr, sizeof(AREAFILE_HDR), 1, fp);
347 uint arearecsize = (ahdr.maxconnections * sizeof(CONNECTION)) + ahdr.recsize;
348
349 fseek(fp, (long)ahdr.hdrsize, SEEK_SET); // Allow for changed struct
350
351 area = (AREAFILE_GE*)throw_malloc(arearecsize);
352
353 if(area) {
354 while(fread(area, arearecsize, 1, fp) == 1) {
355 if(not (area->options & (PASSTHRU|REMOVED))) {
356
357 memset(((byte*)area)+ahdr.recsize, 0, arearecsize-ahdr.recsize);
358
359 aa.reset();
360
361 switch(area->areaformat) {
362 case FORMAT_HMB:
363 if(area->areanumber and area->areanumber < 201) {
364 aa.basetype = "HUDSON";
365 aa.board = area->areanumber;
366 break;
367 }
368 continue;
369 case FORMAT_SDM:
370 if(not strblank(area->path)) {
371 aa.basetype = _fidomsgtype;
372 aa.setpath(area->path);
373 break;
374 }
375 continue;
376 case FORMAT_JAM:
377 if(not strblank(area->path)) {
378 aa.basetype = "JAM";
379 aa.setpath(area->path);
380 break;
381 }
382 continue;
383 case FORMAT_SQUISH:
384 if(not strblank(area->path)) {
385 aa.basetype = "SQUISH";
386 aa.setpath(area->path);
387 break;
388 }
389 continue;
390 case FORMAT_PCB:
391 aa.basetype = "PCBOARD";
392 aa.board = area->areanumber;
393 aa.setpath(area->path);
394 break;
395 case FORMAT_WC:
396 aa.basetype = "WILDCAT";
397 aa.board = area->areanumber;
398 aa.setpath(area->path);
399 break;
400 default:
401 if(ge_version >= 102)
402 continue;
403 if(area->areanumber and area->areanumber < 201) {
404 aa.basetype = "HUDSON";
405 aa.board = area->areanumber;
406 }
407 else if((area->options & SDM) and not strblank(area->path)) {
408 aa.basetype = _fidomsgtype;
409 aa.setpath(area->path);
410 }
411 }
412
413 aa.groupid = area->group + ((ge_version >= 120) ? 0x8001 : 0);
414 if(_aka[area->pkt_origin].net)
415 aa.aka = _aka[area->pkt_origin];
416 switch(area->areatype) {
417 case NETMAIL:
418 aa.type = GMB_NET;
419 aa.attr = attribsnet;
420 break;
421 case LOCAL:
422 aa.type = GMB_LOCAL;
423 aa.attr = attribslocal;
424 break;
425 case BADECHO:
426 case ECHOMAIL:
427 case PERSONAL:
428 default:
429 aa.type = GMB_ECHO;
430 aa.attr = attribsecho;
431 }
432 aa.setdesc(area->comment);
433 aa.setechoid(area->name);
434 aa.setorigin(area->originlinenr ? gesetup->originline[area->originlinenr-1] : area->originline);
435 AddNewArea(aa);
436 }
437 }
438 throw_free(area);
439 }
440
441 fclose(fp);
442 }
443 }
444 else
445 STD_PRINTNL("* Error: GEcho system file revision level " << sysrev << " is not supported - Skipping.");
446 }
447 throw_free(gesetup);
448 }
449 }
450
451
452 // ------------------------------------------------------------------
453