From 3eff7e378d71553cac9572fa102193540c22ef74 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Tue, 23 Nov 2004 22:35:34 +0000 Subject: [PATCH] Upload Ymodem more or less works --- mbsebbs/ymrecv.c | 12 ++++++++++-- mbsebbs/zmrecv.c | 30 +++++++++++++++++------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/mbsebbs/ymrecv.c b/mbsebbs/ymrecv.c index 2f520d93..d5265d51 100644 --- a/mbsebbs/ymrecv.c +++ b/mbsebbs/ymrecv.c @@ -43,6 +43,7 @@ static int eof_seen; static int errors; extern long Bytesleft; +extern off_t rxbytes; extern int Crcflg; extern char Lastrx; extern char *secbuf; @@ -52,6 +53,12 @@ extern char *secbuf; int wcgetsec(size_t *, char *, unsigned int); + +/* + * Fetch a pathname from the other end as a C ctyle ASCIZ string. + * Length is indeterminate as long as less than Blklen + * A null string represents no more files (YMODEM) + */ int wcrxpn(char *rpn) { register int c; @@ -102,7 +109,7 @@ int wcrx(void) ioctl(1, TCFLSH, 0); purgeline(0); /* Do read next time ... */ sectcurr = wcgetsec(&Blklen, secbuf, (unsigned int) ((sectnum & 0177) ? 5 : 13)); - Syslog('x', "%s: got sector %d", sectcurr); + Syslog('x', "%s: got sector %d", protname(), sectcurr); if (sectcurr == ((sectnum+1) &0377)) { sectnum++; @@ -110,6 +117,7 @@ int wcrx(void) if (Bytesleft && (Bytesleft - bytes_received) < Blklen) Blklen = Bytesleft - bytes_received; bytes_received += Blklen; + rxbytes += Blklen; if (putsec(secbuf, Blklen) == ERROR) return ERROR; sendchar = ACK; @@ -153,7 +161,7 @@ int wcgetsec(size_t *Blklen, char *rxbuf, unsigned int maxtime) if (firstch == SOH) { *Blklen=128; get2: - Syslog('x', "%s: wcgetsec blklen %d", protname(), Blklen); + Syslog('x', "%s: wcgetsec blklen %d", protname(), *Blklen); sectcurr = GETCHAR(1); if ((sectcurr + (oldcrc = GETCHAR(1))) == 0377) { oldcrc = Checksum = 0; diff --git a/mbsebbs/zmrecv.c b/mbsebbs/zmrecv.c index c4252799..8f0db14e 100644 --- a/mbsebbs/zmrecv.c +++ b/mbsebbs/zmrecv.c @@ -44,10 +44,10 @@ static FILE *fout = NULL; char *curfile = NULL; -static off_t rxbytes; +off_t rxbytes; static int Eofseen; /* indicates cpm eof (^Z) has been received */ static int errors; -static long sbytes; +long sbytes; struct timeval starttime, endtime; struct timezone tz; @@ -85,22 +85,26 @@ int zmrcvfiles(void) if (secbuf == NULL) secbuf = malloc(MAXBLOCK+1); tryzhdrtype = ZRINIT; - protocol = ZM_ZMODEM; if ((rc = tryz()) < 0) { Syslog('+', "%s: could not initiate receive, rc=%d", protname(), rc); } else { if (rc == 0) { - if (wcrxpn(secbuf) == TERROR) { - rc = 2; - goto fubar; + if (protocol == ZM_ZMODEM) { + Syslog('+', "%s: switching to Ymodem", protname()); + protocol = ZM_YMODEM; } - /* - * Enter X/Y modem receive loop - */ for (;;) { + /* + * Ymodem or Xmodem receive loop + */ + rxbytes = 0l; + if (wcrxpn(secbuf) == TERROR) { + rc = 2; + goto fubar; + } if (secbuf[0] == 0) { - Syslog('z', "%s: seems complete", protname()); + Syslog('z', "%s: session seems complete", protname()); goto fubar; } if (procheader(secbuf) == ZFERR) { @@ -453,9 +457,9 @@ int closeit(int success) sbytes = rxbytes - sbytes; gettimeofday(&endtime, &tz); if (success) - Syslog('+', "Zmodem: OK %s", transfertime(starttime, endtime, sbytes, FALSE)); + Syslog('+', "%s: OK %s", protname(), transfertime(starttime, endtime, sbytes, FALSE)); else - Syslog('+', "Zmodem: dropped after %lu bytes", sbytes); + Syslog('+', "%s: dropped after %lu bytes", protname(), sbytes); rcvdbytes += sbytes; return rc; } @@ -531,7 +535,7 @@ int procheader(char *Name) // 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); + Syslog('+', "%s: \"%s\" %ld bytes, %s mode %o", protname(), Name, Bytesleft, ctt, Filemode); if (curfile) free(curfile);