added internal zmodem download

This commit is contained in:
Michiel Broek 2004-11-08 14:36:34 +00:00
parent 5e3b1b09d5
commit c1ae6ed787
7 changed files with 432 additions and 459 deletions

View File

@ -32,6 +32,7 @@ v0.71.0 27-Oct-2004
from the users upload directory.
We don't reward upload time anymore, only bytes. It's more
troubles to implement right then it's worth these days.
Added internal zmodem download protocol.
mbnewusr:
Rewrote terminal i/o.

View File

@ -112,7 +112,7 @@ newuser.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h funcs.h inp
pinfo.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h pinfo.h input.h term.h ttyio.h
timecheck.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h timecheck.h funcs.h bye.h exitinfo.h language.h input.h term.h ttyio.h
change.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h change.h dispfile.h funcs.h input.h language.h misc.h timeout.h exitinfo.h bye.h term.h ttyio.h
transfer.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h transfer.h change.h whoson.h funcs.h term.h ttyio.h filesub.h language.h openport.h timeout.h
transfer.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h transfer.h change.h whoson.h funcs.h term.h ttyio.h filesub.h language.h openport.h timeout.h zmsend.h
exitinfo.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h funcs.h input.h language.h oneline.h misc.h bye.h timeout.h timecheck.h exitinfo.h
mbsebbs.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msg.h mbsebbs.h user.h dispfile.h language.h menu.h misc.h bye.h timeout.h funcs.h term.h ttyio.h openport.h
menu.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h oneline.h mail.h bbslist.h change.h chat.h file.h funcs.h input.h misc.h timeout.h menu.h page.h pinfo.h bye.h timecheck.h whoson.h language.h offline.h email.h door.h dispfile.h userlist.h timestats.h logentry.h morefile.h lastcallers.h signature.h term.h ttyio.h

View File

@ -318,6 +318,7 @@ void Download(void)
/*
* Download error
*/
Syslog('+', "Download error rc=%d", rc);
free(temp);
tidy_download(&dl);
return;
@ -342,7 +343,7 @@ void Download(void)
PUTCHAR('.');
if (Tag.Active) {
for (tmpf = dl; tmpf; tmpf = tmpf->next) {
if (strcmp(tmpf->remote, Tag.SFile) == 0) {
if (strcmp(tmpf->remote, Tag.LFile) == 0) {
if (tmpf->sent) {
Tag.Active = FALSE;

View File

@ -42,6 +42,7 @@
#include "language.h"
#include "openport.h"
#include "timeout.h"
#include "zmsend.h"
/*
@ -67,8 +68,8 @@
*/
int sentbytes = 0;
int rcvdbytes = 0;
int sentbytes;
int rcvdbytes;
@ -257,7 +258,14 @@ int download(down_list *download_list)
sleep(2);
if (uProtInternal) {
for (tmpf = download_list; tmpf && (maxrc < 2); tmpf = tmpf->next) {
if (strncasecmp(sProtName, "zmodem", 6) == 0) {
sprintf(temp, "%s/%s/tag", CFG.bbs_usersdir, exitinfo.Name);
chdir(temp);
maxrc = zmsndfiles(download_list);
Home();
} else {
Syslog('!', "Warning internal protocol %s not supported", sProtName);
maxrc = 1;
}
} else {
gettimeofday(&starttime, &tz);
@ -347,6 +355,7 @@ int download(down_list *download_list)
tmpf->kfs ?"KFS":"KEEP", tmpf->sent ?"SENT":"N/A", tmpf->failed ?"FAILED":"N/A");
}
Syslog('b', "download() rc=%d", maxrc);
return maxrc;
}

View File

@ -386,8 +386,7 @@ crcfoo:
case GOTCRCE:
case GOTCRCG:
case GOTCRCQ:
case GOTCRCW:
crc = updcrc16((((d=c))&0377), crc);
case GOTCRCW: crc = updcrc16((((d=c))&0377), crc);
if ((c = zdlread()) & ~0377)
goto crcfoo;
crc = updcrc16(c, crc);
@ -401,17 +400,13 @@ crcfoo:
Rxcount = length - (end - buf);
Syslog('z', "zrdata: %d %s", Rxcount, Zendnames[(d-GOTCRCE)&3]);
return d;
case GOTCAN:
Syslog('+', "Zmodem: Sender Canceled");
case GOTCAN: Syslog('+', "Zmodem: Sender Canceled");
return ZCAN;
case TIMEOUT:
Syslog('+', "Zmodem: TIMEOUT receiving data");
case TIMEOUT: Syslog('+', "Zmodem: TIMEOUT receiving data");
return c;
case HANGUP:
Syslog('+', "Zmodem: Carrier lost while receiving");
case HANGUP: Syslog('+', "Zmodem: Carrier lost while receiving");
return c;
default:
garbitch();
default: garbitch();
return c;
}
}
@ -439,8 +434,7 @@ crcfoo:
case GOTCRCE:
case GOTCRCG:
case GOTCRCQ:
case GOTCRCW:
d = c; c &= 0377;
case GOTCRCW: d = c; c &= 0377;
crc = updcrc32(c, crc);
if ((c = zdlread()) & ~0377)
goto crcfoo;
@ -463,17 +457,13 @@ crcfoo:
Syslog('z', "zrdat32: %d %s", Rxcount, Zendnames[(d-GOTCRCE)&3]);
return d;
case GOTCAN:
Syslog('+', "Zmodem: Sender Canceled");
case GOTCAN: Syslog('+', "Zmodem: Sender Canceled");
return ZCAN;
case TIMEOUT:
Syslog('+', "Zmodem: TIMEOUT");
case TIMEOUT: Syslog('+', "Zmodem: TIMEOUT");
return c;
case HANGUP:
Syslog('+', "Zmodem: Carrier lost while receiving");
case HANGUP: Syslog('+', "Zmodem: Carrier lost while receiving");
return c;
default:
garbitch();
default: garbitch();
return c;
}
}

