Changed to use the new download function

This commit is contained in:
Michiel Broek 2004-11-06 16:27:46 +00:00
parent 6ad38d7d66
commit d4213642c7
8 changed files with 209 additions and 309 deletions

View File

@ -24,6 +24,10 @@ v0.71.0 27-Oct-2004
After forced chat, redisplay the last menu. After forced chat, redisplay the last menu.
Removed support for non-batching protocols (xmodem) and for Removed support for non-batching protocols (xmodem) and for
bidirectional protocols. bidirectional protocols.
Removed Ctrl-F G, this is of no use anymore.
Switched to new modular download function.
With download from file areas, the long filename is sent to
the users, we will only support protocols that allow this.
mbnewusr: mbnewusr:
Rewrote terminal i/o. Rewrote terminal i/o.
@ -31,6 +35,7 @@ v0.71.0 27-Oct-2004
mbsetup: mbsetup:
In file transfers edit, removed switches for batch and bidirect In file transfers edit, removed switches for batch and bidirect
protocols, added a switch for internal protocols. protocols, added a switch for internal protocols.
In file areas, free downloads is now default for new areas.
lang: lang:
Changed width of prompt 261. Changed width of prompt 261.

View File

@ -14,7 +14,7 @@
</HEAD> </HEAD>
<BODY> <BODY>
<BLOCKQUOTE> <BLOCKQUOTE>
<DIV align=right><h5>Last update 24-Feb-2004</h5></div> <DIV align=right><h5>Last update 06-Nov-2004</h5></div>
<DIV align=center><h1>MBSE BBS Control Codes in ANSI and ASCII files</h1></DIV> <DIV align=center><h1>MBSE BBS Control Codes in ANSI and ASCII files</h1></DIV>
<hr> <hr>
@ -47,7 +47,6 @@ For example: ^B32000^BThis is the text^B<br>
D Uploads in Kilobytes D Uploads in Kilobytes
E Download plus upload Kilobytes E Download plus upload Kilobytes
F Download Kilobyte limit F Download Kilobyte limit
G Last transfer time
H Current file area number H Current file area number
I Current file area description I Current file area description
J Download files limit J Download files limit

View File

@ -383,10 +383,6 @@ void ControlCodeF(int ch)
sprintf(temp, "%lu", LIMIT.DownK); sprintf(temp, "%lu", LIMIT.DownK);
break; break;
case 'G':
sprintf(temp, "%d", exitinfo.iTransferTime);
break;
case 'H': case 'H':
sprintf(temp, "%d", iAreaNumber); sprintf(temp, "%d", iAreaNumber);
break; break;

View File

