home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
VP2SRC.ZIP
/
AREASBBS.C
< prev
next >
Wrap
Text File
|
1991-04-20
|
21KB
|
683 lines
/*
$Header: areasbbs.c 3.3 87/12/12 00:40:08 Bob Exp $
The Conference Mail System
This module was originally written by Bob Hartman
Sysop of FidoNet node 1:132/101
Spark Software, 427-3 Amherst St, CS 2032, Suite 232, Nashua, NH 03061
The Conference Mail System is a complete Echomail processing package. It
is a superset of the original Echomail utilities created by Jeff Rush, and
also contains ideas gleaned from the ARCmail, Renum, oMMM, MGM, and Opus
programs that were created by various software authors.
This program source code is being released with the following provisions:
1. You are free to make changes to this source code for use on your own
machine, however, altered source files may not be distributed without the
consent of Spark Software.
2. You may distribute "patches" or "diff" files for any changes that you
have made, provided that the "patch" or "diff" files are also sent to Spark
Software for inclusion in future releases of the entire package. A "diff"
file for the source archives may also contain a compiled version, provided
it is clearly marked as not being created from the original source code.
No other executable versions may be distributed without the consent of
Spark Software.
3. You are free to include portions of this source code in any program you
develop, providing: a) Credit is given to Spark Software for any code that
may is used, and b) The resulting program is free to anyone wanting to use
it, including commercial and government users.
4. There is NO technical support available for dealing with this source
code, or the accompanying executable files. This source code is provided
as is, with no warranty expressed or implied (I hate legalease). In other
words, if you don't know what to do with it, don't use it, and if you are
brave enough to use it, you're on your own.
Spark Software may be contacted by modem at (603) 888-8179 (node 1:132/101)
on the public FidoNet network, or at the address given above.
To use this code you will need Microsoft C version 4.0, and also Microsoft
Macro Assembler version 4.0.
*/
/*
$Log: areasbbs.c $
* Revision 3.3 87/12/12 00:40:08 Bob
* Source code release
*
*/
#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <process.h>
#include "fastecho.h"
#define DEBUG 0
/* Remember to change the security check routine also! */
#ifdef OS2
char *NAME="\r\n--- VPurge[OS/2] V%s\r\n";
#else /* OS2 */
char *NAME="\r\n--- VPurge [DOS] V%s\r\n";
#endif /* OS2 */
extern SEACONFIG config;
extern AREAS_PTR areas[];
extern char board_name[], sysop_name[];
extern int tot_areas;
extern char bbsfile[];
extern int seen_aka;
char tmpjunk[256], tmpjunk1[80], tmpjunk2[80];
extern char *areaserr;
int priv_net = 0;
int boss_net = 0;
int boss_node = 0;
int zone_zone[10];
int zone_net[10];
int zone_node[10];
int num_zone = 0;
int pass_thru = -1;
int route_thru = -1;
int bad_msgs = -1;
int do_pickup = 0;
int mail_dir = -1;
char pickup_dir[64];
extern PW_PTR pw[];
extern int num_pw;
int compile_areas (char *fname)
{
FILE *f;
char *p, *q, *r;
int i, k, last_net, err, intt1, intt2, last_zone;
int *tmpzone, *tmpnet, *tmpnode;
AREAS *aptr, *aptr1;
PW_PTR pptr;
tmpzone = (int *) malloc (sizeof(int) * 100);
tmpnet = (int *) malloc (sizeof(int) * 100);
tmpnode = (int *) malloc (sizeof (int) * 100);
if ((tmpnet == NULL) || (tmpnode == NULL) || (tmpzone == NULL))
{
printf (areaserr);
exit (2);
}
strncpy (bbsfile, fname, 80);
if (bbsfile[0] == '\0')
strcpy (bbsfile, "AREAS.BBS");
if ((f = fopen (bbsfile, "r")) == NULL)
{
#if DEBUG
printf ("Could not open AREAS file\n");
#endif
free ((char *) tmpzone);
free ((char *) tmpnet);
free ((char *) tmpnode);
return (-1);
}
#if DEBUG
printf ("Going into areasbbs loop\n");
#endif
tot_areas = -1;
while (echo_fgets (tmpjunk, 256, f) != 0)
{
/* Was it a comment line? */
if (tmpjunk[0] == ';')
{
/* Yes it was, so continue */
continue;
}
#if DEBUG
printf ("Got '%s'\n", tmpjunk);
#endif
/* Was it a special FastEcho line? */
if (tmpjunk[0] == '-')
{
/* Yes it was, so do whatever it says */
if (strnicmp (tmpjunk, "-ZONEGATE=", 10) == 0)
{
/* It is a ZONEGATE statement */
q = &tmpjunk[10];
i = 0;
last_zone = config.net[1];
while (*q)
{
zone_net[num_zone] = atoi (q);
while (*q)
{
if (*q == '/')
break;
else
++q;
}
if (*q == '/')
{
++q;
zone_node[num_zone] = atoi (q);
last_zone = zone_net[num_zone];
}
else
{
zone_node[num_zone] = zone_net[num_zone];
zone_net[num_zone] = last_zone;
}
++num_zone;
while (*q)
{
if (isdigit(*q))
++q;
else
break;
}
while (*q)
{
if (isspace(*q))
++q;
else
break;
}
}
continue;
}
if (strnicmp (tmpjunk, "-PASSWORD=", 9) == 0)
{
/* It is a PASSWORD statement */
q = &tmpjunk[10];
intt1 = atoi (q);
while (*q)
{
if (!isdigit(*q))
break;
else
++q;
}
if (*q == '/')
{
++q;
intt2 = atoi (q);
}
else
{
intt2 = intt1;
intt1 = config.net[1];
}
while (*q)
{
if (isdigit(*q) || isspace(*q))
++q;
else
break;
}
p = q;
while (*q)
{
if (isspace (*q))
{
*q = '\0';
break;
}
++q;
}
/* If we are here we have the proper net/node for the password
and we are pointing at the password itself, now just fill
in the proper fields and increment the counter */
pptr = pw[num_pw] = (PW_PTR) calloc (1, sizeof (PW));
if (pptr == NULL)
{
printf (areaserr);
exit (2);
}
pptr->net = intt1;
pptr->node = intt2;
/* Length of password hoped for */
intt1 = strlen(p);
/* Max it out at 8 */
intt2 = (intt1>8)?8:intt1;
/* Allocate 9 bytes */
pptr->password = calloc (1, 9);
/* Copy in what we have */
strncpy (pptr->password, p, intt2);
for (intt1 = 0; intt1 < 8; intt1++)
pptr->password[intt1] = (char) toupper (pptr->password[intt1]);
++num_pw;
continue;
}
#if POINT_TYPE
else if (strnicmp (tmpjunk, "-PICKUPDIR=", 11) == 0)
{
q = &tmpjunk[11];
while (*q && !isspace (*q))
++q;
*q = '\0';
strcpy (pickup_dir, &tmpjunk[11]);
do_pickup = 1;
continue;
}
else if (strnicmp (tmpjunk, "-POINTNET=", 10) == 0)
{
/* It is a POINTNET statement */
q = &tmpjunk[10];
priv_net = atoi (q);
#if DEBUG
printf ("Point network '%d' found\n", priv_net);
#endif
continue;
}
else if (strnicmp (tmpjunk, "-BOSSNODE=", 10) == 0)
{
q = &tmpjunk[10];
boss_net = atoi (q);
while (*q)
{
if (*q == '/')
break;
else
++q;
}
if (*q == '/')
{
++q;
boss_node = atoi (q);
}
else
{
boss_node = boss_net;
boss_net = config.net[1];
}
continue;
}
#endif
continue;
}
p = tmpjunk;
q = tmpjunk1;
/* Extract first word */
if (get_word (&p, q) == 0)
{
continue;
}
/* Is this the header stuff? */
if (tot_areas == -1)
{
/* It is, so create the board name and sysop name */
q = (char *) (tmpjunk + strlen (tmpjunk) - 1);
while ((q >= tmpjunk) && (isspace (*q)))
*q-- = '\0';
if ((q = strrchr (tmpjunk, '!')) != NULL)
{
r = q-1;
while (isspace (*r))
{
*r-- = '\0';
}
*q++ = '\0';
while (isspace (*q))
++q;
strncpy (sysop_name, q, 126);
strncpy (board_name, tmpjunk, 126);
tot_areas = 0;
continue;
}
else
{
strncpy (board_name, tmpjunk, 126);
tot_areas = 0;
continue;
}
}
q = tmpjunk1;
if (q[strlen(q)-1] == '\\')
q[strlen(q)-1] = '\0';
while (*q)
{
*q = (char) toupper (*q);
++q;
}
strcpy (tmpjunk2, tmpjunk1);
/* Is it a legitimate directory? */
if (!(filedir (tmpjunk1, 0, tmpjunk1, ST_DIRECT) & ST_DIRECT))
{
strcpy (tmpjunk1,tmpjunk2);
/* Not a directory, continue on */
if (get_fido_sys (tmpjunk1, 1))
{
continue;
}
}
else
strcpy (tmpjunk1, tmpjunk2);
/* It is the message path directly */
aptr = areas[tot_areas] = (AREAS_PTR) calloc (1, sizeof (AREAS));
if (aptr == NULL)
{
printf (areaserr);
exit (2);
}
aptr->msg_path = malloc ((unsigned) (strlen(tmpjunk1)+1));
if (aptr->msg_path == NULL)
{
printf (areaserr);
exit (2);
}
strcpy (aptr->msg_path, tmpjunk1);
q = aptr->msg_path;
while (*q)
{
*q = (char) toupper(*q);
++q;
}
/* Now get the next word into the area name field */
q = tmpjunk1;
if (get_word (&p, q) == 0)
{
continue;
}
while (*q)
{
*q = (char) toupper (*q);
++q;
}
aptr->area_name = malloc ((unsigned) (strlen (tmpjunk1)+1));
if (aptr->area_name == NULL)
{
printf (areaserr);
exit (2);
}
strcpy (aptr->area_name, tmpjunk1);
if (strcmp (tmpjunk1, "PASSTHRU") == 0)
{
aptr->flags |= PASS_THRU;
pass_thru = tot_areas;
}
else if (strcmp (tmpjunk1, "ROUTETHRU") == 0)
{
aptr->flags |= ROUTETHRU;
route_thru = tot_areas;
}
else if (strcmp (tmpjunk1, "BAD_MSGS") == 0)
{
aptr->flags |= BAD_MSGS;
bad_msgs = tot_areas;
}
else if (strcmp (tmpjunk1, "aMAIL_DIR") == 0)
{
aptr->flags |= MAIL_DIR;
mail_dir = tot_areas;
}
#ifdef VPURGE
#if DEBUG
printf ("Checking for V_PURGE now.\n");
#endif
if (strchr(tmpjunk, '#') != NULL)
{
#if DEBUG
printf ("Setting V_PURGE now.\n");
#endif
aptr->flags |= V_PURGE;
}
#endif
/* Finally, get all of the net/node pairs */
i = 0;
last_net = config.net[1];
while (get_word (&p, tmpjunk1) != 0)
{
if ((err = sscanf (tmpjunk1, "%d:%d/%d", &(tmpzone[i]), &(tmpnet[i]),
&(tmpnode[i]))) < 3)
{
if (err == 0)
continue;
tmpzone[i] = config.zone[1];
if ((err = sscanf (tmpjunk1, "%d/%d", &(tmpnet[i]),
&(tmpnode[i]))) < 2)
{
tmpnode[i] = tmpnet[i];
tmpnet[i] = last_net;
}
}
#if DEBUG
printf ("Using %d:%d/%d for i=%d\n", tmpzone[i], tmpnet[i], tmpnode[i], i);
#endif
for (k = 0; k < i; k++)
{
if ((tmpnet[k] == tmpnet[i]) &&
(tmpnode[k] == tmpnode[i]) &&
(tmpzone[k] == tmpzone[i]))
{
break;
}
}
if (k >= i)
{
last_net = tmpnet[i];
++i;
}
}
aptr->num_nodes = i;
aptr->zone = (int *) malloc ((unsigned) (sizeof(int) * (i + seen_aka)));
aptr->net = (int *) malloc ((unsigned) (sizeof(int) * (i + seen_aka)));
aptr->node = (int *) malloc ((unsigned) (sizeof (int) * (i + seen_aka)));
aptr->handle = (int *) malloc ((unsigned) (sizeof (int) * (i + seen_aka)));
aptr->aname = (char **) malloc ((unsigned) (sizeof (char *) * (i + seen_aka)));
if ((aptr->net == NULL) || (aptr->node == NULL) || (aptr->zone == NULL) ||
(aptr->handle == NULL) || (aptr->aname == NULL))
{
printf (areaserr);
exit (2);
}
for (i = 0; i < aptr->num_nodes; i++)
{
aptr->zone[i] = tmpzone[i];
aptr->net[i] = tmpnet[i];
aptr->node[i] = tmpnode[i];
}
for (i = 0; i < aptr->num_nodes + seen_aka; i++)
{
aptr->handle[i] = -1;
aptr->aname[i] = aptr->area_name;
}
if (tot_areas > 0)
{
for (i = 0; i < tot_areas; i++)
{
if (strcmp (aptr->msg_path, areas[i]->msg_path) == 0)
{
aptr->msgs_in_area = areas[i]->msgs_in_area;
aptr->flags |= SIBLING;
areas[i]->flags |= PARENT;
/* Now add to the PARENT */
aptr1 = areas[i];
aptr1->zone = (int *) realloc ((char *) aptr1->zone, (unsigned) (sizeof(int) *
(aptr1->num_nodes + aptr->num_nodes + seen_aka)));
aptr1->net = (int *) realloc ((char *) aptr1->net, (unsigned) (sizeof(int) *
(aptr1->num_nodes + aptr->num_nodes + seen_aka)));
aptr1->node = (int *) realloc ((char *) aptr1->node, (unsigned) (sizeof (int) *
(aptr1->num_nodes + aptr->num_nodes + seen_aka)));
aptr1->handle = (int *) realloc ((char *) aptr1->handle, (unsigned) (sizeof (int) *
(aptr1->num_nodes + aptr->num_nodes + seen_aka)));
aptr1->aname = (char **) realloc ((char *) aptr1->aname, (unsigned) (sizeof (char *) *
(aptr1->num_nodes + aptr->num_nodes + seen_aka)));
if ((aptr1->net == NULL) || (aptr1->node == NULL) || (aptr1->zone == NULL) ||
(aptr1->handle == NULL) || (aptr1->aname == NULL))
{
printf (areaserr);
exit (2);
}
for (k = aptr1->num_nodes; k < aptr1->num_nodes+aptr->num_nodes; k++)
{
aptr1->zone[k] = aptr->zone[k-aptr1->num_nodes];
aptr1->net[k] = aptr->net[k-aptr1->num_nodes];
aptr1->node[k] = aptr->node[k-aptr1->num_nodes];
}
for (k = aptr1->num_nodes; k < aptr1->num_nodes+aptr->num_nodes; k++)
{
aptr1->handle[k] = aptr->handle[k-aptr1->num_nodes];
aptr1->aname[k] = aptr->aname[k-aptr1->num_nodes];
}
aptr1->num_nodes += aptr->num_nodes;
sort_em (&(aptr1->zone[0]), &(aptr1->net[0]), &(aptr1->node[0]),
aptr1->num_nodes, 1, &(aptr1->handle[0]),
&(aptr1->aname[0]));
break;
}
}
if (i >= tot_areas)
{
aptr->msgs_in_area = (int *) calloc (1, sizeof (int));
*(aptr->msgs_in_area) = -1;
}
}
else
{
aptr->msgs_in_area = (int *) calloc (1, sizeof (int));
*(aptr->msgs_in_area) = -1;
}
#if DEBUG
printf ("\nRECAP1\n\n");
for (i = 0; i < tot_areas; i++)
{
printf ("AREA #%2d: DIR='%s' NAME='%s'\n", i, areas[i]->msg_path,
areas[i]->area_name);
for (k = 0; k < areas[i]->num_nodes; k++)
printf ("NODE %d=%d:%d/%d:%s\n", k, areas[i]->zone[k], areas[i]->net[k], areas[i]->node[k], areas[i]->aname[k]);
}
#endif
sort_em (&(aptr->zone[0]), &(aptr->net[0]), &(aptr->node[0]),
aptr->num_nodes, 1, &(aptr->handle[0]), &(aptr->aname[0]));
#if DEBUG
for (k = 0; k < aptr->num_nodes; k++)
printf ("Net/node[%d] = %d:%d/%d\n", k, aptr->zone[k], aptr->net[k], aptr->node[k]);
#endif
++tot_areas;
}
#if DEBUG
printf ("\nRECAP\n\n");
for (i = 0; i < tot_areas; i++)
{
printf ("AREA #%2d: DIR='%s' NAME='%s'\n", i, areas[i]->msg_path,
areas[i]->area_name);
for (k = 0; k < areas[i]->num_nodes; k++)
printf ("NODE %d=%d:%d/%d:%s\n", k, areas[i]->zone[k], areas[i]->net[k], areas[i]->node[k], areas[i]->aname[k]);
}
#endif
free ((char *) tmpzone);
free ((char *) tmpnet);
free ((char *) tmpnode);
fclose (f);
if (num_zone)
{
sort_em (&(zone_zone[1]), &(zone_net[1]), &(zone_node[1]), num_zone-1, 0, NULL, NULL);
}
return (0);
}
void sort_em(
int zones[],
int nets[],
int nodes[],
int num_nodes,
int others,
int o1[],
char *o2[])
{
register int i, j;
int tmp1, tmp2, tmp3, swaps;
char *tmp4;
i = 0;
j = num_nodes;
swaps = 1;
while (swaps)
{
for (j--, i = 0, swaps = 0; i < j; i++)
{
if ((nets[i] > nets[i+1]) ||
((nets[i] == nets[i+1]) && (nodes[i] > nodes[i+1])))
{
tmp3 = zones[i];
tmp1 = nets[i];
tmp2 = nodes[i];
zones[i] = zones[i+1];
nets[i] = nets[i+1];
nodes[i] = nodes[i+1];
zones[i+1] = tmp3;
nets[i+1] = tmp1;
nodes[i+1] = tmp2;
if (others)
{
tmp1 = o1[i];
tmp4 = o2[i];
o1[i] = o1[i+1];
o2[i] = o2[i+1];
o1[i+1] = tmp1;
o2[i+1] = tmp4;
}
++swaps;
}
}
}
/*
for (i = 0; i < num_nodes; i++)
{
printf ("%d = %d/%d\n", i, nets[i], nodes[i]);
}
for (i = 0; i < num_nodes; i++)
for (j = i+1; j < num_nodes; j++)
{
if ((nets[j] < nets[i]) ||
((nets[j] == nets[i]) && (nodes[j] < nodes[i])))
{
tmp1 = nets[i];
tmp2 = nodes[i];
nets[i] = nets[j];
nodes[i] = nodes[j];
nets[j] = tmp1;
nodes[j] = tmp2;
}
}
*/
}