Overview
Comment: | Updated to make mime types file configurable |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
ad6e43c2bdba13640b786a699fd00c72 |
User & Date: | rkeene on 2014-02-08 03:14:05 |
Other Links: | manifest | tags |
Context
2014-02-08
| ||
03:15 | Updated to emit correct code for an empty mime types file check-in: 4e6097bf48 user: rkeene tags: trunk | |
03:14 | Updated to make mime types file configurable check-in: ad6e43c2bd user: rkeene tags: trunk | |
03:10 | Noted that status should be reported check-in: 1127550a5c user: rkeene tags: trunk | |
Changes
Modified Makefile from [1dfba37223] to [27a49087e1].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | CC = gcc CFLAGS = -Wall -Werror -W -pthread -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE LDFLAGS = -pthread LIBS = -lpthread PREFIX = /usr/local prefix = $(PREFIX) bindir = $(prefix)/bin 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 | > | | 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 | CC = gcc CFLAGS = -Wall -Werror -W -pthread -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE LDFLAGS = -pthread LIBS = -lpthread MIMETYPES = /etc/httpd/mime.types PREFIX = /usr/local prefix = $(PREFIX) bindir = $(prefix)/bin 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 "$(MIMETYPES)" > 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)/" |
︙ | ︙ |
Modified generate-mime-types from [a953fb49d0] to [ce8a54e188].
1 2 3 4 5 6 7 8 9 10 11 | #! /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] | > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #! /usr/bin/env tclsh if {[llength $argv] != 1} { puts stderr "Usage: generate-mime-type <file>" exit 1 } set mimeinfofile [lindex $argv 0] set modulus 16777259 # Must match what is in filed.c 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] |
︙ | ︙ | |||
30 31 32 33 34 35 36 | set retval [expr {$retval % $mod}] return $retval } | < | > | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | set retval [expr {$retval % $mod}] return $retval } # Read contents of mime types file set fd [open $mimeinfofile] set mimeinfo [read $fd] close $fd # Parse into type and extensions pairs foreach line [split $mimeinfo "\n"] { regsub {#.*} $line {} line set line [string trim $line] if {$line == ""} { continue } |
︙ | ︙ | |||
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | 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\}" | > > > > > > > | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | continue } set extensioninfo($extension) $mime } } # For every extension, generate a hash # For every hash, note the extension foreach extension [array names extensioninfo] { set hash_id [filed_hash $extension $modulus] lappend hashinfo($hash_id) $extension } # Emit a C fragment to take a pointer (p) to an extension determine the mime type 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\}" # Declare victory exit 0 |