@ -163,19 +163,20 @@ void File_List()
*/ */
void Download(void) void Download(void)
{ {
DIR *dirp;
struct dirent *dp;
FILE *tf, *fd; FILE *tf, *fd;
int i, err, Count = 0, OldArea; int rc = 0, i, Count = 0, OldArea;
char *symTo, *symFrom, *temp; char *local, *temp;
long Size = 0, CostSize = 0; long Size = 0, CostSize = 0, dsize;
time_t ElapstimeStart, ElapstimeFin, iTime;
long iTransfer = 0;
struct _fdbarea *fdb_area = NULL; struct _fdbarea *fdb_area = NULL;
down_list *dl = NULL, *tmpf;
Enter(2); Enter(2);
OldArea = iAreaNumber; OldArea = iAreaNumber;
WhosDoingWhat(DOWNLOAD, NULL); WhosDoingWhat(DOWNLOAD, NULL);
/*
* Clean users tag directory.
*/
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "-rf %s/%s/tag", CFG.bbs_usersdir, exitinfo.Name); sprintf(temp, "-rf %s/%s/tag", CFG.bbs_usersdir, exitinfo.Name);
execute_pth((char *)"rm", temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); execute_pth((char *)"rm", temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
@ -188,12 +189,10 @@ void Download(void)
pout(LIGHTRED, BLACK, (char *) Language(258)); pout(LIGHTRED, BLACK, (char *) Language(258));
Enter(2); Enter(2);
Pause(); Pause();
free(temp);
return; return;
} }
symTo = calloc(PATH_MAX, sizeof(char)); local = calloc(PATH_MAX, sizeof(char));
symFrom = calloc(PATH_MAX, sizeof(char));
/* Checking your marked downloads, please wait... */ /* Checking your marked downloads, please wait... */
pout(LIGHTMAGENTA, BLACK, (char *) Language(255)); pout(LIGHTMAGENTA, BLACK, (char *) Language(255));
Enter(2); Enter(2);
@ -234,8 +233,8 @@ void Download(void)
* can unlink it aftwerwards. We also insert CR * can unlink it aftwerwards. We also insert CR
* characters to please the poor DOS (M$oft) users. * characters to please the poor DOS (M$oft) users.
*/ */
sprintf(symTo, "./tag/filedesc.%ld", exitinfo.Downloads % 256); sprintf(local, "./tag/filedesc.%ld", exitinfo.Downloads % 256);
if ((fd = fopen(symTo, "a")) != NULL) { if ((fd = fopen(local, "a")) != NULL) {
fprintf(fd, "%s (%s)\r\n", fdb.LName, fdb.Name); fprintf(fd, "%s (%s)\r\n", fdb.LName, fdb.Name);
for (i = 0; i < 25; i++) { for (i = 0; i < 25; i++) {
if (strlen(fdb.Desc[i]) > 1) if (strlen(fdb.Desc[i]) > 1)
@ -243,33 +242,14 @@ void Download(void)
} }
fprintf(fd, "\r\n"); fprintf(fd, "\r\n");
fclose(fd); fclose(fd);
Syslog('b', "Added info to %s", symTo); Syslog('b', "Added info to %s", local);
} else { } else {
WriteError("Can't add info to %s", symTo); WriteError("Can't add info to %s", local);
} }
/* sprintf(local, "%s/%s", sAreaPath, Tag.LFile);
* Make a symlink to the users download dir. add_download(&dl, local, Tag.LFile, Tag.Area, fdb.Size, FALSE);
* First unlink, in case there was an old one.
* The shortname is linked to the original longname.
*/
chdir("./tag");
unlink(Tag.SFile);
sprintf(symFrom, "%s", Tag.SFile);
sprintf(symTo, "%s/%s", sAreaPath, Tag.LFile);
if (symlink(symTo, symFrom)) {
WriteError("$Can't create symlink %s %s %d", symTo, symFrom, errno);
Tag.Active = FALSE;
} else {
Syslog('b', "Created symlink %s -> %s", symFrom, symTo);
}
if ((access(symFrom, R_OK)) != 0) {
/*
* Extra check, is symlink really there?
*/
WriteError("Symlink %s check failed, unmarking download", symFrom);
Tag.Active = FALSE;
}
Home(); Home();
} }
@ -304,170 +284,100 @@ void Download(void)
pout(LIGHTRED, BLACK, (char *) Language(258)); pout(LIGHTRED, BLACK, (char *) Language(258));
Enter(2); Enter(2);
Pause(); Pause();
free(symTo);
free(symFrom);
free(temp); free(temp);
free(local);
tidy_download(&dl);
Syslog('+', "No files left to download"); Syslog('+', "No files left to download");
return; return;
} }
/*
* Add descriptions file to the queue.
*/
sprintf(local, "%s/%s/tag/filedesc.%ld", CFG.bbs_usersdir, exitinfo.Name, exitinfo.Downloads % 256);
dsize = file_size(local);
sprintf(temp, "filedesc.%ld", exitinfo.Downloads % 256);
add_download(&dl, local, temp, 0, dsize, TRUE);
free(local);
/* You have */ /* files( */ /* bytes) marked for download */ /* You have */ /* files( */ /* bytes) marked for download */
sprintf(temp, "%s %d %s%ld %s", (char *) Language(249), Count, (char *) Language(280), Size, (char *) Language(281)); sprintf(temp, "%s %d %s%ld %s", (char *) Language(249), Count, (char *) Language(280), Size, (char *) Language(281));
pout(YELLOW, BLACK, temp); pout(YELLOW, BLACK, temp);
Enter(2); Enter(2);
/*
* If user has no default protocol, make sure he has one.
*/
if (!ForceProtocol()) {
SetFileArea(OldArea);
free(symTo);
free(symFrom);
free(temp);
return;
}
if (!CheckBytesAvailable(CostSize)) { if (!CheckBytesAvailable(CostSize)) {
SetFileArea(OldArea); SetFileArea(OldArea);
free(symTo);
free(symFrom);
free(temp); free(temp);
tidy_download(&dl);
return; return;
} }
Pause(); Pause();
clear(); if ((rc = download(dl))) {
/* File(s) : */ /*
pout(YELLOW, BLACK, (char *) Language(349)); sprintf(temp, "%d", Count); PUTSTR(temp); Enter(1); * Download error
/* Size : */ */
pout( CYAN, BLACK, (char *) Language(350)); sprintf(temp, "%lu", Size); PUTSTR(temp); Enter(1);
/* Protocol : */
pout( CYAN, BLACK, (char *) Language(351)); sprintf(temp, "%s", sProtName); PUTSTR(temp); Enter(1);
Syslog('+', "Download tagged files start, protocol: %s", sProtName);
PUTSTR(sProtAdvice);
Enter(2);
/*
* Wait a while before download
*/
sleep(2);
ElapstimeStart = time(NULL);
/*
* Transfer the files. Set the Client/Server time at the maximum
* time the user has plus 10 minutes. The overall timer 10 seconds
* less. Not a nice but working solution.
*/
alarm_set(((exitinfo.iTimeLeft + 10) * 60) - 10);
Altime((exitinfo.iTimeLeft + 10) * 60);
sprintf(temp, "%s/%s/tag", CFG.bbs_usersdir, exitinfo.Name);
if ((dirp = opendir(temp)) == NULL) {
WriteError("$Download: Can't open dir: %s", temp);
free(temp); free(temp);
} else { tidy_download(&dl);
chdir(temp); return;
free(temp);
temp = NULL;
while ((dp = readdir(dirp)) != NULL ) {
if (*(dp->d_name) != '.') {
if (temp != NULL) {
temp = xstrcat(temp, (char *)" ");
temp = xstrcat(temp, dp->d_name);
} else {
temp = xstrcpy(dp->d_name);
}
}
}
if (temp != NULL) {
if ((err = execute_str(sProtDn, temp, NULL, NULL, NULL, NULL))) {
WriteError("$Download error %d, prot: %s", err, sProtDn);
}
/*
* Restore rawport
*/
rawport();
free(temp);
} else {
WriteError("No filebatch created");
}
closedir(dirp);
} }
Altime(0);
alarm_off();
alarm_on();
Home();
ElapstimeFin = time(NULL);
/*
* Get time from Before Download and After Download to get
* download time, if the time is zero, it will be one.
*/
iTime = ElapstimeFin - ElapstimeStart;
if (!iTime)
iTime = 1;
/* /*
* Checking the successfull sent files, they are missing from * Checking the successfull sent files, they are missing from
* the ./tag directory. Failed files are still there. * the ./tag directory. Failed files are still there.
*/ */
PUTCHAR('\r'); Enter(1);
/* Updating download counters, please wait ... */ /* Updating download counters, please wait ... */
pout(LIGHTCYAN, BLACK, (char *) Language(352)); pout(LIGHTCYAN, BLACK, (char *) Language(352));
Enter(2);
Count = Size = 0; Count = Size = 0;
/*
* Update downloadcounters, don't log anything because the state
* of sucessfull sent files is already logged by the download
* function.
*/
if ((tf = fopen("taglist", "r+")) != NULL) { if ((tf = fopen("taglist", "r+")) != NULL) {
while (fread(&Tag, sizeof(Tag), 1, tf) == 1) { while (fread(&Tag, sizeof(Tag), 1, tf) == 1) {
PUTCHAR('.');
if (Tag.Active) { if (Tag.Active) {
sprintf(symTo, "./tag/%s", Tag.SFile); for (tmpf = dl; tmpf; tmpf = tmpf->next) {
/* if (strcmp(tmpf->remote, Tag.SFile) == 0) {
* If symlink is gone the file is sent. if (tmpf->sent) {
*/
if ((access(symTo, R_OK)) != 0) {
Syslog('+', "File %s from area %d sent ok", Tag.LFile, Tag.Area);
Tag.Active = FALSE;
fseek(tf, - sizeof(Tag), SEEK_CUR);
fwrite(&Tag, sizeof(Tag), 1, tf);
/* Tag.Active = FALSE;
* Update the download counter and the last download date. fseek(tf, - sizeof(Tag), SEEK_CUR);
*/ fwrite(&Tag, sizeof(Tag), 1, tf);
SetFileArea(Tag.Area);
if ((fdb_area = mbsedb_OpenFDB(Tag.Area, 30))) { /*
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) { * Update the download counter and the last download date.
if (strcmp(fdb.LName, Tag.LFile) == 0) */
break; SetFileArea(Tag.Area);
if ((fdb_area = mbsedb_OpenFDB(Tag.Area, 30))) {
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
if (strcmp(fdb.LName, Tag.LFile) == 0)
break;
}
Size += fdb.Size;
fdb.TimesDL++;
fdb.LastDL = time(NULL);
if (mbsedb_LockFDB(fdb_area, 30)) {
fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR);
fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
mbsedb_UnlockFDB(fdb_area);
}
mbsedb_CloseFDB(fdb_area);
Count++;
}
} }
Size += fdb.Size; break;
fdb.TimesDL++;
fdb.LastDL = time(NULL);
if (mbsedb_LockFDB(fdb_area, 30)) {
fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR);
fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
mbsedb_UnlockFDB(fdb_area);
}
mbsedb_CloseFDB(fdb_area);
Count++;
} }
} else {
Syslog('+', "Failed to sent %s from area %d", Tag.LFile, Tag.Area);
} }
} }
} }
fclose(tf); fclose(tf);
} }
Enter(2);
/*
* Work out transfer rate in seconds by dividing the
* Size of the File by the amount of time it took to download
* the file.
*/
iTransfer = Size / iTime;
Syslog('+', "Download time %ld seconds (%lu cps), %d files", iTime, iTransfer, Count);
/* /*
* Update the users record. * Update the users record.
@ -483,14 +393,13 @@ void Download(void)
*/ */
if (LIMIT.DownK || LIMIT.DownF) { if (LIMIT.DownK || LIMIT.DownF) {
exitinfo.DownloadKToday -= (Size / 1024); exitinfo.DownloadKToday -= (Size / 1024);
exitinfo.iTransferTime = iTransfer;
} }
WriteExitinfo(); WriteExitinfo();
Pause(); Pause();
SetFileArea(OldArea); SetFileArea(OldArea);
free(symTo); free(temp);
free(symFrom); tidy_download(&dl);
} }
@ -1140,11 +1049,9 @@ int Upload()
*/ */
int DownloadDirect(char *Name, int Wait) int DownloadDirect(char *Name, int Wait)
{ {
int err, rc; int rc = 0;
char *symTo, *symFrom, temp[81]; long Size;
long Size; down_list *dl = NULL;
time_t ElapstimeStart, ElapstimeFin, iTime;
long iTransfer = 0;
if ((Size = file_size(Name)) == -1) { if ((Size = file_size(Name)) == -1) {
WriteError("No file %s", Name); WriteError("No file %s", Name);
@ -1153,110 +1060,28 @@ int DownloadDirect(char *Name, int Wait)
Pause(); Pause();
} }
/* Syslog('+', "Download direct %s", Name);
* Make a symlink to the users tmp dir.
*/
symTo = calloc(PATH_MAX, sizeof(char));
symFrom = calloc(PATH_MAX, sizeof(char));
sprintf(symFrom, "%s/%s/tmp%s", CFG.bbs_usersdir, exitinfo.Name, strrchr(Name, '/'));
sprintf(symTo, "%s", Name);
if (symlink(symTo, symFrom)) {
WriteError("$Can't create symlink %s %s", symTo, symFrom);
free(symTo);
free(symFrom);
return FALSE;
}
/*
* If user has no default protocol, make sure he has one.
*/
if (!ForceProtocol()) {
unlink(symFrom);
free(symTo);
free(symFrom);
return FALSE;
}
add_download(&dl, Name, basename(Name), 0, Size, FALSE);
WhosDoingWhat(DOWNLOAD, NULL); WhosDoingWhat(DOWNLOAD, NULL);
ReadExitinfo();
clear(); if ((rc = download(dl))) {
/* File(s) : */
pout(YELLOW, BLACK, (char *) Language(349)); sprintf(temp, "%s", symFrom); PUTSTR(temp); Enter(1);
/* Size : */
pout( CYAN, BLACK, (char *) Language(350)); sprintf(temp, "%lu", Size); PUTSTR(temp); Enter(1);
/* Protocol : */
pout( CYAN, BLACK, (char *) Language(351)); sprintf(temp, "%s", sProtName); PUTSTR(temp); Enter(1);
Syslog('+', "Download direct start %s", Name);
PUTSTR(sProtAdvice);
Enter(2);
/*
* Wait a while before download
*/
sleep(2);
ElapstimeStart = time(NULL);
/*
* Transfer the file. Set the Client/Server time at the maximum
* time the user has plus 10 minutes. The overall timer 10 seconds
* less.
*/
alarm_set(((exitinfo.iTimeLeft + 10) * 60) - 10);
Altime((exitinfo.iTimeLeft + 10) * 60);
err = execute_str(sProtDn, symFrom, NULL, NULL, NULL, NULL);
rawport();
if (err) {
/* /*
* Only log the error, we might have sent some files * Error
* instead of nothing.
*/ */
WriteError("$Download error %d, prot: %s", err, sProtDn); Syslog('+', "Download failed rc=%d", rc);
} poutCR(LIGHTRED, BLACK, (char *)Language(353));
} else {
Altime(0);
alarm_off();
alarm_on();
ElapstimeFin = time(NULL);
/*
* Get time from Before Download and After Download to get
* download time, if the time is zero, it will be one.
*/
iTime = ElapstimeFin - ElapstimeStart;
if (!iTime)
iTime = 1;
if ((access(symFrom, R_OK)) != 0) {
/*
* Work out transfer rate in seconds by dividing the
* Size of the File by the amount of time it took to download
* the file.
*/
iTransfer = Size / iTime;
Syslog('+', "Download ok, time %ld seconds (%lu cps)", iTime, iTransfer);
/* /*
* Update the users record. The file is free, so only statistics. * Update the users record. The file is free, so only statistics.
*/ */
ReadExitinfo(); ReadExitinfo();
exitinfo.Downloads++; /* Increase download counter */ exitinfo.Downloads++; /* Increase download counter */
exitinfo.iTransferTime = iTransfer;
WriteExitinfo(); WriteExitinfo();
rc = TRUE;
} else {
Syslog('+', "Download failed to sent file");
unlink(symFrom);
rc = FALSE;
} }
if (Wait) if (Wait)
Pause(); Pause();
free(symTo);
free(symFrom);
return rc; return rc;
} }

