1 //  This may look like C code, but it is really -*- C++ -*-
2 
3 //  ------------------------------------------------------------------
4 //  The Goldware Library
5 //  Copyright (C) 1999-2002 Alexander S. Aganichev
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: gxcrash.cpp,v 1.21 2006/05/13 16:13:48 ssianky Exp $
23 //  ------------------------------------------------------------------
24 //  Read areas from Crashmail II/CrashEcho
25 //  ------------------------------------------------------------------
26 
27 #include <cstdlib>
28 #include <gcrcall.h>
29 #include <gstrall.h>
30 #if defined(__GOLD_GUI__)
31 #include <gvidall.h>
32 #include <gvidgui.h>
33 #endif
34 #undef GCFG_NOCMAIL
35 #include <gedacfg.h>
36 
37 
38 //  ------------------------------------------------------------------
39 
jbstrcpy(char * dest,char * src,size_t maxlen,size_t * jbc)40 bool gareafile::jbstrcpy(char *dest, char *src, size_t maxlen, size_t *jbc) {
41   size_t d=0;
42   size_t stopchar1,stopchar2;
43   size_t jbcpos;
44 
45   jbcpos= *jbc;
46 
47   while(isspace(src[jbcpos])) jbcpos++;
48 
49   if(src[jbcpos]=='\"') {
50     jbcpos++;
51     stopchar1='\"';
52     stopchar2=0;
53   }
54   else {
55     stopchar1=' ';
56     stopchar2=9;
57   }
58 
59   while(src[jbcpos]!=stopchar1 and src[jbcpos]!=stopchar2 and src[jbcpos]!='\n' and src[jbcpos]!=NUL and d<maxlen-1) {
60     if(src[jbcpos]=='\\' and src[jbcpos+1]!=NUL and src[jbcpos+1]!='\n') {
61       jbcpos++;
62       dest[d++]=src[jbcpos++];
63     }
64     else
65       dest[d++]=src[jbcpos++];
66   }
67   dest[d]=0;
68   if(isspace(src[jbcpos]) or src[jbcpos]=='\"') jbcpos++;
69 
70   *jbc=jbcpos;
71 
72   if(d!=0 or stopchar1=='\"') return true;
73   return false;
74 }
75 
76 
77 //  ------------------------------------------------------------------
78 //  Read areas from Crashmail II/CrashEcho (echomail processor)
79 
ReadCrashmailCfg(const char * file)80 void gareafile::ReadCrashmailCfg(const char* file)
81 {
82   gfile fp(file, "rt", sharemode);
83   if (fp.isopen())
84   {
85     fp.SetvBuf(NULL, _IOFBF, 8192);
86 
87     if (not quiet)
88       STD_PRINTNL("* Reading " << file);
89 
90     char buf[4000];
91     char key[30];
92     char tmp[100], address[50], domain[50];
93     Path path;
94     bool unconfirmed = true;
95     size_t jbcpos;
96     AreaCfg aa;
97     aa.reset();
98     aa.type = GMB_NONE;
99     address[0] = NUL;
100     domain[0] = NUL;
101 
102     const word CRC_AKA = 0x13A4;
103     const word CRC_AREA = 0x010B;
104 #ifndef GCFG_NOCECHO
105     const word CRC_AREAFILE = 0xB487;
106 #endif
107     const word CRC_LOCALAREA = 0xAEC1;
108     const word CRC_DESCRIPTION = 0x2DF1;
109     const word CRC_DOMAIN = 0xFFCA;
110     const word CRC_GROUP = 0x1C9B;
111     const word CRC_NETMAIL = 0xE42E;
112 #ifndef GCFG_NOCECHO
113     const word CRC_NETMAILDIR = 0x180A;
114 #endif
115     const word CRC_SYSOP = 0x967F;
116     const word CRC_UNCONFIRMED = 0x195E;
117 
118     const word CRC_MSG = 0xCA2E;
119     const word CRC_JAM = 0xA8C3;
120     const word CRC_SQUISH = 0xFCF6;
121 
122     word crc16;
123 
124     while (fp.Fgets(buf, 4000))
125     {
126       jbcpos=0;
127       jbstrcpy(key, buf, 30, &jbcpos);
128       switch(crc16 = strCrc16(key)) {
129         case CRC_SYSOP:
130           jbstrcpy(tmp, buf, 100, &jbcpos);
131           CfgUsername(tmp);
132           break;
133         case CRC_AKA:
134           if(address[0]) {
135             strxmerge(tmp, 100, address, "@", domain, NULL);
136             CfgAddress(tmp);
137           }
138           jbstrcpy(address, buf, 50, &jbcpos);
139           break;
140         case CRC_DOMAIN:
141           jbstrcpy(domain, buf, 50, &jbcpos);
142           break;
143 #ifndef GCFG_NOCECHO
144         case CRC_AREAFILE:
145           jbstrcpy(path, buf, sizeof(Path), &jbcpos);
146           ReadCrashmail(path);
147           break;
148         case CRC_NETMAILDIR:
149           if(aa.type != GMB_NONE) {
150             if(not unconfirmed)
151               AddNewArea(aa);
152             aa.reset();
153           }
154           aa.aka = primary_aka;
155           aa.type = GMB_NET;
156           aa.attr = attribsnet;
157           aa.basetype = fidomsgtype;
158           jbstrcpy(path, buf, sizeof(Path), &jbcpos);
159           aa.setpath(path);
160           aa.setdesc("CrashEcho Netmail");
161           aa.setautoid("NETMAIL");
162           unconfirmed = false;
163           break;
164 #endif
165         case CRC_AREA:
166         case CRC_NETMAIL:
167         case CRC_LOCALAREA:
168           if(aa.type != GMB_NONE) {
169             if(not unconfirmed)
170               AddNewArea(aa);
171           }
172           aa.reset();
173           aa.type = GMB_NONE;
174           unconfirmed = false;
175           jbstrcpy(tmp, buf, 100, &jbcpos);
176           if(strieql(tmp, "DEFAULT") or strnieql(tmp, "DEFAULT_", 8)) {
177             break;
178           }
179           switch(crc16) {
180             case CRC_NETMAIL:
181               aa.type = GMB_NET;
182               aa.attr = attribsnet;
183               break;
184             case CRC_AREA:
185               aa.type = GMB_ECHO;
186               aa.attr = attribsecho;
187               break;
188             case CRC_LOCALAREA:
189               aa.type = GMB_LOCAL;
190               aa.attr = attribslocal;
191               break;
192           }
193           aa.setechoid(tmp);
194           jbstrcpy(tmp, buf, 50, &jbcpos);
195           aa.aka = primary_aka;
196           aa.aka.set(tmp);
197           jbstrcpy(tmp, buf, 10, &jbcpos);
198           switch(strCrc16(tmp)) {
199             case CRC_MSG:
200               aa.basetype = fidomsgtype;
201               break;
202             case CRC_JAM:
203               aa.basetype = "JAM";
204               break;
205             case CRC_SQUISH:
206               aa.basetype = "SQUISH";
207               break;
208             default:
209               aa.reset();
210               aa.type = GMB_NONE;
211               break;
212           }
213           if(aa.type == GMB_NONE)
214             break;
215           jbstrcpy(path, buf, sizeof(Path), &jbcpos);
216           aa.setpath(path);
217           break;
218         case CRC_DESCRIPTION:
219           jbstrcpy(tmp, buf, 100, &jbcpos);
220           aa.setdesc(tmp);
221           break;
222         case CRC_UNCONFIRMED:
223           unconfirmed = true;
224           break;
225         case CRC_GROUP:
226           if(jbstrcpy(tmp, buf, 100, &jbcpos)) {
227             if(isdigit(tmp[0]))
228               aa.groupid = 0x8000+atoi(tmp);
229             else if(g_isalpha(tmp[0]))
230               aa.groupid = g_toupper(tmp[0]);
231           }
232           break;
233       }
234     }
235     if(aa.type != GMB_NONE) {
236       if(not unconfirmed) {
237         AddNewArea(aa);
238       }
239     }
240     if(address[0]) {
241       strxmerge(tmp, 100, address, "@", domain, NULL);
242       CfgAddress(tmp);
243     }
244   }
245 }
246 
247 
248 //  ------------------------------------------------------------------
249 //  Initialize parser
250 
ReadCrashmail(char * tag)251 void gareafile::ReadCrashmail(char* tag) {
252 
253   Path file, path;
254   char options[80];
255 
256   strcpy(options, tag);
257   char* ptr = strtok(tag, " \t");
258   while(ptr) {
259     if(*ptr != '-') {
260       strcpy(file, ptr);
261       strschg_environ(file);
262     }
263     ptr = strtok(NULL, " \t");
264   }
265 
266   extractdirname(path, file);
267 
268   CfgSquishuserpath(path);
269 
270   ReadCrashmailCfg(file);
271 }
272 
273 
274 //  ------------------------------------------------------------------
275