Category : C Source Code
Archive   : BSRC_140.ZIP
Filename : FTSC.C

 
Output of file : FTSC.C contained in archive : BSRC_140.ZIP
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / No-Cost Software. */
/* \ 1011 / */
/* ------ KopyRong (K) 1987. ALL RIGHTS REVERSED. */
/* */
/* */
/* This module was written by Bob Hartman */
/* */
/* */
/* BinkleyTerm FTSC Mail Session Routines */
/* */
/* */
/* This software package is being distributed WITH FULL SOURCE CODE */
/* with the following conditions: 1) If anything awful happens */
/* because you use it (or don't use it), you accept full */
/* responsibility; 2) you don't start making tons of voice calls to */
/* the authors to complain or make suggestions about enhancements, */
/* useful or otherwise; 3) you do not reuse this code in commercial */
/* products without specific permission to do so from the authors; */
/* 4) If you find any problems you send fixes to the authors for */
/* inclusion in updates; 5) You find some way to express your */
/* appreciation for this method of distribution, either by writing */
/* code or application notes, or just sending along a "Thank You" */
/* message. */
/* */
/* There is copyrighted code in this product. We either wrote it */
/* ourselves or got permission to use it. Please don't force us to */
/* pay a lawyer -- have some respect for our motives and don't abuse */
/* this "license". */
/* */
/* */
/*--------------------------------------------------------------------------*/

#include
#include
#include
#include

#define WAZOO_SECTION
#define MATRIX_SECTION

#define isBITBRAIN 0x1b

#include "zmodem.h"
#include "com.h"

#define rb_plus "r+b"

extern char *BUNDLE_msg;
extern char *FIND_msg;
extern char *WRITE_msg;
extern char *FLAGGING_msg;
extern char *TRUNC_msg;

extern char *ext_flags; /* Change to whatever, and */
extern int net_problems; /* This should be external */
extern int un_attended;
extern int fullscreen;
extern char no_pickup;
extern char no_requests;
extern int on_our_nickel;
extern int remote_net, remote_node;
extern int called_net, called_node;
extern char *remote_password;
extern int sent_mail;
extern int got_bundle, got_arcmail, got_mail;
extern int caller;
extern struct _newnode newnodedes; /* structure in new list */
char no_requests = 0;
int n_requests = 100;
int who_is_he = 0;

#define NUM_FLAGS 4

FTSC_Whack_CR ()
{
long t1, t2, timerset ();
char i, j, k, l, m;
char buf[80];

t1 = timerset (3000); /* set 30 second timeout */
j = CR;
if (un_attended && fullscreen)
{
gotoxy (0, 15);
clear_bottom ();
}
else
{
set_xy ("");
}
strcpy (buf, "Intro: ");
l = strlen (buf);
m = 0;
while (!timeup (t1) && CARRIER) /* till then or CD lost */
{

/* Send either the CR or SPACE */
SENDBYTE (j);

/* Now switch to either CR or SPACE based on last output */
j = 45 - j;

/* Now read what we get back to see if we get anything useful */
while (((i = TIMED_READ (0)) != EOF) && (!timeup (t1)) && CARRIER)
{
if (i == CR)
{
if (m)
{
if (un_attended && fullscreen)
{
gotoxy (0, 16);
}
scr_printf (buf);
/* We got what we wanted */
/* Now try to stop output on an Opus */
SENDBYTE (' ');
return (0);
}
}
else
if (i >= ' ')
{
buf[l++] = i;
buf[l] = '\0';
if (l > 77)
l = 77;
m = 1;
}
}

/* Delay for a second */
t2 = timerset (100);
while (!timeup (t2))
time_release ();
}

status_line ("*Nobody answered the door");
return (-1);
}