View File

@ -57,7 +57,7 @@ int Waitchar(unsigned char *ch, int wtime)
return 1; return 1;
} }
if (tty_status != STAT_TIMEOUT) { if (tty_status != STAT_TIMEOUT) {
Syslog('t', "Waitchar(): error rc=%d", rc); // Syslog('t', "Waitchar(): error rc=%d", rc);
return rc; return rc;
} }
msleep(10); msleep(10);
@ -78,7 +78,7 @@ int Escapechar(unsigned char *ch)
* 50 mSec, the user really pressed <esc>. * 50 mSec, the user really pressed <esc>.
*/ */
if ((rc = Waitchar(ch, 5)) == TIMEOUT) { if ((rc = Waitchar(ch, 5)) == TIMEOUT) {
Syslog('t', "Escapechar() real escape"); // Syslog('t', "Escapechar() real escape");
return rc; return rc;
} }
@ -87,9 +87,9 @@ int Escapechar(unsigned char *ch)
* Start of CSI sequence. If nothing follows, * Start of CSI sequence. If nothing follows,
* return immediatly. * return immediatly.
*/ */
Syslog('t', "Escapechar() CSI intro"); // Syslog('t', "Escapechar() CSI intro");
if ((rc = Waitchar(ch, 5)) == TIMEOUT) { if ((rc = Waitchar(ch, 5)) == TIMEOUT) {
Syslog('t', "Escapechar() nothing follows"); // Syslog('t', "Escapechar() nothing follows");
return rc; return rc;
} }
@ -99,7 +99,7 @@ int Escapechar(unsigned char *ch)
* guaranteed to work with PC-clients. * guaranteed to work with PC-clients.
*/ */
c = *ch; c = *ch;
Syslog('t', "Escapechar() CSI input %d", c); // Syslog('t', "Escapechar() CSI input %d", c);
if (c == 'A') if (c == 'A')
c = KEY_UP; c = KEY_UP;
else if (c == 'B') else if (c == 'B')
@ -125,12 +125,12 @@ int Escapechar(unsigned char *ch)
Waitchar(ch, 5); /* Eat following ~ char */ Waitchar(ch, 5); /* Eat following ~ char */
c = KEY_PGDN; c = KEY_PGDN;
} else if (c == '1') { } else if (c == '1') {
Syslog('t', "Possible function key"); // Syslog('t', "Possible function key");
if ((rc = Waitchar(ch, 5)) == TIMEOUT) { if ((rc = Waitchar(ch, 5)) == TIMEOUT) {
c = KEY_HOME; c = KEY_HOME;
} else { } else {
c = *ch; c = *ch;
Syslog('t', "next %d %c", c, c); // Syslog('t', "next %d %c", c, c);
Waitchar(ch, 5); /* Eat following ~ char */ Waitchar(ch, 5); /* Eat following ~ char */
switch (c) { switch (c) {
case '1' : c = KEY_F1; break; case '1' : c = KEY_F1; break;
@ -144,11 +144,11 @@ int Escapechar(unsigned char *ch)
} }
} }
} }
Syslog('t', "Escapechar() will return %d", c); // Syslog('t', "Escapechar() will return %d", c);
memcpy(ch, &c, sizeof(unsigned char)); memcpy(ch, &c, sizeof(unsigned char));
return rc; return rc;
} }
Syslog('t', "Escapechar() not a CSI sequence"); // Syslog('t', "Escapechar() not a CSI sequence");
return -1; return -1;
} }
@ -167,7 +167,7 @@ unsigned char Readkey(void)
unsigned char ch = 0; unsigned char ch = 0;
int rc = TIMEOUT; int rc = TIMEOUT;
Syslog('t', "Readkey()"); // Syslog('t', "Readkey()");
while (rc == TIMEOUT) { while (rc == TIMEOUT) {
rc = Waitchar(&ch, 5); rc = Waitchar(&ch, 5);
// Syslog('t', "rc = %d, ch = %d", rc, ch); // Syslog('t', "rc = %d, ch = %d", rc, ch);
@ -177,22 +177,22 @@ unsigned char Readkey(void)
* then this function is finished. * then this function is finished.
*/ */
if ((rc == 1) && (ch != KEY_ESCAPE)) { if ((rc == 1) && (ch != KEY_ESCAPE)) {
Syslog('t', "Readkey() returns %d", ch); // Syslog('t', "Readkey() returns %d", ch);
return ch; return ch;
} }
if ((rc == 1) && (ch == KEY_ESCAPE)) { if ((rc == 1) && (ch == KEY_ESCAPE)) {
rc = Escapechar(&ch); rc = Escapechar(&ch);
if (rc == 1) { if (rc == 1) {
Syslog('t', "Readkey() escaped returns %d", ch); // Syslog('t', "Readkey() escaped returns %d", ch);
return ch; return ch;
} else { } else {
Syslog('t', "Readkey() escaped returns %d (real escape)", KEY_ESCAPE); // Syslog('t', "Readkey() escaped returns %d (real escape)", KEY_ESCAPE);
return KEY_ESCAPE; return KEY_ESCAPE;
} }
} }
} }
Syslog('t', "Readkey() returns %d", rc); // Syslog('t', "Readkey() returns %d", rc);
return rc; return rc;
} }

