home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
OS2OMMM.SRC
/
ROUTEMSC.C
< prev
Wrap
Text File
|
1989-06-01
|
14KB
|
594 lines
/***************************************************************************/
/*** ***/
/*** oMMM - The Outbound Matrix Message Masher ***/
/*** Copyright 1989 BS Software ***/
/*** ***/
/*** FILENAME: ROUTEMSC.C ***/
/*** ***/
/*** Miscellaneous Router Functions ***/
/*** ***/
/*** Based on the original oMMM, a portion of ***/
/*** the Opus Computer-Based Conversation System ***/
/*** Copyright 1986, Wynn Wagner III ***/
/*** ***/
/***************************************************************************/
/*** ***/
/*** Tabs set at every 4th column ***/
/*** ***/
/***************************************************************************/
/*
Polytron Version Control System Comments:
The revision of this file is *** $Revision: 1.40 $ ***
History of changes from 1.30 release version
$Log: C:/OMMM/PROJFILE/ROUTEMSC.C_V $
*
* Rev 1.40BP 2 June 1989 20:22:00 Bill Andrus
* Public Release Version 1.40BP (OS/2 Protected and Bound)
*
* Rev 1.40 12 Feb 1989 4:56:52 Marshall Presnell
* Public Release Version 1.40
*
* Rev 1.31 31 Jan 1989 0:59:00 Marshall Presnell
* oMMM 1.35 Beta Release Version
*
* Rev 1.30 23 Jan 1989 17:54:04 Marshall Presnell
* Public Source Code Release - Version 1.30
*/
/*--------------------------------------------------------------------------*/
/* Include files */
/*--------------------------------------------------------------------------*/
#include "ommm.h"
#ifdef MSC
#include <sys\types.h>
#endif
#include <sys\stat.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <time.h>
#ifdef ZTC
# include <sys\stat.h>
# include <dos.h>
#endif
/*--------------------------------------------------------------------------*/
/* Static function declarations */
/*--------------------------------------------------------------------------*/
static void append_flo(char *oldname, char *newname);
/*--------------------------------------------------------------------------*/
/* Static variable definitions */
/*--------------------------------------------------------------------------*/
static char modpktpath[100];
static unsigned int last_dig = 0;
static char * name_storage[256];
static char t1[100];
/*--------------------------------------------------------------------------*/
/* External variable declarations */
/*--------------------------------------------------------------------------*/
extern NETADDRESS ctlnet[];
/*--------------------------------------------------------------------------*/
/* External function declarations */
/*--------------------------------------------------------------------------*/
#ifdef ZTC
int access(char *fn, int mode);
#endif
/*--------------------------------------------------------------------------*/
/* Local Definitions */
/*--------------------------------------------------------------------------*/
#ifdef ZTC
# define O_BINARY 0
# define ENOTBLK 15
#endif
/****************************************************************************/
/*--------------------------------------------------------------------------*/
/* PULL ADDRESS */
/*--------------------------------------------------------------------------*/
char *
pull_address(char * s)
{
static char * others = "others";
static char * all = "all";
static char * world = "world";
static char * ournet = "ournet";
static char * netword = "net";
unsigned int u;
char * t;
s = stpblk(s);
t = s;
cur.zone = our_zone;
if (isdigit(*t)) {
while (isdigit(*t))
++t;
if (*t == ':') {
u = atoi(s);
while (isdigit(s[0]))
s++;
cur.zone = u;
++s;
}
}
if (isdigit(s[0])) {
u = atoi(s);
while (isdigit(s[0]))
s++;
if (s[0] == '/') {
cur.net = u;
s++;
if (isdigit(s[0])) {
cur.node = atoi(s);
while (isdigit(s[0]))
s++;
} else if (!strncmp(s, others, 6)) {
cur.node = DO_OTHERS;
s += 6;
} else if (!strncmp(s, all, 3)) {
cur.node = DO_ALL;
s += 3;
} else if (!strncmp(s, world, 5)) {
cur.node = DO_ALL;
s += 5;
}
} else {
cur.net = OURNET;
cur.node = u;
}
} else if (!strncmp(s, others, 6)) {
cur.net = DO_OTHERS;
s += 6;
} else if (!strncmp(s, ournet, 6)) {
cur.net = DO_OURNET;
s += 6;
} else if (!strncmp(s, all, 3)) {
cur.net = DO_ALL;
cur.node = DO_ALL;
s += 3;
} else if (!strncmp(s, world, 5)) {
cur.net = DO_ALL;
cur.node = DO_ALL;
s += 5;
} else if (!strncmp(s, netword, 3)) {
cur.net = atoi(&s[3]);
cur.node = DO_ALL;
s += 3;
while (isdigit(s[0]))
++s;
} else {
while (s[0] && (!isalnum(s[0])))
++s;
cur.net = DO_ILLEGAL;
cur.node = DO_ILLEGAL;
}
return (s);
}
/*--------------------------------------------------------------------------*/
/* ADD PARM */
/*--------------------------------------------------------------------------*/
void
add_parm(char * parm)
{
struct _dta dta;
char temp[80];
char new_fname[80];
char ournet_str[10];
int i;
unsigned int curr_net;
unsigned int net1;
unsigned int node1;
# ifdef IBMC
char tnet[5];
char tnode[5];
# endif
char * format;
if (cur.node == DO_OTHERS)
cur.net = DO_OTHERS;
if (cur.net == DO_ALL)
cur.node = DO_ALL;
if (cur.net == DO_OURNET)
cur.node = DO_ALL;
if (cur.node == DO_ALL)
format = "%s%04x*.OUT";
else
format = "%s%04x%04x.OUT";
curr_net = cur.net;
if ((cur.net == DO_OTHERS) || (cur.net == DO_ALL)) {
format = "%s*.OUT";
} else if (cur.net == DO_OURNET) {
curr_net = OURNET;
}
sprintf(temp, format, adjust_packet_path(cur.zone), curr_net, cur.node);
sprintf(ournet_str, "%04X", ctlnet[0].net);
if (!dir_findfirst(temp, NORMAL, &dta)) {
do {
if (cur.net == DO_OTHERS) {
if (!strncmp(ournet_str, dta.name, 4)) {
continue;
}
}
sprintf(temp, "%s%s", adjust_packet_path(cur.zone), dta.name);
# ifdef IBMC
sscanf(dta.name, "%4s%4s", tnet, tnode);
sscanf(tnet, "%04x", &net1);
sscanf(tnode, "%04x", &node1);
# else
sscanf(dta.name, "%04x%04x", &net1, &node1);
# endif
i = strlen(temp) - 1;
temp[i--] = 'O';
temp[i--] = 'L';
temp[i] = 'F';
if ((!access(temp, 0)) && (dest.net != cur.net) && (cur.node != dest.node)) {
continue;
}
temp[i++] = 'O';
temp[i++] = 'U';
temp[i] = 'T';
# ifdef RANDALL
dostime(&hr, &mn, &se);
dosdate(&mo, &md, &yr, &i);
# endif
do {
errno = 0;
rename(temp, strcpy(new_fname,get_packet_name(our_zone,net1,node1)));
++last_dig;
} while (errno == ENOTBLK);
if (errno) {
perror("Can't rename");
continue;
}
if ((strlen(parm) + strlen(new_fname) + strlen(adjust_packet_path(cur.zone)) + 30) > 100) {
archive(parm);
parm[0] = 0;
}
strcat(parm, new_fname);
strcat(parm," ");
} while (!dir_findnext(&dta));
}
}
/*--------------------------------------------------------------------------*/
/* MAKE NORMAL */
/*--------------------------------------------------------------------------*/
void
make_normal(int zone, char * template1, char newtype, int verbose)
{
register char * p;
register char * q;
char template[80];
char oldname[80];
char newname[80];
# ifdef IBMC
char tnet[5];
char tnode[5];
# endif
int nnet;
int nnode;
int i;
int j;
if (verbose)
printf("\nNormalizing ...\n");
sprintf(template, "%s%s", adjust_packet_path(zone), template1);
big_loop:
if (dir_findfirst(template, NORMAL, &dta)) {
if (verbose)
printf("\rNormalizing completed\n");
return;
}
i = 0;
do {
name_storage[i] = malloc(80);
if (!name_storage[i]) {
printf("MEM\n");
exit(1);
}
sprintf(name_storage[i++], "%s", dta.name);
} while ((!dir_findnext(&dta)) && (i < 256));
for (j = 0; j < i; j++) {
sprintf(oldname, "%s%s", adjust_packet_path(zone), name_storage[j]);
strcpy(newname, adjust_packet_path(zone));
q = &newname[strlen(newname)];
for (p = name_storage[j]; *p != '.';)
*q++ = *p++;
*q++ = '.';
if (newtype == 'O') {
p += 2;
*q++ = *p++;
switch (*p) {
case 'T':
*q++ = 'U';
break;
case 'O':
*q++ = 'L';
break;
case 'Q':
*q++ = 'E';
break;
case 'S':
default:
free(name_storage[j]);
continue;
}
*q++ = *p;
# ifdef IBMC
sscanf(name_storage[j], "%4s%4s", tnet, tnode);
sscanf(tnet, "%04x", &nnet);
sscanf(tnode, "%04x", &nnode);
# else
sscanf(name_storage[j], "%04x%04x", &nnet, &nnode);
# endif
if (!verbose)
printf("\rSEND TO %d:%d/%d", zone, nnet, nnode);
} else {
p += 2;
switch (*p) {
case 'U':
if (newtype == 'o')
*q++ = 'O';
else
*q++ = newtype;
break;
case 'L':
if (newtype == 'o')
*q++ = 'F';
else
*q++ = newtype;
break;
case 'E':
case 'M':
default:
free(name_storage[j]);
continue;
}
*q++ = *p++;
*q++ = *p++;
# ifdef IBMC
sscanf(name_storage[j], "%4s%4s", tnet, tnode);
sscanf(tnet, "%04x", &nnet);
sscanf(tnode, "%04x", &nnode);
# else
sscanf(name_storage[j], "%04x%04x", &nnet, &nnode);
# endif
if (!verbose)
printf("\r%s %d:%d/%d", ((newtype != 'C') ? ((newtype != 'H') ? ((newtype != 'D') ? "UNDO " : "DIRECT ") :
"HOLD ") : "CM "),zone,nnet, nnode);
}
*q = 0;
q--;
free(name_storage[j]);
if (!access(newname, 0)) {
if (*q == 'O') {
/* Handle the case of a FLO file collision */
append_flo(oldname, newname);
} else {
/* Handle the case of a packet collision */
append_out(oldname, newname);
}
} else {
errno = 0;
/*
* This is not at all right. I believe the kludge
* could result in
*/
/* multiple flow files existing in the outbound. */
# ifdef ADD_STUFF
if (!AddFlag)
rename(oldname, newname);
# else
rename(oldname, newname);
# endif
if (errno) {
printf("\nCan't rename '%s' to '%s'\n", oldname, newname);
}
}
}
if (i == 256)
goto big_loop;
if (verbose)
printf("\rNormalizing completed\n");
}
/*--------------------------------------------------------------------------*/
/* APPEND FLO LOCAL FUNCTION */
/*--------------------------------------------------------------------------*/
static void
append_flo(char * oldname, char * newname)
{
FILE * in1;
FILE * out1;
printf("\nappend_flo: %s %s\n",
oldname,
newname);
# ifdef ADD_STUFF
if (AddFlag) {
printf("Add mode - skipping flow file alteration\n");
return;
}
# endif
in1 = fopen(oldname, "rt");
if (in1 == NULL) {
printf("\rName collision cannot be avoided '%s' -=> '%s'\n", oldname, newname);
return;
}
out1 = fopen(newname, "at");
if (out1 == NULL) {
printf("\rName collision cannot be avoided '%s' -=> '%s'\n", oldname, newname);
fclose(in1);
in1 = NULL;
return;
}
printf("adding %s to %s\n", oldname, newname);
while (fgets(t1, 100, in1)) {
fputs(t1, out1);
putc('\n', out1);
}
fclose(in1);
fclose(out1);
in1 = out1 = NULL;
unlink(oldname);
}
/*--------------------------------------------------------------------------*/
/* APPEND OUT */
/*--------------------------------------------------------------------------*/
void
append_out(char * oldname, char * newname)
{
FILE * in1;
FILE * out1;
in1 = fopen(oldname, "rb");
out1 = fopen(newname,"r+b");
fseek(in1, (long) sizeof(struct _pkthdr), SEEK_SET);
fseek(out1, -2L, SEEK_END);
buffer = malloc(BUFFER_SIZE);
if (!buffer) {
printf("MEM\n");
return;
}
copy_out(in1, out1, buffer, BUFFER_SIZE);
fclose(in1);
fclose(out1);
in1 = out1 = NULL;
free(buffer);
unlink(oldname);
}
/*--------------------------------------------------------------------------*/
/* ADJUST PACKET PATH */
/*--------------------------------------------------------------------------*/
char *
adjust_packet_path(int n)
{
char *p;
if ((n <= 0) || (our_zone == 0) || (n == our_zone))
return (holding_path);
strcpy(modpktpath, holding_path);
p = modpktpath + strlen(modpktpath) - 1;
sprintf(p, ".%03x\\", n);
return (modpktpath);
}
/*--------------------------------------------------------------------------*/
/* ACCESS FOR ZORTECH */
/*--------------------------------------------------------------------------*/
#ifdef ZTC
int
access(char * fn, int mode)
{
struct stat buf;
if (stat(fn, &buf) != 0)
return (-1);
if (mode == 0) {
errno = 0;
return (0);
}
if ((mode & 6) == 2)
if ((buf.st_mode & S_IWRITE) == 0) {
errno = EACCES;
return (-1);
} else {
errno = 0;
return (0);
}
if ((mode & 6) == 4)
if ((buf.st_mode & S_IREAD) == 0) {
errno = EACCES;
return (-1);
} else {
errno = 0;
return (0);
}
if ((mode & 6) == 6)
if (((buf.st_mode & S_IREAD) == 0) &&
((buf.st_mode & S_IWRITE) == 0)) {
errno = EACCES;
return (-1);
} else {
return (0);
errno = 0;
}
errno = EACCES;
return (-1);
}
#endif
/*--------------------------------------------------------------------------*/
/* END OF FILE */
/*--------------------------------------------------------------------------*/