3
MimeTableEntry and MimeTable definitions
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
24
#include "libts.h" /* MAGIC_EDITING_TAG */
27
MimeTable::m_table[] = {
28
{"ai", "application/postscript", "8bit", "text"},
29
{"aif", "audio/x-aiff", "binary", "sound"},
30
{"aifc", "audio/x-aiff", "binary", "sound"},
31
{"aiff", "audio/x-aiff", "binary", "sound"},
32
{"arj", "application/x-arj-compressed", "binary", "binary"},
33
{"au", "audio/basic", "binary", "sound"},
34
{"avi", "video/x-msvideo", "binary", "movie"},
35
{"bcpio", "application/x-bcpio", "binary", "binary"},
36
{"bin", "application/macbinary", "macbinary", "binary"},
37
{"c", "text/plain", "7bit", "text"},
38
{"cc", "text/plain", "7bit", "text"},
39
{"cdf", "application/x-netcdf", "binary", "binary"},
40
{"cpio", "application/x-cpio", "binary", "binary"},
41
{"csh", "application/x-csh", "7bit", "text"},
42
{"doc", "application/msword", "binary", "binary"},
43
{"dvi", "application/x-dvi", "binary", "binary"},
44
{"eps", "application/postscript", "8bit", "text"},
45
{"etx", "text/x-setext", "7bit", "text"},
46
{"exe", "application/octet-stream", "binary", "binary"},
47
{"f90", "text/plain", "7bit", "text"},
48
{"gif", "image/gif", "binary", "image"},
49
{"gtar", "application/x-gtar", "binary", "binary"},
50
{"gz", "application/x-gzip", "x-gzip", "binary"},
51
{"h", "text/plain", "7bit", "text"},
52
{"hdf", "application/x-hdf", "binary", "binary"},
53
{"hh", "text/plain", "7bit", "text"},
54
{"hqx", "application/mac-binhex40", "mac-binhex40", "binary"},
55
{"htm", "text/html", "8bit", "text"},
56
{"html", "text/html", "8bit", "text"},
57
{"ief", "image/ief", "binary", "image"},
58
{"jpe", "image/jpeg", "binary", "image"},
59
{"jpeg", "image/jpeg", "binary", "image"},
60
{"jpg", "image/jpeg", "binary", "image"},
61
{"latex", "application/x-latex", "8bit", "text"},
62
{"lha", "application/x-lha-compressed", "binary", "binary"},
63
{"lsm", "text/plain", "7bit", "text"},
64
{"lzh", "application/x-lha-compressed", "binary", "binary"},
65
{"m", "text/plain", "7bit", "text"},
66
{"man", "application/x-troff-man", "7bit", "text"},
67
{"me", "application/x-troff-me", "7bit", "text"},
68
{"mif", "application/x-mif", "binary", "binary"},
69
{"mime", "www/mime", "8bit", "text"},
70
{"mov", "video/quicktime", "binary", "movie"},
71
{"movie", "video/x-sgi-movie", "binary", "movie"},
72
{"mp2", "audio/mpeg", "binary", "sound"},
73
{"mp3", "audio/mpeg", "binary", "sound"},
74
{"mpe", "video/mpeg", "binary", "movie"},
75
{"mpeg", "video/mpeg", "binary", "movie"},
76
{"mpg", "video/mpeg", "binary", "movie"},
77
{"ms", "application/x-troff-ms", "7bit", "text"},
78
{"msw", "application/msword", "binary", "binary"},
79
{"mwrt", "application/macwriteii", "binary", "binary"},
80
{"nc", "application/x-netcdf", "binary", "binary"},
81
{"oda", "application/oda", "binary", "binary"},
82
{"pbm", "image/x-portable-bitmap", "binary", "image"},
83
{"pdf", "application/pdf", "binary", "binary"},
84
{"pgm", "image/x-portable-graymap", "binary", "image"},
85
{"pic", "application/pict", "binary", "image"},
86
{"pict", "application/pict", "binary", "image"},
87
{"pnm", "image/x-portable-anymap", "binary", "image"},
88
{"ppm", "image/x-portable-pixmap", "binary", "image"},
89
{"ps", "application/postscript", "8bit", "text"},
90
{"qt", "video/quicktime", "binary", "movie"},
91
{"ras", "image/cmu-raster", "binary", "image"},
92
{"rgb", "image/x-rgb", "binary", "image"},
93
{"roff", "application/x-troff", "7bit", "text"},
94
{"rpm", "application/x-rpm", "binary", "binary"},
95
{"rtf", "application/x-rtf", "7bit", "binary"},
96
{"rtx", "text/richtext", "7bit", "text"},
97
{"sh", "application/x-sh", "7bit", "text"},
98
{"shar", "application/x-shar", "8bit", "text"},
99
{"sit", "application/stuffit", "binary", "binary"},
100
{"snd", "audio/basic", "binary", "sound"},
101
{"src", "application/x-wais-source", "7bit", "text"},
102
{"sv4cpio", "application/x-sv4cpio", "binary", "binary"},
103
{"sv4crc", "application/x-sv4crc", "binary", "binary"},
104
{"t", "application/x-troff", "7bit", "text"},
105
{"tar", "application/x-tar", "binary", "binary"},
106
{"tcl", "application/x-tcl", "7bit", "text"},
107
{"tex", "application/x-tex", "8bit", "text"},
108
{"texi", "application/x-texinfo", "7bit", "text"},
109
{"texinfo", "application/x-texinfo", "7bit", "text"},
110
{"tgz", "application/x-tar", "x-gzip", "binary"},
111
{"tif", "image/tiff", "binary", "image"},
112
{"tiff", "image/tiff", "binary", "image"},
113
{"tr", "application/x-troff", "7bit", "text"},
114
{"tsv", "text/tab-separated-values", "7bit", "text"},
115
{"txt", "text/plain", "7bit", "text"},
116
{"ustar", "application/x-ustar", "binary", "binary"},
117
{"wav", "audio/x-wav", "binary", "sound"},
118
{"xbm", "image/x-xbitmap", "binary", "image"},
119
{"xpm", "image/x-xpixmap", "binary", "image"},
120
{"xwd", "image/x-xwindowdump", "binary", "image"},
121
{"Z", "application/x-compressed", "x-compress", "binary"},
122
{"zip", "application/x-zip-compressed", "zip", "binary"}
125
MimeTable::m_table_size = (sizeof(MimeTable::m_table)) / (sizeof(MimeTable::m_table[0]));
127
MimeTable::m_unknown = { "unknown", "application/x-unknown-content-type", "binary", "unknown" };
130
////////////////////////////////////////////////////////////////
134
////////////////////////////////////////////////////////////////
135
////////////////////////////////////////////////////////////////
137
// MimeTable::get_entry_path()
139
////////////////////////////////////////////////////////////////
141
MimeTable::get_entry_path(const char *path)
143
const char *p = strrchr(path, '.');
144
MimeTableEntry *e = 0;
147
e = get_entry(p + 1);
149
/////////////////////////////////////////
150
// file has no extension. make a best //
151
// guess, or return null for unknown //
152
/////////////////////////////////////////
153
if (ParseRules::strcasestr(path, "index") ||
154
ParseRules::strcasestr(path, "README") ||
155
ParseRules::strcasestr(path, "ls-lR") ||
156
ParseRules::strcasestr(path, "config") || (path[0] == '\0') || (path[strlen(path) - 1] == '/'))
157
e = get_entry("txt");
165
////////////////////////////////////////////////////////////////
167
// MimeTable::get_entry()
169
////////////////////////////////////////////////////////////////
171
MimeTable::get_entry(const char *name)
177
// do a binary search. extensions are unique
179
int high = m_table_size - 1;
180
int mid = ((high - low) / 2) + low;
188
if (m_table[mid] == key) {
191
} else if (m_table[mid] < key) {
197
mid = ((high - low) / 2) + low;
205
mid = ((high - low) / 2) + low;
210
return ((found >= 0) ? (&m_table[found]) : 0);