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 We don't reward upload time anymore, only bytes. It's more
troubles to implement right then it's worth these days. troubles to implement right then it's worth these days.
Added internal zmodem download protocol. Added internal zmodem download protocol.
With user chat, the timeout timer wasn't refreshed.
mbnewusr: mbnewusr:
Rewrote terminal i/o. 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 zmrecv.o: ../config.h ../lib/mbselib.h ../lib/users.h ttyio.h transfer.h zmmisc.h zmrecv.h
# End of generated dependencies # End of generated dependencies

View File

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

View File

@ -43,6 +43,7 @@
#include "openport.h" #include "openport.h"
#include "timeout.h" #include "timeout.h"
#include "zmsend.h" #include "zmsend.h"
#include "zmrecv.h"
/* /*
@ -422,6 +423,51 @@ int upload(up_list **upload_list)
sleep(2); sleep(2);
if (uProtInternal) { 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 { } else {
/* /*
* External protocol * External protocol
@ -487,6 +533,7 @@ int upload(up_list **upload_list)
} }
} }
free(temp); free(temp);
Syslog('b', "Done, return rc=%d", rc);
return rc; return rc;
} }

View File

@ -65,7 +65,6 @@ static void garbitch(void);
#include "../config.h" #include "../config.h"
#include "../lib/mbselib.h" #include "../lib/mbselib.h"
#include "../lib/nodelist.h"
#include "ttyio.h" #include "ttyio.h"
#include "zmrle.h" #include "zmrle.h"
#include "zmmisc.h" #include "zmmisc.h"
@ -75,32 +74,12 @@ static void garbitch(void);
does timing in whole seconds. does timing in whole seconds.
*/ */
static int Rxtimeout = 10; /* Seconds to wait for something */ 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 */
int Rxhlen; /* Length of header received */
char *txbuf=NULL; char *txbuf=NULL;
char *rxbuf=NULL; static int lastsent; /* Last char we sent */
static int Not8bit; /* Seven bits seen on header */
static int lastsent; /* Last char we sent */
static int Not8bit; /* Seven bits seen on header */
char *frametypes[] = { char *frametypes[] = {
(char *)"EMPTY", /* -16 */ (char *)"EMPTY", /* -16 */
@ -193,7 +172,8 @@ void zsbhdr(int len, int type, register char *shdr)
for (n = Znulls; --n >=0; ) for (n = Znulls; --n >=0; )
BUFFER_BYTE(0); BUFFER_BYTE(0);
BUFFER_BYTE(ZPAD); BUFFER_BYTE(ZDLE); BUFFER_BYTE(ZPAD);
BUFFER_BYTE(ZDLE);
switch (Crc32t=Txfcs32) { switch (Crc32t=Txfcs32) {
case 2: zsbh32(len, shdr, type, Usevhdrs?ZVBINR32:ZBINR32); 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) if (Usevhdrs)
zsendline(len); zsendline(len);
zsendline(type); zsendline(type);
crc = 0xFFFFFFFFL; crc = updcrc32(type, crc); crc = 0xFFFFFFFFL;
crc = updcrc32(type, crc);
for (n=len; --n >= 0; ++shdr) { for (n=len; --n >= 0; ++shdr) {
crc = updcrc32((0377 & *shdr), crc); crc = updcrc32((0377 & *shdr), crc);
@ -258,7 +239,7 @@ void zshhdr(int len, int type, register char *shdr)
register int n; register int n;
register unsigned short crc; 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(); BUFFER_CLEAR();
@ -275,7 +256,8 @@ void zshhdr(int len, int type, register char *shdr)
crc = updcrc16(type, 0); crc = updcrc16(type, 0);
for (n=len; --n >= 0; ++shdr) { 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)); crc = updcrc16(0,updcrc16(0,crc));
zputhex(((int)(crc>>8))); zputhex(crc); zputhex(((int)(crc>>8))); zputhex(crc);
@ -316,14 +298,16 @@ void zsdata(register char *buf, int length, int frameend)
break; break;
default: crc = 0; default: crc = 0;
for (;--length >= 0; ++buf) { for (;--length >= 0; ++buf) {
zsendline(*buf); crc = updcrc16((0377 & *buf), crc); zsendline(*buf);
crc = updcrc16((0377 & *buf), crc);
} }
BUFFER_BYTE(ZDLE); BUFFER_BYTE(ZDLE);
BUFFER_BYTE(frameend); BUFFER_BYTE(frameend);
crc = updcrc16(frameend, crc); crc = updcrc16(frameend, crc);
crc = updcrc16(0,updcrc16(0,crc)); crc = updcrc16(0,updcrc16(0,crc));
zsendline(((int)(crc>>8))); zsendline(crc); zsendline(((int)(crc>>8)));
zsendline(crc);
} }
if (frameend == ZCRCW) if (frameend == ZCRCW)
BUFFER_BYTE(XON); BUFFER_BYTE(XON);
@ -353,7 +337,8 @@ void zsda32(register char *buf, int length, int frameend)
crc = ~crc; crc = ~crc;
for (c=4; --c >= 0;) { 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 char *end;
register int d; register int d;
Syslog('z', "zrdata: len=%d, Crc32r=%d", length, Crc32r);
switch (Crc32r) { switch (Crc32r) {
case 1: case 1:
return zrdat32(buf, length); return zrdat32(buf, length);
@ -378,7 +365,9 @@ int zrdata(register char *buf, int length)
return zrdatr32(buf, length); return zrdatr32(buf, length);
} }
crc = Rxcount = 0; end = buf + length; crc = Rxcount = 0;
end = buf + length;
while (buf <= end) { while (buf <= end) {
if ((c = zdlread()) & ~0377) { if ((c = zdlread()) & ~0377) {
crcfoo: crcfoo:
@ -426,7 +415,10 @@ int zrdat32(register char *buf, int length)
register char *end; register char *end;
register int d; register int d;
crc = 0xFFFFFFFFL; Rxcount = 0; end = buf + length; crc = 0xFFFFFFFFL;
Rxcount = 0;
end = buf + length;
while (buf <= end) { while (buf <= end) {
if ((c = zdlread()) & ~0377) { if ((c = zdlread()) & ~0377) {
crcfoo: crcfoo:
@ -493,161 +485,170 @@ void garbitch(void)
*/ */
int zgethdr(char *shdr) int zgethdr(char *shdr)
{ {
register int c, n, cancount; register int c, n, cancount;
int Zrwindow = 1400;
int Baudrate = 9600;
int Zrwindow = 1400; n = Zrwindow + Baudrate;
int Baudrate = 9600; Rxframeind = Rxtype = 0;
n = Zrwindow + Baudrate; Syslog('z', "zgethdr(%lx)", rclhdr(shdr));
Rxframeind = Rxtype = 0;
startover: startover:
cancount = 5; cancount = 5;
again: again:
/* /*
* Return immediate ERROR if ZCRCW sequence seen * Return immediate ERROR if ZCRCW sequence seen
*/ */
if (((c = GETCHAR(Rxtimeout)) < 0) && (c != TIMEOUT)) if (((c = GETCHAR(Rxtimeout)) < 0) && (c != TIMEOUT))
goto fifi; goto fifi;
else switch(c) { else {
case 021: case 0221: // Syslog('z', "Zmodem: Got %c %d", c, c);
goto again; switch(c) {
case 021:
case 0221: goto again;
case HANGUP: case HANGUP:
case TIMEOUT: case TIMEOUT: goto fifi;
goto fifi;
case CAN: case CAN:
gotcan: gotcan:
if (--cancount <= 0) { Syslog('z', "zgethdr: got CAN");
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:
goto fifi;
default:
goto agn2;
}
case HANGUP:
goto fifi;
default:
break;
case CAN:
if (--cancount <= 0) { if (--cancount <= 0) {
c = ZCAN; goto fifi; c = ZCAN;
goto fifi;
} }
goto again; switch (c = GETCHAR(Rxtimeout)) {
} case TIMEOUT: goto again;
/* **** FALL THRU TO **** */ case ZCRCW: switch (GETCHAR(Rxtimeout)) {
case TIMEOUT: c = TERROR;
goto fifi;
case HANGUP: goto fifi;
default: goto agn2;
}
case HANGUP: goto fifi;
default: break;
case CAN: if (--cancount <= 0) {
c = ZCAN;
goto fifi;
}
goto again;
}
/* **** FALL THRU TO **** */
default: default:
agn2: agn2:
#define GCOUNT (-4) #define GCOUNT (-4)
if ( --n == 0) { if ( --n == 0) {
c = GCOUNT; goto fifi; c = GCOUNT;
} goto fifi;
goto startover; }
case ZPAD|0200: /* This is what we want. */ goto startover;
Not8bit = c; case ZPAD|0200: /* This is what we want. */
case ZPAD: /* This is what we want. */ Not8bit = c;
break; case ZPAD: /* This is what we want. */
// Syslog('z', "zgethdr: got ZPAD");
break;
} }
cancount = 5; }
cancount = 5;
splat: splat:
switch (c = noxrd7()) { switch (c = noxrd7()) {
case ZPAD: case ZPAD: goto splat;
goto splat;
case HANGUP: case HANGUP:
case TIMEOUT: case TIMEOUT: goto fifi;
goto fifi; default: goto agn2;
default: case ZDLE: /* This is what we want. */
goto agn2; // Syslog('z', "zgethdr: got ZDLE");
case ZDLE: /* This is what we want. */ break;
break; }
}
Rxhlen = 4; /* Set default length */ Rxhlen = 4; /* Set default length */
Rxframeind = c = noxrd7(); Rxframeind = c = noxrd7();
switch (c) { Syslog('z', "zgethdr: header type %d", c);
case ZVBIN32: switch (c) {
if ((Rxhlen = c = zdlread()) < 0) case ZVBIN32: if ((Rxhlen = c = zdlread()) < 0)
goto fifi; goto fifi;
if (c > ZMAXHLEN) if (c > ZMAXHLEN)
goto agn2; goto agn2;
Crc32r = 1; c = zrbhd32(shdr); break; Crc32r = 1;
case ZBIN32: c = zrbhd32(shdr);
if (Usevhdrs) break;
goto agn2; case ZBIN32: if (Usevhdrs)
Crc32r = 1; c = zrbhd32(shdr); break; goto agn2;
case ZVBINR32: Crc32r = 1;
if ((Rxhlen = c = zdlread()) < 0) c = zrbhd32(shdr);
goto fifi; break;
if (c > ZMAXHLEN) case ZVBINR32: if ((Rxhlen = c = zdlread()) < 0)
goto agn2; goto fifi;
Crc32r = 2; c = zrbhd32(shdr); break; if (c > ZMAXHLEN)
case ZBINR32: goto agn2;
if (Usevhdrs) Crc32r = 2;
goto agn2; c = zrbhd32(shdr);
Crc32r = 2; c = zrbhd32(shdr); break; break;
case ZBINR32: if (Usevhdrs)
goto agn2;
Crc32r = 2;
c = zrbhd32(shdr);
break;
case HANGUP: case HANGUP:
case TIMEOUT: case TIMEOUT: goto fifi;
goto fifi; case ZVBIN: if ((Rxhlen = c = zdlread()) < 0)
case ZVBIN: goto fifi;
if ((Rxhlen = c = zdlread()) < 0) if (c > ZMAXHLEN)
goto fifi; goto agn2;
if (c > ZMAXHLEN) Crc32r = 0;
goto agn2; c = zrbhdr(shdr);
Crc32r = 0; c = zrbhdr(shdr); break; break;
case ZBIN: case ZBIN: if (Usevhdrs)
if (Usevhdrs) goto agn2;
goto agn2; Crc32r = 0;
Crc32r = 0; c = zrbhdr(shdr); break; c = zrbhdr(shdr);
case ZVHEX: break;
if ((Rxhlen = c = zgethex()) < 0) case ZVHEX: if ((Rxhlen = c = zgethex()) < 0)
goto fifi; goto fifi;
if (c > ZMAXHLEN) if (c > ZMAXHLEN)
goto agn2; goto agn2;
Crc32r = 0; c = zrhhdr(shdr); break; Crc32r = 0;
case ZHEX: c = zrhhdr(shdr);
if (Usevhdrs) break;
goto agn2; case ZHEX: if (Usevhdrs)
Crc32r = 0; c = zrhhdr(shdr); break; goto agn2;
case CAN: Crc32r = 0;
goto gotcan; c = zrhhdr(shdr);
default: break;
goto agn2; case CAN: goto gotcan;
} default: goto agn2;
for (n = Rxhlen; ++n < ZMAXHLEN; ) /* Clear unused hdr bytes */ }
shdr[n] = 0;
Rxpos = shdr[ZP3] & 0377; for (n = Rxhlen; ++n < ZMAXHLEN; ) /* Clear unused hdr bytes */
Rxpos = (Rxpos<<8) + (shdr[ZP2] & 0377); shdr[n] = 0;
Rxpos = (Rxpos<<8) + (shdr[ZP1] & 0377); Rxpos = shdr[ZP3] & 0377;
Rxpos = (Rxpos<<8) + (shdr[ZP0] & 0377); Rxpos = (Rxpos<<8) + (shdr[ZP2] & 0377);
Rxpos = (Rxpos<<8) + (shdr[ZP1] & 0377);
Rxpos = (Rxpos<<8) + (shdr[ZP0] & 0377);
fifi: fifi:
switch (c) { Syslog('z', "Zmodem: at fifi Got %d", c);
case GOTCAN: switch (c) {
c = ZCAN; case GOTCAN: c = ZCAN;
/* **** FALL THRU TO **** */ /* **** FALL THRU TO **** */
case ZNAK: case ZNAK:
case ZCAN: case ZCAN:
case TERROR: case TERROR:
case TIMEOUT: case TIMEOUT:
case HANGUP: case HANGUP: Syslog('+', "Zmodem: Got %s", frametypes[c+FTOFFSET]);
Syslog('+', "Zmodem: Got %s", frametypes[c+FTOFFSET]); /* **** FALL THRU TO **** */
/* **** FALL THRU TO **** */ default: if (c >= -FTOFFSET && c <= FRTYPES)
default: Syslog('z', "zgethdr: %c %d %s %lx", Rxframeind, Rxhlen, frametypes[c+FTOFFSET], Rxpos);
if (c >= -FTOFFSET && c <= FRTYPES) else
Syslog('z', "zgethdr: %c %d %s %ld", Rxframeind, Rxhlen, frametypes[c+FTOFFSET], Rxpos); Syslog('z', "zgethdr: %d %d %ld", Rxframeind, c, Rxpos);
else }
Syslog('z', "zgethdr: %c %d %ld", Rxframeind, c, Rxpos);
} /* Use variable length headers if we got one */
/* Use variable length headers if we got one */ if (c >= 0 && c <= FRTYPES && Rxframeind & 040) {
if (c >= 0 && c <= FRTYPES && Rxframeind & 040) Usevhdrs = 1;
Usevhdrs = 1; Syslog('z', "zgethdr: Usevhdrs");
return c; }
return c;
} }
@ -657,31 +658,31 @@ fifi:
*/ */
int zrbhdr(register char *shdr) int zrbhdr(register char *shdr)
{ {
register int c, n; register int c, n;
register unsigned short crc; register unsigned short crc;
if ((c = zdlread()) & ~0377) if ((c = zdlread()) & ~0377)
return c; return c;
Rxtype = c; Rxtype = c;
crc = updcrc16(c, 0); crc = updcrc16(c, 0);
for (n=Rxhlen; --n >= 0; ++shdr) { for (n=Rxhlen; --n >= 0; ++shdr) {
if ((c = zdlread()) & ~0377)
return c;
crc = updcrc16(c, crc);
*shdr = c;
}
if ((c = zdlread()) & ~0377) if ((c = zdlread()) & ~0377)
return c; return c;
crc = updcrc16(c, crc); crc = updcrc16(c, crc);
if ((c = zdlread()) & ~0377) *shdr = c;
return c; }
crc = updcrc16(c, crc); if ((c = zdlread()) & ~0377)
if (crc & 0xFFFF) { return c;
Syslog('+', "Zmodem zrbhdr: Bad CRC"); crc = updcrc16(c, crc);
return TERROR; if ((c = zdlread()) & ~0377)
} return c;
return Rxtype; crc = updcrc16(c, crc);
if (crc & 0xFFFF) {
Syslog('+', "Zmodem zrbhdr: Bad CRC");
return TERROR;
}
return Rxtype;
} }
@ -691,30 +692,30 @@ int zrbhdr(register char *shdr)
*/ */
int zrbhd32(register char *shdr) int zrbhd32(register char *shdr)
{ {
register int c, n; register int c, n;
register unsigned long crc; register unsigned long crc;
if ((c = zdlread()) & ~0377)
return c;
Rxtype = c;
crc = 0xFFFFFFFFL; crc = updcrc32(c, crc);
for (n=Rxhlen; --n >= 0; ++shdr) {
if ((c = zdlread()) & ~0377) if ((c = zdlread()) & ~0377)
return c; return c;
Rxtype = c; crc = updcrc32(c, crc);
crc = 0xFFFFFFFFL; crc = updcrc32(c, crc); *shdr = c;
}
for (n=Rxhlen; --n >= 0; ++shdr) { for (n=4; --n >= 0;) {
if ((c = zdlread()) & ~0377) if ((c = zdlread()) & ~0377)
return c; return c;
crc = updcrc32(c, crc); crc = updcrc32(c, crc);
*shdr = c; }
} if (crc != 0xDEBB20E3) {
for (n=4; --n >= 0;) { Syslog('+', "Zmodem zrbhd32: Bad CRC");
if ((c = zdlread()) & ~0377) return TERROR;
return c; }
crc = updcrc32(c, crc); return Rxtype;
}
if (crc != 0xDEBB20E3) {
Syslog('+', "Zmodem zrbhd32: Bad CRC");
return TERROR;
}
return Rxtype;
} }
@ -724,45 +725,43 @@ int zrbhd32(register char *shdr)
*/ */
int zrhhdr(char *shdr) int zrhhdr(char *shdr)
{ {
register int c; register int c;
register unsigned short crc; register unsigned short crc;
register int n; register int n;
if ((c = zgethex()) < 0) if ((c = zgethex()) < 0)
return c; return c;
Rxtype = c; Rxtype = c;
crc = updcrc16(c, 0); crc = updcrc16(c, 0);
for (n=Rxhlen; --n >= 0; ++shdr) { for (n=Rxhlen; --n >= 0; ++shdr) {
if ((c = zgethex()) < 0)
return c;
crc = updcrc16(c, crc);
*shdr = c;
}
if ((c = zgethex()) < 0) if ((c = zgethex()) < 0)
return c; return c;
crc = updcrc16(c, crc); crc = updcrc16(c, crc);
if ((c = zgethex()) < 0) *shdr = c;
return c; }
crc = updcrc16(c, crc); if ((c = zgethex()) < 0)
if (crc & 0xFFFF) { return c;
Syslog('+', "Zmodem zrhhdr: Bad CRC"); crc = updcrc16(c, crc);
return TERROR; if ((c = zgethex()) < 0)
} return c;
switch (c = GETCHAR(Rxtimeout)) { crc = updcrc16(c, crc);
case 0215: if (crc & 0xFFFF) {
Not8bit = c; Syslog('+', "Zmodem zrhhdr: Bad CRC");
/* **** FALL THRU TO **** */ return TERROR;
case 015: }
/* Throw away possible cr/lf */
switch (c = GETCHAR(Rxtimeout)) { switch (c = GETCHAR(Rxtimeout)) {
case 012: case 0215: Not8bit = c;
Not8bit |= c; /* **** FALL THRU TO **** */
} case 015: /* Throw away possible cr/lf */
} switch (c = GETCHAR(Rxtimeout)) {
if (c < 0) case 012: Not8bit |= c;
return c; }
return Rxtype; }
if (c < 0)
return c;
return Rxtype;
} }
@ -772,10 +771,10 @@ int zrhhdr(char *shdr)
*/ */
void zputhex(register int c) void zputhex(register int c)
{ {
static char digits[] = "0123456789abcdef"; static char digits[] = "0123456789abcdef";
BUFFER_BYTE(digits[(c&0xF0)>>4]); BUFFER_BYTE(digits[(c&0xF0)>>4]);
BUFFER_BYTE(digits[(c)&0xF]); BUFFER_BYTE(digits[(c)&0xF]);
} }
@ -786,39 +785,35 @@ void zputhex(register int c)
*/ */
void zsendline(int c) void zsendline(int c)
{ {
/* Quick check for non control characters */ /* Quick check for non control characters */
if (c & 0140) if (c & 0140)
BUFFER_BYTE(lastsent = c); BUFFER_BYTE(lastsent = c);
else { else {
switch (c &= 0377) { switch (c &= 0377) {
case ZDLE: case ZDLE: BUFFER_BYTE(ZDLE);
BUFFER_BYTE(ZDLE);
BUFFER_BYTE (lastsent = (c ^= 0100)); BUFFER_BYTE (lastsent = (c ^= 0100));
break; break;
case 015: case 015:
case 0215: case 0215: if (!Zctlesc && (lastsent & 0177) != '@')
if (!Zctlesc && (lastsent & 0177) != '@') goto sendit;
goto sendit; /* **** FALL THRU TO **** */
/* **** FALL THRU TO **** */ case 020:
case 020: case 021:
case 021: case 023:
case 023: case 0220:
case 0220: case 0221:
case 0221: case 0223: BUFFER_BYTE(ZDLE);
case 0223:
BUFFER_BYTE(ZDLE);
c ^= 0100; c ^= 0100;
sendit: sendit:
BUFFER_BYTE(lastsent = c); BUFFER_BYTE(lastsent = c);
break; break;
default: default: if (Zctlesc && ! (c & 0140)) {
if (Zctlesc && ! (c & 0140)) { BUFFER_BYTE(ZDLE);
BUFFER_BYTE(ZDLE); c ^= 0100;
c ^= 0100;
} }
BUFFER_BYTE(lastsent = c); BUFFER_BYTE(lastsent = c);
}
} }
}
} }
@ -826,34 +821,34 @@ void zsendline(int c)
/* Decode two lower case hex digits into an 8 bit byte value */ /* Decode two lower case hex digits into an 8 bit byte value */
int zgethex(void) int zgethex(void)
{ {
register int c; register int c;
c = zgeth1(); c = zgeth1();
return c; return c;
} }
int zgeth1(void) int zgeth1(void)
{ {
register int c, n; register int c, n;
if ((c = noxrd7()) < 0) if ((c = noxrd7()) < 0)
return c;
n = c - '0';
if (n > 9)
n -= ('a' - ':');
if (n & ~0xF)
return TERROR;
if ((c = noxrd7()) < 0)
return c;
c -= '0';
if (c > 9)
c -= ('a' - ':');
if (c & ~0xF)
return TERROR;
c += (n<<4);
return c; return c;
n = c - '0';
if (n > 9)
n -= ('a' - ':');
if (n & ~0xF)
return TERROR;
if ((c = noxrd7()) < 0)
return c;
c -= '0';
if (c > 9)
c -= ('a' - ':');
if (c & ~0xF)
return TERROR;
c += (n<<4);
return c;
} }
@ -864,62 +859,57 @@ int zgeth1(void)
*/ */
int zdlread(void) int zdlread(void)
{ {
register int c; register int c;
again: again:
/* Quick check for non control characters */ /* Quick check for non control characters */
if ((c = GETCHAR(Rxtimeout)) & 0140) if ((c = GETCHAR(Rxtimeout)) & 0140)
return c; return c;
switch (c) {
case ZDLE: switch (c) {
break; case ZDLE: break;
case 023: case 023:
case 0223: case 0223:
case 021: case 021:
case 0221: case 0221: goto again;
goto again; default: if (Zctlesc && !(c & 0140)) {
default:
if (Zctlesc && !(c & 0140)) {
goto again; goto again;
} }
return c; return c;
} }
again2: again2:
if ((c = GETCHAR(Rxtimeout)) < 0) if ((c = GETCHAR(Rxtimeout)) < 0)
return c; return c;
if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0) if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0)
return c; return c;
if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0) if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0)
return c; return c;
if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0) if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0)
return c; return c;
switch (c) {
case CAN: switch (c) {
return GOTCAN; case CAN: return GOTCAN;
case ZCRCE: case ZCRCE:
case ZCRCG: case ZCRCG:
case ZCRCQ: case ZCRCQ:
case ZCRCW: case ZCRCW: return (c | GOTOR);
return (c | GOTOR); case ZRUB0: return 0177;
case ZRUB0: case ZRUB1: return 0377;
return 0177;
case ZRUB1:
return 0377;
case 023: case 023:
case 0223: case 0223:
case 021: case 021:
case 0221: case 0221: goto again2;
goto again2; default: if (Zctlesc && ! (c & 0140)) {
default:
if (Zctlesc && ! (c & 0140)) {
goto again2; goto again2;
} }
if ((c & 0140) == 0100) if ((c & 0140) == 0100)
return (c ^ 0100); return (c ^ 0100);
break; break;
} }
Syslog('+', "Zmodem: Bad escape sequence 0x%x", c);
return TERROR; Syslog('+', "Zmodem: Bad escape sequence 0x%x", c);
return TERROR;
} }
@ -930,24 +920,22 @@ again2:
*/ */
int noxrd7(void) int noxrd7(void)
{ {
register int c; register int c;
for (;;) { for (;;) {
if ((c = GETCHAR(Rxtimeout)) < 0) if ((c = GETCHAR(Rxtimeout)) < 0)
return c; return c;
switch (c &= 0177) {
case XON: switch (c &= 0177) {
case XOFF: case XON:
continue; case XOFF: continue;
default: default: if (Zctlesc && !(c & 0140))
if (Zctlesc && !(c & 0140)) continue;
continue; case '\r':
case '\r': case '\n':
case '\n': case ZDLE: return c;
case ZDLE:
return c;
}
} }
}
} }
@ -957,10 +945,10 @@ int noxrd7(void)
*/ */
void stohdr(long pos) void stohdr(long pos)
{ {
Txhdr[ZP0] = pos; Txhdr[ZP0] = pos;
Txhdr[ZP1] = pos>>8; Txhdr[ZP1] = pos>>8;
Txhdr[ZP2] = pos>>16; Txhdr[ZP2] = pos>>16;
Txhdr[ZP3] = pos>>24; Txhdr[ZP3] = pos>>24;
} }
@ -970,13 +958,13 @@ void stohdr(long pos)
*/ */
long rclhdr(register char *shdr) long rclhdr(register char *shdr)
{ {
register long l; register long l;
l = (shdr[ZP3] & 0377); l = (shdr[ZP3] & 0377);
l = (l << 8) | (shdr[ZP2] & 0377); l = (l << 8) | (shdr[ZP2] & 0377);
l = (l << 8) | (shdr[ZP1] & 0377); l = (l << 8) | (shdr[ZP1] & 0377);
l = (l << 8) | (shdr[ZP0] & 0377); l = (l << 8) | (shdr[ZP0] & 0377);
return l; return l;
} }
/* End of zmmisc.c */ /* End of zmmisc.c */

View File

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

View File

@ -40,7 +40,6 @@
static FILE *fout = NULL; static FILE *fout = NULL;
char *curfile = NULL; char *curfile = NULL;
static int Usevhdrs;
static off_t rxbytes; static off_t rxbytes;
static int Eofseen; /* indicates cpm eof (^Z) has been received */ static int Eofseen; /* indicates cpm eof (^Z) has been received */
static int errors; static int errors;
@ -52,13 +51,8 @@ struct timezone tz;
static long Bytesleft; /* number of bytes of incoming file left */ static long Bytesleft; /* number of bytes of incoming file left */
static long Modtime; /* Unix style mod time for incoming file */ static long Modtime; /* Unix style mod time for incoming file */
static int Filemode; /* Unix style mode for incoming file */ static int Filemode; /* Unix style mode for incoming file */
static int Thisbinary = TRUE; /* current file is to be received in bin mode */
static int Thisbinary; /* current file is to be received in bin mode */ static char *secbuf=0; /* "sector" buffer */
char Lzconv; /* Local ZMODEM file conversion request */
char Lzmanag; /* Local file management request */
static char *secbuf=0;
static int tryzhdrtype; static int tryzhdrtype;
static char zconv; /* ZMODEM file conversion request */ static char zconv; /* ZMODEM file conversion request */
static char zmanag; /* ZMODEM file management request */ static char zmanag; /* ZMODEM file management request */
@ -75,45 +69,44 @@ static int ackbibi(void);
static long getfree(void); static long getfree(void);
void get_frame_buffer(void);
void free_frame_buffer(void);
extern unsigned long rcvdbytes; extern unsigned long rcvdbytes;
int zmrcvfiles(void) int zmrcvfiles(void)
{ {
int rc; int rc;
Syslog('+', "Zmodem: start Zmodem receive"); Syslog('+', "Zmodem: start Zmodem receive");
get_frame_buffer(); get_frame_buffer();
if (secbuf == NULL) if (secbuf == NULL)
secbuf = malloc(MAXBLOCK+1); secbuf = malloc(MAXBLOCK+1);
tryzhdrtype = ZRINIT; tryzhdrtype = ZRINIT;
if ((rc = tryz()) < 0) { if ((rc = tryz()) < 0) {
Syslog('+', "Zmodem: could not initiate receive, rc=%d",rc); Syslog('+', "Zmodem: could not initiate receive, rc=%d",rc);
} else } else
switch (rc) { switch (rc) {
case ZCOMPL: rc = 0; break; case ZCOMPL: rc = 0;
case ZFILE: rc = rzfiles(); break; break;
} case ZFILE: rc = rzfiles();
break;
if (fout) {
if (closeit(0)) {
WriteError("Zmodem: Error closing file");
}
} }
if (secbuf) if (fout) {
free(secbuf); if (closeit(0)) {
secbuf = NULL; WriteError("Zmodem: Error closing file");
free_frame_buffer(); }
}
Syslog('z', "Zmodem: receive rc=%d",rc); if (secbuf)
return abs(rc); free(secbuf);
secbuf = NULL;
free_frame_buffer();
Syslog('z', "Zmodem: receive rc=%d",rc);
return abs(rc);
} }
@ -126,87 +119,96 @@ int zmrcvfiles(void)
*/ */
int tryz(void) int tryz(void)
{ {
int c, n; int c, n;
int cmdzack1flg; int cmdzack1flg;
for (n = 15; --n >= 0; ) { for (n = 15; --n >= 0; ) {
/* /*
* Set buffer length (0) and capability flags * Set buffer length (0) and capability flags
*/ */
Syslog('z', "tryz attempt %d", n); Syslog('z', "tryz attempt %d", n);
stohdr(0L); stohdr(0L);
Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO; // Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO;
if (Zctlesc) Txhdr[ZF0] = CANFC32;
Txhdr[ZF0] |= TESCCTL; if (Zctlesc)
Txhdr[ZF0] |= CANRLE; Txhdr[ZF0] |= TESCCTL;
Txhdr[ZF1] = CANVHDR; // Txhdr[ZF0] |= CANRLE;
zshhdr(4, tryzhdrtype, Txhdr); Txhdr[ZF1] = CANVHDR;
if (tryzhdrtype == ZSKIP) /* Don't skip too far */ zshhdr(4, tryzhdrtype, Txhdr);
tryzhdrtype = ZRINIT; /* CAF 8-21-87 */ if (tryzhdrtype == ZSKIP) /* Don't skip too far */
tryzhdrtype = ZRINIT; /* CAF 8-21-87 */
again: again:
switch (zgethdr(Rxhdr)) { switch (zgethdr(Rxhdr)) {
case ZRQINIT: case ZRQINIT: if (Rxhdr[ZF3] & 0x80)
if (Rxhdr[ZF3] & 0x80)
Usevhdrs = TRUE; /* we can var header */ Usevhdrs = TRUE; /* we can var header */
continue; continue;
case ZEOF: case ZEOF: continue;
continue; case TIMEOUT: Syslog('+', "Zmodem: tryz() timeout attempt %d", n);
case TIMEOUT: continue;
Syslog('+', "Zmodem: tryz() timeout attempt %d", n); case ZFILE: zconv = Rxhdr[ZF0];
continue; if (!zconv) {
case ZFILE: Syslog('z', "*** !zconv %d", zconv);
zconv = Rxhdr[ZF0]; }
zmanag = Rxhdr[ZF1]; zmanag = Rxhdr[ZF1];
ztrans = Rxhdr[ZF2]; ztrans = Rxhdr[ZF2];
if (Rxhdr[ZF3] & ZCANVHDR) if (Rxhdr[ZF3] & ZCANVHDR)
Usevhdrs = TRUE; Usevhdrs = TRUE;
tryzhdrtype = ZRINIT; tryzhdrtype = ZRINIT;
c = zrdata(secbuf, MAXBLOCK); c = zrdata(secbuf, MAXBLOCK);
if (c == GOTCRCW) if (c == GOTCRCW) {
Syslog('z', "tryz return ZFILE");
return ZFILE; return ZFILE;
zshhdr(4,ZNAK, Txhdr); }
goto again; zshhdr(4,ZNAK, Txhdr);
case ZSINIT: goto again;
Zctlesc = TESCCTL & Rxhdr[ZF0]; case ZSINIT: /* this once was:
if (zrdata(Attn, ZATTNLEN) == GOTCRCW) { * 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); stohdr(1L);
zshhdr(4,ZACK, Txhdr); zshhdr(4,ZACK, Txhdr);
goto again; goto again;
} }
zshhdr(4,ZNAK, Txhdr); zshhdr(4,ZNAK, Txhdr);
goto again; goto again;
case ZFREECNT: case ZFREECNT: stohdr(getfree());
stohdr(getfree()); zshhdr(4,ZACK, Txhdr);
zshhdr(4,ZACK, Txhdr); goto again;
goto again; case ZCOMMAND: cmdzack1flg = Rxhdr[ZF0];
case ZCOMMAND: if (zrdata(secbuf, MAXBLOCK) == GOTCRCW) {
cmdzack1flg = Rxhdr[ZF0];
if (zrdata(secbuf, MAXBLOCK) == GOTCRCW) {
if (cmdzack1flg & ZCACK1) if (cmdzack1flg & ZCACK1)
stohdr(0L); stohdr(0L);
else else
Syslog('+', "Zmodem: request for command \"%s\" ignored", printable(secbuf,-32)); Syslog('+', "Zmodem: request for command \"%s\" ignored", printable(secbuf,-32));
stohdr(0L); stohdr(0L);
do { do {
zshhdr(4,ZCOMPL, Txhdr); zshhdr(4,ZCOMPL, Txhdr);
} while (++errors<20 && zgethdr(Rxhdr) != ZFIN); } while (++errors<20 && zgethdr(Rxhdr) != ZFIN);
return ackbibi(); return ackbibi();
} }
zshhdr(4,ZNAK, Txhdr); goto again; zshhdr(4,ZNAK, Txhdr);
case ZCOMPL: goto again;
goto again; case ZCOMPL: goto again;
case ZRINIT: case ZRINIT: Syslog('z', "tryz: got ZRINIT");
case ZFIN: /* do not beleive in first ZFIN */ return TERROR;
ackbibi(); return ZCOMPL; case ZFIN: /* do not beleive in first ZFIN */
case TERROR: ackbibi();
case HANGUP: return ZCOMPL;
case ZCAN: case TERROR:
return TERROR; case HANGUP:
default: case ZCAN: return TERROR;
continue; default: continue;
}
} }
return 0; }
Syslog('z', "tryz return 0");
return 0;
} }
@ -216,31 +218,25 @@ again:
*/ */
int rzfiles(void) int rzfiles(void)
{ {
int c; int c;
Syslog('z', "rzfiles"); Syslog('z', "rzfiles");
for (;;) { for (;;) {
switch (c = rzfile()) { switch (c = rzfile()) {
case ZEOF: case ZEOF:
case ZSKIP: case ZSKIP:
case ZFERR: case ZFERR: switch (tryz()) {
switch (tryz()) { case ZCOMPL: return OK;
case ZCOMPL: default: return TERROR;
return OK; case ZFILE: break;
default: }
return TERROR; continue;
case ZFILE: default: return c;
break; case TERROR: return TERROR;
}
continue;
default:
return c;
case TERROR:
return TERROR;
}
} }
/* NOTREACHED */ }
/* NOTREACHED */
} }
@ -251,50 +247,45 @@ int rzfiles(void)
*/ */
int rzfile(void) int rzfile(void)
{ {
int c, n; int c, n;
Syslog('z', "rzfile"); Syslog('z', "rzfile");
Eofseen=FALSE; Eofseen=FALSE;
rxbytes = 0l; rxbytes = 0l;
if ((c = procheader(secbuf))) { if ((c = procheader(secbuf))) {
return (tryzhdrtype = c); return (tryzhdrtype = c);
} }
n = 20; n = 20;
for (;;) { for (;;) {
stohdr(rxbytes); Syslog('z', "rxbytes %ld", rxbytes);
zshhdr(4,ZRPOS, Txhdr); stohdr(rxbytes);
zshhdr(4,ZRPOS, Txhdr);
nxthdr: nxthdr:
switch (c = zgethdr(Rxhdr)) { switch (c = zgethdr(Rxhdr)) {
default: default: Syslog('z', "rzfile: Wrong header %d", c);
Syslog('z', "rzfile: Wrong header %d", c); if ( --n < 0) {
if ( --n < 0) {
Syslog('+', "Zmodem: wrong header %d", c); Syslog('+', "Zmodem: wrong header %d", c);
return TERROR; return TERROR;
} }
continue; continue;
case ZCAN: case ZCAN: Syslog('+', "Zmodem: sender CANcelled");
Syslog('+', "Zmodem: sender CANcelled"); return TERROR;
return TERROR; case ZNAK: if ( --n < 0) {
case ZNAK:
if ( --n < 0) {
Syslog('+', "Zmodem: Got ZNAK"); Syslog('+', "Zmodem: Got ZNAK");
return TERROR; return TERROR;
} }
continue; continue;
case TIMEOUT: case TIMEOUT: if ( --n < 0) {
if ( --n < 0) {
Syslog('+', "Zmodem: TIMEOUT"); Syslog('+', "Zmodem: TIMEOUT");
return TERROR; return TERROR;
} }
continue; continue;
case ZFILE: case ZFILE: zrdata(secbuf, MAXBLOCK);
zrdata(secbuf, MAXBLOCK); continue;
continue; case ZEOF: if (rclhdr(Rxhdr) != rxbytes) {
case ZEOF:
if (rclhdr(Rxhdr) != rxbytes) {
/* /*
* Ignore eof if it's at wrong place - force * Ignore eof if it's at wrong place - force
* a timeout because the eof might have gone * a timeout because the eof might have gone
@ -302,90 +293,81 @@ nxthdr:
*/ */
errors = 0; errors = 0;
goto nxthdr; goto nxthdr;
} }
if (closeit(1)) { if (closeit(1)) {
tryzhdrtype = ZFERR; tryzhdrtype = ZFERR;
Syslog('+', "Zmodem: error closing file"); Syslog('+', "Zmodem: error closing file");
return TERROR; return TERROR;
} }
fout=NULL; fout = NULL;
Syslog('z', "rzfile: normal EOF"); Syslog('z', "rzfile: normal EOF");
return c; return c;
case HANGUP: case HANGUP: Syslog('+', "Zmodem: Lost Carrier");
Syslog('+', "Zmodem: Lost Carrier"); return TERROR;
return TERROR; case TERROR: /* Too much garbage in header search error */
case TERROR: /* Too much garbage in header search error */ if (--n < 0) {
if (--n < 0) {
Syslog('+', "Zmodem: Too many errors"); Syslog('+', "Zmodem: Too many errors");
return TERROR; return TERROR;
} }
zmputs(Attn); zmputs(Attn);
continue; continue;
case ZSKIP: case ZSKIP: Modtime = 1;
Modtime = 1; closeit(1);
closeit(1); Syslog('+', "Zmodem: Sender SKIPPED file");
Syslog('+', "Zmodem: Sender SKIPPED file"); return c;
return c; case ZDATA: if (rclhdr(Rxhdr) != rxbytes) {
case ZDATA:
if (rclhdr(Rxhdr) != rxbytes) {
if ( --n < 0) { if ( --n < 0) {
Syslog('+', "Zmodem: Data has bad address"); Syslog('+', "Zmodem: Data has bad address");
return TERROR; return TERROR;
}
zmputs(Attn); continue;
}
moredata:
Syslog('z', "%7ld ZMODEM%s ",
rxbytes, Crc32r?" CRC-32":"");
Nopper();
switch (c = zrdata(secbuf, MAXBLOCK)) {
case ZCAN:
Syslog('+', "Zmodem: sender CANcelled");
return TERROR;
case HANGUP:
Syslog('+', "Zmodem: Lost Carrier");
return TERROR;
case TERROR: /* CRC error */
if (--n < 0) {
Syslog('+', "Zmodem: Too many errors");
return TERROR;
} }
zmputs(Attn); zmputs(Attn);
continue; continue;
case TIMEOUT: }
if ( --n < 0) { moredata:
Syslog('+', "Zmodem: TIMEOUT"); Syslog('z', "%7ld ZMODEM%s ", rxbytes, Crc32r?" CRC-32":"");
return TERROR; Nopper();
} switch (c = zrdata(secbuf, MAXBLOCK)) {
continue; case ZCAN: Syslog('+', "Zmodem: sender CANcelled");
case GOTCRCW: return TERROR;
n = 20; case HANGUP: Syslog('+', "Zmodem: Lost Carrier");
putsec(secbuf, Rxcount); return TERROR;
rxbytes += Rxcount; case TERROR: /* CRC error */
stohdr(rxbytes); if (--n < 0) {
PUTCHAR(XON); Syslog('+', "Zmodem: Too many errors");
zshhdr(4,ZACK, Txhdr); return TERROR;
goto nxthdr; }
case GOTCRCQ: zmputs(Attn);
n = 20; continue;
putsec(secbuf, Rxcount); case TIMEOUT: if ( --n < 0) {
rxbytes += Rxcount; Syslog('+', "Zmodem: TIMEOUT");
stohdr(rxbytes); return TERROR;
zshhdr(4,ZACK, Txhdr); }
goto moredata; continue;
case GOTCRCG: case GOTCRCW: n = 20;
n = 20; putsec(secbuf, Rxcount);
putsec(secbuf, Rxcount); rxbytes += Rxcount;
rxbytes += Rxcount; Syslog('z', "rxbytes %ld, will ACK", rxbytes);
goto moredata; stohdr(rxbytes);
case GOTCRCE: PUTCHAR(XON);
n = 20; zshhdr(4,ZACK, Txhdr);
putsec(secbuf, Rxcount); goto nxthdr;
rxbytes += Rxcount; case GOTCRCQ: n = 20;
goto nxthdr; putsec(secbuf, Rxcount);
} rxbytes += Rxcount;
} stohdr(rxbytes);
zshhdr(4,ZACK, Txhdr);
goto moredata;
case GOTCRCG: n = 20;
putsec(secbuf, Rxcount);
rxbytes += Rxcount;
goto moredata;
case GOTCRCE: n = 20;
putsec(secbuf, Rxcount);
rxbytes += Rxcount;
goto nxthdr;
}
} }
}
} }
@ -396,22 +378,21 @@ moredata:
*/ */
void zmputs(char *s) void zmputs(char *s)
{ {
int c; int c;
Syslog('z', "zmputs: \"%s\"", printable(s, strlen(s))); Syslog('z', "zmputs: \"%s\"", printable(s, strlen(s)));
while (*s) { while (*s) {
switch (c = *s++) { switch (c = *s++) {
case '\336': case '\336': Syslog('z', "zmputs: sleep(1)");
Syslog('z', "zmputs: sleep(1)"); sleep(1);
sleep(1); continue; continue;
case '\335': case '\335': Syslog('z', "zmputs: send break");
Syslog('z', "zmputs: send break"); sendbrk();
sendbrk(); continue; continue;
default: default: PUTCHAR(c);
PUTCHAR(c);
}
} }
}
} }
@ -421,6 +402,13 @@ int closeit(int success)
struct utimbuf ut; struct utimbuf ut;
int rc; int rc;
Syslog('z', "closeit(%d)", success);
if ((fout == NULL) || (curfile == NULL)) {
Syslog('+', "closeit(), nothing to close");
return 1;
}
rc = fclose(fout); rc = fclose(fout);
fout = NULL; fout = NULL;
@ -450,29 +438,28 @@ int closeit(int success)
*/ */
int ackbibi(void) int ackbibi(void)
{ {
int n; int n;
int c; int c;
Syslog('z', "ackbibi:"); Syslog('z', "ackbibi:");
stohdr(0L); stohdr(0L);
for (n=3; --n>=0; ) {
zshhdr(4,ZFIN, Txhdr); for (n=3; --n>=0; ) {
switch ((c=GETCHAR(10))) { zshhdr(4,ZFIN, Txhdr);
case 'O':
GETCHAR(1); /* Discard 2nd 'O' */ switch ((c = GETCHAR(10))) {
Syslog('z', "Zmodem: ackbibi complete"); case 'O': GETCHAR(1); /* Discard 2nd 'O' */
return ZCOMPL; Syslog('z', "Zmodem: ackbibi complete");
case TERROR: return ZCOMPL;
case HANGUP: case TERROR:
Syslog('z', "Zmodem: ackbibi got %d, ignore",c); case HANGUP: Syslog('z', "Zmodem: ackbibi got %d, ignore",c);
return 0; return 0;
case TIMEOUT: case TIMEOUT:
default: default: Syslog('z', "Zmodem: ackbibi got '%s', continue", printablec(c));
Syslog('z', "Zmodem: ackbibi got '%s', continue", printablec(c)); break;
break;
}
} }
return ZCOMPL; }
return ZCOMPL;
} }
@ -490,18 +477,29 @@ int procheader(char *Name)
/* set default parameters and overrides */ /* set default parameters and overrides */
openmode = (char *)"w"; openmode = (char *)"w";
Syslog('z', "zmanag=%d", zmanag);
Syslog('z', "zconv=%d", zconv);
/* /*
* Process ZMODEM remote file management requests * 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) if (zmanag == ZMAPND)
openmode = (char *)"a"; openmode = (char *)"a";
Syslog('z', "Thisbinary %s", Thisbinary ?"TRUE":"FALSE");
Bytesleft = DEFBYTL; Bytesleft = DEFBYTL;
Filemode = 0; Filemode = 0;
Modtime = 0L; Modtime = 0L;
Eofseen = FALSE;
p = Name + 1 + strlen(Name); 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); sscanf(p, "%ld%lo%o%o%d%d%d%d", &Bytesleft, &Modtime, &Filemode, &dummy, &dummy, &dummy, &dummy, &dummy);
strcpy(ctt, rfcdate(Modtime)); strcpy(ctt, rfcdate(Modtime));
Syslog('+', "Zmodem: \"%s\" %ld bytes, %s mode %o", Name, Bytesleft, ctt, Filemode); 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, exitinfo.Name);
curfile = xstrcat(curfile, (char *)"/upl/"); curfile = xstrcat(curfile, (char *)"/upl/");
curfile = xstrcat(curfile, Name); 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); 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. /* if (Bytesleft == rxbytes) { FIXME: if file already received, use this.
Syslog('+', "Zmodem: Skipping %s", Name); Syslog('+', "Zmodem: Skipping %s", Name);
@ -538,28 +542,30 @@ int procheader(char *Name)
*/ */
int putsec(char *buf, int n) int putsec(char *buf, int n)
{ {
register char *p; register char *p;
if (n == 0) Syslog('z', "putsec %d characters %s mode", n, Thisbinary ? "binary":"ascii");
return OK;
if (Thisbinary) { if (n == 0)
for (p = buf; --n>=0; )
putc( *p++, fout);
} else {
if (Eofseen)
return OK;
for (p = buf; --n>=0; ++p ) {
if ( *p == '\r')
continue;
if (*p == SUB) {
Eofseen=TRUE;
return OK;
}
putc(*p ,fout);
}
}
return OK; return OK;
if (Thisbinary) {
for (p = buf; --n>=0; )
putc( *p++, fout);
} else {
if (Eofseen)
return OK;
for (p = buf; --n>=0; ++p ) {
if ( *p == '\r')
continue;
if (*p == SUB) {
Eofseen=TRUE;
return OK;
}
putc(*p ,fout);
}
}
return OK;
} }

View File

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

View File

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