Fixed idle timer during chat

This commit is contained in:
Michiel Broek 2004-11-12 21:25:59 +00:00
parent c1ae6ed787
commit 9eb6526fff
9 changed files with 761 additions and 695 deletions

View File

@ -33,6 +33,7 @@ v0.71.0 27-Oct-2004
We don't reward upload time anymore, only bytes. It's more
troubles to implement right then it's worth these days.
Added internal zmodem download protocol.
With user chat, the timeout timer wasn't refreshed.
mbnewusr:
Rewrote terminal i/o.

View File

@ -112,14 +112,14 @@ newuser.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h funcs.h inp
pinfo.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h pinfo.h input.h term.h ttyio.h
timecheck.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h timecheck.h funcs.h bye.h exitinfo.h language.h input.h term.h ttyio.h
change.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h change.h dispfile.h funcs.h input.h language.h misc.h timeout.h exitinfo.h bye.h term.h ttyio.h
transfer.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h transfer.h change.h whoson.h funcs.h term.h ttyio.h filesub.h language.h openport.h timeout.h zmsend.h
transfer.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h transfer.h change.h whoson.h funcs.h term.h ttyio.h filesub.h language.h openport.h timeout.h zmsend.h zmrecv.h
exitinfo.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h funcs.h input.h language.h oneline.h misc.h bye.h timeout.h timecheck.h exitinfo.h
mbsebbs.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msg.h mbsebbs.h user.h dispfile.h language.h menu.h misc.h bye.h timeout.h funcs.h term.h ttyio.h openport.h
menu.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h oneline.h mail.h bbslist.h change.h chat.h file.h funcs.h input.h misc.h timeout.h menu.h page.h pinfo.h bye.h timecheck.h whoson.h language.h offline.h email.h door.h dispfile.h userlist.h timestats.h logentry.h morefile.h lastcallers.h signature.h term.h ttyio.h
pop3.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbinet.h ../lib/msgtext.h ../lib/msg.h msgutil.h pop3.h term.h ttyio.h
lastcallers.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h language.h lastcallers.h term.h ttyio.h
timeout.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msg.h timeout.h funcs.h bye.h filesub.h language.h term.h
chat.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h chat.h funcs.h input.h language.h misc.h whoson.h term.h ttyio.h
chat.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h chat.h funcs.h input.h language.h misc.h whoson.h term.h ttyio.h timeout.h
file.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbsedb.h filesub.h file.h funcs.h input.h language.h misc.h timeout.h exitinfo.h whoson.h change.h dispfile.h term.h ttyio.h openport.h transfer.h
misc.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msg.h funcs.h input.h language.h misc.h timeout.h exitinfo.h ttyio.h term.h
offline.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/bluewave.h ../lib/msgtext.h ../lib/msg.h mail.h funcs.h input.h language.h file.h filesub.h exitinfo.h timeout.h msgutil.h pop3.h offline.h whoson.h term.h ttyio.h openport.h transfer.h
@ -133,7 +133,7 @@ userlist.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h userlist.h
timestats.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h timestats.h funcs.h language.h input.h exitinfo.h term.h
logentry.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h logentry.h
zmrle.o: ../config.h ../lib/mbselib.h ttyio.h zmrle.h zmmisc.h
zmmisc.o: ../config.h ../lib/mbselib.h ../lib/nodelist.h ttyio.h zmrle.h zmmisc.h
zmmisc.o: ../config.h ../lib/mbselib.h ttyio.h zmrle.h zmmisc.h
zmsend.o: ../config.h ../lib/mbselib.h ttyio.h zmmisc.h zmrle.h transfer.h
zmrecv.o: ../config.h ../lib/mbselib.h ../lib/users.h ttyio.h transfer.h zmmisc.h zmrecv.h
# End of generated dependencies

View File

