Check-in [ad6e43c2bd]
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:ad6e43c2bdba13640b786a699fd00c724357745e
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      1   CC = gcc
     2      2   CFLAGS = -Wall -Werror -W -pthread -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
     3      3   LDFLAGS = -pthread
     4      4   LIBS = -lpthread
            5  +MIMETYPES = /etc/httpd/mime.types
     5      6   
     6      7   PREFIX = /usr/local
     7      8   prefix = $(PREFIX)
     8      9   bindir = $(prefix)/bin
     9     10   mandir = $(prefix)/share/man
    10     11   
    11     12   all: filed
................................................................................
    12     13   
    13     14   filed: filed.o
    14     15   	$(CC) $(CFLAGS) $(LDFLAGS) -o "$@" $^ $(LIBS)
    15     16   
    16     17   filed.o: filed.c filed-mime-types.h
    17     18   
    18     19   filed-mime-types.h: generate-mime-types
    19         -	./generate-mime-types > filed-mime-types.h
           20  +	./generate-mime-types "$(MIMETYPES)" > filed-mime-types.h
    20     21   
    21     22   install: filed filed.1
    22     23   	test -d "$(DESTDIR)$(mandir)/man1" || mkdir -p "$(DESTDIR)$(mandir)/man1"
    23     24   	test -d "$(DESTDIR)$(bindir)" || mkdir -p "$(DESTDIR)$(bindir)"
    24     25   	cp filed.1 "$(DESTDIR)$(mandir)/man1/"
    25     26   	cp filed "$(DESTDIR)$(bindir)/"
    26     27   

Modified generate-mime-types from [a953fb49d0] to [ce8a54e188].

     1      1   #! /usr/bin/env tclsh
     2      2   
            3  +if {[llength $argv] != 1} {
            4  +	puts stderr "Usage: generate-mime-type <file>"
            5  +
            6  +	exit 1
            7  +}
            8  +
            9  +set mimeinfofile [lindex $argv 0]
           10  +
     3     11   set modulus 16777259
     4     12   
           13  +# Must match what is in filed.c
     5     14   proc filed_hash {str mod} {
     6     15   	set retval [expr {$mod - 1}]
     7     16   	set prev [expr {$mod % 255}]
     8     17   	for {set idx 0} {$idx < [string length $str]} {incr idx} {
     9     18   		set curr [string index $str $idx]
    10     19   		binary scan $curr H* curr
    11     20   		set curr [format %u 0x$curr]
................................................................................
    30     39   
    31     40   	set retval [expr {$retval % $mod}]
    32     41   
    33     42   	return $retval
    34     43   
    35     44   }
    36     45   
    37         -set mimeinfofile "/etc/httpd/mime.types"
    38         -
           46  +# Read contents of mime types file
    39     47   set fd [open $mimeinfofile]
    40     48   set mimeinfo [read $fd]
    41     49   close $fd
    42     50   
           51  +# Parse into type and extensions pairs
    43     52   foreach line [split $mimeinfo "\n"] {
    44     53   	regsub {#.*} $line {} line
    45     54   	set line [string trim $line]
    46     55   
    47     56   	if {$line == ""} {
    48     57   		continue
    49     58   	}
................................................................................
    58     67   			continue
    59     68   		}
    60     69   
    61     70   		set extensioninfo($extension) $mime
    62     71   	}
    63     72   }
    64     73   
           74  +# For every extension, generate a hash
           75  +# For every hash, note the extension
    65     76   foreach extension [array names extensioninfo] {
    66     77   	set hash_id [filed_hash $extension $modulus]
    67     78   
    68     79   	lappend hashinfo($hash_id) $extension
    69     80   
    70     81   }
           82  +
           83  +# Emit a C fragment to take a pointer (p) to an extension determine the mime type
    71     84   puts "\tswitch (filed_hash((const unsigned char *) p, $modulus)) \{"
    72     85   foreach hash [lsort -integer -increasing [array names hashinfo]] {
    73     86   	puts "\t\tcase $hash:"
    74     87   	foreach extension $hashinfo($hash) {
    75     88   		puts "\t\t\tif (strcmp(p, \"$extension\") == 0) \{"
    76     89   		puts "\t\t\t\treturn(\"$extensioninfo($extension)\");"
    77     90   		puts "\t\t\t\}"
    78     91   	}
    79     92   	puts "\t\t\treturn(FILED_DEFAULT_TYPE);"
    80     93   }
    81     94   puts "\t\}"
           95  +
           96  +# Declare victory
           97  +exit 0