Corrections for file upload descriptions

This commit is contained in:
Michiel Broek 2002-08-25 12:30:16 +00:00
parent ca5faeea0d
commit 040c0a37e5
2 changed files with 211 additions and 163 deletions

View File

@ -77,6 +77,12 @@ v0.35.03 06-Jul-2002
Added test for HA archiver.
When changing a Handle, Unix names are checked as forbidden
names as well.
Improved import of FILE_ID.DIZ with file uploads. Only if
FILE_ID.DIZ is processed successfull the user will see that
this file has been used.
Corrected length for manual file description to prevent string
overflow.
Added missing space in message to user about file unpack.
mbtask:
Changed logging of multiple logmessages that are equal.

View File

@ -846,11 +846,9 @@ int ImportFile(char *fn, int Area, int fileid, time_t iTime, off_t Size)
int Addfile(char *File, int AreaNum, int fileid)
{
FILE *id, *pFileDB, *pPrivate;
int err = 1, iDesc = 1, iPrivate = FALSE, GotId = FALSE;
char *Filename, *temp1, *idname = NULL;
char *Desc[26];
int err = 1, iDesc = 1, iPrivate = FALSE, GotId = FALSE, lines, i, j;
char *Filename, *temp1, *idname = NULL, *Desc[26];
struct stat statfile;
int i;
char temp[81];
Filename = calloc(PATH_MAX, sizeof(char));
@ -927,31 +925,75 @@ int Addfile(char *File, int AreaNum, int fileid)
if (!err) {
Syslog('+', "Found %s", idname);
GotId = TRUE;
colour(CFG.TextColourF, CFG.TextColourB);
/* Found FILE_ID.DIZ in */
printf("%s %s\n", (char *) Language(257), File);
fflush(stdout);
}
}
if (GotId) {
lines = 0;
if ((id = fopen(idname, "r")) != NULL) {
/*
* Import FILE_ID.DIZ, format to max. 25
* lines, 48 chars width.
*/
while ((fgets(temp1, 256, id)) != NULL) {
if (iDesc < 26) {
while (((fgets(temp1, PATH_MAX -1, id)) != NULL) && (lines < 25)) {
Striplf(temp1);
temp1[48] = '\0';
strcpy(file.Desc[iDesc - 1], temp1);
if (strlen(temp1) > 51) {
/*
* Malformed FILE_ID.DIZ
*/
GotId = FALSE;
for (i = 0; i < 25; i++)
file.Desc[i][0] = '\0';
lines = 0;
Syslog('!', "Trashing illegal formatted FILE_ID.DIZ");
break;
}
if (strlen(temp1) > 0) {
j = 0;
for (i = 0; i < strlen(temp1); i++) {
if (isprint(temp1[i])) {
file.Desc[lines][j] = temp1[i];
j++;
if (j > 47)
break;
}
}
/*
* Remove trailing spaces
*/
while (j && isspace(file.Desc[lines][j-1]))
j--;
file.Desc[lines][j] = '\0';
lines++;
}
iDesc++;
}
}
fclose(id);
unlink(idname);
if (GotId) {
/*
* Strip empty FILE_ID.DIZ lines at the end
*/
while ((strlen(file.Desc[lines-1]) == 0) && (lines)) {
file.Desc[lines-1][0] = '\0';
lines--;
}
if (lines) {
Syslog('+', "Using %d FILE_ID.DIZ lines for description", lines);
colour(CFG.TextColourF, CFG.TextColourB);
/* Found FILE_ID.DIZ in */
printf("%s %s\n", (char *) Language(257), File);
fflush(stdout);
} else {
Syslog('!', "No FILE_ID.DIZ lines left to use");
GotId = FALSE;
}
}
}
if (!GotId) {
/*
* Ask the user for a description.
*/
@ -967,7 +1009,7 @@ int Addfile(char *File, int AreaNum, int fileid)
fflush(stdout);
colour(CFG.InputColourF, CFG.InputColourB);
GetstrC(*(Desc + iDesc), 48);
GetstrC(*(Desc + iDesc), 47);
if ((strcmp(*(Desc + iDesc), "")) == 0)
break;