updated protocol type flag

This commit is contained in:
Michiel Broek 2004-11-21 11:20:08 +00:00
parent 164b54d91e
commit efccc0441a
4 changed files with 73 additions and 106 deletions

View File

@ -124,37 +124,8 @@ char *frametypes[] = {
}; };
/***** Hack by mj ***********************************************************/
/*
* Buffer for outgoing frames. Sending them with single character write()'s
* is a waste of processor time and causes severe performance degradation
* on TCP and ISDN connections.
*/
#define FRAME_BUFFER_SIZE 16384
static char *frame_buffer=NULL;
static int frame_length = 0;
#define BUFFER_CLEAR() do { frame_length=0; } while(0)
#define BUFFER_BYTE(c) do { frame_buffer[frame_length++]=(c); } while(0)
#define BUFFER_FLUSH() do { PUT(frame_buffer, frame_length); \
frame_length=0; } while(0);
/****************************************************************************/ /****************************************************************************/
void get_frame_buffer(void)
{
if (frame_buffer == NULL)
frame_buffer = malloc(FRAME_BUFFER_SIZE);
}
void free_frame_buffer(void)
{
if (frame_buffer)
free(frame_buffer);
frame_buffer = NULL;
}
/* /*
* Send ZMODEM binary header hdr of type type * Send ZMODEM binary header hdr of type type
@ -166,22 +137,17 @@ void zsbhdr(int type, char *shdr)
Syslog('z', "zsbhdr: %s %lx", frametypes[type+FTOFFSET], rclhdr(shdr)); Syslog('z', "zsbhdr: %s %lx", frametypes[type+FTOFFSET], rclhdr(shdr));
BUFFER_CLEAR();
if (type == ZDATA) if (type == ZDATA)
for (n = Znulls; --n >=0; ) for (n = Znulls; --n >=0; )
BUFFER_BYTE(0); PUTCHAR(0);
BUFFER_BYTE(ZPAD); PUTCHAR(ZPAD);
BUFFER_BYTE(ZDLE); PUTCHAR(ZDLE);
switch (Crc32t=Txfcs32) { if ((Crc32t = Txfcs32))
case 2: zsbh32(shdr, type); zsbh32(shdr, type);
BUFFER_FLUSH(); else {
break; PUTCHAR(ZBIN);
case 1: zsbh32(shdr, type);
break;
default: BUFFER_BYTE(ZBIN);
zsendline(type); zsendline(type);
crc = updcrc16(type, 0); crc = updcrc16(type, 0);
@ -194,7 +160,8 @@ void zsbhdr(int type, char *shdr)
zsendline(crc); zsendline(crc);
} }
BUFFER_FLUSH(); if (type != ZDATA)
fflush(stdout);
} }
@ -207,7 +174,7 @@ void zsbh32(char *shdr, int type)
register int n; register int n;
register unsigned long crc; register unsigned long crc;
BUFFER_BYTE(ZBIN32); PUTCHAR(ZBIN32);
zsendline(type); zsendline(type);
crc = 0xFFFFFFFFL; crc = 0xFFFFFFFFL;
crc = updcrc32(type, crc); crc = updcrc32(type, crc);
@ -235,12 +202,10 @@ void zshhdr(int type, register char *shdr)
Syslog('z', "zshhdr: %s %lx", frametypes[type+FTOFFSET], rclhdr(shdr)); Syslog('z', "zshhdr: %s %lx", frametypes[type+FTOFFSET], rclhdr(shdr));
BUFFER_CLEAR(); PUTCHAR(ZPAD);
PUTCHAR(ZPAD);
BUFFER_BYTE(ZPAD); PUTCHAR(ZDLE);
BUFFER_BYTE(ZPAD); PUTCHAR(ZHEX);
BUFFER_BYTE(ZDLE);
BUFFER_BYTE(ZHEX);
zputhex(type & 0x7f); zputhex(type & 0x7f);
Crc32t = 0; Crc32t = 0;
@ -256,16 +221,16 @@ void zshhdr(int type, register char *shdr)
/* /*
* Make it printable on remote machine * Make it printable on remote machine
*/ */
BUFFER_BYTE(015); PUTCHAR(015);
BUFFER_BYTE(0212); PUTCHAR(0212);
/* /*
* Uncork the remote in case a fake XOFF has stopped data flow * Uncork the remote in case a fake XOFF has stopped data flow
*/ */
if (type != ZFIN && type != ZACK) if (type != ZFIN && type != ZACK)
BUFFER_BYTE(021); PUTCHAR(021);
BUFFER_FLUSH(); fflush(stdout);
} }
@ -280,8 +245,6 @@ void zsdata(register char *buf, int length, int frameend)
Syslog('z', "zsdata: %d %s", length, Zendnames[(frameend-ZCRCE)&3]); Syslog('z', "zsdata: %d %s", length, Zendnames[(frameend-ZCRCE)&3]);
BUFFER_CLEAR();
if (Crc32t) if (Crc32t)
zsda32(buf, length, frameend); zsda32(buf, length, frameend);
else { else {
@ -290,8 +253,8 @@ void zsdata(register char *buf, int length, int frameend)
zsendline(*buf); zsendline(*buf);
crc = updcrc16((0377 & *buf), crc); crc = updcrc16((0377 & *buf), crc);
} }
BUFFER_BYTE(ZDLE); PUTCHAR(ZDLE);
BUFFER_BYTE(frameend); PUTCHAR(frameend);
crc = updcrc16(frameend, crc); crc = updcrc16(frameend, crc);
crc = updcrc16(0,updcrc16(0,crc)); crc = updcrc16(0,updcrc16(0,crc));
@ -299,10 +262,10 @@ void zsdata(register char *buf, int length, int frameend)
zsendline(crc); zsendline(crc);
} }
if (frameend == ZCRCW) if (frameend == ZCRCW) {
BUFFER_BYTE(XON); PUTCHAR(XON);
fflush(stdout);
BUFFER_FLUSH(); }
} }
@ -316,13 +279,13 @@ void zsda32(register char *buf, int length, int frameend)
for (;--length >= 0; ++buf) { for (;--length >= 0; ++buf) {
c = *buf & 0377; c = *buf & 0377;
if (c & 0140) if (c & 0140)
BUFFER_BYTE(lastsent = c); PUTCHAR(lastsent = c);
else else
zsendline(c); zsendline(c);
crc = updcrc32(c, crc); crc = updcrc32(c, crc);
} }
BUFFER_BYTE(ZDLE); PUTCHAR(ZDLE);
BUFFER_BYTE(frameend); PUTCHAR(frameend);
crc = updcrc32(frameend, crc); crc = updcrc32(frameend, crc);
crc = ~crc; crc = ~crc;
@ -476,7 +439,6 @@ int zgethdr(char *shdr)
n = Zrwindow + Baudrate; n = Zrwindow + Baudrate;
Rxframeind = Rxtype = 0; Rxframeind = Rxtype = 0;
// Syslog('z', "zgethdr(%lx)", rclhdr(shdr));
startover: startover:
cancount = 5; cancount = 5;
@ -583,10 +545,6 @@ fifi:
Syslog('z', "zgethdr: %d %d %lx", Rxframeind, c, Rxpos); Syslog('z', "zgethdr: %d %d %lx", Rxframeind, c, Rxpos);
} }
/* Use variable length headers if we got one */
if (c >= 0 && c <= FRTYPES && Rxframeind & 040) {
Syslog('z', "zgethdr: Usevhdrs");
}
return c; return c;
} }
@ -621,6 +579,8 @@ int zrbhdr(register char *shdr)
Syslog('+', "Zmodem zrbhdr: Bad CRC"); Syslog('+', "Zmodem zrbhdr: Bad CRC");
return TERROR; return TERROR;
} }
protocol = ZM_ZMODEM;
return Rxtype; return Rxtype;
} }
@ -654,6 +614,8 @@ int zrbhd32(register char *shdr)
Syslog('+', "Zmodem zrbhd32: Bad CRC"); Syslog('+', "Zmodem zrbhd32: Bad CRC");
return TERROR; return TERROR;
} }
protocol = ZM_ZMODEM;
return Rxtype; return Rxtype;
} }
@ -700,6 +662,8 @@ int zrhhdr(char *shdr)
} }
if (c < 0) if (c < 0)
return c; return c;
protocol = ZM_ZMODEM;
return Rxtype; return Rxtype;
} }
@ -712,8 +676,8 @@ void zputhex(register int c)
{ {
static char digits[] = "0123456789abcdef"; static char digits[] = "0123456789abcdef";
BUFFER_BYTE(digits[(c&0xF0)>>4]); PUTCHAR(digits[(c&0xF0)>>4]);
BUFFER_BYTE(digits[(c)&0xF]); PUTCHAR(digits[(c)&0xF]);
} }
@ -726,11 +690,11 @@ 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); PUTCHAR(lastsent = c);
else { else {
switch (c &= 0377) { switch (c &= 0377) {
case ZDLE: BUFFER_BYTE(ZDLE); case ZDLE: PUTCHAR(ZDLE);
BUFFER_BYTE (lastsent = (c ^= 0100)); PUTCHAR(lastsent = (c ^= 0100));
break; break;
case 015: case 015:
case 0215: if (!Zctlesc && (lastsent & 0177) != '@') case 0215: if (!Zctlesc && (lastsent & 0177) != '@')
@ -741,16 +705,16 @@ void zsendline(int c)
case 023: case 023:
case 0220: case 0220:
case 0221: case 0221:
case 0223: BUFFER_BYTE(ZDLE); case 0223: PUTCHAR(ZDLE);
c ^= 0100; c ^= 0100;
sendit: sendit:
BUFFER_BYTE(lastsent = c); PUTCHAR(lastsent = c);
break; break;
default: if (Zctlesc && ! (c & 0140)) { default: if (Zctlesc && ! (c & 0140)) {
BUFFER_BYTE(ZDLE); PUTCHAR(ZDLE);
c ^= 0100; c ^= 0100;
} }
BUFFER_BYTE(lastsent = c); PUTCHAR(lastsent = c);
} }
} }
} }

