Upload Ymodem more or less works

This commit is contained in:
Michiel Broek 2004-11-23 22:35:34 +00:00
parent 51e402ef71
commit 3eff7e378d
2 changed files with 27 additions and 15 deletions

View File

@ -43,6 +43,7 @@ static int eof_seen;
static int errors; static int errors;
extern long Bytesleft; extern long Bytesleft;
extern off_t rxbytes;
extern int Crcflg; extern int Crcflg;
extern char Lastrx; extern char Lastrx;
extern char *secbuf; extern char *secbuf;
@ -52,6 +53,12 @@ extern char *secbuf;
int wcgetsec(size_t *, char *, unsigned int); 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) int wcrxpn(char *rpn)
{ {
register int c; register int c;
@ -102,7 +109,7 @@ int wcrx(void)
ioctl(1, TCFLSH, 0); ioctl(1, TCFLSH, 0);
purgeline(0); /* Do read next time ... */ purgeline(0); /* Do read next time ... */
sectcurr = wcgetsec(&Blklen, secbuf, (unsigned int) ((sectnum & 0177) ? 5 : 13)); 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)) { if (sectcurr == ((sectnum+1) &0377)) {
sectnum++; sectnum++;
@ -110,6 +117,7 @@ int wcrx(void)
if (Bytesleft && (Bytesleft - bytes_received) < Blklen) if (Bytesleft && (Bytesleft - bytes_received) < Blklen)
Blklen = Bytesleft - bytes_received; Blklen = Bytesleft - bytes_received;
bytes_received += Blklen; bytes_received += Blklen;
rxbytes += Blklen;
if (putsec(secbuf, Blklen) == ERROR) if (putsec(secbuf, Blklen) == ERROR)
return ERROR; return ERROR;
sendchar = ACK; sendchar = ACK;
@ -153,7 +161,7 @@ int wcgetsec(size_t *Blklen, char *rxbuf, unsigned int maxtime)
if (firstch == SOH) { if (firstch == SOH) {
*Blklen=128; *Blklen=128;
get2: get2:
Syslog('x', "%s: wcgetsec blklen %d", protname(), Blklen); Syslog('x', "%s: wcgetsec blklen %d", protname(), *Blklen);
sectcurr = GETCHAR(1); sectcurr = GETCHAR(1);
if ((sectcurr + (oldcrc = GETCHAR(1))) == 0377) { if ((sectcurr + (oldcrc = GETCHAR(1))) == 0377) {
oldcrc = Checksum = 0; oldcrc = Checksum = 0;

View File

@ -44,10 +44,10 @@
static FILE *fout = NULL; static FILE *fout = NULL;
char *curfile = NULL; char *curfile = NULL;
static off_t rxbytes; 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;
static long sbytes; long sbytes;
struct timeval starttime, endtime; struct timeval starttime, endtime;
struct timezone tz; struct timezone tz;
@ -85,22 +85,26 @@ int zmrcvfiles(void)
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('+', "%s: could not initiate receive, rc=%d", protname(), rc); Syslog('+', "%s: could not initiate receive, rc=%d", protname(), rc);
} else { } else {
if (rc == 0) { if (rc == 0) {
if (wcrxpn(secbuf) == TERROR) { if (protocol == ZM_ZMODEM) {
rc = 2; Syslog('+', "%s: switching to Ymodem", protname());
goto fubar; protocol = ZM_YMODEM;
} }
/*
* Enter X/Y modem receive loop
*/
for (;;) { for (;;) {
/*
* Ymodem or Xmodem receive loop
*/
rxbytes = 0l;
if (wcrxpn(secbuf) == TERROR) {
rc = 2;
goto fubar;
}
if (secbuf[0] == 0) { if (secbuf[0] == 0) {
Syslog('z', "%s: seems complete", protname()); Syslog('z', "%s: session seems complete", protname());
goto fubar; goto fubar;
} }
if (procheader(secbuf) == ZFERR) { if (procheader(secbuf) == ZFERR) {
@ -453,9 +457,9 @@ int closeit(int success)
sbytes = rxbytes - sbytes; sbytes = rxbytes - sbytes;
gettimeofday(&endtime, &tz); gettimeofday(&endtime, &tz);
if (success) if (success)
Syslog('+', "Zmodem: OK %s", transfertime(starttime, endtime, sbytes, FALSE)); Syslog('+', "%s: OK %s", protname(), transfertime(starttime, endtime, sbytes, FALSE));
else else
Syslog('+', "Zmodem: dropped after %lu bytes", sbytes); Syslog('+', "%s: dropped after %lu bytes", protname(), sbytes);
rcvdbytes += sbytes; rcvdbytes += sbytes;
return rc; return rc;
} }
@ -531,7 +535,7 @@ int procheader(char *Name)
// illegal characters in the filename. // 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('+', "%s: \"%s\" %ld bytes, %s mode %o", protname(), Name, Bytesleft, ctt, Filemode);
if (curfile) if (curfile)
free(curfile); free(curfile);