home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
XGRP_000.SZH
/
CONFIG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-21
|
26KB
|
782 lines
#include "xgroup.h"
/* variables visible only to this module */
#define GROUPIN 1
#define GROUPOUT 2
#define MSGDIR 3
#define ARCHIVE 4
#define UNARCHIVE 5
#define GROUPR 6
#define PACKSIZE 7
#define GROUPHOLD 8
#define XBBSOS2 9
#define OUTBOUND 10
#define INBOUND 11
#define ROUTER 12
#define ANADDRESS 13
#define NETAREA 14
#define ECHOR 15
#define NOTINY 16
#define PRIORITIES 17
#define NOFORWARD 18
#define NOLOCALFORWARD 19
#define FORWARDFILES 20
#define MAXIMUMDUPES 21
#define NODUPES 22
#define LOGFILE 23
#define KEEPPATH 24
#define KEEPSEENBYS 25
#define KEEPDUPES 26
#define TONAME 27
#define KILLBADDATES 28
#define MESSAGES 29
#define KEEPNOFORWARDS 30
#define ALLOWBADAREAS 31
struct __keywords__ { /* Keyword lookup table structure */
char *keyword;
char tok;
};
typedef struct __keywords__ KEYWORD;
static KEYWORD table[]= { /* config verb lookup table */
"groupin",GROUPIN,
"groupout",GROUPOUT,
"msgdir",MSGDIR,
"archive",ARCHIVE,
"unarchive",UNARCHIVE,
"group",GROUPR,
"packsize",PACKSIZE,
"grouphold",GROUPHOLD,
"xbbsos2",XBBSOS2,
"outbound",OUTBOUND,
"inbound",INBOUND,
"address",ANADDRESS,
"echo",ECHOR,
"notiny",NOTINY,
"priority",PRIORITIES,
"noforward",NOFORWARD,
"nolocalforward",NOLOCALFORWARD,
"forwardfiles",FORWARDFILES,
"netarea",NETAREA,
"maxdupes",MAXIMUMDUPES,
"nodupes",NODUPES,
"logfile",LOGFILE,
"route",ROUTER,
"keeppath",KEEPPATH,
"keepseenbys",KEEPSEENBYS,
"keepdupes",KEEPDUPES,
"toname",TONAME,
"killbaddates",KILLBADDATES,
"messages",MESSAGES,
"keepnoforwards",KEEPNOFORWARDS,
"allowbadareas",ALLOWBADAREAS,
NULL,0
};
/* external global variables */
char machstate;
/* Global variables created in this module */
char *groupin = NULL; /* groupmail inbound dir */
char *groupout = NULL; /* groupmail outbound dir */
char *grouphold = NULL; /* groupmail hold dir */
char *msgdir = NULL; /* xbbs msg dir */
char *outbound = NULL; /* bink-style outbound dir */
char *inbound = NULL; /* mailer's inbound dir */
char *archive = NULL; /* archiver spawn string */
char *unarchive = NULL; /* unarchiver spawn string */
CONTROLS control;
GROUP *group = NULL; /* list of groups being processed */
ADDR *myaddr = NULL; /* our network address(es) */
ECHOREC *echos = NULL; /* 'normal' echos */
ASSHOLE *assholes = NULL; /* assholes, natch */
ROUTE *routes = NULL; /* route statements */
TONAMES *tonames = NULL; /* special to: fields */
word packsize = 0; /* size at which to begin compressing */
word netarea = 0; /* netmail area # */
word maxdupes = MAXDUPES; /* max # dupe recs/echo area (8 bytes ea.) */
char *logfile = NULL; /* logfile filename */
int logfilehandle = -1; /* logfile handle */
char *putmsgs = NULL; /* where *.MSG files go */
/* functions visible only to this module */
static int _fastcall look_up (char *s);
int _fastcall config (char *configfile) {
/* Reads configuration information from file. Returns 0 (ok) or
-1 (fatal error, terminate with prejudice). */
int handle,token;
int pri1,pri2;
struct __pid__ {
word pid;
word thread;
word parentpid;
} pid;
char s[513],*p,*pp,wasplus,valid_types[] = "CHDNM";
GROUP *ginfo = NULL,*glast = NULL;
ADDR *ainfo = NULL,*alast = NULL,*ealast = NULL;
ECHOREC *einfo = NULL,*elast = NULL;
ROUTE *rinfo = NULL,*rlast = NULL;
TONAMES *tinfo = NULL,*tlast = NULL;
if(!configfile || !*configfile) configfile = "XGROUP.CTL";
handle = sopen(configfile,O_RDONLY | O_BINARY,SH_DENYNO);
if(handle == -1) {
printf("\nCan't open configfile \"%s\"\n",configfile);
return -1;
}
control.xbbsos2 = 0;
control.tinysbs = 1; /* fingers down the throat of echopol */
control.noforward = 0;
control.nolocalfor = 0;
control.forfiles = 0;
control.nodupes = 0;
control.keeppath = 0;
control.keepsbs = 0;
control.keepdupes = 0;
control.delbaddate = 0;
control.keepnoforwards = 0;
control.allowbadareas = 0;
while(!eof(handle)) {
if(!fgetsx(s,512,handle)) break; /* break if EOF */
p = strchr(s,';'); /* strip any comments */
if(p) *p = 0;
lstrip(s);
stripcr(s);
rstrip(s);
if(!*s) continue; /* blank line or comment */
wasplus = (char)(s[strlen(s) - 1] == '+');
p = skip_nonwhite(s); /* isolate keyword */
if(*p) { /* point p at any arg */
*p=0;
p++;
p = skip_white(p);
}
/* now process keyword/arg combination */
token = look_up(s);
switch(token) {
case 0:
printf("\nUnknown keyword \"%s\"\n",s);
break;
case PRIORITIES:
if(!machstate) {
printf("\nI can't adjust my priority under DOS.\n");
}
else {
pri1 = atoi(p);
if(pri1 < 1) pri1 = 1;
if(pri1 > 3) pri1 = 3;
p = skip_nonwhite(p);
p = skip_white(p);
pri2 = atoi(p);
if(pri2 < 0) pri2 = 0;
if(pri2 > 31) pri2 = 31;
DosGetPID(&pid);
if(!DosSetPrty(2,pri1,pri2,pid.thread)) {
printf("\nMy priority set to %d,%d\n",pri1,pri2);
}
else {
printf("\nCouldn't adjust my priority.\n");
}
}
break;
case ALLOWBADAREAS:
control.allowbadareas = 1;
break;
case KILLBADDATES:
control.delbaddate = 1;
break;
case KEEPDUPES:
control.keepdupes = 1;
break;
case KEEPSEENBYS:
control.keepsbs = 1;
break;
case KEEPNOFORWARDS:
control.keepnoforwards = 1;
break;
case KEEPPATH:
control.keeppath = 1;
break;
case LOGFILE:
logfile = assign(logfile,p);
break;
case NODUPES:
control.nodupes = 1;
break;
case MAXIMUMDUPES:
maxdupes = atoi(p);
if(maxdupes > 8150) maxdupes = 8150;
break;
case NOFORWARD:
control.noforward = 1;
break;
case NOLOCALFORWARD:
control.nolocalfor = 1;
break;
case FORWARDFILES:
control.forfiles = 1;
break;
case NOTINY:
control.tinysbs = 0;
break;
case MESSAGES:
putmsgs = assign(putmsgs,strip_trail_bksl(p));
break;
case GROUPIN:
groupin = assign(groupin,strip_trail_bksl(p));
break;
case GROUPOUT:
groupout = assign(groupout,strip_trail_bksl(p));
break;
case GROUPHOLD:
grouphold = assign(grouphold,strip_trail_bksl(p));
break;
case MSGDIR:
msgdir = assign(msgdir,strip_trail_bksl(p));
break;
case ARCHIVE:
archive = assign(archive,p);
break;
case UNARCHIVE:
unarchive = assign(unarchive,p);
break;
case NETAREA:
netarea = atoi(p);
break;
case TONAME:
if(p && *p) p++;
pp = to_delim(p,"\"");
if(!*pp) {
IncompleteTo:
printf("\nIncomplete To: \"%s\" skipped\n",p);
break;
}
*pp = 0;
pp++;
pp = skip_white(pp); /* point pp at keyword */
if(!*pp) goto IncompleteTo;
tinfo = (TONAMES *)malloc(sizeof(TONAMES));
tinfo->prgname = NULL;
tinfo->addr = NULL;
tinfo->next = NULL;
tinfo->msg = 0;
tinfo->route = 0;
tinfo->prog = 0;
tinfo->reserved = 0;
if(!tinfo) {
goto OutOfMemory;
}
tinfo->to = strdup(p);
if(!tinfo->to) {
my_free(tinfo);
goto OutOfMemory;
}
p = skip_nonwhite(pp);
p = skip_white(p);
if(!stricmp(pp,"ROUTE")) tinfo->route = 1;
else if(!stricmp(pp,"MSG")) tinfo->msg = 1;
else if(!stricmp(pp,"PROG")) tinfo->prog = 1;
else {
InvalidTo:
my_free(tinfo->to);
my_free(tinfo);
printf("\nInvalid To: command \"%s\"--skipped\n",pp);
break;
}
if(tinfo->route || tinfo->prog) {
if(!*p) {
my_free(tinfo->to);
my_free(tinfo);
goto IncompleteTo;
}
pp = skip_nonwhite(p);
if(*pp) *pp = 0;
}
if(tinfo->route) {
tinfo->addr = (ADDR *)malloc(sizeof(ADDR));
if(!tinfo->addr) {
my_free(tinfo->to);
my_free(tinfo);
goto OutOfMemory;
}
tinfo->addr->next = NULL;
pp = p;
if(parse_addr(&p,tinfo->addr,myaddr)) {
my_free(tinfo->to);
my_free(tinfo->addr);
my_free(tinfo);
printf("\nInvalid address \"%s\"--skipped\n",pp);
break;
}
}
else if(tinfo->prog) {
tinfo->prgname = strdup(strupr(p));
if(!tinfo->prgname) {
my_free(tinfo->to);
my_free(tinfo);
goto OutOfMemory;
}
}
if(!tonames) {
tonames = tinfo;
}
else {
tlast->next = tinfo;
}
tinfo->next = NULL;
tlast = tinfo;
break;
case GROUPR:
pp = skip_nonwhite(p);
if(!*pp) {
Incomplete:
printf("\nIncomplete group \"%s\" skipped\n",p);
break;
}
*pp = 0;
pp++;
pp = skip_white(pp); /* point pp at area # */
if(!*pp) goto Incomplete;
ginfo = (GROUP *)malloc(sizeof(GROUP));
if(!ginfo) {
OutOfMemory:
printf("\nOut of memory\n");
break;
}
ginfo->id = strdup(p);
if(!ginfo->id) {
my_free(ginfo);
goto OutOfMemory;
}
ginfo->reserved = 0;
ginfo->areano = atoi(pp);
ginfo->password = NULL;
ginfo->forwarded = ginfo->imported = ginfo->exported = 0;
pp = skip_nonwhite(pp);
if(!*pp) {
my_free(ginfo->id);
my_free(ginfo);
goto Incomplete;
}
*pp = 0;
pp++;
pp = skip_white(pp); /* point pp at numdays */
if(!*pp) {
my_free(ginfo->id);
my_free(ginfo);
goto Incomplete;
}
ginfo->numdays = atoi(pp);
pp = skip_nonwhite(pp);
if(!*pp) {
my_free(ginfo->id);
my_free(ginfo);
goto Incomplete;
}
*pp = 0;
pp++;
pp = skip_white(pp); /* point pp at address (or topstar option) */
if(!*pp) {
my_free(ginfo->id);
my_free(ginfo);
goto Incomplete;
}
if(*pp == '!') { /* top star */
ginfo->uplink = NULL;
if(toupper(pp[1]) == 'F') ginfo->style = 2;
else if(toupper(pp[1]) == 'P') ginfo->style = 1;
else {
ginfo->style = 0;
if(toupper(pp[1]) != 'N') {
printf("\nInvalid topstar option \"%c\" for group \"%s\"\n",
toupper(pp[1]),ginfo->id);
}
}
}
else {
ginfo->style = 0;
ginfo->uplink = (ADDR *)malloc(sizeof(ADDR));
if(!ginfo->uplink) {
my_free(ginfo->id);
my_free(ginfo);
goto OutOfMemory;
}
ginfo->uplink->next = NULL;
if(parse_addr(&pp,ginfo->uplink,myaddr)) {
printf("\nInvalid address info for group \"%s\"\n",ginfo->id);
my_free(ginfo->id);
my_free(ginfo->uplink);
my_free(ginfo);
break;
}
}
pp = skip_nonwhite(pp);
if(*pp) {
*pp = 0;
pp++;
pp = skip_white(pp); /* point pp at password */
if(*pp) {
ginfo->password = strdup(pp);
}
}
if(!group) {
group = ginfo;
}
else {
glast->next = ginfo;
}
ginfo->next = NULL;
glast = ginfo;
break;
case PACKSIZE:
packsize = atoi(p);
if(packsize && packsize < 1024) packsize = 1024;
break;
case XBBSOS2:
if(!machstate) {
printf("\nI can't access long file names from DOS,\n"
"therefore I can't support XBBS-OS/2 from DOS.\n");
close(handle);
return -1;
}
control.xbbsos2 = 1;
break;
case INBOUND:
inbound = assign(inbound,p);
break;
case OUTBOUND:
outbound = assign(outbound,strip_trail_bksl(p));
break;
case ROUTER:
if(!machstate) {
printf("\nI can't access long file names from DOS,\n"
"therefore I can't route for XBBS-OS/2 from DOS.\n");
break;
}
pp = skip_nonwhite(p);
if(!*pp) {
Incomplerte:
printf("\nIncomplete route \"%s\" skipped\n",p);
break;
}
*pp = 0;
pp++;
pp = skip_white(pp); /* point pp at type */
if(!*pp) goto Incomplerte;
rinfo = (ROUTE *)malloc(sizeof(ROUTE));
if(!rinfo) {
OutOfMemoryR:
printf("\nOut of memory\n");
break;
}
rinfo->mask = strdup(p);
rinfo->type = (char)toupper(*pp);
if(!strchr(valid_types,rinfo->type)) {
rinfo->type = 'H';
}
if(!rinfo->mask) {
my_free(rinfo);
goto OutOfMemoryR;
}
pp = skip_nonwhite(pp);
if(!*pp) {
my_free(rinfo->mask);
my_free(rinfo);
goto Incomplerte;
}
*pp = 0;
pp++;
pp = skip_white(pp); /* point pp at address */
if(!*pp) {
my_free(rinfo->mask);
my_free(rinfo);
goto Incomplerte;
}
p = skip_nonwhite(pp); /* point p at archive cmd */
if(*p) {
*p = 0;
p++;
}
p = skip_white(p);
if(!*p) {
my_free(rinfo->mask);
my_free(rinfo);
goto Incomplerte;
}
rinfo->archive = strdup(p);
if(!rinfo->archive) {
my_free(rinfo->mask);
my_free(rinfo);
goto OutOfMemoryR;
}
if(!stricmp(pp,"SAME")) {
rinfo->addr = NULL;
}
else {
rinfo->addr = (ADDR *)malloc(sizeof(ADDR));
if(!rinfo->addr) {
my_free(rinfo->archive);
my_free(rinfo->mask);
my_free(rinfo);
goto OutOfMemoryR;
}
rinfo->addr->next = NULL;
if(parse_addr(&pp,rinfo->addr,myaddr)) {
printf("\nInvalid address info for route \"%s\"\n",rinfo->mask);
my_free(rinfo->archive);
my_free(rinfo->mask);
my_free(rinfo->addr);
my_free(rinfo);
}
}
if(!routes) {
routes = rinfo;
}
else {
rlast->next = rinfo;
}
rinfo->next = NULL;
rlast = rinfo;
break;
case ECHOR:
pp = skip_nonwhite(p);
if(!*pp) {
Incomplecho:
printf("\nIncomplete echo \"%s\" skipped\n",p);
break;
}
*pp = 0;
pp++;
pp = skip_white(pp); /* point pp at area # */
if(!*pp) goto Incomplecho;
einfo = (ECHOREC *)malloc(sizeof(ECHOREC));
if(!einfo) {
OutOfMemoryE:
printf("\nOut of memory\n");
break;
}
einfo->forwarded = einfo->imported = einfo->exported = 0;
einfo->password = NULL;
einfo->tag = strdup(p);
if(!einfo->tag) {
my_free(einfo);
goto OutOfMemoryE;
}
einfo->areano = atoi(pp);
pp = skip_nonwhite(pp);
if(!*pp) {
einfo->addr = NULL;
goto SkipEchoAddr;
}
*pp = 0;
pp++;
pp = skip_white(pp); /* point pp at addresses, if any */
if(!*pp) {
einfo->addr = NULL;
goto SkipEchoAddr;
}
einfo->addr = (ADDR *)malloc(sizeof(ADDR));
if(!einfo->addr) {
my_free(einfo->tag);
my_free(einfo);
goto OutOfMemoryE;
}
einfo->addr->next = NULL;
if(parse_addr(&pp,einfo->addr,myaddr)) {
printf("\nInvalid address info for echo \"%s\"\n",einfo->tag);
my_free(einfo->tag);
my_free(einfo->addr);
my_free(einfo);
break;
}
ealast = einfo->addr;
AnotherLine:
while(pp && *pp) {
ainfo = (ADDR *)malloc(sizeof(ADDR));
if(!ainfo) goto OutOfMemoryE;
if(parse_addr(&pp,ainfo,einfo->addr)) {
my_free(ainfo->domain);
my_free(ainfo);
break;
}
ealast->next = ainfo;
ainfo->next = NULL;
ealast = ainfo;
}
if(wasplus) {
if(fgetsx(s,1023,handle)) {
pp = strchr(s,';'); /* strip any comments */
if(pp) *pp = 0;
lstrip(s);
stripcr(s);
rstrip(s);
if(*s) {
wasplus = (char)(s[strlen(s) - 1] == '+');
pp = s;
goto AnotherLine;
}
}
}
SkipEchoAddr:
if(!echos) {
echos = einfo;
}
else {
elast->next = einfo;
}
einfo->next = NULL;
elast = einfo;
break;
case ANADDRESS:
ainfo = (ADDR *)malloc(sizeof(ADDR));
if(!ainfo) {
OutOfMemoryA:
printf("\nOut of memory\n");
break;
}
if(parse_addr(&p,ainfo,myaddr)) {
printf("\nInvalid address skipped\n");
my_free(ainfo->domain);
my_free(ainfo);
break;
}
if(!myaddr) {
myaddr = ainfo;
}
else {
alast->next = ainfo;
}
ainfo->next = NULL;
alast = ainfo;
while(p && *p) {
ainfo = (ADDR *)malloc(sizeof(ADDR));
if(!ainfo) goto OutOfMemoryA;
if(parse_addr(&p,ainfo,myaddr)) {
my_free(ainfo->domain);
my_free(ainfo);
break;
}
if(!myaddr) {
myaddr = ainfo;
}
else {
alast->next = ainfo;
}
ainfo->next = NULL;
alast = ainfo;
}
break;
}
}
close(handle);
if((group && (!groupin || !groupout)) || !msgdir || (!group && !echos) ||
!archive || !outbound || !inbound || !myaddr || !netarea) {
printf("\nFatal error: \"%s\" missing vital info:\n",configfile);
if(group && !groupin) printf("GROUPIN directory\n");
if(group && !groupout) printf("GROUPOUT directory\n");
if(!msgdir) printf("MSGDIR directory\n");
if(!echos && !group) printf("GROUPs and/or ECHOs\n");
if(!archive) printf("ARCHIVE command\n");
if(!unarchive) printf("UNARCHIVE command\n");
if(!outbound) printf("OUTBOUND directory\n");
if(!inbound) printf("INBOUND directory\n");
if(!myaddr) printf("ADDRESS\n");
if(!netarea) printf("NETAREA #\n");
return -1;
}
if(logfile && *logfile) {
logfilehandle = sopen(logfile,O_RDWR | O_BINARY | O_CREAT,SH_DENYWR,S_IWRITE | S_IREAD);
if(logfilehandle != -1) lseek(logfilehandle,0L,SEEK_END);
}
if(!maxdupes) control.nodupes = 1;
return 0;
}
static int _fastcall look_up (char *s) {
/* Look up a token's internal representation in the token table */
register int i = 0;
while(table[i].keyword) {
if(!stricmp(table[i].keyword,s)) return (int)table[i].tok;
i++;
}
return 0; /* unknown command */
}