View File

@ -146,8 +146,9 @@ enum zm_type_enum {
enum zm_type_enum protocol; enum zm_type_enum protocol;
void get_frame_buffer(void);
void free_frame_buffer(void); //void get_frame_buffer(void);
//void free_frame_buffer(void);
void zsbhdr(int, char *); void zsbhdr(int, char *);
void zshhdr(int, char *); void zshhdr(int, char *);
void zsdata(register char *, int, int); void zsdata(register char *, int, int);

View File

@ -83,20 +83,24 @@ int zmrcvfiles(void)
Syslog('+', "Zmodem: start Zmodem receive"); Syslog('+', "Zmodem: start Zmodem receive");
get_frame_buffer();
if (secbuf == NULL) if (secbuf == NULL)
secbuf = malloc(MAXBLOCK+1); secbuf = malloc(MAXBLOCK+1);
tryzhdrtype = ZRINIT; tryzhdrtype = ZRINIT;
protocol = ZM_ZMODEM;
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 {
if (rc == 0) {
/* Check for ymodem sector */
}
switch (rc) { switch (rc) {
case ZCOMPL: rc = 0; case ZCOMPL: rc = 0;
break; break;
case ZFILE: rc = rzfiles(); case ZFILE: rc = rzfiles();
break; break;
} }
}
if (fout) { if (fout) {
if (closeit(0)) { if (closeit(0)) {
@ -107,17 +111,16 @@ int zmrcvfiles(void)
if (secbuf) if (secbuf)
free(secbuf); free(secbuf);
secbuf = NULL; secbuf = NULL;
free_frame_buffer();
io_mode(0, 1); /* Normal raw mode */ io_mode(0, 1); /* Normal raw mode */
/* /*
* Some programs (Dynacom) send some garbage after the transfer * Some programs send some garbage after the transfer, eat these.
*/ */
Syslog('z', "zmrcvfiles: garbage check");
do { do {
c = Waitchar(&ch, 100); c = Waitchar(&ch, 100);
count++; count++;
} while (c == 1); } while (c == 1);
if (count)
Syslog('z', "zmrcvfiles: purged %d garbage characters", count); Syslog('z', "zmrcvfiles: purged %d garbage characters", count);
Syslog('z', "Zmodem: receive rc=%d",rc); Syslog('z', "Zmodem: receive rc=%d",rc);
@ -137,6 +140,9 @@ int tryz(void)
int c, n; int c, n;
int cmdzack1flg; int cmdzack1flg;
if (protocol != ZM_ZMODEM)
return 0;
for (n = 15; --n >= 0; ) { for (n = 15; --n >= 0; ) {
/* /*
* Set buffer length (0) and capability flags * Set buffer length (0) and capability flags
@ -549,8 +555,6 @@ int putsec(char *buf, int n)
{ {
register char *p; register char *p;
// Syslog('z', "putsec %d characters %s mode", n, Thisbinary ? "binary":"ascii");
if (n == 0) if (n == 0)
return OK; return OK;

View File

@ -89,13 +89,11 @@ int zmsndfiles(down_list *lst)
Syslog('+', "Zmodem: start Zmodem send"); Syslog('+', "Zmodem: start Zmodem send");
get_frame_buffer(); protocol = ZM_ZMODEM;
if ((rc = initsend())) { if ((rc = initsend())) {
if (txbuf) if (txbuf)
free(txbuf); free(txbuf);
txbuf = NULL; txbuf = NULL;
free_frame_buffer();
return abs(rc); return abs(rc);
} }
@ -127,7 +125,6 @@ int zmsndfiles(down_list *lst)
if (txbuf) if (txbuf)
free(txbuf); free(txbuf);
txbuf = NULL; txbuf = NULL;
free_frame_buffer();
io_mode(0, 1); io_mode(0, 1);
Syslog('z', "Zmodem: send rc=%d", maxrc); Syslog('z', "Zmodem: send rc=%d", maxrc);
@ -237,7 +234,7 @@ static int sendzfile(char *rn)
/* /*
* Get the receiver's init parameters * Get the receiver's init parameters
*/ */
int getzrxinit(void) // CHECKED BUT NOT WELL TESTED int getzrxinit(void)
{ {
int n; int n;
@ -423,7 +420,8 @@ again:
return zsendfdata(); return zsendfdata();
} }
} }
fclose(in); return TERROR; fclose(in);
return TERROR;
} }