Implemented new name mangle algorithm

This commit is contained in:
Michiel Broek 2002-11-24 11:30:38 +00:00
parent d728493cff
commit 40317d6cfe
2 changed files with 25 additions and 41 deletions

View File

@ -16,6 +16,15 @@ v0.35.06
Added better support for 8.3 and long filenames by creating
hard links in the download directories.
common.a:
Changed the LFN name mangle functions to prevent 8.3 name
collisions. Now the basepart is 4 characters followed by the
tilde char and then a 3 characters code calculated from the
16 bits crc of the original filename. Original this was base 5
followed by a tilde and 2 characters code calculated from the
checksum of the string modulo 1849. Both methods are different
then what MS does.
mbsebbs:
Several user input functions don't allow comma's anymore.
Uploaded files will now also have a 8.3 hard link to the long

View File

@ -42,7 +42,6 @@
* Prototype functions
*/
int strhaslower(const char *);
int str_checksum(const char *);
char *safe_strcpy(char *, const char *, size_t);
static void init_chartest(void);
static int is_reserved_msdos(char *);
@ -112,34 +111,6 @@ int strhaslower(const char *s)
/*****************************************************************************
* Provide a checksum on a string
*
* Input: s - the null-terminated character string for which the checksum
* will be calculated.
*
* Output: The checksum value calculated for s.
*
* ****************************************************************************
*/
int str_checksum(const char *s)
{
int res = 0;
int c;
int i=0;
while(*s) {
c = *s;
res ^= (c << (i % 15)) ^ (c >> (15-(i%15)));
s++;
i++;
}
// Syslog('f', "str_cksum(%s) %d", s, res);
return res;
}
/*******************************************************************
safe string copy into a known length string. maxlength does not
include the terminating zero.
@ -347,7 +318,7 @@ int is_8_3( char *fname)
*/
void mangle_name_83(char *s)
{
int csum, crc16, i;
int crc16, i;
char *p, *q;
char extension[4];
char base[9];
@ -379,6 +350,9 @@ void mangle_name_83(char *s)
} else if (strcmp(q = s + strlen(s) - strlen(".conf"), ".conf") == 0) {
*q = '\0';
q = (char *)"cnf";
} else if (strcmp(q = s + strlen(s) - strlen(".mpeg"), ".mpeg") == 0) {
*q = '\0';
q = (char *)"mpg";
} else {
q = NULL;
}
@ -404,15 +378,12 @@ void mangle_name_83(char *s)
if (all_normal && p[1] != 0) {
*p = 0;
csum = str_checksum(s);
crc16 = crc16xmodem(s, strlen(s));
*p = '.';
} else {
csum = str_checksum(s);
crc16 = crc16xmodem(s, strlen(s));
}
} else {
csum = str_checksum(s);
crc16 = crc16xmodem(s, strlen(s));
}
// Syslog('f', "crc16xmodem(%s) %d", s, crc16);
@ -435,19 +406,22 @@ void mangle_name_83(char *s)
p = s;
while (*p && baselen < 5) {
/*
* Changed to baselen 4, original this is 5.
* 24-11-2002 MB.
*/
while (*p && baselen < 4) {
if (*p != '.' )
base[baselen++] = p[0];
p++;
}
base[baselen] = 0;
csum = csum % (MANGLE_BASE * MANGLE_BASE);
crc16 = crc16 % (MANGLE_BASE * MANGLE_BASE);
sprintf(s, "%s%c%c%c", base, magic_char, mangle(csum / MANGLE_BASE), mangle(csum));
Syslog('f', "csum %4d mangle old %c%c%c crc16 %4d mangle new %c%c%c",
csum, magic_char, mangle(csum / MANGLE_BASE), mangle(csum),
crc16, magic_char, mangle(crc16 / MANGLE_BASE), mangle(crc16));
if (crc16 > (MANGLE_BASE * MANGLE_BASE * MANGLE_BASE))
Syslog('!', "WARNING: mangle_name_83() crc16 overflow");
crc16 = crc16 % (MANGLE_BASE * MANGLE_BASE * MANGLE_BASE);
sprintf(s, "%s%c%c%c%c", base, magic_char,
mangle(crc16 / (MANGLE_BASE * MANGLE_BASE)), mangle(crc16 / MANGLE_BASE), mangle(crc16));
if ( *extension ) {
(void)strcat(s, ".");
(void)strcat(s, extension);
@ -477,6 +451,7 @@ void name_mangle(char *OutName)
*/
if (!is_8_3(OutName)) {
mangle_name_83(OutName);
Syslog('f',"name_mangle(%s) ==> [%s]", p, OutName);
} else {
/*
* No mangling needed, convert to uppercase