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