From d2ebff86f12124cc5bce9a163daaf8439e19cd70 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 4 Mar 2006 12:40:49 +0000 Subject: [PATCH] Several zmodem code changes --- mbsebbs/zmmisc.c | 107 ++++++++++++++++++++++++++++------------------- mbsebbs/zmmisc.h | 3 +- mbsebbs/zmrecv.c | 1 + mbsebbs/zmsend.c | 36 ++++------------ 4 files changed, 76 insertions(+), 71 deletions(-) diff --git a/mbsebbs/zmmisc.c b/mbsebbs/zmmisc.c index 819a2ce1..97f384b3 100644 --- a/mbsebbs/zmmisc.c +++ b/mbsebbs/zmmisc.c @@ -77,7 +77,7 @@ int Rxtimeout = 10; /* Seconds to wait for something, receiver */ char *txbuf=NULL; static int lastsent; /* Last char we sent */ static int Not8bit; /* Seven bits seen on header */ - +static char zsendline_tab[256]; extern unsigned Baudrate; extern int zmodem_requested; @@ -171,7 +171,8 @@ void zsbhdr(int type, char *shdr) register int n; register unsigned short crc; - Syslog('z', "zsbhdr: %s %lx", frametypes[type+FTOFFSET], rclhdr(shdr)); + Crc32t = Txfcs32; + Syslog('z', "zsbh%s: %s %lx", Crc32t ? "32":"dr", frametypes[type+FTOFFSET], rclhdr(shdr)); BUFFER_CLEAR(); @@ -182,7 +183,7 @@ void zsbhdr(int type, char *shdr) BUFFER_BYTE(ZPAD); BUFFER_BYTE(ZDLE); - if ((Crc32t = Txfcs32)) + if (Crc32t) zsbh32(shdr, type); else { BUFFER_BYTE(ZBIN); @@ -321,7 +322,10 @@ void zsda32(register char *buf, int length, int frameend) crc = 0xFFFFFFFFL; for (;--length >= 0; ++buf) { c = *buf & 0377; - zsendline(*buf); + if (c & 0140) + BUFFER_BYTE(lastsent = c); + else + zsendline(c); crc = updcrc32(c, crc); } BUFFER_BYTE(ZDLE); @@ -332,11 +336,6 @@ void zsda32(register char *buf, int length, int frameend) for (c=4; --c >= 0;) { zsendline((int)crc); crc >>= 8; } - -// if (frameend == ZCRCW) { -// BUFFER_BYTE(XON); -// fflush(stdout); - // } } @@ -477,7 +476,6 @@ void garbitch(void) int zgethdr(char *shdr) { register int c, n, cancount, tmcount; -// int Zrwindow = 1400; int Zrwindow = 1024; n = Zrwindow + Baudrate; @@ -737,42 +735,65 @@ void zputhex(int c) /* * Send character c with ZMODEM escape sequence encoding. - * Escape XON, XOFF. Escape CR following @ (Telenet net escape) + * Escape XON, XOFF. Escape CR following @ (Telenet net escape) */ 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); - 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); - c ^= 0100; -sendit: - BUFFER_BYTE(lastsent = c); - break; - default: - if (Zctlesc && ! (c & 0140)) { - BUFFER_BYTE(ZDLE); - c ^= 0100; - - } - BUFFER_BYTE(lastsent = c); + switch(zsendline_tab[(unsigned) (c&=0377)]) { + case 0: BUFFER_BYTE(lastsent = c); + break; + case 1: BUFFER_BYTE(ZDLE); + c ^= 0100; + BUFFER_BYTE(lastsent = c); + break; + case 2: if ((lastsent & 0177) != '@') { + BUFFER_BYTE(lastsent = c); + } else { + BUFFER_BYTE(ZDLE); + c ^= 0100; + BUFFER_BYTE(lastsent = c); + } + break; + } +} + + + +void zsendline_init(void) +{ + int i; + + Syslog('z', "zendline_init() Zctlesc=%d", Zctlesc); + + for (i = 0; i < 256; i++) { + if (i & 0140) + zsendline_tab[i] = 0; + else { + switch(i) { + case ZDLE: + case XOFF: /* ^Q */ + case XON: /* ^S */ + case (XOFF | 0200): + case (XON | 0200): + zsendline_tab[i]=1; + break; + case 020: /* ^P */ + case 0220: + zsendline_tab[i]=1; + break; + case 015: + case 0215: + if (Zctlesc) + zsendline_tab[i]=1; + else + zsendline_tab[i]=2; + break; + default: + if (Zctlesc) + zsendline_tab[i]=1; + else + zsendline_tab[i]=0; + } } } } diff --git a/mbsebbs/zmmisc.h b/mbsebbs/zmmisc.h index 17359429..be5e4f02 100644 --- a/mbsebbs/zmmisc.h +++ b/mbsebbs/zmmisc.h @@ -134,7 +134,7 @@ 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 */ +//char Zsendmask[33]; /* Additional control characters to mask */ int Zctlesc; enum zm_type_enum { @@ -159,6 +159,7 @@ int zdlread(void); void stohdr(int); int rclhdr(register char *); char *protname(void); +void zsendline_init(void); void purgeline(int); void canit(int); diff --git a/mbsebbs/zmrecv.c b/mbsebbs/zmrecv.c index d00ad118..e4de0915 100644 --- a/mbsebbs/zmrecv.c +++ b/mbsebbs/zmrecv.c @@ -88,6 +88,7 @@ int zmrcvfiles(int want1k, int wantg) Syslog('+', "%s: start receive", protname()); get_frame_buffer(); + zsendline_init(); Rxtimeout = 10; if (secbuf == NULL) diff --git a/mbsebbs/zmsend.c b/mbsebbs/zmsend.c index 2ddd49c1..08afc6bf 100644 --- a/mbsebbs/zmsend.c +++ b/mbsebbs/zmsend.c @@ -47,7 +47,6 @@ static int zfilbuf(void); static int zsendfile(char*,int); static int zsendfdata(void); static int getinsync(int); -void initzsendmsk(char *); static FILE *in; static int Eofseen; /* EOF seen on input set by zfilbuf */ @@ -90,6 +89,7 @@ int zmsndfiles(down_list *lst, int try8) Syslog('+', "Zmodem: start Zmodem%s send", try8 ? "-8K":""); get_frame_buffer(); + zsendline_init(); use8k = try8; protocol = ZM_ZMODEM; @@ -263,13 +263,13 @@ int getzrxinit(void) case ZRINIT: Rxflags = 0377 & Rxhdr[ZF0]; Txfcs32 = (Wantfcs32 && (Rxflags & CANFC32)); -// { -// int old = Zctlesc; + { + int old = Zctlesc; Zctlesc |= Rxflags & TESCCTL; -// /* update table - was initialised to not escape */ -// if (Zctlesc && !old) -// zsendline_init(); -// } + /* update table - was initialised to not escape */ + if (Zctlesc && !old) + zsendline_init(); + } Rxbuflen = (0377 & Rxhdr[ZP0])+((0377 & Rxhdr[ZP1])<<8); if ( !(Rxflags & CANFDX)) @@ -333,7 +333,6 @@ int sendzsinit(void) Txhdr[ZF0] |= TESCCTL; zshhdr(ZSINIT, Txhdr); } else zsbhdr(ZSINIT, Txhdr); -// zsdata(Myattn, ZATTNLEN, ZCRCW); zsdata(Myattn, 1 + strlen(Myattn), ZCRCW); c = zgethdr(Rxhdr); switch (c) { @@ -504,7 +503,7 @@ gotack: */ if (TCHECK()) { c = GETCHAR(1); - Syslog('z', "zsendfdata(): check getchar(1)=%d", c); + Syslog('z', "zsendfdata(): 1 check getchar(1)=%d %c", c, c); if (c < 0) { return c; } else switch (c) { @@ -557,6 +556,7 @@ to: */ if (TCHECK()) { c = GETCHAR(1); + Syslog('z', "zsendfdata(): 2 check getchar(1)=%d %c", c, c); if (c < 0) { return c; } else switch (c) { @@ -669,21 +669,3 @@ int getinsync(int flag) } - -/* - * Set additional control chars to mask in Zsendmask - * according to bit array stored in char array at p - */ -void initzsendmsk(register char *p) -{ - int c; - - for (c = 0; c < 33; ++c) { - if (p[c>>3] & (1 << (c & 7))) { - Zsendmask[c] = 1; - Syslog('z', "Zmodem: Escaping %02o", c); - } - } -} - -