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/gxhpt.cpp

440 lines
11 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 Fidoconfig
// ------------------------------------------------------------------
#include <cstdlib>
#include <cerrno>
2000-02-25 10:15:17 +00:00
#include <gcrcall.h>
#include <gstrall.h>
#include <gmemdbg.h>
#if defined(__GOLD_GUI__)
#include <gvidall.h>
#include <gvidgui.h>
#endif
#undef GCFG_NOFIDOCONF
2000-02-25 10:15:17 +00:00
#include <gedacfg.h>
// ------------------------------------------------------------------
2005-08-26 23:12:29 +00:00
static char comment_char = '#';
2000-02-25 10:15:17 +00:00
// ------------------------------------------------------------------
2007-01-11 22:26:06 +00:00
bool gareafile::ReadHPTLine(gfile &f, std::string& str)
2006-05-13 16:15:35 +00:00
{
2007-01-11 22:26:06 +00:00
char buf[1024];
2000-02-25 10:15:17 +00:00
2007-01-11 22:26:06 +00:00
if (!f.Fgets(buf, ARRAYSIZE(buf)))
return false; // eof
2000-02-25 10:15:17 +00:00
str = buf;
2007-01-11 22:26:06 +00:00
if (!str.empty() && (*(str.end() - 1) != '\n'))
2006-05-13 16:15:35 +00:00
{
2007-01-11 22:26:06 +00:00
while (f.Fgets(buf, ARRAYSIZE(buf)))
2006-05-13 16:15:35 +00:00
{
2000-02-25 10:15:17 +00:00
str += buf;
2007-01-11 22:26:06 +00:00
if (*(str.end() - 1) == '\n')
2000-02-25 10:15:17 +00:00
break;
}
}
std::string::iterator ptr = str.begin();
2007-01-11 22:26:06 +00:00
std::string::iterator end = str.end();
bool state = false;
2000-02-25 10:15:17 +00:00
// state 0: normal state
// 1: between ""
// 2: end
// 3: whitespace
2007-01-11 22:26:06 +00:00
for (; ptr != end; ptr++)
{
if (comment_char == *ptr)
{
if (!state)
{
str.erase(ptr, end);
break;
2001-04-08 08:02:01 +00:00
}
}
2007-01-11 22:26:06 +00:00
else if ('\"' == *ptr)
{
state = !state;
2000-02-25 10:15:17 +00:00
}
}
2007-01-11 22:26:06 +00:00
strltrim(strtrim(str));
2000-02-25 10:15:17 +00:00
2005-08-26 23:12:29 +00:00
return true;
2000-02-25 10:15:17 +00:00
}
// ------------------------------------------------------------------
void gareafile::gettok(char** key, char** val) {
char* p = strskip_wht(*val);
// Get the keyword
switch(*p) {
// Strip "double" quotes
case '\"':
*key = ++p;
do {
p = strskip_to(p, '\"');
if(not *p or (*(p-1) != '\\'))
break;
else
p++;
} while(*p);
break;
// Strip 'single' quotes
case '\'':
*key = ++p;
do {
p = strskip_to(p, '\'');
if(not *p or (*(p-1) != '\\'))
break;
else
p++;
} while(*p);
break;
// Strip round brackets
case '(': /*)*/
*key = ++p;
p = strskip_to(p, /*(*/ ')');
break;
// Get straight keyword
default:
*key = p;
while(*p and not isspace(*p))
p++;
}
// Nul-terminate keyword
if(*p)
*p++ = NUL;
// Skip whitespace if any
p = strskip_wht(p);
// Get the value
*val = p;
}
// ------------------------------------------------------------------
2002-10-05 21:13:23 +00:00
void gareafile::ReadHPTFile(char* path, char* file, char* origin, int group) {
2000-02-25 10:15:17 +00:00
const word CRC_ADDRESS = 0xFDD6;
const word CRC_INCLUDE = 0x379B;
2001-11-15 11:08:21 +00:00
const word CRC_NETAREA = 0x8F1C;
const word CRC_NETMAILAREA = 0xD2D7;
2000-02-25 10:15:17 +00:00
const word CRC_LOCALAREA = 0xAEC1;
const word CRC_ECHOAREA = 0x0D63;
const word CRC_DUPEAREA = 0xD8B9;
const word CRC_BADAREA = 0x8DA5;
const word CRC_SYSOP = 0x967F;
const word CRC_VERSION = 0xF78F;
2001-04-08 08:02:01 +00:00
const word CRC_COMMENTCHAR = 0xE2CC;
2002-09-29 16:06:10 +00:00
const word CRC_ECHOAREADEFAULTS = 0x2CBB;
2006-06-29 15:50:19 +00:00
const word CRC_SET = 0x2FC2;
2000-02-25 10:15:17 +00:00
2002-10-05 21:13:23 +00:00
AreaCfg aa;
2000-02-25 10:15:17 +00:00
Path buf2;
2006-05-13 16:15:35 +00:00
gfile fp(file, "rb", sharemode);
if (fp.isopen())
{
2006-05-13 16:15:35 +00:00
fp.SetvBuf(NULL, _IOFBF, 8192);
2000-02-25 10:15:17 +00:00
if (not quiet)
2006-01-20 11:55:12 +00:00
STD_PRINTNL("* Reading " << file);
2000-02-25 10:15:17 +00:00
aa.reset();
2002-10-11 05:54:11 +00:00
aa.type = GMB_NONE;
2003-12-10 08:35:16 +00:00
aa.basetype = fidomsgtype;
2002-10-11 05:54:11 +00:00
aa.groupid = group;
2000-02-25 10:15:17 +00:00
std::string s;
2007-01-11 22:26:06 +00:00
while (ReadHPTLine(fp, s))
2006-05-13 16:15:35 +00:00
{
2007-01-11 22:26:06 +00:00
if (not s.empty())
{
2000-02-25 10:15:17 +00:00
char *alptr = throw_xstrdup(s.c_str());
char *ptr = alptr;
char* key;
char* val = ptr;
gettok(&key, &val);
2006-06-29 15:50:19 +00:00
switch (strCrc16(key))
2007-01-11 22:26:06 +00:00
{
case CRC_SET:
if (strchg(val, '[', '%') != 0)
strchg(val, ']', '%');
putenv(val);
break;
case CRC_VERSION:
{
int ver_maj, ver_min;
sscanf(val, "%d.%d", &ver_maj, &ver_min);
if (((ver_maj << 16) + ver_min) > 0x00010009)
2000-02-25 10:15:17 +00:00
{
2007-01-11 22:26:06 +00:00
STD_PRINTNL("* Error: Unknown fidoconfig version " << ver_maj << '.' << ver_min << " - Skipping.");
throw_xfree(alptr);
goto skip_config;
2000-02-25 10:15:17 +00:00
}
2007-01-11 22:26:06 +00:00
}
break;
case CRC_ADDRESS:
CfgAddress(val);
break;
case CRC_SYSOP:
CfgUsername(val);
break;
case CRC_INCLUDE:
strxcpy(buf2, val, sizeof(buf2));
if(strchg(buf2, '[', '%') != 0)
strchg(buf2, ']', '%');
MakePathname(buf2, path, buf2);
ReadHPTFile(path, buf2, origin, group);
break;
case CRC_COMMENTCHAR:
if((strlen(val) == 3) and (val[0] == val[2]) and strpbrk(val, "\'\""))
comment_char = val[1];
else if(*val)
comment_char = val[0];
break;
case CRC_NETAREA:
case CRC_NETMAILAREA:
aa.type = GMB_NET;
break;
case CRC_LOCALAREA:
case CRC_DUPEAREA:
case CRC_BADAREA:
aa = echoareadefaults;
aa.type = GMB_LOCAL;
break;
case CRC_ECHOAREA:
aa = echoareadefaults;
aa.type = GMB_ECHO;
break;
case CRC_ECHOAREADEFAULTS:
echoareadefaults.reset();
aa.type = GMB_DEFAULT;
aa.basetype = fidomsgtype;
aa.groupid = group;
break;
2000-02-25 10:15:17 +00:00
}
2002-09-29 16:06:10 +00:00
if(aa.type != GMB_NONE) {
if(aa.type == GMB_DEFAULT) {
*key = NUL;
}
else {
2000-02-25 10:15:17 +00:00
2002-09-29 16:06:10 +00:00
// Get echoid
gettok(&key, &val);
aa.setechoid(key);
2000-02-25 10:15:17 +00:00
2002-09-29 16:06:10 +00:00
// Get path
gettok(&key, &val);
}
2000-02-25 10:15:17 +00:00
// If not pass-through
2007-01-11 22:26:06 +00:00
if (not strieql("Passthrough", key))
{
if (strchg(key, '[', '%') != 0)
strchg(key, ']', '%');
aa.setpath(key);
2000-02-25 10:15:17 +00:00
gettok(&key, &val);
2007-01-11 22:26:06 +00:00
for (;;)
{
if (*key == '-')
{
2000-02-25 10:15:17 +00:00
char *opt = key + 1;
2005-08-26 23:12:29 +00:00
2007-01-11 22:26:06 +00:00
if (strieql(opt, "a"))
{
2000-02-25 10:15:17 +00:00
gettok(&key, &val);
CfgAddress(key);
aa.aka.set(key);
}
2007-01-11 22:26:06 +00:00
else if (strieql(opt, "g"))
{
2000-02-25 10:15:17 +00:00
gettok(&key, &val);
2005-08-26 23:12:29 +00:00
2007-01-11 22:26:06 +00:00
if (isdigit(*key))
aa.groupid = 0x8000 + atoi(key);
else if (g_isalpha(*key))
aa.groupid = g_toupper(*key);
2000-02-25 10:15:17 +00:00
}
2007-01-11 22:26:06 +00:00
else if (strieql(opt, "d"))
{
2000-02-25 10:15:17 +00:00
gettok(&key, &val);
aa.setdesc(key);
}
2007-01-11 22:26:06 +00:00
else if (strieql(opt, "pass"))
{
2003-10-23 10:44:32 +00:00
aa.type = GMB_NONE;
break;
}
2007-01-11 22:26:06 +00:00
else if (strieql(opt, "p") or strieql(opt, "$m")
or strieql(opt, "lr") or strieql(opt, "lw")
or strieql(opt, "dupeCheck") or strieql(opt, "dupehistory")
or strieql(opt, "r") or strieql(opt, "w")
or strieql(opt, "l") or strieql(opt, "fperm")
or strieql(opt, "fowner") or strnieql(opt, "sbadd(", 6)
or strnieql(opt, "sbign(", 6))
{
gettok(&key, &val);
}
//else if(strieql(opt, "h") or strieql(opt, "manual")
// or strieql(opt, "nopause") or strieql(opt, "mandatory")
// or strieql(opt, "dosfile") or strieql(opt, "ccoff")
// or strieql(opt, "b") or strieql(opt, "tinysb")
// or strieql(opt, "killsb") or strieql(opt, "keepunread")
// or strieql(opt, "killread") or strieql(opt, "h")
// or strieql(opt, "nolink") or strieql(opt, "debug")
// or strieql(opt, "nopack") or strieql(opt, "keepsb")
// or strieql(opt, "$") or strieql(opt, "0"))
//{
//}
}
else if (strieql(key, "Squish")) aa.basetype = "SQUISH";
else if (strieql(key, "Jam" )) aa.basetype = "JAM";
else if (strieql(key, "MSG" )) aa.basetype = fidomsgtype;
else
{
break;
2000-02-25 10:15:17 +00:00
}
gettok(&key, &val);
}
2005-08-26 23:12:29 +00:00
2002-09-29 16:06:10 +00:00
aa.setorigin(origin);
2000-02-25 10:15:17 +00:00
switch(aa.type) {
case GMB_NET:
aa.attr = attribsnet;
2007-01-08 12:09:42 +00:00
if (aa.basetype.empty())
2003-12-10 08:35:16 +00:00
aa.basetype = fidomsgtype;
2002-09-29 16:06:10 +00:00
AddNewArea(aa);
2000-02-25 10:15:17 +00:00
break;
case GMB_ECHO:
aa.attr = attribsecho;
2007-01-08 12:09:42 +00:00
if (aa.basetype.empty())
2003-12-10 08:35:16 +00:00
aa.basetype = fidomsgtype;
2002-09-29 16:06:10 +00:00
AddNewArea(aa);
2000-02-25 10:15:17 +00:00
break;
case GMB_LOCAL:
aa.attr = attribslocal;
2007-01-08 12:09:42 +00:00
if (aa.basetype.empty())
2003-12-10 08:35:16 +00:00
aa.basetype = fidomsgtype;
2002-09-29 16:06:10 +00:00
AddNewArea(aa);
break;
case GMB_DEFAULT:
2002-10-05 21:13:23 +00:00
echoareadefaults = aa;
2002-09-29 16:06:10 +00:00
break;
default:
2000-02-25 10:15:17 +00:00
break;
}
}
aa.reset();
}
throw_xfree(alptr);
}
}
2006-05-13 16:15:35 +00:00
skip_config:;
}
else
{
STD_PRINTNL(" * AREAFILE FIDOCONFIG: Can't open file '" << path << '/' << file << ": " << strerror(errno) );
2000-02-25 10:15:17 +00:00
}
}
// ------------------------------------------------------------------
// Read areas from HPT (echomail processor)
void gareafile::ReadHPT(char* tag) {
char origin[80];
char options[80];
word defaultgroup = 0;
Path file, path;
*origin = NUL;
*file = NUL;
strcpy(options, tag);
char* ptr = strtok(tag, " \t");
while(ptr) {
if(*ptr != '-')
strcpy(file, ptr);
else {
if(g_toupper(*(++ptr)) == 'G') {
2000-02-25 10:15:17 +00:00
if(*(++ptr) == '=')
ptr++;
if(*ptr == '#')
defaultgroup = (word)(atoi(ptr+1)+0x8000u);
else
defaultgroup = (word)(g_isupper(*ptr) ? *ptr : 0);
2000-02-25 10:15:17 +00:00
}
}
ptr = strtok(NULL, " \t");
}
if(not *file and ((ptr = getenv("FIDOCONFIG"))!=NULL))
strcpy(file, ptr);
extractdirname(path, file);
CfgSquishuserpath(path);
2000-02-25 10:15:17 +00:00
CfgJAMSMAPIHighwater(true);
2002-10-05 21:13:23 +00:00
echoareadefaults.type = GMB_NONE;
2003-12-10 08:35:16 +00:00
echoareadefaults.basetype = fidomsgtype;
2002-10-05 21:13:23 +00:00
echoareadefaults.groupid = defaultgroup;
ReadHPTFile(path, file, origin, defaultgroup);
2000-02-25 10:15:17 +00:00
}
// ------------------------------------------------------------------