FTSC_sender (wz)
int wz;
{
int j;
char junkbuff[128];
long t1, timerset ();

if (!wz)
{
status_line ("*Initiating LoTek Matrix Session");
who_is_he = 0;
sprintf (junkbuff, "Remote System: %s (%u/%u)",
newnodedes.SystemName,
remote_net,
remote_node);

if (un_attended && fullscreen)
{
gotoxy (0, 18);
}

set_xy (junkbuff);
}

FTSC_sendmail ();
t1 = timerset (1000);


/* See what the receiver would like us to do */
while ((!timeup (t1)) && CARRIER)
{
if ((j = PEEKBYTE ()) >= 0)
{
switch (j)
{
case TSYNC:
CLEAR_INBOUND ();
if (FTSC_recvmail ())
goto get_out;
t1 = timerset (1000);
break;

case SYN:
CLEAR_INBOUND ();
if (on_our_nickel)
SEA_recvreq ();
else
{
SENDBYTE (CAN);
status_line ("*Refusing inbound file requests");
}
t1 = timerset (1000);
break;

case ENQ:
CLEAR_INBOUND ();
SEA_sendreq ();
goto get_out;
break;

case NAK:
case 'C':
TIMED_READ (0);
TIMED_READ (1);
TIMED_READ (1);
SENDBYTE (EOT);
t1 = timerset (1000);
break;

case SUB:
TIMED_READ (0);
SENDBYTE (CAN);
break;

default:
TIMED_READ (0);
SENDBYTE (EOT);
break;
}
}
else
{
time_release ();
}
}

if (!CARRIER)
{
status_line ("!Other end hung up on us .");
CLEAR_INBOUND ();
return FALSE;
}

if (timeup (t1))
{
FTSC_recvmail ();
status_line ("!Tired of waiting for other end.");
}

get_out:
t1 = timerset (100);
while (!timeup (t1))
time_release ();
if (!wz)
status_line ("*End of LoTek Matrix Session");
}

FTSC_receiver (wz)
int wz;
{
char fname[64];
int havemail, done;
unsigned int i, j;
long t1, t2, timerset ();
struct FILEINFO dt1;
struct stat buf;

if (!wz)
{
status_line ("*Answering LoTek Matrix Session");
who_is_he = 1;
}

CLEAR_INBOUND ();

/* Save the state of pickup for now */
done = no_pickup;
no_pickup = 0;
if (FTSC_recvmail ())
{
/* Restore the state of pickup */
no_pickup = done;
if (!wz)
status_line ("*End of LoTek Matrix Session");
return (1);
}

/* Restore the state of pickup */
no_pickup = done;

remote_net = called_net;
remote_node = called_node;

/* Now see if we should send anything back to him */
sprintf (fname, "%s%04x%04x.?UT", ctl.hold_area, remote_net, remote_node);
havemail = dfind (&dt1, fname, 0);

if (havemail)
{
sprintf (fname, "%s%04x%04x.?LO", ctl.hold_area, remote_net, remote_node);
havemail = dfind (&dt1, fname, 0);
}

if (havemail)
{
sprintf (fname, "%s%04x%04x.REQ", ctl.filepath, ctl.alias[0].net, ctl.alias[0].node);
havemail = dfind (&dt1, fname, 0);
}

if (havemail)
{
status_line ("*No mail waiting for %d/%d", remote_net, remote_node);
}
else
{
status_line ("*Giving mail to %d/%d", remote_net, remote_node);
/* Send the TSYNC's until we get a C or NAK back */
t1 = timerset (3000); /* set 30 second timeout */
j = 0xffff;
done = 0;
while (!timeup (t1) && CARRIER && !done) /* till then or CD lost */
{
SENDBYTE (TSYNC);

t2 = timerset (300);
while (CARRIER && (!timeup (t2)) && !done)
{
i = (unsigned) TIMED_READ (0);

switch (i)
{
case 'C':
case 0x00:
case 0x01:
if (j == 'C')
{
done = 1;
FTSC_sendmail ();
}
break;

case 0xfe:
if (j == 0x01)
{
done = 1;
FTSC_sendmail ();
}
break;

case 0xff:
if (j == 0x00)
{
done = 1;
FTSC_sendmail ();
}
else
{
time_release ();
}
break;

case NAK:
if (j == NAK)
{
done = 1;
FTSC_sendmail ();
}
break;
}
if (i != 0xffff)
j = i;
}
}
}

/* Now see if we want to request anything */
sprintf (fname, "%s%04x%04x.REQ", ctl.hold_area, remote_net, remote_node);
if (!stat (fname, &buf))
{
/* Send the SYN character and wait for an ENQ or CAN */
t1 = timerset (3000); /* set 30 second timeout */
done = 0;
while (!timeup (t1) && CARRIER && !done) /* till then or CD lost */
{
SENDBYTE (SYN);

t2 = timerset (300);
while (CARRIER && (!timeup (t2)) && !done)
{
i = TIMED_READ (0);

switch (i)
{
case ENQ:
SEA_sendreq ();

case CAN:
done = 1;
break;

case 'C':
case NAK:
SENDBYTE (EOT);
break;

case SUB:
SENDBYTE (CAN);
break;

default:
time_release ();
}
}
}
}

/* Finally, can he request anything from us */
if (!no_requests)
SEA_recvreq ();

if (!wz)
status_line ("*End of LoTek Matrix Session");
}

