From d4213642c79890b48be5b9c2d0696efa234e5219 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 6 Nov 2004 16:27:46 +0000 Subject: [PATCH] Changed to use the new download function --- ChangeLog | 5 + html/menus/control.html | 3 +- mbsebbs/dispfile.c | 4 - mbsebbs/file.c | 343 ++++++++++------------------------------ mbsebbs/input.c | 28 ++-- mbsebbs/offline.c | 9 +- mbsebbs/transfer.c | 124 ++++++++++++--- mbsebbs/transfer.h | 2 + 8 files changed, 209 insertions(+), 309 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8bed390a..7135fe1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,10 @@ v0.71.0 27-Oct-2004 After forced chat, redisplay the last menu. Removed support for non-batching protocols (xmodem) and for 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: Rewrote terminal i/o. @@ -31,6 +35,7 @@ v0.71.0 27-Oct-2004 mbsetup: In file transfers edit, removed switches for batch and bidirect protocols, added a switch for internal protocols. + In file areas, free downloads is now default for new areas. lang: Changed width of prompt 261. diff --git a/html/menus/control.html b/html/menus/control.html index 94669a99..5dfa4d70 100644 --- a/html/menus/control.html +++ b/html/menus/control.html @@ -14,7 +14,7 @@
-
Last update 24-Feb-2004
+
Last update 06-Nov-2004

MBSE BBS Control Codes in ANSI and ASCII files


