aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknarf <knarf@61ea717e-8e0c-4c3c-b38e-e9c67f54f1f1>2009-10-09 19:12:21 +0000
committerknarf <knarf@61ea717e-8e0c-4c3c-b38e-e9c67f54f1f1>2009-10-09 19:12:21 +0000
commitfdc1b9f3b1006c0e58cbf68af3ee597e53b5fc86 (patch)
tree8ed7f1573b569425afbf0c5132498a8a59a56f72
parent12a47382e07f018985a1a26b119b2c765d083dbf (diff)
This patch lets the internal list not grow if a file was already added
to that list. It is in some way not the ideal way of doing this, because it does not let the advertising thorn change e.g. the mime type and other information like the description, but this would require either making the list entries non-const (which I refrain from because that would probably be a big change, although it would probably be the best path to go), or it would require to remove the entry and add a new - which is possible, but has a potential of breaking something which does not expect entries to be removed and it might slow down things if that list is long. So, this patch only looks for an entry with the filename of an advertised file and if there is already one, it does not touch it, nor is a new entry added. git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPDExtra/trunk@78 61ea717e-8e0c-4c3c-b38e-e9c67f54f1f1
-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;
}