FTSC_sendmail ()
{
FILE *fp;
char fname[80];
char s[80];
char *sptr;
char *password;
char p;
int c;
int i, j;
int fsent;
struct stat buf;
struct _pkthdr *tmppkt;
long t1, time (), timerset ();
struct tm *tm1, *localtime ();

long current, last_start;

sptr = s;
/*--------------------------------------------------------------------*/
/* Send all waiting ?UT files (mail bundles) */
/*--------------------------------------------------------------------*/
*ext_flags = 'O';
for (c = 0; c < NUM_FLAGS; c++)
{
if (caller && (ext_flags[c] == 'H'))
continue;

sprintf (fname,
"%s%04x%04x.%cUT",
ctl.hold_area, called_net, called_node, ext_flags[c]);
errno = 0;

if (!stat (fname, &buf))
break;
} /* for */

/*--- Build a dummy PKT file name */
invent_pkt_name (s);

status_line (" Sending bundle to %d/%d", called_net, called_node);

if (c == NUM_FLAGS)
{
sprintf (fname,
"%s%04x%04x.OUT",
ctl.hold_area, called_net, called_node);
errno = 0;
fp = fopen (fname, "wb");
if (got_error (OPEN_msg, fname))
{
return (1);
}
errno = 0;
t1 = time (NULL);
tm1 = localtime (&t1);

tmppkt = (struct _pkthdr *) calloc (sizeof (struct _pkthdr), 1);
if (tmppkt == NULL)
{
status_line ("!Mem err in sending");
fclose (fp);
return (1);
}
tmppkt->orig_node = ctl.alias[0].node;
tmppkt->dest_node = called_node;
tmppkt->year = tm1->tm_year;
tmppkt->month = tm1->tm_mon;
tmppkt->day = tm1->tm_mday;
tmppkt->hour = tm1->tm_hour;
tmppkt->minute = tm1->tm_min;
tmppkt->second = tm1->tm_sec;
tmppkt->rate = 0;
tmppkt->ver = PKTVER;
tmppkt->orig_net = ctl.alias[0].net;
tmppkt->dest_net = called_net;
tmppkt->product = isBITBRAIN;
/* This has to have the proper zone put in it */
if (n_getpassword (ctl.our_zone, called_net, called_node))
{
if (remote_password != NULL)
{
strncpy (tmppkt->pwd_kludge, remote_password, 6);
strupr (tmppkt->pwd_kludge);
}
}
fwrite ((char *) tmppkt, sizeof (struct _pkthdr), 1, fp);
free (tmppkt);
if (got_error (WRITE_msg, fname))
{
fclose (fp);
return (1);
}
fwrite ("\0\0", 2, 1, fp);
fclose (fp);
}
else
{
/* This has to have the proper zone put in it */
if (n_getpassword (ctl.our_zone, called_net, called_node))
{
if (remote_password != NULL)
{
errno = 0;
fp = fopen (fname, rb_plus);
if (got_error (OPEN_msg, fname))
{
return (1);
}
tmppkt = (struct _pkthdr *) calloc (sizeof (struct _pkthdr), 1);
if (tmppkt == NULL)
{
status_line ("!Mem err in sending");
return (1);
}
errno = 0;
fread (tmppkt, 1, sizeof (struct _pkthdr), fp);
if (got_error (READ_msg, fname))
{
free (tmppkt);
fclose (fp);
return (1);
}
strncpy (tmppkt->pwd_kludge, remote_password, 6);
strupr (tmppkt->pwd_kludge);

errno = 0;
fseek (fp, 0L, SEEK_SET);
fwrite (tmppkt, 1, sizeof (struct _pkthdr), fp);
fclose (fp);
free (tmppkt);
}
}
}

net_problems = send_file (fname, 'S');
if ((net_problems == TSYNC) || (net_problems == 0))
{
if (c == NUM_FLAGS)
unlink (fname);
return (net_problems);
}

/* Delete the sent bundle */
unlink (fname);


/*--------------------------------------------------------------------*/
/* Send files listed in ?LO files (attached files) */
/*--------------------------------------------------------------------*/
*ext_flags = 'F';
status_line (" Outbound file attaches");
for (c = 0; c < NUM_FLAGS + 1; c++)
{
if (caller && (ext_flags[c] == 'H'))
continue;

if (c < NUM_FLAGS)
{
sprintf (fname, "%s%04x%04x.%cLO",
ctl.hold_area, called_net, called_node, ext_flags[c]);
}
else
{
sprintf (fname, "%s%04x%04x.REQ",
ctl.filepath, ctl.alias[0].net, ctl.alias[0].node);
}
errno = 0;

if (!stat (fname, &buf))
{

errno = 0;
fp = fopen (fname, rb_plus);

if (got_error (OPEN_msg, fname))
{
continue;
}

current = 0L;
while (!feof (fp))
{
s[0] = 0;
last_start = current;
fgets (s, 79, fp);
if (got_error (READ_msg, fname))
s[0] = 0;

sptr = s;
password = NULL;

for (i = 0; sptr[i]; i++)
if (sptr[i] == '!')
password = sptr + i + 1;

if (password)
{
password = sptr + i + 1;
for (i = 0; password[i]; i++)
if (password[i] <= ' ')
password[i] = 0;
fancy_str (password);
if (strcmp (password, remote_password))
{
status_line ("!RemotePwdErr %s %s", password, remote_password);
continue;
}
}

for (i = 0; sptr[i]; i++)
if (sptr[i] <= ' ')
sptr[i] = 0;

current = ftell (fp);

if (sptr[0] == '#')
{
sptr++;
i = TRUNC_AFTER;
}
else
i = NOTHING_AFTER;

if (!sptr[0])
{
continue;
}

if (sptr[0] != '~')
{
if (stat (sptr, &buf)) /* file exist? */
{
got_error (FIND_msg, sptr);
continue;
}
else
if (!buf.st_size)
{
continue; /* 0 length? */
}

j = xfermdm7 (sptr);
p = 'T';
if (j == 0)
{
net_problems = 1;
return FALSE;
}
else
if (j == 2)
p = 'F';

if (!send_file (sptr, p))
{
fclose (fp);
net_problems = 1;
return FALSE;
}

/*--------------------------------------------*/
/* File was sent. Flag file name */
/*--------------------------------------------*/

fseek (fp, last_start, SEEK_SET);
putc ('~', fp); /* flag it */
fflush (fp);
rewind (fp); /* clear any eof flags */
fseek (fp, current, SEEK_SET);
errno = 0;

if (i == TRUNC_AFTER)
{
CLEAR_IOERR ();
i = open (sptr, O_TRUNC, S_IWRITE);
got_error (TRUNC_msg, sptr);
status_line (FLAGGING_msg, sptr);
close (i);
}
}
} /* while */

errno = 0;
fclose (fp);
got_error (CLOSE_msg, fname);
unlink (fname);
errno = 0;
} /* !stat */
} /* for */

/* Now close out the file attaches */
sent_mail = 1;
*sptr = 0;
status_line (" End of outbound file attaches");
t1 = timerset (100);
while (CARRIER && !timeup (t1))
{
j = TIMED_READ (0);
if ((j == 'C') || (j == NAK))
{
SENDBYTE (EOT);
t1 = timerset (100);
}
else
{
time_release ();
}
}
}