@@ -47,7 +47,6 @@ For example: ^B32000^BThis is the text^B
D Uploads in Kilobytes E Download plus upload Kilobytes F Download Kilobyte limit - G Last transfer time H Current file area number I Current file area description J Download files limit diff --git a/mbsebbs/dispfile.c b/mbsebbs/dispfile.c index 1bec7360..ed5eff5e 100644 --- a/mbsebbs/dispfile.c +++ b/mbsebbs/dispfile.c @@ -383,10 +383,6 @@ void ControlCodeF(int ch) sprintf(temp, "%lu", LIMIT.DownK); break; - case 'G': - sprintf(temp, "%d", exitinfo.iTransferTime); - break; - case 'H': sprintf(temp, "%d", iAreaNumber); break; diff --git a/mbsebbs/file.c b/mbsebbs/file.c index d155c9c1..cc0d287b 100644 --- a/mbsebbs/file.c +++ b/mbsebbs/file.c @@ -163,19 +163,20 @@ void File_List() */ void Download(void) { - DIR *dirp; - struct dirent *dp; FILE *tf, *fd; - int i, err, Count = 0, OldArea; - char *symTo, *symFrom, *temp; - long Size = 0, CostSize = 0; - time_t ElapstimeStart, ElapstimeFin, iTime; - long iTransfer = 0; + int rc = 0, i, Count = 0, OldArea; + char *local, *temp; + long Size = 0, CostSize = 0, dsize; struct _fdbarea *fdb_area = NULL; + down_list *dl = NULL, *tmpf; Enter(2); OldArea = iAreaNumber; WhosDoingWhat(DOWNLOAD, NULL); + + /* + * Clean users tag directory. + */ 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"); @@ -188,12 +189,10 @@ void Download(void) pout(LIGHTRED, BLACK, (char *) Language(258)); Enter(2); Pause(); - free(temp); return; } - symTo = calloc(PATH_MAX, sizeof(char)); - symFrom = calloc(PATH_MAX, sizeof(char)); + local = calloc(PATH_MAX, sizeof(char)); /* Checking your marked downloads, please wait... */ pout(LIGHTMAGENTA, BLACK, (char *) Language(255)); Enter(2); @@ -234,8 +233,8 @@ void Download(void) * can unlink it aftwerwards. We also insert CR * characters to please the poor DOS (M$oft) users. */ - sprintf(symTo, "./tag/filedesc.%ld", exitinfo.Downloads % 256); - if ((fd = fopen(symTo, "a")) != NULL) { + sprintf(local, "./tag/filedesc.%ld", exitinfo.Downloads % 256); + if ((fd = fopen(local, "a")) != NULL) { fprintf(fd, "%s (%s)\r\n", fdb.LName, fdb.Name); for (i = 0; i < 25; i++) { if (strlen(fdb.Desc[i]) > 1) @@ -243,33 +242,14 @@ void Download(void) } fprintf(fd, "\r\n"); fclose(fd); - Syslog('b', "Added info to %s", symTo); + Syslog('b', "Added info to %s", local); } else { - WriteError("Can't add info to %s", symTo); + WriteError("Can't add info to %s", local); } - /* - * Make a symlink to the users download dir. - * 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; - } + sprintf(local, "%s/%s", sAreaPath, Tag.LFile); + add_download(&dl, local, Tag.LFile, Tag.Area, fdb.Size, FALSE); + Home(); } @@ -304,170 +284,100 @@ void Download(void) pout(LIGHTRED, BLACK, (char *) Language(258)); Enter(2); Pause(); - free(symTo); - free(symFrom); free(temp); + free(local); + tidy_download(&dl); Syslog('+', "No files left to download"); 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 */ sprintf(temp, "%s %d %s%ld %s", (char *) Language(249), Count, (char *) Language(280), Size, (char *) Language(281)); pout(YELLOW, BLACK, temp); 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)) { SetFileArea(OldArea); - free(symTo); - free(symFrom); free(temp); + tidy_download(&dl); return; } Pause(); - clear(); - /* File(s) : */ - pout(YELLOW, BLACK, (char *) Language(349)); sprintf(temp, "%d", Count); 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 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); + if ((rc = download(dl))) { + /* + * Download error + */ free(temp); - } else { - chdir(temp); - 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); + tidy_download(&dl); + return; } - 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 * the ./tag directory. Failed files are still there. */ - PUTCHAR('\r'); + Enter(1); /* Updating download counters, please wait ... */ pout(LIGHTCYAN, BLACK, (char *) Language(352)); - Enter(2); 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) { while (fread(&Tag, sizeof(Tag), 1, tf) == 1) { + PUTCHAR('.'); if (Tag.Active) { - sprintf(symTo, "./tag/%s", Tag.SFile); - /* - * If symlink is gone the file is 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); + for (tmpf = dl; tmpf; tmpf = tmpf->next) { + if (strcmp(tmpf->remote, Tag.SFile) == 0) { + if (tmpf->sent) { + + Tag.Active = FALSE; + fseek(tf, - sizeof(Tag), SEEK_CUR); + fwrite(&Tag, sizeof(Tag), 1, tf); - /* - * Update the download counter and the last download date. - */ - 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; + /* + * Update the download counter and the last download date. + */ + 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; - 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++; + break; } - } else { - Syslog('+', "Failed to sent %s from area %d", Tag.LFile, Tag.Area); } } } fclose(tf); } - - /* - * 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); + Enter(2); /* * Update the users record. @@ -483,14 +393,13 @@ void Download(void) */ if (LIMIT.DownK || LIMIT.DownF) { exitinfo.DownloadKToday -= (Size / 1024); - exitinfo.iTransferTime = iTransfer; } WriteExitinfo(); Pause(); SetFileArea(OldArea); - free(symTo); - free(symFrom); + free(temp); + tidy_download(&dl); } @@ -1140,11 +1049,9 @@ int Upload() */ int DownloadDirect(char *Name, int Wait) { - int err, rc; - char *symTo, *symFrom, temp[81]; - long Size; - time_t ElapstimeStart, ElapstimeFin, iTime; - long iTransfer = 0; + int rc = 0; + long Size; + down_list *dl = NULL; if ((Size = file_size(Name)) == -1) { WriteError("No file %s", Name); @@ -1153,110 +1060,28 @@ int DownloadDirect(char *Name, int Wait) Pause(); } - /* - * 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; - } + Syslog('+', "Download direct %s", Name); + add_download(&dl, Name, basename(Name), 0, Size, FALSE); WhosDoingWhat(DOWNLOAD, NULL); - ReadExitinfo(); - clear(); - /* 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) { + if ((rc = download(dl))) { /* - * Only log the error, we might have sent some files - * instead of nothing. + * Error */ - WriteError("$Download error %d, prot: %s", err, sProtDn); - } - - 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); - + Syslog('+', "Download failed rc=%d", rc); + poutCR(LIGHTRED, BLACK, (char *)Language(353)); + } else { /* * Update the users record. The file is free, so only statistics. */ ReadExitinfo(); exitinfo.Downloads++; /* Increase download counter */ - exitinfo.iTransferTime = iTransfer; WriteExitinfo(); - rc = TRUE; - } else { - Syslog('+', "Download failed to sent file"); - unlink(symFrom); - rc = FALSE; } + if (Wait) Pause(); - free(symTo); - free(symFrom); return rc; } diff --git a/mbsebbs/input.c b/mbsebbs/input.c index a893b24e..20ef80f9 100644 --- a/mbsebbs/input.c +++ b/mbsebbs/input.c @@ -57,7 +57,7 @@ int Waitchar(unsigned char *ch, int wtime) return 1; } if (tty_status != STAT_TIMEOUT) { - Syslog('t', "Waitchar(): error rc=%d", rc); +// Syslog('t', "Waitchar(): error rc=%d", rc); return rc; } msleep(10); @@ -78,7 +78,7 @@ int Escapechar(unsigned char *ch) * 50 mSec, the user really pressed . */ if ((rc = Waitchar(ch, 5)) == TIMEOUT) { - Syslog('t', "Escapechar() real escape"); +// Syslog('t', "Escapechar() real escape"); return rc; } @@ -87,9 +87,9 @@ int Escapechar(unsigned char *ch) * Start of CSI sequence. If nothing follows, * return immediatly. */ - Syslog('t', "Escapechar() CSI intro"); +// Syslog('t', "Escapechar() CSI intro"); if ((rc = Waitchar(ch, 5)) == TIMEOUT) { - Syslog('t', "Escapechar() nothing follows"); +// Syslog('t', "Escapechar() nothing follows"); return rc; } @@ -99,7 +99,7 @@ int Escapechar(unsigned char *ch) * guaranteed to work with PC-clients. */ c = *ch; - Syslog('t', "Escapechar() CSI input %d", c); +// Syslog('t', "Escapechar() CSI input %d", c); if (c == 'A') c = KEY_UP; else if (c == 'B') @@ -125,12 +125,12 @@ int Escapechar(unsigned char *ch) Waitchar(ch, 5); /* Eat following ~ char */ c = KEY_PGDN; } else if (c == '1') { - Syslog('t', "Possible function key"); +// Syslog('t', "Possible function key"); if ((rc = Waitchar(ch, 5)) == TIMEOUT) { c = KEY_HOME; } else { c = *ch; - Syslog('t', "next %d %c", c, c); +// Syslog('t', "next %d %c", c, c); Waitchar(ch, 5); /* Eat following ~ char */ switch (c) { 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)); return rc; } - Syslog('t', "Escapechar() not a CSI sequence"); +// Syslog('t', "Escapechar() not a CSI sequence"); return -1; } @@ -167,7 +167,7 @@ unsigned char Readkey(void) unsigned char ch = 0; int rc = TIMEOUT; - Syslog('t', "Readkey()"); +// Syslog('t', "Readkey()"); while (rc == TIMEOUT) { rc = Waitchar(&ch, 5); // Syslog('t', "rc = %d, ch = %d", rc, ch); @@ -177,22 +177,22 @@ unsigned char Readkey(void) * then this function is finished. */ if ((rc == 1) && (ch != KEY_ESCAPE)) { - Syslog('t', "Readkey() returns %d", ch); +// Syslog('t', "Readkey() returns %d", ch); return ch; } if ((rc == 1) && (ch == KEY_ESCAPE)) { rc = Escapechar(&ch); if (rc == 1) { - Syslog('t', "Readkey() escaped returns %d", ch); +// Syslog('t', "Readkey() escaped returns %d", ch); return ch; } else { - Syslog('t', "Readkey() escaped returns %d (real escape)", KEY_ESCAPE); +// Syslog('t', "Readkey() escaped returns %d (real escape)", KEY_ESCAPE); return KEY_ESCAPE; } } } - Syslog('t', "Readkey() returns %d", rc); +// Syslog('t', "Readkey() returns %d", rc); return rc; } diff --git a/mbsebbs/offline.c b/mbsebbs/offline.c index 466a8ebc..42ffcc13 100644 --- a/mbsebbs/offline.c +++ b/mbsebbs/offline.c @@ -1239,7 +1239,7 @@ void OLR_DownBW() time_t Now; char Pktname[32], *Work, *Temp; long Area = 0; - int RetVal = FALSE, rc; + int RetVal = FALSE, rc = 0; FILE *fp, *tf, *mf, *af; INF_HEADER Inf; INF_AREA_INFO AreaInf; @@ -1437,7 +1437,6 @@ void OLR_DownBW() } fclose(tf); - rc = FALSE; alarm_on(); if (Total) { @@ -1472,7 +1471,7 @@ void OLR_DownBW() } } - if (rc == FALSE) { + if (rc) { Syslog('+', "BlueWave download failed"); /* Download failed */ 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"); /* Download failed */ 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"); /* Download failed */ pout(CFG.HiliteF, CFG.HiliteB, (char *)Language(447)); diff --git a/mbsebbs/transfer.c b/mbsebbs/transfer.c index 69cf6957..dcbffba0 100644 --- a/mbsebbs/transfer.c +++ b/mbsebbs/transfer.c @@ -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. * Returns: @@ -107,6 +169,12 @@ int download(down_list *download_list) struct timeval starttime, endtime; 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. */ @@ -114,39 +182,40 @@ int download(down_list *download_list) 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)); symFrom = calloc(PATH_MAX, sizeof(char)); - + temp = calloc(PATH_MAX, sizeof(char)); + /* * Build symlinks into the users tag directory. */ chdir("./tag"); for (tmpf = download_list; tmpf; tmpf = tmpf->next) { if (!tmpf->sent && !tmpf->failed) { - unlink(tmpf->remote); - 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; + sprintf(symFrom, "%s/%s/tag/%s", CFG.bbs_usersdir, exitinfo.Name, tmpf->remote); + Syslog('b', "test \"%s\" \"%s\"", symFrom, tmpf->local); + if (strcmp(symFrom, tmpf->local)) { + Syslog('b', "different, need a symlink"); + unlink(tmpf->remote); + 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 { - 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? - */ - WriteError("Symlink %s check failed, unmarking download", symFrom); + + /* + * Check if file or symlink is really there. + */ + sprintf(symFrom, "%s", tmpf->remote); + if ((access(symFrom, F_OK)) != 0) { + WriteError("File or symlink %s check failed, unmarking download", symFrom); tmpf->failed = TRUE; } else { Count++; @@ -174,7 +243,7 @@ int download(down_list *download_list) /* Protocol : */ 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); 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 * 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(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; } diff --git a/mbsebbs/transfer.h b/mbsebbs/transfer.h index 3bcad5c2..034f18ec 100644 --- a/mbsebbs/transfer.h +++ b/mbsebbs/transfer.h @@ -35,6 +35,8 @@ typedef struct _up_list { int ForceProtocol(void); +void add_download(down_list **, char *, char *, long, unsigned long, int); +void tidy_download(down_list **); int download(down_list *); int upload(up_list *);