@ -40,6 +40,7 @@
#include "whoson.h"
#include "term.h"
#include "ttyio.h"
#include "timeout.h"
int chat_with_sysop = FALSE; /* Global sysop chat flag */
@ -278,6 +279,7 @@ void Chat(char *username, char *channel)
*/
ch = testkey(exitinfo.iScreenLen -1, curpos + 2);
if (isprint(ch)) {
alarm_on();
if (curpos < 77) {
PUTCHAR(ch);
sbuf[curpos] = ch;
@ -286,6 +288,7 @@ void Chat(char *username, char *channel)
PUTCHAR(7);
}
} else if ((ch == KEY_BACKSPACE) || (ch == KEY_RUBOUT) || (ch == KEY_DEL)) {
alarm_on();
if (curpos) {
curpos--;
sbuf[curpos] = '\0';
@ -294,6 +297,7 @@ void Chat(char *username, char *channel)
PUTCHAR(7);
}
} else if ((ch == '\r') && curpos) {
alarm_on();
sprintf(buf, "CPUT:2,%d,%s;", mypid, sbuf);
Syslog('c', "> %s", buf);
if (socket_send(buf) == 0) {

View File

@ -43,6 +43,7 @@
#include "openport.h"
#include "timeout.h"
#include "zmsend.h"
#include "zmrecv.h"
/*
@ -422,6 +423,51 @@ int upload(up_list **upload_list)
sleep(2);
if (uProtInternal) {
if (strncasecmp(sProtName, "zmodem", 6) == 0) {
rc = zmrcvfiles();
Syslog('b', "Begin dir processing");
if ((dirp = opendir(".")) == NULL) {
WriteError("$Upload: can't open ./upl");
Home();
rc = 1;
} else {
while ((dp = readdir(dirp)) != NULL) {
if (*(dp->d_name) != '.') {
if (rc == 0) {
stat(dp->d_name, &statfile);
Syslog('+', "Uploaded \"%s\", %ld bytes", dp->d_name, statfile.st_size);
sprintf(temp, "%s/%s/upl/%s", CFG.bbs_usersdir, exitinfo.Name, dp->d_name);
chmod(temp, 0660);
/*
* Add uploaded file to the list
*/
tmp = (up_list *)malloc(sizeof(up_list));
tmp->next = NULL;
tmp->filename = xstrcpy(temp);
tmp->size = Size;
if (*upload_list == NULL) {
*upload_list = tmp;
} else {
for (ta = *upload_list; ta; ta = ta->next) {
if (ta->next == NULL) {
ta->next = (up_list *)tmp;
break;
}
}
}
} else {
Syslog('+', "Remove failed %s result %d", dp->d_name, unlink(dp->d_name));
}
}
}
closedir(dirp);
}
} else {
Syslog('!', "Internal protocol %s not supported", sProtName);
free(temp);
return 1;
}
} else {
/*
* External protocol
@ -487,6 +533,7 @@ int upload(up_list **upload_list)
}
}
free(temp);
Syslog('b', "Done, return rc=%d", rc);
return rc;
}

View File

@ -65,7 +65,6 @@ static void garbitch(void);
#include "../config.h"
#include "../lib/mbselib.h"
#include "../lib/nodelist.h"
#include "ttyio.h"
#include "zmrle.h"
#include "zmmisc.h"
@ -75,33 +74,13 @@ static void garbitch(void);
does timing in whole seconds.
*/
static int Rxtimeout = 10; /* Seconds to wait for something */
int Zctlesc;
/* Globals used by ZMODEM functions */
int Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame */
int Rxtype; /* Type of header received */
int Rxhlen; /* Length of header received */
int Rxcount; /* Count of data bytes received */
char Rxhdr[ZMAXHLEN]; /* Received header */
char Txhdr[ZMAXHLEN]; /* Transmitted header */
long Rxpos; /* Received file position */
long Txpos; /* Transmitted file position */
int Txfcs32; /* TRUE means send binary frames with 32 bit FCS */
int Crc32t; /* Controls 32 bit CRC being sent */
/* 1 == CRC32, 2 == CRC32 + RLE */
int Crc32r; /* Indicates/controls 32 bit CRC being received */
/* 0 == CRC16, 1 == CRC32, 2 == CRC32 + RLE */
int Usevhdrs; /* Use variable length headers */
int Znulls; /* Number of nulls to send at beginning of ZDATA hdr */
char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
char *Altcan; /* Alternate canit string */
char *txbuf=NULL;
char *rxbuf=NULL;
static int lastsent; /* Last char we sent */
static int Not8bit; /* Seven bits seen on header */
char *frametypes[] = {
(char *)"EMPTY", /* -16 */
(char *)"Can't be (-15)",
@ -193,7 +172,8 @@ void zsbhdr(int len, int type, register char *shdr)
for (n = Znulls; --n >=0; )
BUFFER_BYTE(0);
BUFFER_BYTE(ZPAD); BUFFER_BYTE(ZDLE);
BUFFER_BYTE(ZPAD);
BUFFER_BYTE(ZDLE);
switch (Crc32t=Txfcs32) {
case 2: zsbh32(len, shdr, type, Usevhdrs?ZVBINR32:ZBINR32);
@ -235,7 +215,8 @@ void zsbh32(int len, register char *shdr, int type, int flavour)
if (Usevhdrs)
zsendline(len);
zsendline(type);
crc = 0xFFFFFFFFL; crc = updcrc32(type, crc);
crc = 0xFFFFFFFFL;
crc = updcrc32(type, crc);
for (n=len; --n >= 0; ++shdr) {
crc = updcrc32((0377 & *shdr), crc);
@ -258,7 +239,7 @@ void zshhdr(int len, int type, register char *shdr)
register int n;
register unsigned short crc;
Syslog('z', "zshhdr: %c %d %s %ld", Usevhdrs?'v':'f', len, frametypes[type+FTOFFSET], rclhdr(shdr));
Syslog('z', "zshhdr: %c %d %s %lx", Usevhdrs?'v':'f', len, frametypes[type+FTOFFSET], rclhdr(shdr));
BUFFER_CLEAR();
@ -275,7 +256,8 @@ void zshhdr(int len, int type, register char *shdr)
crc = updcrc16(type, 0);
for (n=len; --n >= 0; ++shdr) {
zputhex(*shdr); crc = updcrc16((0377 & *shdr), crc);
zputhex(*shdr);
crc = updcrc16((0377 & *shdr), crc);
}
crc = updcrc16(0,updcrc16(0,crc));
zputhex(((int)(crc>>8))); zputhex(crc);
@ -316,14 +298,16 @@ void zsdata(register char *buf, int length, int frameend)
break;
default: crc = 0;
for (;--length >= 0; ++buf) {
zsendline(*buf); crc = updcrc16((0377 & *buf), crc);
zsendline(*buf);
crc = updcrc16((0377 & *buf), crc);
}
BUFFER_BYTE(ZDLE);
BUFFER_BYTE(frameend);
crc = updcrc16(frameend, crc);
crc = updcrc16(0,updcrc16(0,crc));
zsendline(((int)(crc>>8))); zsendline(crc);
zsendline(((int)(crc>>8)));
zsendline(crc);
}
if (frameend == ZCRCW)
BUFFER_BYTE(XON);
@ -353,7 +337,8 @@ void zsda32(register char *buf, int length, int frameend)
crc = ~crc;
for (c=4; --c >= 0;) {
zsendline((int)crc); crc >>= 8;
zsendline((int)crc);
crc >>= 8;
}
}
@ -371,6 +356,8 @@ int zrdata(register char *buf, int length)
register char *end;
register int d;
Syslog('z', "zrdata: len=%d, Crc32r=%d", length, Crc32r);
switch (Crc32r) {
case 1:
return zrdat32(buf, length);
@ -378,7 +365,9 @@ int zrdata(register char *buf, int length)
return zrdatr32(buf, length);
}
crc = Rxcount = 0; end = buf + length;
crc = Rxcount = 0;
end = buf + length;
while (buf <= end) {
if ((c = zdlread()) & ~0377) {
crcfoo:
@ -426,7 +415,10 @@ int zrdat32(register char *buf, int length)
register char *end;
register int d;
crc = 0xFFFFFFFFL; Rxcount = 0; end = buf + length;
crc = 0xFFFFFFFFL;
Rxcount = 0;
end = buf + length;
while (buf <= end) {
if ((c = zdlread()) & ~0377) {
crcfoo:
@ -494,50 +486,49 @@ void garbitch(void)
int zgethdr(char *shdr)
{
register int c, n, cancount;
int Zrwindow = 1400;
int Baudrate = 9600;
n = Zrwindow + Baudrate;
Rxframeind = Rxtype = 0;
Syslog('z', "zgethdr(%lx)", rclhdr(shdr));
startover:
cancount = 5;
again:
/*
* Return immediate ERROR if ZCRCW sequence seen
*/
if (((c = GETCHAR(Rxtimeout)) < 0) && (c != TIMEOUT))
goto fifi;
else switch(c) {
case 021: case 0221:
goto again;
else {
// Syslog('z', "Zmodem: Got %c %d", c, c);
switch(c) {
case 021:
case 0221: goto again;
case HANGUP:
case TIMEOUT:
goto fifi;
case TIMEOUT: goto fifi;
case CAN:
gotcan:
Syslog('z', "zgethdr: got CAN");
if (--cancount <= 0) {
c = ZCAN; goto fifi;
c = ZCAN;
goto fifi;
}
switch (c = GETCHAR(Rxtimeout)) {
case TIMEOUT:
goto again;
case ZCRCW:
switch (GETCHAR(Rxtimeout)) {
case TIMEOUT:
c = TERROR; goto fifi;
case HANGUP:
case TIMEOUT: goto again;
case ZCRCW: switch (GETCHAR(Rxtimeout)) {
case TIMEOUT: c = TERROR;
goto fifi;
default:
goto agn2;
case HANGUP: goto fifi;
default: goto agn2;
}
case HANGUP:
case HANGUP: goto fifi;
default: break;
case CAN: if (--cancount <= 0) {
c = ZCAN;
goto fifi;
default:
break;
case CAN:
if (--cancount <= 0) {
c = ZCAN; goto fifi;
}
goto again;
}
@ -546,80 +537,89 @@ gotcan:
agn2:
#define GCOUNT (-4)
if ( --n == 0) {
c = GCOUNT; goto fifi;
c = GCOUNT;
goto fifi;
}
goto startover;
case ZPAD|0200: /* This is what we want. */
Not8bit = c;
case ZPAD: /* This is what we want. */
// Syslog('z', "zgethdr: got ZPAD");
break;
}
}
cancount = 5;
splat:
switch (c = noxrd7()) {
case ZPAD:
goto splat;
case ZPAD: goto splat;
case HANGUP:
case TIMEOUT:
goto fifi;
default:
goto agn2;
case TIMEOUT: goto fifi;
default: goto agn2;
case ZDLE: /* This is what we want. */
// Syslog('z', "zgethdr: got ZDLE");
break;
}
Rxhlen = 4; /* Set default length */
Rxframeind = c = noxrd7();
Syslog('z', "zgethdr: header type %d", c);
switch (c) {
case ZVBIN32:
if ((Rxhlen = c = zdlread()) < 0)
case ZVBIN32: if ((Rxhlen = c = zdlread()) < 0)
goto fifi;
if (c > ZMAXHLEN)
goto agn2;
Crc32r = 1; c = zrbhd32(shdr); break;
case ZBIN32:
if (Usevhdrs)
Crc32r = 1;
c = zrbhd32(shdr);
break;
case ZBIN32: if (Usevhdrs)
goto agn2;
Crc32r = 1; c = zrbhd32(shdr); break;
case ZVBINR32:
if ((Rxhlen = c = zdlread()) < 0)
Crc32r = 1;
c = zrbhd32(shdr);
break;
case ZVBINR32: if ((Rxhlen = c = zdlread()) < 0)
goto fifi;
if (c > ZMAXHLEN)
goto agn2;
Crc32r = 2; c = zrbhd32(shdr); break;
case ZBINR32:
if (Usevhdrs)
Crc32r = 2;
c = zrbhd32(shdr);
break;
case ZBINR32: if (Usevhdrs)
goto agn2;
Crc32r = 2; c = zrbhd32(shdr); break;
Crc32r = 2;
c = zrbhd32(shdr);
break;
case HANGUP:
case TIMEOUT:
goto fifi;
case ZVBIN:
if ((Rxhlen = c = zdlread()) < 0)
case TIMEOUT: goto fifi;
case ZVBIN: if ((Rxhlen = c = zdlread()) < 0)
goto fifi;
if (c > ZMAXHLEN)
goto agn2;
Crc32r = 0; c = zrbhdr(shdr); break;
case ZBIN:
if (Usevhdrs)
Crc32r = 0;
c = zrbhdr(shdr);
break;
case ZBIN: if (Usevhdrs)
goto agn2;
Crc32r = 0; c = zrbhdr(shdr); break;
case ZVHEX:
if ((Rxhlen = c = zgethex()) < 0)
Crc32r = 0;
c = zrbhdr(shdr);
break;
case ZVHEX: if ((Rxhlen = c = zgethex()) < 0)
goto fifi;
if (c > ZMAXHLEN)
goto agn2;
Crc32r = 0; c = zrhhdr(shdr); break;
case ZHEX:
if (Usevhdrs)
goto agn2;
Crc32r = 0; c = zrhhdr(shdr); break;
case CAN:
goto gotcan;
default:
Crc32r = 0;
c = zrhhdr(shdr);
break;
case ZHEX: if (Usevhdrs)
goto agn2;
Crc32r = 0;
c = zrhhdr(shdr);
break;
case CAN: goto gotcan;
default: goto agn2;
}
for (n = Rxhlen; ++n < ZMAXHLEN; ) /* Clear unused hdr bytes */
shdr[n] = 0;
Rxpos = shdr[ZP3] & 0377;
@ -627,26 +627,27 @@ splat:
Rxpos = (Rxpos<<8) + (shdr[ZP1] & 0377);
Rxpos = (Rxpos<<8) + (shdr[ZP0] & 0377);
fifi:
Syslog('z', "Zmodem: at fifi Got %d", c);
switch (c) {
case GOTCAN:
c = ZCAN;
case GOTCAN: c = ZCAN;
/* **** FALL THRU TO **** */
case ZNAK:
case ZCAN:
case TERROR:
case TIMEOUT:
case HANGUP:
Syslog('+', "Zmodem: Got %s", frametypes[c+FTOFFSET]);
case HANGUP: Syslog('+', "Zmodem: Got %s", frametypes[c+FTOFFSET]);
/* **** FALL THRU TO **** */
default:
if (c >= -FTOFFSET && c <= FRTYPES)
Syslog('z', "zgethdr: %c %d %s %ld", Rxframeind, Rxhlen, frametypes[c+FTOFFSET], Rxpos);
default: if (c >= -FTOFFSET && c <= FRTYPES)
Syslog('z', "zgethdr: %c %d %s %lx", Rxframeind, Rxhlen, frametypes[c+FTOFFSET], Rxpos);
else
Syslog('z', "zgethdr: %c %d %ld", Rxframeind, c, Rxpos);
Syslog('z', "zgethdr: %d %d %ld", Rxframeind, c, Rxpos);
}
/* Use variable length headers if we got one */
if (c >= 0 && c <= FRTYPES && Rxframeind & 040)
if (c >= 0 && c <= FRTYPES && Rxframeind & 040) {
Usevhdrs = 1;
Syslog('z', "zgethdr: Usevhdrs");
}
return c;
}
@ -749,15 +750,13 @@ int zrhhdr(char *shdr)
Syslog('+', "Zmodem zrhhdr: Bad CRC");
return TERROR;
}
switch (c = GETCHAR(Rxtimeout)) {
case 0215:
Not8bit = c;
case 0215: Not8bit = c;
/* **** FALL THRU TO **** */
case 015:
/* Throw away possible cr/lf */
case 015: /* Throw away possible cr/lf */
switch (c = GETCHAR(Rxtimeout)) {
case 012:
Not8bit |= c;
case 012: Not8bit |= c;
}
}
if (c < 0)
@ -791,13 +790,11 @@ void zsendline(int c)
BUFFER_BYTE(lastsent = c);
else {
switch (c &= 0377) {
case ZDLE:
BUFFER_BYTE(ZDLE);
case ZDLE: BUFFER_BYTE(ZDLE);
BUFFER_BYTE (lastsent = (c ^= 0100));
break;
case 015:
case 0215:
if (!Zctlesc && (lastsent & 0177) != '@')
case 0215: if (!Zctlesc && (lastsent & 0177) != '@')
goto sendit;
/* **** FALL THRU TO **** */
case 020:
@ -805,14 +802,12 @@ void zsendline(int c)
case 023:
case 0220:
case 0221:
case 0223:
BUFFER_BYTE(ZDLE);
case 0223: BUFFER_BYTE(ZDLE);
c ^= 0100;
sendit:
sendit:
BUFFER_BYTE(lastsent = c);
break;
default:
if (Zctlesc && ! (c & 0140)) {
default: if (Zctlesc && ! (c & 0140)) {
BUFFER_BYTE(ZDLE);
c ^= 0100;
}
@ -870,20 +865,19 @@ again:
/* Quick check for non control characters */
if ((c = GETCHAR(Rxtimeout)) & 0140)
return c;
switch (c) {
case ZDLE:
break;
case ZDLE: break;
case 023:
case 0223:
case 021:
case 0221:
goto again;
default:
if (Zctlesc && !(c & 0140)) {
case 0221: goto again;
default: if (Zctlesc && !(c & 0140)) {
goto again;
}
return c;
}
again2:
if ((c = GETCHAR(Rxtimeout)) < 0)
return c;
@ -893,31 +887,27 @@ again2:
return c;
if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0)
return c;
switch (c) {
case CAN:
return GOTCAN;
case CAN: return GOTCAN;
case ZCRCE:
case ZCRCG:
case ZCRCQ:
case ZCRCW:
return (c | GOTOR);
case ZRUB0:
return 0177;
case ZRUB1:
return 0377;
case ZCRCW: return (c | GOTOR);
case ZRUB0: return 0177;
case ZRUB1: return 0377;
case 023:
case 0223:
case 021:
case 0221:
goto again2;
default:
if (Zctlesc && ! (c & 0140)) {
case 0221: goto again2;
default: if (Zctlesc && ! (c & 0140)) {
goto again2;
}
if ((c & 0140) == 0100)
return (c ^ 0100);
break;
}
Syslog('+', "Zmodem: Bad escape sequence 0x%x", c);
return TERROR;
}
@ -935,17 +925,15 @@ int noxrd7(void)
for (;;) {
if ((c = GETCHAR(Rxtimeout)) < 0)
return c;
switch (c &= 0177) {
case XON:
case XOFF:
continue;
default:
if (Zctlesc && !(c & 0140))
case XOFF: continue;
default: if (Zctlesc && !(c & 0140))
continue;
case '\r':
case '\n':
case ZDLE:
return c;
case ZDLE: return c;
}
}
}

View File

@ -137,31 +137,24 @@
/* Parameters for ZCOMMAND frame ZF0 (otherwise 0) */
#define ZCACK1 1 /* Acknowledge, then do command */
long rclhdr(register char *);
/* Globals used by ZMODEM functions */
extern int Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame */
extern int Rxtype; /* Type of header received */
extern int Rxcount; /* Count of data bytes received */
extern int long Rxpos; /* Received file position */
extern int long Txpos; /* Transmitted file position */
extern int Txfcs32; /* TURE means send binary frames with 32 bit FCS */
extern int Crc32t; /* Display flag indicating 32 bit CRC being sent */
extern int Crc32r; /* Display flag indicating 32 bit CRC being received */
extern int Crc32; /* Display flag indicating 32 bit CRC being received */
extern int Znulls; /* Number of nulls to send at beginning of ZDATA hdr */
extern char Rxhdr[];
extern char Txhdr[];
extern char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
extern char *Altcan; /* Alternate canit string */
extern char *Zendnames[];
extern char *txbuf;
extern char *rxbuf;
int Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame */
int Rxtype; /* Type of header received */
int Rxcount; /* Count of data bytes received */
int long Rxpos; /* Received file position */
int long Txpos; /* Transmitted file position */
int Txfcs32; /* TURE means send binary frames with 32 bit FCS */
int Crc32t; /* Display flag indicating 32 bit CRC being sent */
int Crc32r; /* Display flag indicating 32 bit CRC being received */
int Znulls; /* Number of nulls to send at beginning of ZDATA hdr */
char Rxhdr[ZMAXHLEN]; /* Received header */
char Txhdr[ZMAXHLEN]; /* Transmitted header */
char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
char *Altcan; /* Alternate canit string */
char Zsendmask[33]; /* Additional control characters to mask */
extern int Zctlesc;
extern char *frametypes[];
int Zctlesc;
int Usevhdrs; /* Use variable length headers */
void get_frame_buffer(void);

View File

@ -40,7 +40,6 @@
static FILE *fout = NULL;
char *curfile = NULL;
static int Usevhdrs;
static off_t rxbytes;
static int Eofseen; /* indicates cpm eof (^Z) has been received */
static int errors;
@ -52,13 +51,8 @@ struct timezone tz;
static long Bytesleft; /* number of bytes of incoming file left */
static long Modtime; /* Unix style mod time for incoming file */
static int Filemode; /* Unix style mode for incoming file */
static int Thisbinary; /* current file is to be received in bin mode */
char Lzconv; /* Local ZMODEM file conversion request */
char Lzmanag; /* Local file management request */
static char *secbuf=0;
static int Thisbinary = TRUE; /* current file is to be received in bin mode */
static char *secbuf=0; /* "sector" buffer */
static int tryzhdrtype;
static char zconv; /* ZMODEM file conversion request */
static char zmanag; /* ZMODEM file management request */
@ -75,9 +69,6 @@ static int ackbibi(void);
static long getfree(void);
void get_frame_buffer(void);
void free_frame_buffer(void);
extern unsigned long rcvdbytes;
@ -97,8 +88,10 @@ int zmrcvfiles(void)
Syslog('+', "Zmodem: could not initiate receive, rc=%d",rc);
} else
switch (rc) {
case ZCOMPL: rc = 0; break;
case ZFILE: rc = rzfiles(); break;
case ZCOMPL: rc = 0;
break;
case ZFILE: rc = rzfiles();
break;
}
if (fout) {
@ -135,39 +128,49 @@ int tryz(void)
*/
Syslog('z', "tryz attempt %d", n);
stohdr(0L);
Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO;
// Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO;
Txhdr[ZF0] = CANFC32;
if (Zctlesc)
Txhdr[ZF0] |= TESCCTL;
Txhdr[ZF0] |= CANRLE;
// Txhdr[ZF0] |= CANRLE;
Txhdr[ZF1] = CANVHDR;
zshhdr(4, tryzhdrtype, Txhdr);
if (tryzhdrtype == ZSKIP) /* Don't skip too far */
tryzhdrtype = ZRINIT; /* CAF 8-21-87 */
again:
switch (zgethdr(Rxhdr)) {
case ZRQINIT:
if (Rxhdr[ZF3] & 0x80)
case ZRQINIT: if (Rxhdr[ZF3] & 0x80)
Usevhdrs = TRUE; /* we can var header */
continue;
case ZEOF:
case ZEOF: continue;
case TIMEOUT: Syslog('+', "Zmodem: tryz() timeout attempt %d", n);
continue;
case TIMEOUT:
Syslog('+', "Zmodem: tryz() timeout attempt %d", n);
continue;
case ZFILE:
zconv = Rxhdr[ZF0];
case ZFILE: zconv = Rxhdr[ZF0];
if (!zconv) {
Syslog('z', "*** !zconv %d", zconv);
}
zmanag = Rxhdr[ZF1];
ztrans = Rxhdr[ZF2];
if (Rxhdr[ZF3] & ZCANVHDR)
Usevhdrs = TRUE;
tryzhdrtype = ZRINIT;
c = zrdata(secbuf, MAXBLOCK);
if (c == GOTCRCW)
if (c == GOTCRCW) {
Syslog('z', "tryz return ZFILE");
return ZFILE;
}
zshhdr(4,ZNAK, Txhdr);
goto again;
case ZSINIT:
Zctlesc = TESCCTL & Rxhdr[ZF0];
case ZSINIT: /* this once was:
* Zctlesc = TESCCTL & Rxhdr[ZF0];
* trouble: if rz get --escape flag:
* - it sends TESCCTL to sz,
* get a ZSINIT _without_ TESCCTL (yeah - sender didn't know),
* overwrites Zctlesc flag ...
* - sender receives TESCCTL and uses "|=..."
* so: sz escapes, but rz doesn't unescape ... not good.
*/
Zctlesc |= TESCCTL & Rxhdr[ZF0];
if (zrdata(Attn, ZATTNLEN) == GOTCRCW) {
stohdr(1L);
zshhdr(4,ZACK, Txhdr);
@ -175,12 +178,10 @@ again:
}
zshhdr(4,ZNAK, Txhdr);
goto again;
case ZFREECNT:
stohdr(getfree());
case ZFREECNT: stohdr(getfree());
zshhdr(4,ZACK, Txhdr);
goto again;
case ZCOMMAND:
cmdzack1flg = Rxhdr[ZF0];
case ZCOMMAND: cmdzack1flg = Rxhdr[ZF0];
if (zrdata(secbuf, MAXBLOCK) == GOTCRCW) {
if (cmdzack1flg & ZCACK1)
stohdr(0L);
@ -192,20 +193,21 @@ again:
} while (++errors<20 && zgethdr(Rxhdr) != ZFIN);
return ackbibi();
}
zshhdr(4,ZNAK, Txhdr); goto again;
case ZCOMPL:
zshhdr(4,ZNAK, Txhdr);
goto again;
case ZRINIT:
case ZCOMPL: goto again;
case ZRINIT: Syslog('z', "tryz: got ZRINIT");
return TERROR;
case ZFIN: /* do not beleive in first ZFIN */
ackbibi(); return ZCOMPL;
ackbibi();
return ZCOMPL;
case TERROR:
case HANGUP:
case ZCAN:
return TERROR;
default:
continue;
case ZCAN: return TERROR;
default: continue;
}
}
Syslog('z', "tryz return 0");
return 0;
}
@ -224,20 +226,14 @@ int rzfiles(void)
switch (c = rzfile()) {
case ZEOF:
case ZSKIP:
case ZFERR:
switch (tryz()) {
case ZCOMPL:
return OK;
default:
return TERROR;
case ZFILE:
break;
case ZFERR: switch (tryz()) {
case ZCOMPL: return OK;
default: return TERROR;
case ZFILE: break;
}
continue;
default:
return c;
case TERROR:
return TERROR;
default: return c;
case TERROR: return TERROR;
}
}
/* NOTREACHED */
@ -264,37 +260,32 @@ int rzfile(void)
n = 20;
for (;;) {
Syslog('z', "rxbytes %ld", rxbytes);
stohdr(rxbytes);
zshhdr(4,ZRPOS, Txhdr);
nxthdr:
switch (c = zgethdr(Rxhdr)) {
default:
Syslog('z', "rzfile: Wrong header %d", c);
default: Syslog('z', "rzfile: Wrong header %d", c);
if ( --n < 0) {
Syslog('+', "Zmodem: wrong header %d", c);
return TERROR;
}
continue;
case ZCAN:
Syslog('+', "Zmodem: sender CANcelled");
case ZCAN: Syslog('+', "Zmodem: sender CANcelled");
return TERROR;
case ZNAK:
if ( --n < 0) {
case ZNAK: if ( --n < 0) {
Syslog('+', "Zmodem: Got ZNAK");
return TERROR;
}
continue;
case TIMEOUT:
if ( --n < 0) {
case TIMEOUT: if ( --n < 0) {
Syslog('+', "Zmodem: TIMEOUT");
return TERROR;
}
continue;
case ZFILE:
zrdata(secbuf, MAXBLOCK);
case ZFILE: zrdata(secbuf, MAXBLOCK);
continue;
case ZEOF:
if (rclhdr(Rxhdr) != rxbytes) {
case ZEOF: if (rclhdr(Rxhdr) != rxbytes) {
/*
* Ignore eof if it's at wrong place - force
* a timeout because the eof might have gone
@ -308,11 +299,10 @@ nxthdr:
Syslog('+', "Zmodem: error closing file");
return TERROR;
}
fout=NULL;
fout = NULL;
Syslog('z', "rzfile: normal EOF");
return c;
case HANGUP:
Syslog('+', "Zmodem: Lost Carrier");
case HANGUP: Syslog('+', "Zmodem: Lost Carrier");
return TERROR;
case TERROR: /* Too much garbage in header search error */
if (--n < 0) {
@ -321,29 +311,25 @@ nxthdr:
}
zmputs(Attn);
continue;
case ZSKIP:
Modtime = 1;
case ZSKIP: Modtime = 1;
closeit(1);
Syslog('+', "Zmodem: Sender SKIPPED file");
return c;
case ZDATA:
if (rclhdr(Rxhdr) != rxbytes) {
case ZDATA: if (rclhdr(Rxhdr) != rxbytes) {
if ( --n < 0) {
Syslog('+', "Zmodem: Data has bad address");
return TERROR;
}
zmputs(Attn); continue;
zmputs(Attn);
continue;
}
moredata:
Syslog('z', "%7ld ZMODEM%s ",
rxbytes, Crc32r?" CRC-32":"");
Syslog('z', "%7ld ZMODEM%s ", rxbytes, Crc32r?" CRC-32":"");
Nopper();
switch (c = zrdata(secbuf, MAXBLOCK)) {
case ZCAN:
Syslog('+', "Zmodem: sender CANcelled");
case ZCAN: Syslog('+', "Zmodem: sender CANcelled");
return TERROR;
case HANGUP:
Syslog('+', "Zmodem: Lost Carrier");
case HANGUP: Syslog('+', "Zmodem: Lost Carrier");
return TERROR;
case TERROR: /* CRC error */
if (--n < 0) {
@ -352,34 +338,30 @@ moredata:
}
zmputs(Attn);
continue;
case TIMEOUT:
if ( --n < 0) {
case TIMEOUT: if ( --n < 0) {
Syslog('+', "Zmodem: TIMEOUT");
return TERROR;
}
continue;
case GOTCRCW:
n = 20;
case GOTCRCW: n = 20;
putsec(secbuf, Rxcount);
rxbytes += Rxcount;
Syslog('z', "rxbytes %ld, will ACK", rxbytes);
stohdr(rxbytes);
PUTCHAR(XON);
zshhdr(4,ZACK, Txhdr);
goto nxthdr;
case GOTCRCQ:
n = 20;
case GOTCRCQ: n = 20;
putsec(secbuf, Rxcount);
rxbytes += Rxcount;
stohdr(rxbytes);
zshhdr(4,ZACK, Txhdr);
goto moredata;
case GOTCRCG:
n = 20;
case GOTCRCG: n = 20;
putsec(secbuf, Rxcount);
rxbytes += Rxcount;
goto moredata;
case GOTCRCE:
n = 20;
case GOTCRCE: n = 20;
putsec(secbuf, Rxcount);
rxbytes += Rxcount;
goto nxthdr;
@ -402,14 +384,13 @@ void zmputs(char *s)
while (*s) {
switch (c = *s++) {
case '\336':
Syslog('z', "zmputs: sleep(1)");
sleep(1); continue;
case '\335':
Syslog('z', "zmputs: send break");
sendbrk(); continue;
default:
PUTCHAR(c);
case '\336': Syslog('z', "zmputs: sleep(1)");
sleep(1);
continue;
case '\335': Syslog('z', "zmputs: send break");
sendbrk();
continue;
default: PUTCHAR(c);
}
}
}
@ -421,6 +402,13 @@ int closeit(int success)
struct utimbuf ut;
int rc;
Syslog('z', "closeit(%d)", success);
if ((fout == NULL) || (curfile == NULL)) {
Syslog('+', "closeit(), nothing to close");
return 1;
}
rc = fclose(fout);
fout = NULL;
@ -455,20 +443,19 @@ int ackbibi(void)
Syslog('z', "ackbibi:");
stohdr(0L);
for (n=3; --n>=0; ) {
zshhdr(4,ZFIN, Txhdr);
switch ((c=GETCHAR(10))) {
case 'O':
GETCHAR(1); /* Discard 2nd 'O' */
switch ((c = GETCHAR(10))) {
case 'O': GETCHAR(1); /* Discard 2nd 'O' */
Syslog('z', "Zmodem: ackbibi complete");
return ZCOMPL;
case TERROR:
case HANGUP:
Syslog('z', "Zmodem: ackbibi got %d, ignore",c);
case HANGUP: Syslog('z', "Zmodem: ackbibi got %d, ignore",c);
return 0;
case TIMEOUT:
default:
Syslog('z', "Zmodem: ackbibi got '%s', continue", printablec(c));
default: Syslog('z', "Zmodem: ackbibi got '%s', continue", printablec(c));
break;
}
}
@ -490,18 +477,29 @@ int procheader(char *Name)
/* set default parameters and overrides */
openmode = (char *)"w";
Syslog('z', "zmanag=%d", zmanag);
Syslog('z', "zconv=%d", zconv);
/*
* Process ZMODEM remote file management requests
*/
Thisbinary = (zconv != ZCNL); /* Remote ASCII override */
if (!Thisbinary && zconv == ZCNL) /* Remote ASCII override */
Thisbinary = FALSE;
if (zconv == ZCBIN) /* Remote Binary override */
Thisbinary = TRUE;
if (zmanag == ZMAPND)
openmode = (char *)"a";
Syslog('z', "Thisbinary %s", Thisbinary ?"TRUE":"FALSE");
Bytesleft = DEFBYTL;
Filemode = 0;
Modtime = 0L;
Eofseen = FALSE;
p = Name + 1 + strlen(Name);
// FIXME: Here we must add code that checks the Name for slashes, spaces and other
// illegal characters in the filename.
sscanf(p, "%ld%lo%o%o%d%d%d%d", &Bytesleft, &Modtime, &Filemode, &dummy, &dummy, &dummy, &dummy, &dummy);
strcpy(ctt, rfcdate(Modtime));
Syslog('+', "Zmodem: \"%s\" %ld bytes, %s mode %o", Name, Bytesleft, ctt, Filemode);
@ -515,9 +513,15 @@ int procheader(char *Name)
curfile = xstrcat(curfile, exitinfo.Name);
curfile = xstrcat(curfile, (char *)"/upl/");
curfile = xstrcat(curfile, Name);
fout = fopen(curfile, openmode);
Syslog('z', "try open %s mode \"%s\"", curfile, openmode);
if ((fout = fopen(curfile, openmode)) == NULL) {
WriteError("$Can't open %s mode %s", curfile, openmode);
}
gettimeofday(&starttime, &tz);
sbytes = rxbytes;
sbytes = rxbytes = 0;
Syslog('z', "result %s", fout ? "Ok":"Failed");
/* if (Bytesleft == rxbytes) { FIXME: if file already received, use this.
Syslog('+', "Zmodem: Skipping %s", Name);
@ -540,6 +544,8 @@ int putsec(char *buf, int n)
{
register char *p;
Syslog('z', "putsec %d characters %s mode", n, Thisbinary ? "binary":"ascii");
if (n == 0)
return OK;

View File

@ -44,6 +44,9 @@
#include "zmmisc.h"
extern char *Zendnames[];
/*
* Send data subpacket RLE encoded with 32 bit FCS
*/
@ -52,11 +55,15 @@ void zsdar32(char *buf, int length, int frameend)
register int c, l, n;
register unsigned long crc;
crc = 0xFFFFFFFFL; l = *buf++ & 0377;
crc = 0xFFFFFFFFL;
l = *buf++ & 0377;
if (length == 1) {
zsendline(l); crc = updcrc32(l, crc);
zsendline(l);
crc = updcrc32(l, crc);
if (l == ZRESC) {
zsendline(1); crc = updcrc32(1, crc);
zsendline(1);
crc = updcrc32(1, crc);
}
} else {
for (n = 0; --length >= 0; ++buf) {
@ -67,35 +74,46 @@ void zsdar32(char *buf, int length, int frameend)
case 0: zsendline(l);
crc = updcrc32(l, crc);
if (l == ZRESC) {
zsendline(0100); crc = updcrc32(0100, crc);
zsendline(0100);
crc = updcrc32(0100, crc);
}
l = c; break;
case 1: if (l != ZRESC) {
zsendline(l); zsendline(l);
zsendline(l);
zsendline(l);
crc = updcrc32(l, crc);
crc = updcrc32(l, crc);
n = 0; l = c; break;
n = 0;
l = c;
break;
}
/* **** FALL THRU TO **** */
default: zsendline(ZRESC); crc = updcrc32(ZRESC, crc);
if (l == 040 && n < 34) {
n += 036;
zsendline(n); crc = updcrc32(n, crc);
zsendline(n);
crc = updcrc32(n, crc);
} else {
n += 0101;
zsendline(n); crc = updcrc32(n, crc);
zsendline(l); crc = updcrc32(l, crc);
zsendline(n);
crc = updcrc32(n, crc);
zsendline(l);
crc = updcrc32(l, crc);
}
n = 0; l = c; break;
n = 0;
l = c;
break;
}
}
}
PUTCHAR(ZDLE); PUTCHAR(frameend);
PUTCHAR(ZDLE);
PUTCHAR(frameend);
crc = updcrc32(frameend, crc);
crc = ~crc;
for (length=4; --length >= 0;) {
zsendline((int)crc); crc >>= 8;
zsendline((int)crc);
crc >>= 8;
}
}
@ -110,7 +128,9 @@ int zrdatr32(register char *buf, int length)
register char *end;
register int d;
crc = 0xFFFFFFFFL; Rxcount = 0; end = buf + length;
crc = 0xFFFFFFFFL;
Rxcount = 0;
end = buf + length;
d = 0; /* Use for RLE decoder state */
while (buf <= end) {
if ((c = zdlread()) & ~0377) {
@ -119,7 +139,8 @@ crcfoo:
case GOTCRCE:
case GOTCRCG:
case GOTCRCQ:
case GOTCRCW: d = c; c &= 0377;
case GOTCRCW: d = c;
c &= 0377;
crc = updcrc32(c, crc);
if ((c = zdlread()) & ~0377)
goto crcfoo;
@ -153,17 +174,23 @@ crcfoo:
crc = updcrc32(c, crc);
switch (d) {
case 0: if (c == ZRESC) {
d = -1; continue;
d = -1;
continue;
}
*buf++ = c; continue;
*buf++ = c;
continue;
case -1: if (c >= 040 && c < 0100) {
d = c - 035; c = 040; goto spaces;
d = c - 035;
c = 040;
goto spaces;
}
if (c == 0100) {
d = 0;
*buf++ = ZRESC; continue;
*buf++ = ZRESC;
continue;
}
d = c; continue;
d = c;
continue;
default: d -= 0100;
if (d < 1)
goto badpkt;
@ -172,7 +199,8 @@ spaces:
goto badpkt;
while ( --d >= 0)
*buf++ = c;
d = 0; continue;
d = 0;
continue;
}
}

View File

@ -50,13 +50,11 @@ void initzsendmsk(char *);
static FILE *in;
static int Eofseen; /* EOF seen on input set by zfilbuf */
static int Rxflags = 0;
static int Usevhdrs;
static int Wantfcs32=TRUE; /* Want to send 32 bit FCS */
static int Rxbuflen;
static unsigned Txwindow; /* Control the size of the transmitted window */
static unsigned Txwspac; /* Spacing between zcrcq requests */
static unsigned Txwcnt; /* Counter used to space ack requests */
//static long Tframlen = 0; /* Override for tx frame length */
static int blklen = 128; /* Length of transmitted records */
static int blkopt; /* Override value for zmodem blklen */
static int errors;
@ -75,8 +73,9 @@ struct timezone tz;
extern unsigned long sentbytes;
extern int Rxhlen;
extern void get_frame_buffer(void);
extern void free_frame_buffer(void);
extern char *txbuf;
extern char *frametypes[];
int zmsndfiles(down_list *lst)