FTSC_recvmail ()
{
char fname[80];
char fname1[80];
struct _pkthdr tmppkt;
FILE *fp;
char *s;
char done;
char i;
int j;
extern char *receive_file ();

status_line ("*Receiving inbound mail");

if (!CARRIER)
{
status_line ("!Other end hung up on us .");
CLEAR_INBOUND ();
return (1);
}

/* If we don't want to pickup stuff */
if (no_pickup)
{
status_line ("*Pickup is turned off - refusing mail.");
SENDBYTE (CAN);
}
else
{
status_line (" Inbound bundle");
/* Invent a dummy name for the packet */
invent_pkt_name (fname);

/* Receive the bundle with special netmail protocol */
CLEAR_INBOUND ();
SENDBYTE ('C');
SENDBYTE (0x01);
SENDBYTE (0xfe);
if ((s = receive_file (ctl.filepath, fname, 'B')) != NULL)
{
got_bundle = 1;
}

/* Check the password if there is one */
/* This has to have the proper zone put in it */
if (n_getpassword (ctl.our_zone, remote_net, remote_node))
{
if (remote_password != NULL)
{
got_bundle = 0;
errno = 0;
sprintf (fname, "%s%s", ctl.filepath, s);
fp = fopen (fname, "r");
if (got_error (OPEN_msg, fname))
{
status_line ("!Password Error assumed");
return (1);
}
errno = 0;
fread (&tmppkt, 1, sizeof (struct _pkthdr), fp);
if (got_error (OPEN_msg, fname))
{
status_line ("!Password Error assumed");
fclose (fp);
return (1);
}
fclose (fp);
remote_password[7] = '\0';
tmppkt.pwd_kludge[7] = '\0';
if (stricmp (remote_password, tmppkt.pwd_kludge))
{
status_line ("!Password Error: expected '%s' got '%s'",
remote_password, tmppkt.pwd_kludge);
strcpy (fname1, fname);
j = strlen (fname) - 3;
strcpy (&(fname[j]), "Bad");
if (rename (fname1, fname))
{
status_line ("!Packet '%s' cannot be renamed", fname1);
}
else
{
status_line ("!Packet renamed to '%s'", fname);
}
return (1);
}
}
got_bundle = 1;
}
called_net = remote_net;
called_node = remote_node;
got_mail = got_bundle;

done = 0;
/* Now receive the files if possible */
status_line (" Inbound file attaches");
do
{
if ((i = try_sealink ()) == 0)
{
if (!recvmdm7 (fname))
{
done = 1;
}
else
{
if (!receive_file (ctl.filepath, NULL, 'T'))
{
if (locate_y > 1)
gotoxy (0, locate_y - 1);
done = 1;
}
else
{
got_mail = 1;
}
}

}
else
if (i == 1)
{
if (!receive_file (ctl.filepath, NULL, 'F'))
{
if (locate_y > 1)
gotoxy (0, locate_y - 1);
done = 1;
}
else
{
got_mail = 1;
}
}
else
{
done = 1;
}
} while (!done && CARRIER);
}

status_line (" End of inbound file attaches");
CLEAR_INBOUND ();
return (0);
}


  3 Responses to “Category : C Source Code
Archive   : BSRC_140.ZIP
Filename : FTSC.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/