Fixed idle timer during chat
This commit is contained in:
parent
c1ae6ed787
commit
9eb6526fff
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
700
mbsebbs/zmmisc.c
700
mbsebbs/zmmisc.c
@ -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,32 +74,12 @@ 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 */
|
||||
|
||||
int Rxhlen; /* Length of header received */
|
||||
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 *)"EMPTY", /* -16 */
|
||||
@ -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:
|
||||
@ -493,161 +485,170 @@ void garbitch(void)
|
||||
*/
|
||||
int zgethdr(char *shdr)
|
||||
{
|
||||
register int c, n, cancount;
|
||||
register int c, n, cancount;
|
||||
int Zrwindow = 1400;
|
||||
int Baudrate = 9600;
|
||||
|
||||
int Zrwindow = 1400;
|
||||
int Baudrate = 9600;
|
||||
n = Zrwindow + Baudrate;
|
||||
Rxframeind = Rxtype = 0;
|
||||
n = Zrwindow + Baudrate;
|
||||
Rxframeind = Rxtype = 0;
|
||||
Syslog('z', "zgethdr(%lx)", rclhdr(shdr));
|
||||
|
||||
startover:
|
||||
cancount = 5;
|
||||
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;
|
||||
/*
|
||||
* Return immediate ERROR if ZCRCW sequence seen
|
||||
*/
|
||||
if (((c = GETCHAR(Rxtimeout)) < 0) && (c != TIMEOUT))
|
||||
goto fifi;
|
||||
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:
|
||||
if (--cancount <= 0) {
|
||||
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:
|
||||
Syslog('z', "zgethdr: got CAN");
|
||||
if (--cancount <= 0) {
|
||||
c = ZCAN; goto fifi;
|
||||
c = ZCAN;
|
||||
goto fifi;
|
||||
}
|
||||
goto again;
|
||||
}
|
||||
/* **** FALL THRU TO **** */
|
||||
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) {
|
||||
c = ZCAN;
|
||||
goto fifi;
|
||||
}
|
||||
goto again;
|
||||
}
|
||||
/* **** FALL THRU TO **** */
|
||||
default:
|
||||
agn2:
|
||||
#define GCOUNT (-4)
|
||||
if ( --n == 0) {
|
||||
c = GCOUNT; goto fifi;
|
||||
}
|
||||
goto startover;
|
||||
case ZPAD|0200: /* This is what we want. */
|
||||
Not8bit = c;
|
||||
case ZPAD: /* This is what we want. */
|
||||
break;
|
||||
if ( --n == 0) {
|
||||
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;
|
||||
}
|
||||
cancount = 5;
|
||||
|
||||
splat:
|
||||
switch (c = noxrd7()) {
|
||||
case ZPAD:
|
||||
goto splat;
|
||||
switch (c = noxrd7()) {
|
||||
case ZPAD: goto splat;
|
||||
case HANGUP:
|
||||
case TIMEOUT:
|
||||
goto fifi;
|
||||
default:
|
||||
goto agn2;
|
||||
case ZDLE: /* This is what we want. */
|
||||
break;
|
||||
}
|
||||
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();
|
||||
switch (c) {
|
||||
case ZVBIN32:
|
||||
if ((Rxhlen = c = zdlread()) < 0)
|
||||
goto fifi;
|
||||
if (c > ZMAXHLEN)
|
||||
goto agn2;
|
||||
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)
|
||||
goto fifi;
|
||||
if (c > ZMAXHLEN)
|
||||
goto agn2;
|
||||
Crc32r = 2; c = zrbhd32(shdr); break;
|
||||
case ZBINR32:
|
||||
if (Usevhdrs)
|
||||
goto agn2;
|
||||
Crc32r = 2; c = zrbhd32(shdr); 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)
|
||||
goto fifi;
|
||||
if (c > ZMAXHLEN)
|
||||
goto agn2;
|
||||
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)
|
||||
goto fifi;
|
||||
if (c > ZMAXHLEN)
|
||||
goto agn2;
|
||||
Crc32r = 2;
|
||||
c = zrbhd32(shdr);
|
||||
break;
|
||||
case ZBINR32: if (Usevhdrs)
|
||||
goto agn2;
|
||||
Crc32r = 2;
|
||||
c = zrbhd32(shdr);
|
||||
break;
|
||||
case HANGUP:
|
||||
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)
|
||||
goto agn2;
|
||||
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:
|
||||
goto agn2;
|
||||
}
|
||||
for (n = Rxhlen; ++n < ZMAXHLEN; ) /* Clear unused hdr bytes */
|
||||
shdr[n] = 0;
|
||||
Rxpos = shdr[ZP3] & 0377;
|
||||
Rxpos = (Rxpos<<8) + (shdr[ZP2] & 0377);
|
||||
Rxpos = (Rxpos<<8) + (shdr[ZP1] & 0377);
|
||||
Rxpos = (Rxpos<<8) + (shdr[ZP0] & 0377);
|
||||
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)
|
||||
goto agn2;
|
||||
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: goto agn2;
|
||||
}
|
||||
|
||||
for (n = Rxhlen; ++n < ZMAXHLEN; ) /* Clear unused hdr bytes */
|
||||
shdr[n] = 0;
|
||||
Rxpos = shdr[ZP3] & 0377;
|
||||
Rxpos = (Rxpos<<8) + (shdr[ZP2] & 0377);
|
||||
Rxpos = (Rxpos<<8) + (shdr[ZP1] & 0377);
|
||||
Rxpos = (Rxpos<<8) + (shdr[ZP0] & 0377);
|
||||
fifi:
|
||||
switch (c) {
|
||||
case GOTCAN:
|
||||
c = ZCAN;
|
||||
Syslog('z', "Zmodem: at fifi Got %d", c);
|
||||
switch (c) {
|
||||
case GOTCAN: c = ZCAN;
|
||||
/* **** FALL THRU TO **** */
|
||||
case ZNAK:
|
||||
case ZCAN:
|
||||
case TERROR:
|
||||
case TIMEOUT:
|
||||
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);
|
||||
else
|
||||
Syslog('z', "zgethdr: %c %d %ld", Rxframeind, c, Rxpos);
|
||||
}
|
||||
/* Use variable length headers if we got one */
|
||||
if (c >= 0 && c <= FRTYPES && Rxframeind & 040)
|
||||
Usevhdrs = 1;
|
||||
return c;
|
||||
case HANGUP: Syslog('+', "Zmodem: Got %s", frametypes[c+FTOFFSET]);
|
||||
/* **** FALL THRU TO **** */
|
||||
default: if (c >= -FTOFFSET && c <= FRTYPES)
|
||||
Syslog('z', "zgethdr: %c %d %s %lx", Rxframeind, Rxhlen, frametypes[c+FTOFFSET], Rxpos);
|
||||
else
|
||||
Syslog('z', "zgethdr: %d %d %ld", Rxframeind, c, Rxpos);
|
||||
}
|
||||
|
||||
/* Use variable length headers if we got one */
|
||||
if (c >= 0 && c <= FRTYPES && Rxframeind & 040) {
|
||||
Usevhdrs = 1;
|
||||
Syslog('z', "zgethdr: Usevhdrs");
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
@ -657,31 +658,31 @@ fifi:
|
||||
*/
|
||||
int zrbhdr(register char *shdr)
|
||||
{
|
||||
register int c, n;
|
||||
register unsigned short crc;
|
||||
register int c, n;
|
||||
register unsigned short crc;
|
||||
|
||||
if ((c = zdlread()) & ~0377)
|
||||
return c;
|
||||
Rxtype = c;
|
||||
crc = updcrc16(c, 0);
|
||||
if ((c = zdlread()) & ~0377)
|
||||
return c;
|
||||
Rxtype = c;
|
||||
crc = updcrc16(c, 0);
|
||||
|
||||
for (n=Rxhlen; --n >= 0; ++shdr) {
|
||||
if ((c = zdlread()) & ~0377)
|
||||
return c;
|
||||
crc = updcrc16(c, crc);
|
||||
*shdr = c;
|
||||
}
|
||||
for (n=Rxhlen; --n >= 0; ++shdr) {
|
||||
if ((c = zdlread()) & ~0377)
|
||||
return c;
|
||||
return c;
|
||||
crc = updcrc16(c, crc);
|
||||
if ((c = zdlread()) & ~0377)
|
||||
return c;
|
||||
crc = updcrc16(c, crc);
|
||||
if (crc & 0xFFFF) {
|
||||
Syslog('+', "Zmodem zrbhdr: Bad CRC");
|
||||
return TERROR;
|
||||
}
|
||||
return Rxtype;
|
||||
*shdr = c;
|
||||
}
|
||||
if ((c = zdlread()) & ~0377)
|
||||
return c;
|
||||
crc = updcrc16(c, crc);
|
||||
if ((c = zdlread()) & ~0377)
|
||||
return c;
|
||||
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)
|
||||
{
|
||||
register int c, n;
|
||||
register unsigned long crc;
|
||||
register int c, n;
|
||||
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)
|
||||
return c;
|
||||
Rxtype = c;
|
||||
crc = 0xFFFFFFFFL; crc = updcrc32(c, crc);
|
||||
|
||||
for (n=Rxhlen; --n >= 0; ++shdr) {
|
||||
if ((c = zdlread()) & ~0377)
|
||||
return c;
|
||||
crc = updcrc32(c, crc);
|
||||
*shdr = c;
|
||||
}
|
||||
for (n=4; --n >= 0;) {
|
||||
if ((c = zdlread()) & ~0377)
|
||||
return c;
|
||||
crc = updcrc32(c, crc);
|
||||
}
|
||||
if (crc != 0xDEBB20E3) {
|
||||
Syslog('+', "Zmodem zrbhd32: Bad CRC");
|
||||
return TERROR;
|
||||
}
|
||||
return Rxtype;
|
||||
return c;
|
||||
crc = updcrc32(c, crc);
|
||||
*shdr = c;
|
||||
}
|
||||
for (n=4; --n >= 0;) {
|
||||
if ((c = zdlread()) & ~0377)
|
||||
return c;
|
||||
crc = updcrc32(c, crc);
|
||||
}
|
||||
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)
|
||||
{
|
||||
register int c;
|
||||
register unsigned short crc;
|
||||
register int n;
|
||||
register int c;
|
||||
register unsigned short crc;
|
||||
register int n;
|
||||
|
||||
if ((c = zgethex()) < 0)
|
||||
return c;
|
||||
Rxtype = c;
|
||||
crc = updcrc16(c, 0);
|
||||
if ((c = zgethex()) < 0)
|
||||
return c;
|
||||
Rxtype = c;
|
||||
crc = updcrc16(c, 0);
|
||||
|
||||
for (n=Rxhlen; --n >= 0; ++shdr) {
|
||||
if ((c = zgethex()) < 0)
|
||||
return c;
|
||||
crc = updcrc16(c, crc);
|
||||
*shdr = c;
|
||||
}
|
||||
for (n=Rxhlen; --n >= 0; ++shdr) {
|
||||
if ((c = zgethex()) < 0)
|
||||
return c;
|
||||
return c;
|
||||
crc = updcrc16(c, crc);
|
||||
if ((c = zgethex()) < 0)
|
||||
return c;
|
||||
crc = updcrc16(c, crc);
|
||||
if (crc & 0xFFFF) {
|
||||
Syslog('+', "Zmodem zrhhdr: Bad CRC");
|
||||
return TERROR;
|
||||
}
|
||||
switch (c = GETCHAR(Rxtimeout)) {
|
||||
case 0215:
|
||||
Not8bit = c;
|
||||
/* **** FALL THRU TO **** */
|
||||
case 015:
|
||||
/* Throw away possible cr/lf */
|
||||
switch (c = GETCHAR(Rxtimeout)) {
|
||||
case 012:
|
||||
Not8bit |= c;
|
||||
}
|
||||
}
|
||||
if (c < 0)
|
||||
return c;
|
||||
return Rxtype;
|
||||
*shdr = c;
|
||||
}
|
||||
if ((c = zgethex()) < 0)
|
||||
return c;
|
||||
crc = updcrc16(c, crc);
|
||||
if ((c = zgethex()) < 0)
|
||||
return c;
|
||||
crc = updcrc16(c, crc);
|
||||
if (crc & 0xFFFF) {
|
||||
Syslog('+', "Zmodem zrhhdr: Bad CRC");
|
||||
return TERROR;
|
||||
}
|
||||
|
||||
switch (c = GETCHAR(Rxtimeout)) {
|
||||
case 0215: Not8bit = c;
|
||||
/* **** FALL THRU TO **** */
|
||||
case 015: /* Throw away possible cr/lf */
|
||||
switch (c = GETCHAR(Rxtimeout)) {
|
||||
case 012: Not8bit |= c;
|
||||
}
|
||||
}
|
||||
if (c < 0)
|
||||
return c;
|
||||
return Rxtype;
|
||||
}
|
||||
|
||||
|
||||
@ -772,10 +771,10 @@ int zrhhdr(char *shdr)
|
||||
*/
|
||||
void zputhex(register int c)
|
||||
{
|
||||
static char digits[] = "0123456789abcdef";
|
||||
static char digits[] = "0123456789abcdef";
|
||||
|
||||
BUFFER_BYTE(digits[(c&0xF0)>>4]);
|
||||
BUFFER_BYTE(digits[(c)&0xF]);
|
||||
BUFFER_BYTE(digits[(c&0xF0)>>4]);
|
||||
BUFFER_BYTE(digits[(c)&0xF]);
|
||||
}
|
||||
|
||||
|
||||
@ -786,39 +785,35 @@ void zputhex(register int c)
|
||||
*/
|
||||
void zsendline(int c)
|
||||
{
|
||||
/* Quick check for non control characters */
|
||||
if (c & 0140)
|
||||
BUFFER_BYTE(lastsent = c);
|
||||
else {
|
||||
switch (c &= 0377) {
|
||||
case ZDLE:
|
||||
BUFFER_BYTE(ZDLE);
|
||||
/* Quick check for non control characters */
|
||||
if (c & 0140)
|
||||
BUFFER_BYTE(lastsent = c);
|
||||
else {
|
||||
switch (c &= 0377) {
|
||||
case ZDLE: BUFFER_BYTE(ZDLE);
|
||||
BUFFER_BYTE (lastsent = (c ^= 0100));
|
||||
break;
|
||||
case 015:
|
||||
case 0215:
|
||||
if (!Zctlesc && (lastsent & 0177) != '@')
|
||||
goto sendit;
|
||||
/* **** FALL THRU TO **** */
|
||||
case 020:
|
||||
case 021:
|
||||
case 023:
|
||||
case 0220:
|
||||
case 0221:
|
||||
case 0223:
|
||||
BUFFER_BYTE(ZDLE);
|
||||
case 015:
|
||||
case 0215: if (!Zctlesc && (lastsent & 0177) != '@')
|
||||
goto sendit;
|
||||
/* **** FALL THRU TO **** */
|
||||
case 020:
|
||||
case 021:
|
||||
case 023:
|
||||
case 0220:
|
||||
case 0221:
|
||||
case 0223: BUFFER_BYTE(ZDLE);
|
||||
c ^= 0100;
|
||||
sendit:
|
||||
sendit:
|
||||
BUFFER_BYTE(lastsent = c);
|
||||
break;
|
||||
default:
|
||||
if (Zctlesc && ! (c & 0140)) {
|
||||
BUFFER_BYTE(ZDLE);
|
||||
c ^= 0100;
|
||||
default: if (Zctlesc && ! (c & 0140)) {
|
||||
BUFFER_BYTE(ZDLE);
|
||||
c ^= 0100;
|
||||
}
|
||||
BUFFER_BYTE(lastsent = c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -826,34 +821,34 @@ void zsendline(int c)
|
||||
/* Decode two lower case hex digits into an 8 bit byte value */
|
||||
int zgethex(void)
|
||||
{
|
||||
register int c;
|
||||
register int c;
|
||||
|
||||
c = zgeth1();
|
||||
return c;
|
||||
c = zgeth1();
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int zgeth1(void)
|
||||
{
|
||||
register int c, n;
|
||||
register int c, n;
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -864,62 +859,57 @@ int zgeth1(void)
|
||||
*/
|
||||
int zdlread(void)
|
||||
{
|
||||
register int c;
|
||||
register int c;
|
||||
|
||||
again:
|
||||
/* Quick check for non control characters */
|
||||
if ((c = GETCHAR(Rxtimeout)) & 0140)
|
||||
return c;
|
||||
switch (c) {
|
||||
case ZDLE:
|
||||
break;
|
||||
/* Quick check for non control characters */
|
||||
if ((c = GETCHAR(Rxtimeout)) & 0140)
|
||||
return c;
|
||||
|
||||
switch (c) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
again2:
|
||||
if ((c = GETCHAR(Rxtimeout)) < 0)
|
||||
return c;
|
||||
if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0)
|
||||
return c;
|
||||
if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0)
|
||||
return c;
|
||||
if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0)
|
||||
return c;
|
||||
switch (c) {
|
||||
case CAN:
|
||||
return GOTCAN;
|
||||
if ((c = GETCHAR(Rxtimeout)) < 0)
|
||||
return c;
|
||||
if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0)
|
||||
return c;
|
||||
if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0)
|
||||
return c;
|
||||
if (c == CAN && (c = GETCHAR(Rxtimeout)) < 0)
|
||||
return c;
|
||||
|
||||
switch (c) {
|
||||
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)
|
||||
}
|
||||
if ((c & 0140) == 0100)
|
||||
return (c ^ 0100);
|
||||
break;
|
||||
}
|
||||
Syslog('+', "Zmodem: Bad escape sequence 0x%x", c);
|
||||
return TERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
Syslog('+', "Zmodem: Bad escape sequence 0x%x", c);
|
||||
return TERROR;
|
||||
}
|
||||
|
||||
|
||||
@ -930,24 +920,22 @@ again2:
|
||||
*/
|
||||
int noxrd7(void)
|
||||
{
|
||||
register int c;
|
||||
register int c;
|
||||
|
||||
for (;;) {
|
||||
if ((c = GETCHAR(Rxtimeout)) < 0)
|
||||
return c;
|
||||
switch (c &= 0177) {
|
||||
case XON:
|
||||
case XOFF:
|
||||
continue;
|
||||
default:
|
||||
if (Zctlesc && !(c & 0140))
|
||||
continue;
|
||||
case '\r':
|
||||
case '\n':
|
||||
case ZDLE:
|
||||
return c;
|
||||
}
|
||||
for (;;) {
|
||||
if ((c = GETCHAR(Rxtimeout)) < 0)
|
||||
return c;
|
||||
|
||||
switch (c &= 0177) {
|
||||
case XON:
|
||||
case XOFF: continue;
|
||||
default: if (Zctlesc && !(c & 0140))
|
||||
continue;
|
||||
case '\r':
|
||||
case '\n':
|
||||
case ZDLE: return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -957,10 +945,10 @@ int noxrd7(void)
|
||||
*/
|
||||
void stohdr(long pos)
|
||||
{
|
||||
Txhdr[ZP0] = pos;
|
||||
Txhdr[ZP1] = pos>>8;
|
||||
Txhdr[ZP2] = pos>>16;
|
||||
Txhdr[ZP3] = pos>>24;
|
||||
Txhdr[ZP0] = pos;
|
||||
Txhdr[ZP1] = pos>>8;
|
||||
Txhdr[ZP2] = pos>>16;
|
||||
Txhdr[ZP3] = pos>>24;
|
||||
}
|
||||
|
||||
|
||||
@ -970,13 +958,13 @@ void stohdr(long pos)
|
||||
*/
|
||||
long rclhdr(register char *shdr)
|
||||
{
|
||||
register long l;
|
||||
register long l;
|
||||
|
||||
l = (shdr[ZP3] & 0377);
|
||||
l = (l << 8) | (shdr[ZP2] & 0377);
|
||||
l = (l << 8) | (shdr[ZP1] & 0377);
|
||||
l = (l << 8) | (shdr[ZP0] & 0377);
|
||||
return l;
|
||||
l = (shdr[ZP3] & 0377);
|
||||
l = (l << 8) | (shdr[ZP2] & 0377);
|
||||
l = (l << 8) | (shdr[ZP1] & 0377);
|
||||
l = (l << 8) | (shdr[ZP0] & 0377);
|
||||
return l;
|
||||
}
|
||||
|
||||
/* End of zmmisc.c */
|
||||
|
@ -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;
|
||||
|
||||
char Zsendmask[33]; /* Additional control characters to mask */
|
||||
|
||||
extern int Zctlesc;
|
||||
extern char *frametypes[];
|
||||
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 */
|
||||
int Zctlesc;
|
||||
int Usevhdrs; /* Use variable length headers */
|
||||
|
||||
|
||||
void get_frame_buffer(void);
|
||||
|
578
mbsebbs/zmrecv.c
578
mbsebbs/zmrecv.c
@ -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,45 +69,44 @@ static int ackbibi(void);
|
||||
static long getfree(void);
|
||||
|
||||
|
||||
void get_frame_buffer(void);
|
||||
void free_frame_buffer(void);
|
||||
|
||||
extern unsigned long rcvdbytes;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
secbuf = malloc(MAXBLOCK+1);
|
||||
tryzhdrtype = ZRINIT;
|
||||
if ((rc = tryz()) < 0) {
|
||||
Syslog('+', "Zmodem: could not initiate receive, rc=%d",rc);
|
||||
} else
|
||||
switch (rc) {
|
||||
case ZCOMPL: rc = 0; break;
|
||||
case ZFILE: rc = rzfiles(); break;
|
||||
}
|
||||
|
||||
if (fout) {
|
||||
if (closeit(0)) {
|
||||
WriteError("Zmodem: Error closing file");
|
||||
}
|
||||
if (secbuf == NULL)
|
||||
secbuf = malloc(MAXBLOCK+1);
|
||||
tryzhdrtype = ZRINIT;
|
||||
if ((rc = tryz()) < 0) {
|
||||
Syslog('+', "Zmodem: could not initiate receive, rc=%d",rc);
|
||||
} else
|
||||
switch (rc) {
|
||||
case ZCOMPL: rc = 0;
|
||||
break;
|
||||
case ZFILE: rc = rzfiles();
|
||||
break;
|
||||
}
|
||||
|
||||
if (secbuf)
|
||||
free(secbuf);
|
||||
secbuf = NULL;
|
||||
free_frame_buffer();
|
||||
if (fout) {
|
||||
if (closeit(0)) {
|
||||
WriteError("Zmodem: Error closing file");
|
||||
}
|
||||
}
|
||||
|
||||
Syslog('z', "Zmodem: receive rc=%d",rc);
|
||||
return abs(rc);
|
||||
if (secbuf)
|
||||
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 c, n;
|
||||
int cmdzack1flg;
|
||||
int c, n;
|
||||
int cmdzack1flg;
|
||||
|
||||
for (n = 15; --n >= 0; ) {
|
||||
/*
|
||||
* Set buffer length (0) and capability flags
|
||||
*/
|
||||
Syslog('z', "tryz attempt %d", n);
|
||||
stohdr(0L);
|
||||
Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO;
|
||||
if (Zctlesc)
|
||||
Txhdr[ZF0] |= TESCCTL;
|
||||
Txhdr[ZF0] |= CANRLE;
|
||||
Txhdr[ZF1] = CANVHDR;
|
||||
zshhdr(4, tryzhdrtype, Txhdr);
|
||||
if (tryzhdrtype == ZSKIP) /* Don't skip too far */
|
||||
tryzhdrtype = ZRINIT; /* CAF 8-21-87 */
|
||||
for (n = 15; --n >= 0; ) {
|
||||
/*
|
||||
* Set buffer length (0) and capability flags
|
||||
*/
|
||||
Syslog('z', "tryz attempt %d", n);
|
||||
stohdr(0L);
|
||||
// Txhdr[ZF0] = CANFC32|CANFDX|CANOVIO;
|
||||
Txhdr[ZF0] = CANFC32;
|
||||
if (Zctlesc)
|
||||
Txhdr[ZF0] |= TESCCTL;
|
||||
// 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)
|
||||
switch (zgethdr(Rxhdr)) {
|
||||
case ZRQINIT: if (Rxhdr[ZF3] & 0x80)
|
||||
Usevhdrs = TRUE; /* we can var header */
|
||||
continue;
|
||||
case ZEOF:
|
||||
continue;
|
||||
case TIMEOUT:
|
||||
Syslog('+', "Zmodem: tryz() timeout attempt %d", n);
|
||||
continue;
|
||||
case ZFILE:
|
||||
zconv = Rxhdr[ZF0];
|
||||
zmanag = Rxhdr[ZF1];
|
||||
ztrans = Rxhdr[ZF2];
|
||||
if (Rxhdr[ZF3] & ZCANVHDR)
|
||||
continue;
|
||||
case ZEOF: continue;
|
||||
case TIMEOUT: Syslog('+', "Zmodem: tryz() timeout attempt %d", n);
|
||||
continue;
|
||||
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)
|
||||
tryzhdrtype = ZRINIT;
|
||||
c = zrdata(secbuf, MAXBLOCK);
|
||||
if (c == GOTCRCW) {
|
||||
Syslog('z', "tryz return ZFILE");
|
||||
return ZFILE;
|
||||
zshhdr(4,ZNAK, Txhdr);
|
||||
goto again;
|
||||
case ZSINIT:
|
||||
Zctlesc = TESCCTL & Rxhdr[ZF0];
|
||||
if (zrdata(Attn, ZATTNLEN) == GOTCRCW) {
|
||||
}
|
||||
zshhdr(4,ZNAK, Txhdr);
|
||||
goto again;
|
||||
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);
|
||||
goto again;
|
||||
}
|
||||
zshhdr(4,ZNAK, Txhdr);
|
||||
goto again;
|
||||
case ZFREECNT:
|
||||
stohdr(getfree());
|
||||
zshhdr(4,ZACK, Txhdr);
|
||||
goto again;
|
||||
case ZCOMMAND:
|
||||
cmdzack1flg = Rxhdr[ZF0];
|
||||
if (zrdata(secbuf, MAXBLOCK) == GOTCRCW) {
|
||||
}
|
||||
zshhdr(4,ZNAK, Txhdr);
|
||||
goto again;
|
||||
case ZFREECNT: stohdr(getfree());
|
||||
zshhdr(4,ZACK, Txhdr);
|
||||
goto again;
|
||||
case ZCOMMAND: cmdzack1flg = Rxhdr[ZF0];
|
||||
if (zrdata(secbuf, MAXBLOCK) == GOTCRCW) {
|
||||
if (cmdzack1flg & ZCACK1)
|
||||
stohdr(0L);
|
||||
stohdr(0L);
|
||||
else
|
||||
Syslog('+', "Zmodem: request for command \"%s\" ignored", printable(secbuf,-32));
|
||||
Syslog('+', "Zmodem: request for command \"%s\" ignored", printable(secbuf,-32));
|
||||
stohdr(0L);
|
||||
do {
|
||||
zshhdr(4,ZCOMPL, Txhdr);
|
||||
zshhdr(4,ZCOMPL, Txhdr);
|
||||
} while (++errors<20 && zgethdr(Rxhdr) != ZFIN);
|
||||
return ackbibi();
|
||||
}
|
||||
zshhdr(4,ZNAK, Txhdr); goto again;
|
||||
case ZCOMPL:
|
||||
goto again;
|
||||
case ZRINIT:
|
||||
case ZFIN: /* do not beleive in first ZFIN */
|
||||
ackbibi(); return ZCOMPL;
|
||||
case TERROR:
|
||||
case HANGUP:
|
||||
case ZCAN:
|
||||
return TERROR;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
zshhdr(4,ZNAK, Txhdr);
|
||||
goto again;
|
||||
case ZCOMPL: goto again;
|
||||
case ZRINIT: Syslog('z', "tryz: got ZRINIT");
|
||||
return TERROR;
|
||||
case ZFIN: /* do not beleive in first ZFIN */
|
||||
ackbibi();
|
||||
return ZCOMPL;
|
||||
case TERROR:
|
||||
case HANGUP:
|
||||
case ZCAN: return TERROR;
|
||||
default: continue;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Syslog('z', "tryz return 0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -216,31 +218,25 @@ again:
|
||||
*/
|
||||
int rzfiles(void)
|
||||
{
|
||||
int c;
|
||||
int c;
|
||||
|
||||
Syslog('z', "rzfiles");
|
||||
Syslog('z', "rzfiles");
|
||||
|
||||
for (;;) {
|
||||
switch (c = rzfile()) {
|
||||
case ZEOF:
|
||||
case ZSKIP:
|
||||
case ZFERR:
|
||||
switch (tryz()) {
|
||||
case ZCOMPL:
|
||||
return OK;
|
||||
default:
|
||||
return TERROR;
|
||||
case ZFILE:
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
default:
|
||||
return c;
|
||||
case TERROR:
|
||||
return TERROR;
|
||||
}
|
||||
for (;;) {
|
||||
switch (c = rzfile()) {
|
||||
case ZEOF:
|
||||
case ZSKIP:
|
||||
case ZFERR: switch (tryz()) {
|
||||
case ZCOMPL: return OK;
|
||||
default: return TERROR;
|
||||
case ZFILE: break;
|
||||
}
|
||||
continue;
|
||||
default: return c;
|
||||
case TERROR: return TERROR;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
|
||||
@ -251,50 +247,45 @@ int rzfiles(void)
|
||||
*/
|
||||
int rzfile(void)
|
||||
{
|
||||
int c, n;
|
||||
int c, n;
|
||||
|
||||
Syslog('z', "rzfile");
|
||||
Syslog('z', "rzfile");
|
||||
|
||||
Eofseen=FALSE;
|
||||
rxbytes = 0l;
|
||||
if ((c = procheader(secbuf))) {
|
||||
return (tryzhdrtype = c);
|
||||
}
|
||||
Eofseen=FALSE;
|
||||
rxbytes = 0l;
|
||||
if ((c = procheader(secbuf))) {
|
||||
return (tryzhdrtype = c);
|
||||
}
|
||||
|
||||
n = 20;
|
||||
n = 20;
|
||||
|
||||
for (;;) {
|
||||
stohdr(rxbytes);
|
||||
zshhdr(4,ZRPOS, Txhdr);
|
||||
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);
|
||||
if ( --n < 0) {
|
||||
switch (c = zgethdr(Rxhdr)) {
|
||||
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");
|
||||
return TERROR;
|
||||
case ZNAK:
|
||||
if ( --n < 0) {
|
||||
}
|
||||
continue;
|
||||
case ZCAN: Syslog('+', "Zmodem: sender CANcelled");
|
||||
return TERROR;
|
||||
case ZNAK: if ( --n < 0) {
|
||||
Syslog('+', "Zmodem: Got ZNAK");
|
||||
return TERROR;
|
||||
}
|
||||
continue;
|
||||
case TIMEOUT:
|
||||
if ( --n < 0) {
|
||||
}
|
||||
continue;
|
||||
case TIMEOUT: if ( --n < 0) {
|
||||
Syslog('+', "Zmodem: TIMEOUT");
|
||||
return TERROR;
|
||||
}
|
||||
continue;
|
||||
case ZFILE:
|
||||
zrdata(secbuf, MAXBLOCK);
|
||||
continue;
|
||||
case ZEOF:
|
||||
if (rclhdr(Rxhdr) != rxbytes) {
|
||||
}
|
||||
continue;
|
||||
case ZFILE: zrdata(secbuf, MAXBLOCK);
|
||||
continue;
|
||||
case ZEOF: if (rclhdr(Rxhdr) != rxbytes) {
|
||||
/*
|
||||
* Ignore eof if it's at wrong place - force
|
||||
* a timeout because the eof might have gone
|
||||
@ -302,90 +293,81 @@ nxthdr:
|
||||
*/
|
||||
errors = 0;
|
||||
goto nxthdr;
|
||||
}
|
||||
if (closeit(1)) {
|
||||
}
|
||||
if (closeit(1)) {
|
||||
tryzhdrtype = ZFERR;
|
||||
Syslog('+', "Zmodem: error closing file");
|
||||
return TERROR;
|
||||
}
|
||||
fout=NULL;
|
||||
Syslog('z', "rzfile: normal EOF");
|
||||
return c;
|
||||
case HANGUP:
|
||||
Syslog('+', "Zmodem: Lost Carrier");
|
||||
return TERROR;
|
||||
case TERROR: /* Too much garbage in header search error */
|
||||
if (--n < 0) {
|
||||
}
|
||||
fout = NULL;
|
||||
Syslog('z', "rzfile: normal EOF");
|
||||
return c;
|
||||
case HANGUP: Syslog('+', "Zmodem: Lost Carrier");
|
||||
return TERROR;
|
||||
case TERROR: /* Too much garbage in header search error */
|
||||
if (--n < 0) {
|
||||
Syslog('+', "Zmodem: Too many errors");
|
||||
return TERROR;
|
||||
}
|
||||
zmputs(Attn);
|
||||
continue;
|
||||
case ZSKIP:
|
||||
Modtime = 1;
|
||||
closeit(1);
|
||||
Syslog('+', "Zmodem: Sender SKIPPED file");
|
||||
return c;
|
||||
case ZDATA:
|
||||
if (rclhdr(Rxhdr) != rxbytes) {
|
||||
}
|
||||
zmputs(Attn);
|
||||
continue;
|
||||
case ZSKIP: Modtime = 1;
|
||||
closeit(1);
|
||||
Syslog('+', "Zmodem: Sender SKIPPED file");
|
||||
return c;
|
||||
case ZDATA: if (rclhdr(Rxhdr) != rxbytes) {
|
||||
if ( --n < 0) {
|
||||
Syslog('+', "Zmodem: Data has bad address");
|
||||
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;
|
||||
Syslog('+', "Zmodem: Data has bad address");
|
||||
return TERROR;
|
||||
}
|
||||
zmputs(Attn);
|
||||
continue;
|
||||
case TIMEOUT:
|
||||
if ( --n < 0) {
|
||||
Syslog('+', "Zmodem: TIMEOUT");
|
||||
return TERROR;
|
||||
}
|
||||
continue;
|
||||
case GOTCRCW:
|
||||
n = 20;
|
||||
putsec(secbuf, Rxcount);
|
||||
rxbytes += Rxcount;
|
||||
stohdr(rxbytes);
|
||||
PUTCHAR(XON);
|
||||
zshhdr(4,ZACK, Txhdr);
|
||||
goto nxthdr;
|
||||
case GOTCRCQ:
|
||||
n = 20;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
continue;
|
||||
case TIMEOUT: if ( --n < 0) {
|
||||
Syslog('+', "Zmodem: TIMEOUT");
|
||||
return TERROR;
|
||||
}
|
||||
continue;
|
||||
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;
|
||||
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)
|
||||
{
|
||||
int c;
|
||||
int c;
|
||||
|
||||
Syslog('z', "zmputs: \"%s\"", printable(s, strlen(s)));
|
||||
Syslog('z', "zmputs: \"%s\"", printable(s, strlen(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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -450,29 +438,28 @@ int closeit(int success)
|
||||
*/
|
||||
int ackbibi(void)
|
||||
{
|
||||
int n;
|
||||
int c;
|
||||
int n;
|
||||
int c;
|
||||
|
||||
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' */
|
||||
Syslog('z', "Zmodem: ackbibi complete");
|
||||
return ZCOMPL;
|
||||
case TERROR:
|
||||
case HANGUP:
|
||||
Syslog('z', "Zmodem: ackbibi got %d, ignore",c);
|
||||
return 0;
|
||||
case TIMEOUT:
|
||||
default:
|
||||
Syslog('z', "Zmodem: ackbibi got '%s', continue", printablec(c));
|
||||
break;
|
||||
}
|
||||
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' */
|
||||
Syslog('z', "Zmodem: ackbibi complete");
|
||||
return ZCOMPL;
|
||||
case TERROR:
|
||||
case HANGUP: Syslog('z', "Zmodem: ackbibi got %d, ignore",c);
|
||||
return 0;
|
||||
case TIMEOUT:
|
||||
default: Syslog('z', "Zmodem: ackbibi got '%s', continue", printablec(c));
|
||||
break;
|
||||
}
|
||||
return ZCOMPL;
|
||||
}
|
||||
return ZCOMPL;
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
@ -538,28 +542,30 @@ int procheader(char *Name)
|
||||
*/
|
||||
int putsec(char *buf, int n)
|
||||
{
|
||||
register char *p;
|
||||
register char *p;
|
||||
|
||||
if (n == 0)
|
||||
return OK;
|
||||
Syslog('z', "putsec %d characters %s mode", n, Thisbinary ? "binary":"ascii");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (n == 0)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user