Upload Ymodem more or less works
This commit is contained in:
parent
51e402ef71
commit
3eff7e378d
@ -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;
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user