From edad301e0af2c3989f88f931203c599ba8267551 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Thu, 27 Feb 2003 20:57:36 +0000 Subject: [PATCH] Added new filecase test function --- ChangeLog | 5 +++++ lib/common.h | 2 ++ lib/mbfile.c | 33 ++++++++++++++++++++++++++++++++- mbfido/tic.c | 52 +++++++++++++++++++++++++++++++--------------------- 4 files changed, 70 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6f90b3be..5d38fd33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,11 @@ v0.37.2 23-Feb-2003. System prepared for setting the official FTSC product code, this will be 0x11FF. The code is not yet activated. + common.a: + New function to get the real case of a filename. + + mbfido: + Finding the inbound tic file now uses the new function. v0.37.1 14-Jan-2003 - 23-Feb-2003 diff --git a/lib/common.h b/lib/common.h index 7ea7f412..30de3767 100644 --- a/lib/common.h +++ b/lib/common.h @@ -283,6 +283,8 @@ long file_crc(char *path, int); time_t file_time(char *path); int mkdirs(char *name, mode_t); int diskfree(int); +int getfilecase(char *, char *); + /* diff --git a/lib/mbfile.c b/lib/mbfile.c index 693198e6..eb9eabc2 100644 --- a/lib/mbfile.c +++ b/lib/mbfile.c @@ -4,7 +4,7 @@ * Purpose ...............: Basic File I/O * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2003 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -346,3 +346,34 @@ int diskfree(int needed) } + +/* + * Give a directory path and a filename, locate that filename in that + * directory and return the filename with the correct case. This is + * to be able to detect filename.ext, FILENAME.EXT and FiLeNaMe.ExT + */ +int getfilecase(char *path, char *file) +{ + DIR *dp; + struct dirent *de; + int i, rc = FALSE; + + if ((dp = opendir(path)) == NULL) { + WriteError("$Can't opendir(%s)", path); + return rc; + } + + while ((de = readdir(dp))) { + if (strcasecmp(de->d_name, file) == 0) { + for (i = 0; i < strlen(de->d_name); i++) + file[i] = de->d_name[i]; + rc = TRUE; + break; + } + } + + closedir(dp); + return rc; +} + + diff --git a/mbfido/tic.c b/mbfido/tic.c index 1e8a02eb..9b4336ea 100644 --- a/mbfido/tic.c +++ b/mbfido/tic.c @@ -168,8 +168,8 @@ int LoadTic(char *inb, char *tfn) char *Temp, *Temp2, *Buf, *Log = NULL, RealName[256]; int i, j, rc, bufsize, DescCnt = FALSE; fa_list *sbl = NULL; - DIR *dp; - struct dirent *de; +// DIR *dp; +// struct dirent *de; if (CFG.slow_util && do_quiet) usleep(1); @@ -427,27 +427,36 @@ int LoadTic(char *inb, char *tfn) * Find out what the real name of the file is, * most likely this is a 8.3 filename. */ - if ((dp = opendir(TIC.Inbound)) == NULL) { - WriteError("$Can't opendir(%s)", TIC.Inbound); - return 1; - } - while ((de = readdir(dp))) { - /* - * Check 8.3 FN - */ - if (strcasecmp(de->d_name, TIC.TicIn.File) == 0) { - strncpy(RealName, de->d_name, 255); - break; - } - /* - * Check LFN - */ - if (strcasecmp(de->d_name, TIC.TicIn.FullName) == 0) { - strncpy(RealName, de->d_name, 255); - break; +// if ((dp = opendir(TIC.Inbound)) == NULL) { +// WriteError("$Can't opendir(%s)", TIC.Inbound); +// return 1; +// } +// while ((de = readdir(dp))) { +// /* +// * Check 8.3 FN +// */ +// if (strcasecmp(de->d_name, TIC.TicIn.File) == 0) { +// strncpy(RealName, de->d_name, 255); +// break; +// } +// /* +// * Check LFN +// */ +// if (strcasecmp(de->d_name, TIC.TicIn.FullName) == 0) { +// strncpy(RealName, de->d_name, 255); +// break; +// } +// } +// closedir(dp); + strncpy(RealName, TIC.TicIn.File, 255); + Syslog('f', "getfilecase(%s, %s)", TIC.Inbound, RealName); + if (! getfilecase(TIC.Inbound, RealName)) { + strncpy(RealName, TIC.TicIn.FullName, 255); + Syslog('f', "getfilecase(%s, %s)", TIC.Inbound, RealName); + if (! getfilecase(TIC.Inbound, RealName)) { + memset(&RealName, 0, sizeof(RealName)); } } - closedir(dp); } if (strlen(RealName) == 0) { @@ -458,6 +467,7 @@ int LoadTic(char *inb, char *tfn) TIC.Orphaned = TRUE; WriteError("Can't find file in inbound"); } else { + Syslog('f', "Returned RealName %s", RealName); /* * If no LFN received in the ticfile and the file in the inbound is the same as the 8.3 name * but only the case is different, then treat the real filename as LFN.