View File

@ -36,7 +36,7 @@
#include "transfer.h"
static int initsend(void);
static int sendzfile(char*,char*);
static int sendzfile(char*);
static int finsend(void);
static int getzrxinit(void);
@ -98,14 +98,19 @@ int zmsndfiles(down_list *lst)
for (tmpf = lst; tmpf && (maxrc < 2); tmpf = tmpf->next) {
if (tmpf->remote) {
rc = sendzfile(tmpf->local, tmpf->remote);
rc = sendzfile(tmpf->remote);
rc = abs(rc);
if (rc > maxrc)
maxrc = rc;
if (rc == 0)
unlink(tmpf->remote);
} else if (maxrc == 0)
unlink(tmpf->remote);
if (rc == 0) {
tmpf->sent = TRUE;
} else {
tmpf->failed = TRUE;
}
} else if (maxrc == 0) {
tmpf->failed = TRUE;
}
Syslog('z', "zmsndfiles: unlink(%s) returns %d", tmpf->remote, unlink(tmpf->remote));
}
if (maxrc < 2) {
@ -167,9 +172,9 @@ static int finsend(void)
static int sendzfile(char *ln, char *rn)
static int sendzfile(char *rn)
{
int rc=0;
int rc = 0;
struct stat st;
struct flock fl;
int bufl;
@ -183,30 +188,24 @@ static int sendzfile(char *ln, char *rn)
txbuf = malloc(MAXBLOCK);
skipsize = 0L;
if ((in = fopen(ln, "r")) == NULL) {
if ((in = fopen(rn, "r")) == NULL) {
sverr = errno;
if ((sverr == ENOENT) || (sverr == EINVAL)) {
Syslog('+', "File %s doesn't exist, removing", MBSE_SS(ln));
Syslog('+', "File %s doesn't exist, removing", MBSE_SS(rn));
return 0;
} else {
WriteError("$Zmodem: cannot open file %s, skipping", MBSE_SS(ln));
WriteError("$Zmodem: cannot open file %s, skipping", MBSE_SS(rn));
return 1;
}
}
if (fcntl(fileno(in),F_SETLK,&fl) != 0) {
Syslog('+', "$Zmodem: cannot lock file %s, skipping",MBSE_SS(ln));
if (stat(rn,&st) != 0) {
Syslog('+', "$Zmodem: cannot access \"%s\", skipping",MBSE_SS(rn));
fclose(in);
return 1;
}
if (stat(ln,&st) != 0) {
Syslog('+', "$Zmodem: cannot access \"%s\", skipping",MBSE_SS(ln));
fclose(in);
return 1;
}
Syslog('+', "Zmodem: send \"%s\" as \"%s\"", MBSE_SS(ln), MBSE_SS(rn));
Syslog('+', "Zmodem: send \"%s\"", MBSE_SS(rn));
Syslog('+', "Zmodem: size %lu bytes, dated %s", (unsigned long)st.st_size, rfcdate(st.st_mtime));
gettimeofday(&starttime, &tz);
@ -217,7 +216,7 @@ static int sendzfile(char *ln, char *rn)
Eofseen = 0;
rc = zsendfile(txbuf,bufl);
if (rc == ZSKIP) {
Syslog('+', "Zmodem: remote skipped %s, is OK",MBSE_SS(ln));
Syslog('+', "Zmodem: remote skipped %s, is OK",MBSE_SS(rn));
return 0;
} else if ((rc == OK) && (st.st_size - skipsize)) {
gettimeofday(&endtime, &tz);
@ -308,20 +307,15 @@ int sendzsinit(void)
stohdr(0L);
if (Zctlesc) {
Txhdr[ZF0] |= TESCCTL; zshhdr(4, ZSINIT, Txhdr);
}
else
} else
zsbhdr(4, ZSINIT, Txhdr);
zsdata(Myattn, ZATTNLEN, ZCRCW);
c = zgethdr(Rxhdr);
switch (c) {
case ZCAN:
return TERROR;
case HANGUP:
return HANGUP;
case ZACK:
return OK;
default:
if (++errors > 19)
case ZCAN: return TERROR;
case HANGUP: return HANGUP;
case ZACK: return OK;
default: if (++errors > 19)
return TERROR;
continue;
}
@ -340,7 +334,7 @@ int zfilbuf(void)
n = fread(txbuf, 1, blklen, in);
if (n < blklen) {
Eofseen = 1;
Syslog('z', "zfilbuf return %d", n);
Syslog('Z', "zfilbuf return %d", n);
}
return n;
@ -429,7 +423,7 @@ again:
*/
int zsendfdata(void)
{
int c=0, e, n;
int c = 0, e, n;
int newcnt;
int tcount = 0;
int junkcount; /* Counts garbage chars received by TX */
@ -448,19 +442,14 @@ waitack:
gotack:
switch (c) {
default:
case ZCAN:
fclose(in);
case ZCAN: fclose(in);
return TERROR;
case ZRINIT:
fclose(in);
case ZRINIT: fclose(in);
return ZSKIP;
case ZSKIP:
fclose(in);
case ZSKIP: fclose(in);
return c;
case ZACK:
break; // Possible bug, added 23-08-99
case ZRPOS:
blklen = ((blklen >> 2) > 64) ? (blklen >> 2) : 64;
case ZACK: break; // Possible bug, added 23-08-99
case ZRPOS: blklen = ((blklen >> 2) > 64) ? (blklen >> 2) : 64;
goodblks = 0;
goodneeded = ((goodneeded << 1) > 16) ? 16 : goodneeded << 1;
Syslog('z', "zmsend: blocklen now %d", blklen);
@ -473,6 +462,7 @@ gotack:
fclose(in);
return c;
}
/*
* If the reverse channel can be tested for data,
* this logic may be used to detect error packets
@ -486,12 +476,10 @@ gotack:
return c;
} else switch (c) {
case CAN:
case ZPAD:
c = getinsync(1);
case ZPAD: c = getinsync(1);
goto gotack;
case XOFF: /* Wait a while for an XON */
case XOFF|0200:
GETCHAR(10);
case XOFF|0200: GETCHAR(10);
}
}
}
@ -515,8 +503,7 @@ to:
Txwcnt = 0; e = ZCRCQ;
} else
e = ZCRCG;
Syslog('z', "%7ld ZMODEM%s ",
Txpos, Crc32t?" CRC-32":"");
Syslog('Z', "%7ld ZMODEM%s ", Txpos, Crc32t?" CRC-32":"");
Nopper();
zsdata(txbuf, n, e);
bytcnt = Txpos += n;
@ -541,18 +528,15 @@ to:
return c;
} else switch (c) {
case CAN:
case ZPAD:
c = getinsync(1);
case ZPAD: c = getinsync(1);
if (c == ZACK)
break;
/* zcrce - dinna wanna starta ping-pong game */
zsdata(txbuf, 0, ZCRCE);
goto gotack;
case XOFF: /* Wait a while for an XON */
case XOFF|0200:
GETCHAR(10);
default:
++junkcount;
case XOFF|0200: GETCHAR(10);
default: ++junkcount;
}
}
if (Txwindow) {
@ -575,22 +559,16 @@ to:
zsbhdr(4, ZEOF, Txhdr);
egotack:
switch (getinsync(0)) {
case ZACK:
Syslog('z', "zsendfdata() ZACK");
case ZACK: Syslog('z', "zsendfdata() ZACK");
goto egotack; // continue in old source
case ZRPOS:
goto somemore;
case ZRINIT:
fclose(in);
case ZRPOS: goto somemore;
case ZRINIT: fclose(in);
return OK;
case ZSKIP:
fclose(in);
case ZSKIP: fclose(in);
Syslog('+', "Zmodem: File skipped by receiver request");
return ZSKIP;
default:
Syslog('+', "Zmodem: Got %d trying to send end of file", c);
case TERROR:
fclose(in);
default: Syslog('+', "Zmodem: Got %d trying to send end of file", c);
case TERROR: fclose(in);
return TERROR;
}
}
@ -610,17 +588,14 @@ int getinsync(int flag)
for (;;) {
c = zgethdr(Rxhdr);
switch (c) {
case HANGUP:
return HANGUP;
case HANGUP: return HANGUP;
case ZCAN:
case ZABORT:
case ZFIN:
case TERROR:
case TIMEOUT:
Syslog('+', "Zmodem: Got %s sending data", frametypes[c+FTOFFSET]);
case TIMEOUT: Syslog('+', "Zmodem: Got %s sending data", frametypes[c+FTOFFSET]);
return TERROR;
case ZRPOS:
/* ************************************* */
case ZRPOS: /* ************************************* */
/* If sending to a buffered modem, you */
/* might send a break at this point to */
/* dump the modem's buffer. */
@ -636,28 +611,25 @@ int getinsync(int flag)
Syslog('+', "Zmodem: Can't send block");
return TERROR;
}
if (Beenhereb4 > 4)
if (Beenhereb4 > 4) {
if (blklen > 32) {
blklen /= 2;
Syslog('z', "Zmodem: blocklen now %d", blklen);
}
}
else
} else {
Beenhereb4=0;
}
Lastsync = Rxpos;
return c;
case ZACK:
Lrxpos = Rxpos;
case ZACK: Lrxpos = Rxpos;
if (flag || Txpos == Rxpos)
return ZACK;
continue;
case ZRINIT:
case ZRINIT: return c;
case ZSKIP: Syslog('+', "Zmodem: File skipped by receiver request");
return c;
case ZSKIP:
Syslog('+', "Zmodem: File skipped by receiver request");
return c;
default:
zsbhdr(4, ZNAK, Txhdr);
default: zsbhdr(4, ZNAK, Txhdr);
continue;
}
}

View File

@ -4,7 +4,7 @@
/* $Id$ */
int zmsndfiles(down_list *lst)
int zmsndfiles(down_list *);
#endif