This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-goldedplus/goldlib/gcfg/gxcrash.cpp

270 lines
7.2 KiB
C++
Raw Normal View History

2000-02-25 10:15:17 +00:00
// This may look like C code, but it is really -*- C++ -*-
// ------------------------------------------------------------------
// The Goldware Library
2002-05-12 13:07:37 +00:00
// Copyright (C) 1999-2002 Alexander S. Aganichev
2000-02-25 10:15:17 +00:00
// ------------------------------------------------------------------
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307, USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// Read areas from Crashmail II/CrashEcho
2000-02-25 10:15:17 +00:00
// ------------------------------------------------------------------
#include <cstdlib>
#include <gcrcall.h>
#include <gstrall.h>
#undef GCFG_NOCMAIL
2000-02-25 10:15:17 +00:00
#include <gedacfg.h>
// ------------------------------------------------------------------
bool gareafile::jbstrcpy(char *dest, char *src, size_t maxlen, size_t *jbc) {
size_t d=0;
size_t stopchar1,stopchar2;
size_t jbcpos;
jbcpos= *jbc;
while(isspace(src[jbcpos])) jbcpos++;
if(src[jbcpos]=='\"') {
jbcpos++;
stopchar1='\"';
stopchar2=0;
}
else {
stopchar1=' ';
stopchar2=9;
}
while(src[jbcpos]!=stopchar1 and src[jbcpos]!=stopchar2 and src[jbcpos]!='\n' and src[jbcpos]!=NUL and d<maxlen-1) {
if(src[jbcpos]=='\\' and src[jbcpos+1]!=NUL and src[jbcpos+1]!='\n') {
jbcpos++;
dest[d++]=src[jbcpos++];
}
else
dest[d++]=src[jbcpos++];
}
dest[d]=0;
if(isspace(src[jbcpos]) or src[jbcpos]=='\"') jbcpos++;
*jbc=jbcpos;
if(d!=0 or stopchar1=='\"') return true;
return false;
}
// ------------------------------------------------------------------
// Read areas from Crashmail II/CrashEcho (echomail processor)
2000-02-25 10:15:17 +00:00
2001-12-14 15:51:37 +00:00
void gareafile::ReadCrashmailCfg(const char* file) {
2000-02-25 10:15:17 +00:00
FILE* fp = fsopen(file, "rb", sharemode);
if(fp) {
setvbuf(fp, NULL, _IOFBF, 8192);
if(not quiet)
std::cout << "* Reading " << file << std::endl;
2000-02-25 10:15:17 +00:00
char buf[4000];
char key[30];
char tmp[100], address[50], domain[50];
2001-12-14 15:51:37 +00:00
Path path;
2000-02-25 10:15:17 +00:00
bool unconfirmed = true;
size_t jbcpos;
AreaCfg aa;
aa.reset();
2002-09-29 16:06:10 +00:00
aa.type = GMB_NONE;
2000-02-25 10:15:17 +00:00
address[0] = NUL;
domain[0] = NUL;
2000-02-25 10:15:17 +00:00
const word CRC_AKA = 0x13A4;
const word CRC_AREA = 0x010B;
#ifndef GCFG_NOCECHO
const word CRC_AREAFILE = 0xB487;
#endif
const word CRC_LOCALAREA = 0xAEC1;
2000-02-25 10:15:17 +00:00
const word CRC_DESCRIPTION = 0x2DF1;
const word CRC_DOMAIN = 0xFFCA;
const word CRC_GROUP = 0x1C9B;
const word CRC_NETMAIL = 0xE42E;
#ifndef GCFG_NOCECHO
const word CRC_NETMAILDIR = 0x180A;
#endif
2000-02-25 10:15:17 +00:00
const word CRC_SYSOP = 0x967F;
const word CRC_UNCONFIRMED = 0x195E;
const word CRC_MSG = 0xCA2E;
const word CRC_JAM = 0xA8C3;
const word CRC_SQUISH = 0xFCF6;
word crc16;
while(fgets(buf, 4000, fp) != NULL) {
2000-02-25 10:15:17 +00:00
jbcpos=0;
jbstrcpy(key, buf, 30, &jbcpos);
switch(crc16 = strCrc16(key)) {
2000-02-25 10:15:17 +00:00
case CRC_SYSOP:
jbstrcpy(tmp, buf, 100, &jbcpos);
CfgUsername(tmp);
break;
case CRC_AKA:
if(address[0]) {
strxmerge(tmp, 100, address, "@", domain, NULL);
CfgAddress(tmp);
}
jbstrcpy(address, buf, 50, &jbcpos);
break;
case CRC_DOMAIN:
jbstrcpy(domain, buf, 50, &jbcpos);
break;
#ifndef GCFG_NOCECHO
case CRC_AREAFILE:
2001-12-14 15:51:37 +00:00
jbstrcpy(path, buf, sizeof(Path), &jbcpos);
ReadCrashmail(path);
break;
case CRC_NETMAILDIR:
2002-09-29 16:06:10 +00:00
if(aa.type != GMB_NONE) {
if(not unconfirmed)
AddNewArea(aa);
aa.reset();
}
aa.aka = primary_aka;
aa.type = GMB_NET;
aa.attr = attribsnet;
aa.msgbase = fidomsgtype;
jbstrcpy(path, buf, sizeof(Path), &jbcpos);
aa.setpath(path);
aa.setdesc("CrashEcho Netmail");
aa.setautoid("NETMAIL");
unconfirmed = false;
break;
#endif
2000-02-25 10:15:17 +00:00
case CRC_AREA:
case CRC_NETMAIL:
2000-09-01 16:23:15 +00:00
case CRC_LOCALAREA:
2002-09-29 16:06:10 +00:00
if(aa.type != GMB_NONE) {
2000-02-25 10:15:17 +00:00
if(not unconfirmed)
AddNewArea(aa);
aa.reset();
}
unconfirmed = false;
jbstrcpy(tmp, buf, 100, &jbcpos);
if(strieql(tmp, "DEFAULT") or strnieql(tmp, "DEFAULT_", 8)) {
2002-09-29 16:06:10 +00:00
aa.type = GMB_NONE;
break;
}
2000-09-01 16:23:15 +00:00
switch(crc16) {
case CRC_NETMAIL:
aa.type = GMB_NET;
2000-02-25 10:15:17 +00:00
aa.attr = attribsnet;
break;
2000-09-01 16:23:15 +00:00
case CRC_AREA:
aa.type = GMB_ECHO;
2000-02-25 10:15:17 +00:00
aa.attr = attribsecho;
break;
2000-09-01 16:23:15 +00:00
case CRC_LOCALAREA:
aa.type = GMB_LOCAL;
aa.attr = attribslocal;
break;
2000-02-25 10:15:17 +00:00
}
aa.setechoid(tmp);
jbstrcpy(tmp, buf, 50, &jbcpos);
aa.aka = primary_aka;
aa.aka.set(tmp);
jbstrcpy(tmp, buf, 10, &jbcpos);
switch(strCrc16(tmp)) {
case CRC_MSG:
aa.msgbase = fidomsgtype;
break;
case CRC_JAM:
aa.msgbase = GMB_JAM;
break;
case CRC_SQUISH:
aa.msgbase = GMB_SQUISH;
break;
default:
aa.reset();
2002-09-29 16:06:10 +00:00
aa.type = GMB_NONE;
2000-02-25 10:15:17 +00:00
break;
}
2002-09-29 16:06:10 +00:00
if(aa.type == GMB_NONE)
2000-02-25 10:15:17 +00:00
break;
jbstrcpy(path, buf, sizeof(Path), &jbcpos);
aa.setpath(path);
2000-02-25 10:15:17 +00:00
break;
case CRC_DESCRIPTION:
jbstrcpy(tmp, buf, 100, &jbcpos);
aa.setdesc(tmp);
break;
case CRC_UNCONFIRMED:
unconfirmed = true;
break;
case CRC_GROUP:
2002-05-12 13:07:37 +00:00
if(jbstrcpy(tmp, buf, 100, &jbcpos)) {
if(isdigit(tmp[0]))
aa.groupid = 0x8000+atoi(tmp);
else if(isalpha(tmp[0]))
aa.groupid = toupper(tmp[0]);
}
2000-02-25 10:15:17 +00:00
break;
}
}
2002-09-29 16:06:10 +00:00
if(aa.type != GMB_NONE) {
2000-02-25 10:15:17 +00:00
if(not unconfirmed) {
AddNewArea(aa);
}
}
if(address[0]) {
2000-02-25 10:15:17 +00:00
strxmerge(tmp, 100, address, "@", domain, NULL);
CfgAddress(tmp);
}
fclose(fp);
2000-02-25 10:15:17 +00:00
}
}
2001-12-14 15:51:37 +00:00
// ------------------------------------------------------------------
// Initialize parser
void gareafile::ReadCrashmail(char* tag) {
Path file, path;
char options[80];
strcpy(options, tag);
char* ptr = strtok(tag, " \t");
while(ptr) {
if(*ptr != '-') {
strcpy(file, ptr);
2002-04-21 12:01:13 +00:00
strschg_environ(file);
2001-12-14 15:51:37 +00:00
}
ptr = strtok(NULL, " \t");
}
extractdirname(path, file);
CfgSquishuserpath(path);
ReadCrashmailCfg(file);
}
2000-02-25 10:15:17 +00:00
// ------------------------------------------------------------------