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. from the users upload directory.
We don't reward upload time anymore, only bytes. It's more We don't reward upload time anymore, only bytes. It's more
troubles to implement right then it's worth these days. troubles to implement right then it's worth these days.
Added internal zmodem download protocol.
mbnewusr: mbnewusr:
Rewrote terminal i/o. 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 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 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 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 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 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 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 * Download error
*/ */
Syslog('+', "Download error rc=%d", rc);
free(temp); free(temp);
tidy_download(&dl); tidy_download(&dl);
return; return;
@ -342,7 +343,7 @@ void Download(void)
PUTCHAR('.'); PUTCHAR('.');
if (Tag.Active) { if (Tag.Active) {
for (tmpf = dl; tmpf; tmpf = tmpf->next) { for (tmpf = dl; tmpf; tmpf = tmpf->next) {
if (strcmp(tmpf->remote, Tag.SFile) == 0) { if (strcmp(tmpf->remote, Tag.LFile) == 0) {
if (tmpf->sent) { if (tmpf->sent) {
Tag.Active = FALSE; Tag.Active = FALSE;

View File

@ -42,6 +42,7 @@
#include "language.h" #include "language.h"
#include "openport.h" #include "openport.h"
#include "timeout.h" #include "timeout.h"
#include "zmsend.h"
/* /*
@ -67,8 +68,8 @@
*/ */
int sentbytes = 0; int sentbytes;
int rcvdbytes = 0; int rcvdbytes;
@ -257,7 +258,14 @@ int download(down_list *download_list)
sleep(2); sleep(2);
if (uProtInternal) { 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 { } else {
gettimeofday(&starttime, &tz); 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"); tmpf->kfs ?"KFS":"KEEP", tmpf->sent ?"SENT":"N/A", tmpf->failed ?"FAILED":"N/A");
} }
Syslog('b', "download() rc=%d", maxrc);
return maxrc; return maxrc;
} }

View File

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

View File

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

View File

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