View File

@ -1239,7 +1239,7 @@ void OLR_DownBW()
time_t Now; time_t Now;
char Pktname[32], *Work, *Temp; char Pktname[32], *Work, *Temp;
long Area = 0; long Area = 0;
int RetVal = FALSE, rc; int RetVal = FALSE, rc = 0;
FILE *fp, *tf, *mf, *af; FILE *fp, *tf, *mf, *af;
INF_HEADER Inf; INF_HEADER Inf;
INF_AREA_INFO AreaInf; INF_AREA_INFO AreaInf;
@ -1437,7 +1437,6 @@ void OLR_DownBW()
} }
fclose(tf); fclose(tf);
rc = FALSE;
alarm_on(); alarm_on();
if (Total) { if (Total) {
@ -1472,7 +1471,7 @@ void OLR_DownBW()
} }
} }
if (rc == FALSE) { if (rc) {
Syslog('+', "BlueWave download failed"); Syslog('+', "BlueWave download failed");
/* Download failed */ /* Download failed */
poutCR(CFG.HiliteF, CFG.HiliteB, (char *)Language(447)); poutCR(CFG.HiliteF, CFG.HiliteB, (char *)Language(447));
@ -2204,7 +2203,7 @@ void OLR_DownQWK(void)
} }
} }
if (rc == FALSE) { if (rc) {
Syslog('+', "QWK download failed"); Syslog('+', "QWK download failed");
/* Download failed */ /* Download failed */
pout(CFG.HiliteF, CFG.HiliteB, (char *)Language(447)); pout(CFG.HiliteF, CFG.HiliteB, (char *)Language(447));
@ -2820,7 +2819,7 @@ void OLR_DownASCII(void)
} }
} }
if (rc == FALSE) { if (rc) {
Syslog('+', "ASCII download failed"); Syslog('+', "ASCII download failed");
/* Download failed */ /* Download failed */
pout(CFG.HiliteF, CFG.HiliteB, (char *)Language(447)); pout(CFG.HiliteF, CFG.HiliteB, (char *)Language(447));

View File

@ -89,6 +89,68 @@ int ForceProtocol()
void add_download(down_list **lst, char *local, char *remote, long Area, unsigned long size, int kfs)
{
down_list *tmp, *ta;
int i;
Syslog('b', "add_download(\"%s\",\"%s\",%ld,%ld,%d)", MBSE_SS(local), MBSE_SS(remote), Area, size, kfs);
tmp = (down_list *)malloc(sizeof(down_list));
tmp->next = NULL;
tmp->local = xstrcpy(local);
tmp->remote = xstrcpy(remote);
tmp->cps = 0;
tmp->area = Area;
tmp->size = size;
tmp->kfs = kfs;
tmp->sent = FALSE;
tmp->failed = FALSE;
/*
* Most prottocols don't allow spaces in filenames, so we modify the remote name.
* However, they should not exist on a bbs.
*/
for (i = 0; i < strlen(tmp->remote); i++) {
if (tmp->remote[i] == ' ')
tmp->remote[i] = '_';
}
if (*lst == NULL) {
*lst = tmp;
} else {
for (ta = *lst; ta; ta = ta->next) {
if (ta->next == NULL) {
ta->next = (down_list *)tmp;
break;
}
}
}
return;
}
void tidy_download(down_list **fdp)
{
down_list *tmp, *old;
for (tmp = *fdp; tmp; tmp = old) {
old = tmp->next;
if (tmp->local)
free(tmp->local);
if (tmp->remote)
free(tmp->remote);
free(tmp);
}
*fdp = NULL;
return;
}
/* /*
* Download files to the user. * Download files to the user.
* Returns: * Returns:
@ -107,6 +169,12 @@ int download(down_list *download_list)
struct timeval starttime, endtime; struct timeval starttime, endtime;
struct timezone tz; struct timezone tz;
Syslog('b', "download()");
for (tmpf = download_list; tmpf; tmpf = tmpf->next) {
Syslog('b', "%s,%s,%ld,%ld,%ld,%s,%s,%s", tmpf->local, tmpf->remote, tmpf->cps, tmpf->area, tmpf->size,
tmpf->kfs ?"KFS":"KEEP", tmpf->sent ?"SENT":"N/A", tmpf->failed ?"FAILED":"N/A");
}
/* /*
* If user has no default protocol, make sure he has one. * If user has no default protocol, make sure he has one.
*/ */
@ -114,18 +182,9 @@ int download(down_list *download_list)
return 1; return 1;
} }
/*
* Clean users tag directory.
*/
WhosDoingWhat(DOWNLOAD, NULL);
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "-rf %s/%s/tag", CFG.bbs_usersdir, exitinfo.Name);
execute_pth((char *)"rm", temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
sprintf(temp, "%s/%s/tag", CFG.bbs_usersdir, exitinfo.Name);
CheckDir(temp);
symTo = calloc(PATH_MAX, sizeof(char)); symTo = calloc(PATH_MAX, sizeof(char));
symFrom = calloc(PATH_MAX, sizeof(char)); symFrom = calloc(PATH_MAX, sizeof(char));
temp = calloc(PATH_MAX, sizeof(char));
/* /*
* Build symlinks into the users tag directory. * Build symlinks into the users tag directory.
@ -133,20 +192,30 @@ int download(down_list *download_list)
chdir("./tag"); chdir("./tag");
for (tmpf = download_list; tmpf; tmpf = tmpf->next) { for (tmpf = download_list; tmpf; tmpf = tmpf->next) {
if (!tmpf->sent && !tmpf->failed) { if (!tmpf->sent && !tmpf->failed) {
unlink(tmpf->remote); sprintf(symFrom, "%s/%s/tag/%s", CFG.bbs_usersdir, exitinfo.Name, tmpf->remote);
sprintf(symFrom, "%s", tmpf->remote); Syslog('b', "test \"%s\" \"%s\"", symFrom, tmpf->local);
sprintf(symTo, "%s", tmpf->local); if (strcmp(symFrom, tmpf->local)) {
if (symlink(symTo, symFrom)) { Syslog('b', "different, need a symlink");
WriteError("$Can't create symlink %s %s %d", symTo, symFrom, errno); unlink(tmpf->remote);
tmpf->failed = TRUE; sprintf(symFrom, "%s", tmpf->remote);
sprintf(symTo, "%s", tmpf->local);
if (symlink(symTo, symFrom)) {
WriteError("$Can't create symlink %s %s %d", symTo, symFrom, errno);
tmpf->failed = TRUE;
} else {
Syslog('b', "Created symlink %s -> %s", symFrom, symTo);
}
tmpf->kfs = FALSE;
} else { } else {
Syslog('b', "Created symlink %s -> %s", symFrom, symTo); Syslog('b', "the same, file is in tag directory");
} }
if ((access(symFrom, R_OK)) != 0) {
/* /*
* Extra check, is symlink really there? * Check if file or symlink is really there.
*/ */
WriteError("Symlink %s check failed, unmarking download", symFrom); sprintf(symFrom, "%s", tmpf->remote);
if ((access(symFrom, F_OK)) != 0) {
WriteError("File or symlink %s check failed, unmarking download", symFrom);
tmpf->failed = TRUE; tmpf->failed = TRUE;
} else { } else {
Count++; Count++;
@ -174,7 +243,7 @@ int download(down_list *download_list)
/* Protocol : */ /* Protocol : */
pout( CYAN, BLACK, (char *) Language(351)); sprintf(temp, "%s", sProtName); PUTSTR(temp); Enter(1); pout( CYAN, BLACK, (char *) Language(351)); sprintf(temp, "%s", sProtName); PUTSTR(temp); Enter(1);
Syslog('+', "Download tagged files start, protocol: %s", sProtName); Syslog('+', "Download files start, protocol: %s", sProtName);
PUTSTR(sProtAdvice); PUTSTR(sProtAdvice);
Enter(2); Enter(2);
@ -264,12 +333,17 @@ int download(down_list *download_list)
* Size of the File by the amount of time it took to download * Size of the File by the amount of time it took to download
* the file. * the file.
*/ */
Syslog('+', "Download %s, %d", transfertime(starttime, endtime, (unsigned long)Size, TRUE), Count); Syslog('+', "Download %s in %d file(s)", transfertime(starttime, endtime, (unsigned long)Size, TRUE), Count);
} }
free(symTo); free(symTo);
free(symFrom); free(symFrom);
for (tmpf = download_list; tmpf; tmpf = tmpf->next) {
Syslog('b', "%s,%s,%ld,%ld,%ld,%s,%s,%s", tmpf->local, tmpf->remote, tmpf->cps, tmpf->area, tmpf->size,
tmpf->kfs ?"KFS":"KEEP", tmpf->sent ?"SENT":"N/A", tmpf->failed ?"FAILED":"N/A");
}
return maxrc; return maxrc;
} }

View File

@ -35,6 +35,8 @@ typedef struct _up_list {
int ForceProtocol(void); int ForceProtocol(void);
void add_download(down_list **, char *, char *, long, unsigned long, int);
void tidy_download(down_list **);
int download(down_list *); int download(down_list *);
int upload(up_list *); int upload(up_list *);