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: gxwtr.cpp,v 1.9 2006/05/13 16:13:48 ssianky Exp $
23 //  ------------------------------------------------------------------
24 //  Read areas from WaterGate 0.93 (and newer)
25 //  ------------------------------------------------------------------
26 
27 #include <cstdlib>
28 #include <gstrall.h>
29 #include <gmemdbg.h>
30 #if defined(__GOLD_GUI__)
31 #include <gvidall.h>
32 #include <gvidgui.h>
33 #endif
34 #undef GCFG_NOWATERGATE
35 #include <gedacfg.h>
36 #include <gs_wtr.h>
37 
38 
39 //  ------------------------------------------------------------------
40 
gettype(const char * msgtype,const byte wtrtype)41 const char *gareafile::gettype(const char *msgtype, const byte wtrtype) {
42 
43   switch(wtrtype) {
44     case 1: return msgtype;
45     case 2: return "SQUISH";
46     case 3: return "JAM";
47     case 4: return "WILDCAT";
48   }
49   return "";
50 }
51 
52 
53 //  ------------------------------------------------------------------
54 //  Read WaterGate v0.93
55 
ReadWtrGteFile(char * options,gfile & fp)56 void gareafile::ReadWtrGteFile(char* options, gfile &fp)
57 {
58   AreaCfg aa;
59   ConfigRecord* _tmp = new ConfigRecord; throw_new(_tmp);
60   ConfigRecord& c = *_tmp;
61   fp.Fread(&c, sizeof(ConfigRecord));
62 
63   strp2c(c.systemdir);
64   CfgJampath(c.systemdir);
65   MapPath(c.systemdir);
66 
67   strp2c(c.origins[0]);
68   strp2c(c.origins[1]);
69 
70   if(c.fidonetmailtype) {
71     aa.reset();
72     aa.basetype = gettype(c.opusdateformat ? "OPUS" : "FTS1", c.fidonetmailtype);
73     aa.type = GMB_NET;
74     aa.attr = attribsnet;
75     aa.aka  = CAST(ftn_addr, c.nodenrs[0]);
76     aa.setpath(strp2c(c.fidonetmailpath));
77     aa.setdesc("WaterGate Netmail");
78     aa.setautoid("NETMAIL");
79     AddNewArea(aa);
80   }
81 
82   if(c.fidobadareatype) {
83     aa.reset();
84     aa.basetype = gettype(c.opusdateformat ? "OPUS" : "FTS1", c.fidobadareatype);
85     aa.type = GMB_ECHO;
86     aa.attr = attribsecho;
87     aa.aka  = CAST(ftn_addr, c.nodenrs[0]);
88     aa.setpath(strp2c(c.fidobadpath));
89     aa.setdesc("WaterGate Badmail");
90     aa.setautoid("BADMAIL");
91     AddNewArea(aa);
92   }
93 
94   if(c.fidodupeareatype) {
95     aa.reset();
96     aa.basetype = gettype(c.opusdateformat ? "OPUS" : "FTS1", c.fidodupeareatype);
97     aa.type = GMB_NET;
98     aa.attr = attribsnet;
99     aa.aka  = CAST(ftn_addr, c.nodenrs[0]);
100     aa.setpath(strp2c(c.fidodupepath));
101     aa.setdesc("WaterGate Dupemail");
102     aa.setautoid("DUPEMAIL");
103     AddNewArea(aa);
104   }
105 
106   FILE* fp2;
107   Path file;
108 
109   MakePathname(file, c.systemdir, "areabase.tdb");
110   fp2 = fsopen(file, "rb", sharemode);
111   if (fp2)
112   {
113     char header[26];
114 
115     if (not quiet)
116       STD_PRINTNL("* Reading " << file);
117 
118     fread(header, 26, 1, fp2);
119     strp2c(header);
120 
121     if(streql(header, AreaBaseHeader)) {
122       AreaBaseRecord* ar = new AreaBaseRecord; throw_new(ar);
123 
124       while(fread(ar, sizeof(AreaBaseRecord), 1, fp2) == 1) {
125         if(not ar->deleted and ar->fidomsgstyle) {
126           aa.reset();
127           switch(ar->areatype) {
128             case 0: aa.type = GMB_ECHO;   aa.attr = attribsecho;  break;
129             case 1: aa.type = GMB_NET;    aa.attr = attribsnet;   break;
130             case 2: aa.type = GMB_LOCAL;  aa.attr = attribslocal; break;
131             case 3: aa.type = GMB_EMAIL;  aa.attr = attribsemail; break;
132             default:
133               continue;
134           }
135 
136           aa.basetype = gettype(c.opusdateformat ? "OPUS" : "FTS1", ar->fidomsgstyle);
137           if(in_range(ar->originaka, (byte) 1, (byte) 20))
138             aa.aka  = CAST(ftn_addr, c.nodenrs[ar->originaka-1]);
139           aa.setpath(strp2c(ar->fidomsgpath));
140           aa.setdesc(strp2c(ar->comment));
141           aa.setautoid(strp2c(ar->areaname_F));
142           switch(ar->originnr) {
143             case 0: aa.setorigin(strp2c(ar->origin)); break;
144             case 1: aa.setorigin(c.origins[0]);       break;
145             case 2: aa.setorigin(c.origins[1]);       break;
146           }
147           AddNewArea(aa);
148         }
149       }
150       throw_delete(ar);
151     }
152     else
153       STD_PRINTNL("* Error: WaterGate Areabase \"" << header << "\" is not supported - Skipping.");
154 
155     fclose(fp2);
156   }
157 
158   throw_delete(_tmp);
159 }
160 
161 
162 //  ------------------------------------------------------------------
163 
ReadWtrGte(char * tag)164 void gareafile::ReadWtrGte(char* tag)
165 {
166   char* ptr;
167   char options[80];
168   Path wtrpath, file;
169 
170   *file = NUL;
171   *wtrpath = NUL;
172   strcpy(options, tag);
173   ptr = strtok(tag, " \t");
174   while(ptr) {
175     if(*ptr != '-') {
176       AddBackslash(strcpy(wtrpath, ptr));
177       break;
178     }
179     ptr = strtok(NULL, " \t");
180   }
181   if(*wtrpath == NUL) {
182     ptr = getenv("WTRGATE");
183     if(ptr)
184       AddBackslash(strcpy(wtrpath, ptr));
185   }
186   if(*wtrpath == NUL)
187     strcpy(wtrpath, areapath);
188 
189   MakePathname(file, wtrpath, "wtrcfg.tdb");
190   gfile fp(file, "rb", sharemode);
191   if (fp.isopen())
192   {
193     if (not quiet)
194       STD_PRINTNL("* Reading " << file);
195 
196     char header[26];
197     fp.Fread(header, 26);
198     strp2c(header);
199 
200     if(streql(header, ConfigHeader))
201       ReadWtrGteFile(options, fp);
202     else
203       STD_PRINTNL("* Error: WaterGate \"" << header << "\" is not supported - Skipping.");
204   }
205 }
206 
207 
208 //  ------------------------------------------------------------------
209