Overview
Comment: | Added support for sending correct MIME type |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
12083325549fb0a7c0fbc76a581221d2 |
User & Date: | rkeene on 2014-02-07 22:56:36 |
Other Links: | manifest | tags |
Context
2014-02-07
| ||
23:23 | Added start of logging check-in: 08a3222e4b user: rkeene tags: trunk | |
22:56 | Added support for sending correct MIME type check-in: 1208332554 user: rkeene tags: trunk | |
21:51 | Updated wiki HTML page check-in: e7fa8416e1 user: rkeene tags: trunk | |
Changes
Modified Makefile from [d4f93cadc6] to [1dfba37223].
︙ | ︙ | |||
9 10 11 12 13 14 15 | mandir = $(prefix)/share/man all: filed filed: filed.o $(CC) $(CFLAGS) $(LDFLAGS) -o "$@" $^ $(LIBS) | | > > > > > > | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | mandir = $(prefix)/share/man all: filed filed: filed.o $(CC) $(CFLAGS) $(LDFLAGS) -o "$@" $^ $(LIBS) filed.o: filed.c filed-mime-types.h filed-mime-types.h: generate-mime-types ./generate-mime-types > filed-mime-types.h install: filed filed.1 test -d "$(DESTDIR)$(mandir)/man1" || mkdir -p "$(DESTDIR)$(mandir)/man1" test -d "$(DESTDIR)$(bindir)" || mkdir -p "$(DESTDIR)$(bindir)" cp filed.1 "$(DESTDIR)$(mandir)/man1/" cp filed "$(DESTDIR)$(bindir)/" clean: rm -f filed filed.o distclean: clean mrproper: distclean rm -f filed-mime-types.h .PHONY: all install clean distclean mrproper |
Modified filed.c from [5138c920c1] to [dc9403b4bb].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <errno.h> #include <time.h> #include <pwd.h> /* Compile time constants */ #define FILED_SENDFILE_MAX 16777215 #define MAX_FAILURE_COUNT 30 /* Default values */ #define PORT 80 #define THREAD_COUNT 5 #define BIND_ADDR "::" #define CACHE_SIZE 8209 /* Arguments for worker threads */ struct filed_worker_thread_args { int fd; }; /* File information */ struct filed_fileinfo { pthread_mutex_t mutex; char *path; int fd; off_t len; char *lastmod; char lastmod_b[64]; | > | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <errno.h> #include <time.h> #include <pwd.h> /* Compile time constants */ #define FILED_SENDFILE_MAX 16777215 #define MAX_FAILURE_COUNT 30 #define FILED_DEFAULT_TYPE "application/octet-stream" /* Default values */ #define PORT 80 #define THREAD_COUNT 5 #define BIND_ADDR "::" #define CACHE_SIZE 8209 /* Arguments for worker threads */ struct filed_worker_thread_args { int fd; }; /* File information */ struct filed_fileinfo { pthread_mutex_t mutex; char *path; int fd; off_t len; char *lastmod; char lastmod_b[64]; const char *type; }; /* Request variables */ struct filed_http_request { /** Buffers **/ struct filed_fileinfo fileinfo; char path_b[1010]; |
︙ | ︙ | |||
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | } if (prev < curr) { diff = curr - prev; } else { diff = prev - curr; } retval <<= 3; retval ^= diff; value++; } retval = retval % modulus; return(retval); } /* Open a file and return file information */ static struct filed_fileinfo *filed_open_file(const char *path, struct filed_fileinfo *buffer) { struct filed_fileinfo *cache; unsigned int cache_idx; off_t len; int fd; | > > > > > > > > > > > > > > > > > > > > > > > > | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | } if (prev < curr) { diff = curr - prev; } else { diff = prev - curr; } prev = curr; retval <<= 3; retval &= 0xFFFFFFFFLU; retval ^= diff; value++; } retval = retval % modulus; return(retval); } /* Find a mime-type based on the filename */ static const char *filed_determine_mimetype(const char *path) { const char *p; p = strrchr(path, '.'); if (p == NULL) { return(FILED_DEFAULT_TYPE); } p++; if (*p == '\0') { return(FILED_DEFAULT_TYPE); } filed_log_msg_debug("Looking up MIME type for %s (hash = %llu)", p, (unsigned long long) filed_hash((const unsigned char *) p, 16777259)); #include "filed-mime-types.h" return(FILED_DEFAULT_TYPE); } /* Open a file and return file information */ static struct filed_fileinfo *filed_open_file(const char *path, struct filed_fileinfo *buffer) { struct filed_fileinfo *cache; unsigned int cache_idx; off_t len; int fd; |
︙ | ︙ | |||
268 269 270 271 272 273 274 275 276 | len = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); cache->fd = fd; cache->len = len; cache->path = strdup(path); /* XXX:TODO: Determine */ | > < | 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | len = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); cache->fd = fd; cache->len = len; cache->path = strdup(path); cache->type = filed_determine_mimetype(path); /* XXX:TODO: Determine */ cache->lastmod = filed_format_time(cache->lastmod_b, sizeof(cache->lastmod_b), time(NULL) - 30); } else { filed_log_msg_debug("Cache hit for idx: %lu: PATH \"%s\"", (unsigned long) cache_idx, path); } /* * We have to make a duplicate FD, because once we release the cache |
︙ | ︙ |
Added generate-mime-types version [a953fb49d0].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #! /usr/bin/env tclsh set modulus 16777259 proc filed_hash {str mod} { set retval [expr {$mod - 1}] set prev [expr {$mod % 255}] for {set idx 0} {$idx < [string length $str]} {incr idx} { set curr [string index $str $idx] binary scan $curr H* curr set curr [format %u 0x$curr] if {$curr < 32} { set curr [expr {255 - $curr}] } else { set curr [expr {$curr - 32}] } if {$prev < $curr} { set diff [expr {$curr - $prev}] } else { set diff [expr {$prev - $curr}] } set prev $curr set retval [expr {($retval << 3) & 0xffffffff}] set retval [expr {$retval ^ $diff}] } set retval [expr {$retval % $mod}] return $retval } set mimeinfofile "/etc/httpd/mime.types" set fd [open $mimeinfofile] set mimeinfo [read $fd] close $fd foreach line [split $mimeinfo "\n"] { regsub {#.*} $line {} line set line [string trim $line] if {$line == ""} { continue } set line [split $line] set mime [lindex $line 0] set extensions [lrange $line 1 end] foreach extension $extensions { if {$extension == ""} { continue } set extensioninfo($extension) $mime } } foreach extension [array names extensioninfo] { set hash_id [filed_hash $extension $modulus] lappend hashinfo($hash_id) $extension } puts "\tswitch (filed_hash((const unsigned char *) p, $modulus)) \{" foreach hash [lsort -integer -increasing [array names hashinfo]] { puts "\t\tcase $hash:" foreach extension $hashinfo($hash) { puts "\t\t\tif (strcmp(p, \"$extension\") == 0) \{" puts "\t\t\t\treturn(\"$extensioninfo($extension)\");" puts "\t\t\t\}" } puts "\t\t\treturn(FILED_DEFAULT_TYPE);" } puts "\t\}" |