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: gxfidpcb.cpp,v 1.7 2006/01/20 11:55:12 stas_degteff Exp $
23 //  ------------------------------------------------------------------
24 //  Read areas from FidoPCB.
25 //  ------------------------------------------------------------------
26 
27 #include <cstdlib>
28 #include <gmemdbg.h>
29 #include <gcrcall.h>
30 #include <gstrall.h>
31 #if defined(__GOLD_GUI__)
32 #include <gvidall.h>
33 #include <gvidgui.h>
34 #endif
35 #undef GCFG_NOFIDOPCB
36 #include <gedacfg.h>
37 
38 
39 //  ------------------------------------------------------------------
40 
41 struct fparea {
42 
43   Echo echoid;
44   Path path;
45   int  msgs;
46 };
47 
48 
49 //  ------------------------------------------------------------------
50 
51 const word CRC_AREA      = 0x010B;
52 const word CRC_AREA_MSGS = 0x90E4;
53 const word CRC_LOST_MAIL = 0x7C78;
54 const word CRC_MAIL      = 0x6A39;
55 const word CRC_NET_MAIL  = 0x7F80;
56 const word CRC_SYSOP     = 0x967F;
57 const word CRC_ORIGIN    = 0x4CE5;
58 const word CRC_PCBOARD   = 0x84EC;
59 const word CRC_TAG       = 0x5B36;
60 const word CRC_NODE      = 0xD3AD;
61 
62 
63 //  ------------------------------------------------------------------
64 
ReadFidoPCB(char * tag)65 void gareafile::ReadFidoPCB(char* tag) {
66 
67   AreaCfg aa;
68   char options[80];
69   Path file, path;
70 
71   *path = NUL;
72   strcpy(options, tag);
73   char* ptr = strtok(tag, " \t");
74   while(ptr) {
75     if(*ptr != '-') {
76       AddBackslash(strcpy(path, ptr));
77       break;
78     }
79     ptr = strtok(NULL, " \t");
80   }
81   if(*path == NUL) {
82     ptr = getenv("FIDOPCB");
83     if(ptr)
84       AddBackslash(strcpy(path, ptr));
85   }
86   if(*path == NUL)
87     strcpy(path, areapath);
88 
89   MakePathname(file, path, "fidopcb.cfg");
90 
91   FILE* fp = fsopen(file, "rb", sharemode);
92   if (fp)
93   {
94     setvbuf(fp, NULL, _IOFBF, 8192);
95 
96     if (not quiet)
97       STD_PRINTNL("* Reading " << file);
98 
99     int areas = 0;
100     fparea* area = NULL;
101 
102     Path mailpath;
103     *mailpath = NUL;
104     Path lostmailpath;
105     *lostmailpath = NUL;
106     Path netmailpath;
107     *netmailpath = NUL;
108     ftn_addr mainaddr;
109     char origin[80];
110     *origin = NUL;
111     int innode = false;
112 
113     char buf[512];
114     while(fgets(buf, sizeof(buf), fp)) {
115 
116       char* val = strskip_wht(buf);
117       if(*val != ';' and *val) {
118 
119         // Extract keyword and value
120         char* key;
121         word crc = getkeyvalcrc(&key, &val);
122 
123         switch(crc) {
124           case CRC_MAIL:
125             PathCopy(mailpath, val);
126             break;
127           case CRC_PCBOARD:
128             CfgPcboardpath(val);
129             break;
130           case CRC_LOST_MAIL:
131             PathCopy(lostmailpath, val);
132             break;
133           case CRC_NET_MAIL:
134             PathCopy(netmailpath, val);
135             break;
136           case CRC_SYSOP:
137             if(not innode)
138               NW(val);
139               //CfgUsername(val);
140             break;
141           case CRC_ORIGIN:
142             mainaddr.set(val);
143             innode = false;
144             break;
145           case CRC_TAG:
146             strxcpy(origin, val, sizeof(origin));
147             break;
148           case CRC_AREA:
149             area = (fparea*)throw_realloc(area, (areas+1)*sizeof(fparea));
150             area[areas].msgs = false;
151             getkeyval(&key, &val);  // Skip the unique number
152             getkeyval(&key, &val);  // Get echoid
153             strxcpy(area[areas].echoid, key, sizeof(Echo));
154             getkeyval(&key, &val);  // Get path
155             PathCopy(area[areas].path, key);
156             areas++;
157             break;
158           case CRC_AREA_MSGS:
159             if(areas) {
160               strcat(area[areas-1].path, val);
161               area[areas-1].msgs = true;
162             }
163             break;
164           case CRC_NODE:
165             innode = true;
166             break;
167         }
168 
169       }
170     }
171 
172     // *.MSG style netmail
173     aa.reset();
174     aa.aka = mainaddr;
175     aa.basetype = fidomsgtype;
176     aa.type = GMB_NET;
177     aa.attr = attribsnet;
178     aa.setpath(mailpath);
179     aa.setdesc("FidoPCB Mailer Netmail");
180     aa.setautoid("NETMAIL");
181     AddNewArea(aa);
182 
183     // Matrix area
184     if(*netmailpath) {
185       aa.reset();
186       aa.aka = mainaddr;
187       aa.basetype = "PCBOARD";
188       aa.type = GMB_NET;
189       aa.attr = attribsnet;
190       strcat(AddBackslash(netmailpath), "MATRIX");
191       aa.setpath(netmailpath);
192       aa.setorigin(origin);
193       aa.setdesc("FidoPCB Matrix Board");
194       aa.setautoid("MATRIX");
195       AddNewArea(aa);
196     }
197 
198     // Lost mail area
199     if(*lostmailpath) {
200       aa.reset();
201       aa.aka = mainaddr;
202       aa.basetype = "PCBOARD";
203       aa.type = GMB_ECHO;
204       aa.attr = attribsecho;
205       strcat(AddBackslash(lostmailpath), "LOST");
206       aa.setpath(lostmailpath);
207       aa.setorigin(origin);
208       aa.setdesc("FidoPCB Lost Mail Board");
209       aa.setautoid("LOST");
210       AddNewArea(aa);
211     }
212 
213     // Process areas
214     fparea* ap = area;
215     for(int n=0; n<areas; n++,ap++) {
216       aa.reset();
217       aa.aka = mainaddr;
218       aa.basetype = "PCBOARD";
219       aa.type = GMB_ECHO;
220       aa.attr = attribsecho;
221       if(not ap->msgs)
222         strcat(ap->path, "MSGS");
223       aa.setpath(ap->path);
224       aa.setechoid(ap->echoid);
225       aa.setorigin(origin);
226       AddNewArea(aa);
227     }
228 
229     throw_free(area);
230 
231     fclose(fp);
232   }
233 }
234 
235 
236 //  ------------------------------------------------------------------
237