aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/IO.c60
1 files changed, 47 insertions, 13 deletions
diff --git a/src/IO.c b/src/IO.c
index ee9b1c1..971e4fd 100644
--- a/src/IO.c
+++ b/src/IO.c
@@ -108,6 +108,37 @@ int HTTP_util_RegisterIOPages(void)
******************** Internal Routines ************************
********************************************************************/
/*@@
+ @routine HTTP_util_ExistingFileEntry
+ @date Wed Oct 07 12:49:02 2009
+ @author Frank Loeffler
+ @desc
+ Returns the pointer to an entry with the given
+ filename set or NULL if nothing was found.
+ @enddesc
+@@*/
+static httpFileItem * HTTP_util_ExistingFileEntry(FileList *filelist,
+ const char *filename)
+{
+ if ( !filelist )
+ return NULL;
+
+ /* Look for an entry with this filename */
+ const size_t n = NumberOfFiles( filelist );
+ size_t i;
+ httpFileItem *item;
+ for (i = 0; i < n; i++)
+ {
+ item = HTTPD_FileList_Item(filelist, i);
+ /* When entry found, return its pointer */
+ if (!StringCompareCString(item->filename, filename))
+ {
+ return item;
+ }
+ }
+ return NULL;
+}
+
+/*@@
@routine IOFileListener
@date Sun Sep 17 17:56:22 2000
@author Tom Goodale
@@ -119,32 +150,35 @@ static int IOFileListener(const cGH *GH, const char *filename,
const ioAdvertisedFileDesc *description)
{
size_t position = 0;
- httpFileItem *entry = (httpFileItem *)malloc( sizeof( httpFileItem));
-
-
(void) (GH + 0); /* avoid compiler warning about unused parameter */
- if(entry)
+ if( !filelist )
+ filelist = HTTPD_FileList_New();
+ httpFileItem *entry = HTTP_util_ExistingFileEntry(filelist, filename);
+ /* If there is already an entry, we cannot change it directly (const).
+ We _could_ remove it and insert a new entry, but that would probably
+ be too expensive. So we do nothing and assume nothing changed
+ anyway in the entry */
+ if (entry)
{
-/* SW--HEY where does this all get deleted ? */
- String *linknameString = String_Make( filename);
+ return 0;
+ }
+ entry = (httpFileItem *)malloc(sizeof( httpFileItem));
+ if (entry)
+ {
+ entry->filename = String_Make( filename);
entry->thorn = String_Make( description->thorn);
entry->varname = String_Make( description->varname);
entry->mimetype = String_Make( description->mimetype);
entry->slice = String_Make( description->slice);
entry->description = String_Make( description->description);
- entry->filename = String_Make( filename);
+ String *linknameString = String_Make( filename);
entry->linkname = linknameString;
-
- if( filelist == NULL )
- filelist = HTTPD_FileList_New();
- AppendFile( filelist, entry );
-
/* Need to mangle the filename to get a decent linkname */
while( FindCharFrom( linknameString, '/', &position ) )
SetNthChar( linknameString, position, '@');
+ AppendFile( filelist, entry );
}
-
return 0;
}