Several ymodem bugfixes
This commit is contained in:
parent
636c03fece
commit
983ea43925
@ -851,18 +851,26 @@ int Addfile(char *File, int AreaNum, int fileid)
|
||||
}
|
||||
|
||||
memset(&fdb, 0, fdbhdr.recsize);
|
||||
strcpy(fdb.LName, File);
|
||||
strcpy(fdb.LName, File); /* LFN, currently real file */
|
||||
strcpy(temp1, File);
|
||||
name_mangle(temp1);
|
||||
strcpy(fdb.Name, temp1);
|
||||
strcpy(fdb.Name, temp1); /* 8.3 name */
|
||||
fdb.Size = (long)(statfile.st_size);
|
||||
fdb.FileDate = statfile.st_mtime;
|
||||
fdb.Crc32 = file_crc(Filename, TRUE);
|
||||
strcpy(fdb.Uploader, exitinfo.sUserName);
|
||||
fdb.UploadDate = time(NULL);
|
||||
if (strcmp(fdb.Name, fdb.LName)) {
|
||||
/*
|
||||
* Rename the file first to the 8.3 name, this is the
|
||||
* standard way to store files in the filebase.
|
||||
*/
|
||||
sprintf(lname, "%s/%s", area.Path, fdb.Name);
|
||||
if (symlink(Filename, lname)) {
|
||||
rename(Filename, lname);
|
||||
/*
|
||||
* Then make a symlink to the 8.3 name
|
||||
*/
|
||||
if (symlink(lname, Filename)) {
|
||||
WriteError("$Can't create link %s to %s", lname, Filename);
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,41 @@ extern char *secbuf;
|
||||
#define sendline(c) PUTCHAR((c) & 0377)
|
||||
|
||||
int wcgetsec(size_t *, char *, unsigned int);
|
||||
int wcrxpn(char *, int);
|
||||
int wcrx(void);
|
||||
|
||||
|
||||
int ymrcvfiles(int want1k)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
Syslog('x', "%s: ymrcvfiles(%s)", protname(), want1k ? "TRUE":"FALSE");
|
||||
|
||||
for (;;) {
|
||||
rxbytes = 0l;
|
||||
if (wcrxpn(secbuf, want1k) == TERROR) {
|
||||
rc = 2;
|
||||
break;
|
||||
}
|
||||
if (secbuf[0] == 0) {
|
||||
Syslog('+', "%s: end of batch", protname());
|
||||
break;
|
||||
}
|
||||
if (procheader(secbuf) == ZFERR) {
|
||||
canit(1);
|
||||
rc = 2;
|
||||
break;
|
||||
}
|
||||
if (wcrx() == TERROR) {
|
||||
rc = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Syslog('x', "%s: ymrcvfiles rc=%d", protname(), rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@ -73,21 +108,20 @@ et_tu:
|
||||
Firstsec = TRUE;
|
||||
eof_seen = FALSE;
|
||||
sendline(Crcflg?WANTCRC:NAK);
|
||||
// ioctl(1, TCFLSH, 0);
|
||||
ioctl(1, TCFLSH, 0);
|
||||
purgeline(0); /* Do read next time ... */
|
||||
while ((c = wcgetsec(&Blklen, rpn, 10)) != 0) {
|
||||
if (c == WCEOT) {
|
||||
Syslog('x', "Pathname fetch returned EOT");
|
||||
sendline(ACK);
|
||||
// ioctl(1, TCFLSH, 0);
|
||||
ioctl(1, TCFLSH, 0);
|
||||
purgeline(0); /* Do read next time ... */
|
||||
// GETCHAR(1);
|
||||
goto et_tu;
|
||||
}
|
||||
return ERROR;
|
||||
return TERROR;
|
||||
}
|
||||
sendline(ACK);
|
||||
// ioctl(1, TCFLSH, 0);
|
||||
ioctl(1, TCFLSH, 0);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -108,7 +142,7 @@ int wcrx(void)
|
||||
|
||||
for (;;) {
|
||||
sendline(sendchar); /* send it now, we're ready! */
|
||||
// ioctl(1, TCFLSH, 0);
|
||||
ioctl(1, TCFLSH, 0);
|
||||
purgeline(0); /* Do read next time ... */
|
||||
|
||||
/*
|
||||
@ -138,7 +172,7 @@ int wcrx(void)
|
||||
if (closeit(1))
|
||||
return ERROR;
|
||||
sendline(ACK);
|
||||
// ioctl(1, TCFLSH, 0);
|
||||
ioctl(1, TCFLSH, 0);
|
||||
purgeline(0); /* Do read next time ... */
|
||||
return OK;
|
||||
}
|
||||
@ -225,14 +259,14 @@ humbug:
|
||||
|
||||
if (Firstsec) {
|
||||
sendline(Crcflg ? WANTCRC:NAK);
|
||||
// ioctl(1, TCFLSH, 0);
|
||||
ioctl(1, TCFLSH, 0);
|
||||
Syslog('x', "%s: send %s", protname(), Crcflg ? "WANTCRC":"NAK");
|
||||
purgeline(0); /* Do read next time ... */
|
||||
} else {
|
||||
maxtime = 40;
|
||||
sendline(NAK);
|
||||
Syslog('x', "%s: send NAK", protname());
|
||||
// ioctl(1, TCFLSH, 0);
|
||||
ioctl(1, TCFLSH, 0);
|
||||
purgeline(0); /* Do read next time ... */
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,8 @@
|
||||
|
||||
#define RETRYMAX 10
|
||||
|
||||
int wcrxpn(char *, int);
|
||||
int wcrx(void);
|
||||
|
||||
int ymrcvfiles(int);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -113,8 +113,8 @@ int ymsndfiles(down_list *lst, int use1k)
|
||||
Syslog('x', "%s: will use 1K blocks", protname());
|
||||
blklen = 1024;
|
||||
}
|
||||
if (wctx(tmpf->size) == ERROR) {
|
||||
Syslog('x', "wctx returned error");
|
||||
if (wctx(tmpf->size) == TERROR) {
|
||||
Syslog('+', "%s: wctx returned error", protname());
|
||||
tmpf->failed = TRUE;
|
||||
} else {
|
||||
tmpf->sent = TRUE;
|
||||
@ -131,11 +131,16 @@ int ymsndfiles(down_list *lst, int use1k)
|
||||
Syslog('+', "%s: could not unlink %s", protname(), tmpf->remote);
|
||||
}
|
||||
|
||||
if (protocol == ZM_YMODEM) {
|
||||
/*
|
||||
* Send empty filename to signal end of batch
|
||||
*/
|
||||
wctxpn((char *)"");
|
||||
if (maxrc == 2) {
|
||||
canit(1);
|
||||
purgeline(50);
|
||||
} else {
|
||||
if (protocol == ZM_YMODEM) {
|
||||
/*
|
||||
* Send empty filename to signal end of batch
|
||||
*/
|
||||
wctxpn((char *)"");
|
||||
}
|
||||
}
|
||||
|
||||
if (txbuf)
|
||||
@ -143,7 +148,7 @@ int ymsndfiles(down_list *lst, int use1k)
|
||||
txbuf = NULL;
|
||||
io_mode(0, 1);
|
||||
|
||||
Syslog('x', "%s: send rc=%d", protname(), maxrc);
|
||||
Syslog('+', "%s: end send files rc=%d", protname(), maxrc);
|
||||
return (maxrc < 2)?0:maxrc;
|
||||
}
|
||||
|
||||
@ -191,8 +196,7 @@ static int wctxpn(char *fname)
|
||||
|
||||
if (!zmodem_requested)
|
||||
if (getnak()) {
|
||||
PUTSTR((char *)"getnak failed");
|
||||
Syslog('+', "%s/%s: getnak failed", MBSE_SS(fname), protname());
|
||||
Syslog('+', "%s: timeout sending filename %s", protname(), MBSE_SS(fname));
|
||||
return TERROR;
|
||||
}
|
||||
|
||||
@ -229,7 +233,7 @@ static int wctxpn(char *fname)
|
||||
}
|
||||
// if (zmodem_requested)
|
||||
// return zsendfile(zi,txbuf, 1+strlen(p)+(p-txbuf));
|
||||
if (wcputsec(txbuf, 0, 128)==ERROR) {
|
||||
if (wcputsec(txbuf, 0, 128) == TERROR) {
|
||||
PUTSTR((char *)"wcputsec failed");
|
||||
Syslog('+', "%s/%s: wcputsec failed", fname,protname());
|
||||
return TERROR;
|
||||
@ -257,8 +261,8 @@ static int getnak(void)
|
||||
// return FALSE;
|
||||
case TIMEOUT:
|
||||
Syslog('x', "getnak: timeout try %d", tries);
|
||||
/* 30 seconds are enough */
|
||||
if (tries == 3) {
|
||||
/* 50 seconds are enough */
|
||||
if (tries == 5) {
|
||||
Syslog('x', "Timeout on pathname");
|
||||
return TRUE;
|
||||
}
|
||||
@ -290,6 +294,7 @@ static int getnak(void)
|
||||
if ((firstch = GETCHAR(2)) == CAN && Lastrx == CAN)
|
||||
return TRUE;
|
||||
default:
|
||||
Syslog('x', "got %d", firstch);
|
||||
break;
|
||||
}
|
||||
Lastrx = firstch;
|
||||
@ -343,7 +348,7 @@ static int wctx(long bytes_total)
|
||||
do {
|
||||
purgeline(5);
|
||||
PUTCHAR(EOT);
|
||||
// ioctl(1, TCFLSH, 0);
|
||||
ioctl(1, TCFLSH, 0);
|
||||
++attempts;
|
||||
} while ((firstch = (GETCHAR(Rxtimeout)) != ACK) && attempts < RETRYMAX);
|
||||
if (attempts == RETRYMAX) {
|
||||
@ -365,9 +370,10 @@ static int wcputsec(char *buf, int sectnum, size_t cseclen)
|
||||
|
||||
firstch = 0; /* part of logic to detect CAN CAN */
|
||||
|
||||
Syslog('x', "%s: wcputsec: sectnum %d, len %d", protname(), sectnum, cseclen);
|
||||
Syslog('x', "%s: wcputsec: sectnum %d, len %d, %s", protname(), sectnum, cseclen, Crcflg ? "crc":"checksum");
|
||||
|
||||
for (attempts = 0; attempts <= RETRYMAX; attempts++) {
|
||||
Syslog('x', "send sector");
|
||||
Lastrx = firstch;
|
||||
sendline(cseclen == 1024 ? STX:SOH);
|
||||
sendline(sectnum);
|
||||
@ -386,7 +392,7 @@ static int wcputsec(char *buf, int sectnum, size_t cseclen)
|
||||
else
|
||||
sendline(Checksum);
|
||||
|
||||
// ioctl(1, TCFLSH, 0);
|
||||
ioctl(1, TCFLSH, 0);
|
||||
if (Optiong) {
|
||||
firstsec = FALSE;
|
||||
return OK;
|
||||
@ -399,7 +405,7 @@ gotnak:
|
||||
if(Lastrx == CAN) {
|
||||
cancan:
|
||||
Syslog('x', "Cancelled");
|
||||
return ERROR;
|
||||
return TERROR;
|
||||
}
|
||||
break;
|
||||
case TIMEOUT:
|
||||
@ -409,9 +415,11 @@ cancan:
|
||||
if (firstsec)
|
||||
Crcflg = TRUE;
|
||||
case NAK:
|
||||
Syslog('x', "NAK on sector");
|
||||
Syslog('+', "%s: got NAK on sector %d", protname(), sectnum);
|
||||
purgeline(10);
|
||||
continue;
|
||||
case ACK:
|
||||
Syslog('x', "Got ACK");
|
||||
firstsec=FALSE;
|
||||
Totsecs += (cseclen>>7);
|
||||
return OK;
|
||||
|
@ -970,6 +970,9 @@ char *protname(void)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Purge input, maximum wait time in n * 10 mSec.
|
||||
*/
|
||||
void purgeline(int howlong)
|
||||
{
|
||||
int c, count = 0;
|
||||
@ -991,6 +994,7 @@ void canit(int fd)
|
||||
{
|
||||
static char canistr[] = { 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0 };
|
||||
|
||||
Syslog('z', "%s: send canit to fd %d", protname(), fd);
|
||||
ioctl(fd, TCFLSH, 0);
|
||||
write(fd, canistr, strlen(canistr));
|
||||
if (fd == 0)
|
||||
|
@ -66,7 +66,6 @@ static int tryz(void);
|
||||
static int rzfiles(void);
|
||||
static int rzfile(void);
|
||||
static void zmputs(char*);
|
||||
static int procheader(char*);
|
||||
static int ackbibi(void);
|
||||
static long getfree(void);
|
||||
|
||||
@ -100,29 +99,10 @@ int zmrcvfiles(int want1k)
|
||||
Syslog('+', "%s: switching to Ymodem", protname());
|
||||
protocol = ZM_YMODEM;
|
||||
}
|
||||
for (;;) {
|
||||
/*
|
||||
* Ymodem or Xmodem receive loop
|
||||
*/
|
||||
rxbytes = 0l;
|
||||
if (wcrxpn(secbuf, want1k) == TERROR) {
|
||||
rc = 2;
|
||||
goto fubar;
|
||||
}
|
||||
if (secbuf[0] == 0) {
|
||||
Syslog('z', "%s: session seems complete", protname());
|
||||
goto fubar;
|
||||
}
|
||||
if (procheader(secbuf) == ZFERR) {
|
||||
rc = 2;
|
||||
goto fubar;
|
||||
}
|
||||
if (wcrx() == TERROR) {
|
||||
rc = 2;
|
||||
goto fubar;
|
||||
}
|
||||
}
|
||||
rc = ymrcvfiles(want1k);
|
||||
goto fubar;
|
||||
}
|
||||
|
||||
/*
|
||||
* Zmodem receiver
|
||||
*/
|
||||
@ -151,7 +131,7 @@ fubar:
|
||||
*/
|
||||
purgeline(100);
|
||||
|
||||
Syslog('z', "%s: receive rc=%d", protname(), rc);
|
||||
Syslog('+', "%s: end receive rc=%d", protname(), rc);
|
||||
return abs(rc);
|
||||
}
|
||||
|
||||
@ -525,12 +505,17 @@ int procheader(char *Name)
|
||||
if (!*p) {
|
||||
/* alert - file name ended in with a / */
|
||||
Syslog('!', "%s: file name ends with a /, skipped: %s", protname(), Name);
|
||||
return ERROR;
|
||||
return ZFERR;
|
||||
}
|
||||
Name = p;
|
||||
Syslog('z', "filename converted to \"%s\"", MBSE_SS(Name));
|
||||
}
|
||||
|
||||
if (strlen(Name) > 80) {
|
||||
Syslog('!', "%s: file name received is longer then 80 characters, skipped: %s", protname(), Name);
|
||||
return ZFERR;
|
||||
}
|
||||
|
||||
Syslog('z', "zmanag=%d", zmanag);
|
||||
Syslog('z', "zconv=%d", zconv);
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
int procheader(char*);
|
||||
int zmrcvfiles(int);
|
||||
int putsec(char*,int);
|
||||
int closeit(int);
|
||||
|
Reference in New Issue
Block a user