]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_mime_magic.xml
fix copyright notice
[apache] / docs / manual / mod / mod_mime_magic.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Copyright 2002-2005 The Apache Software Foundation or its licensors,
8                      as applicable.
9
10  Licensed under the Apache License, Version 2.0 (the "License");
11  you may not use this file except in compliance with the License.
12  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <modulesynopsis metafile="mod_mime_magic.xml.meta">
24
25 <name>mod_mime_magic</name>
26 <description>Determines the MIME type of a file
27     by looking at a few bytes of its contents</description>
28 <status>Extension</status>
29 <sourcefile>mod_mime_magic.c</sourcefile>
30 <identifier>mime_magic_module</identifier>
31
32 <summary>
33     <p>This module determines the MIME type of files in the same
34     way the Unix <code>file(1)</code> command works: it looks at the first
35     few bytes of the file. It is intended as a "second line of defense"
36     for cases that <module>mod_mime</module> can't resolve.</p>
37
38     <p>This module is derived from a free version of the
39     <code>file(1)</code> command for Unix, which uses "magic
40     numbers" and other hints from a file's contents to figure out
41     what the contents are. This module is active only if the magic
42     file is specified by the <directive module="mod_mime_magic"
43     >MimeMagicFile</directive> directive.</p>
44 </summary>
45
46 <section id="format"><title>Format of the Magic File</title>
47
48     <p>The contents of the file are plain ASCII text in 4-5
49     columns. Blank lines are allowed but ignored. Commented lines
50     use a hash mark (<code>#</code>). The remaining lines are parsed for
51     the following columns:</p>
52
53     <table style="zebra" border="1">
54     <columnspec><column width=".15"/><column width=".8"/></columnspec>
55     <tr><th>Column</th><th>Description</th></tr>
56     <tr><td>1</td>
57         <td>byte number to begin checking from<br />
58          "<code>&gt;</code>" indicates a dependency upon the previous
59          non-"<code>&gt;</code>" line</td></tr>
60
61     <tr><td>2</td>
62         <td><p>type of data to match</p>
63         <table border="1">
64         <columnspec><column width=".2"/><column width=".7"/></columnspec>
65         <tr><td><code>byte</code></td>
66             <td>single character</td></tr>
67         <tr><td><code>short</code></td>
68             <td>machine-order 16-bit integer</td></tr>
69         <tr><td><code>long</code></td>
70             <td>machine-order 32-bit integer</td></tr>
71         <tr><td><code>string</code></td>
72             <td>arbitrary-length string</td></tr>
73         <tr><td><code>date</code></td>
74             <td>long integer date (seconds since Unix epoch/1970)</td></tr>
75         <tr><td><code>beshort</code></td>
76             <td>big-endian 16-bit integer</td></tr>
77         <tr><td><code>belong</code></td>
78             <td>big-endian 32-bit integer</td></tr>
79         <tr><td><code>bedate</code></td>
80             <td>big-endian 32-bit integer date</td></tr>
81         <tr><td><code>leshort</code></td>
82             <td>little-endian 16-bit integer</td></tr>
83         <tr><td><code>lelong</code></td>
84             <td>little-endian 32-bit integer</td></tr>
85         <tr><td><code>ledate</code></td>
86             <td>little-endian 32-bit integer date</td></tr>
87         </table></td></tr>
88
89     <tr><td>3</td>
90         <td>contents of data to match</td></tr>
91
92     <tr><td>4</td>
93         <td>MIME type if matched</td></tr>
94
95     <tr><td>5</td>
96         <td>MIME encoding if matched (optional)</td></tr>
97     </table>
98
99     <p>For example, the following magic file lines would recognize
100     some audio formats:</p>
101
102     <example>
103 <pre># Sun/NeXT audio data
104 0      string      .snd
105 &gt;12    belong      1       audio/basic
106 &gt;12    belong      2       audio/basic
107 &gt;12    belong      3       audio/basic
108 &gt;12    belong      4       audio/basic
109 &gt;12    belong      5       audio/basic
110 &gt;12    belong      6       audio/basic
111 &gt;12    belong      7       audio/basic
112 &gt;12    belong     23       audio/x-adpcm</pre>
113     </example>
114
115     <p>Or these would recognize the difference between <code>*.doc</code>
116     files containing Microsoft Word or FrameMaker documents. (These are
117     incompatible file formats which use the same file suffix.)</p>
118
119     <example>
120 <pre># Frame
121 0  string  \&lt;MakerFile        application/x-frame
122 0  string  \&lt;MIFFile          application/x-frame
123 0  string  \&lt;MakerDictionary  application/x-frame
124 0  string  \&lt;MakerScreenFon   application/x-frame
125 0  string  \&lt;MML              application/x-frame
126 0  string  \&lt;Book             application/x-frame
127 0  string  \&lt;Maker            application/x-frame
128
129 # MS-Word
130 0  string  \376\067\0\043            application/msword
131 0  string  \320\317\021\340\241\261  application/msword
132 0  string  \333\245-\0\0\0           application/msword</pre>
133     </example>
134
135     <p>An optional MIME encoding can be included as a fifth column.
136     For example, this can recognize gzipped files and set the
137     encoding for them.</p>
138
139     <example>
140 <pre># gzip (GNU zip, not to be confused with
141 #       [Info-ZIP/PKWARE] zip archiver)
142
143 0  string  \037\213  application/octet-stream  x-gzip</pre>
144     </example>
145 </section>
146
147 <section id="performance"><title>Performance Issues</title>
148     <p>This module is not for every system. If your system is barely
149     keeping up with its load or if you're performing a web server
150     benchmark, you may not want to enable this because the
151     processing is not free.</p>
152
153     <p>However, an effort was made to improve the performance of
154     the original <code>file(1)</code> code to make it fit in a busy web
155     server. It was designed for a server where there are thousands of users
156     who publish their own documents. This is probably very common
157     on intranets. Many times, it's helpful if the server can make
158     more intelligent decisions about a file's contents than the
159     file name allows ...even if just to reduce the "why doesn't my
160     page work" calls when users improperly name their own files.
161     You have to decide if the extra work suits your
162     environment.</p>
163 </section>
164
165 <section id="notes"><title>Notes</title>
166     <p>The following notes apply to the <module>mod_mime_magic</module>
167     module and are included here for compliance with contributors'
168     copyright restrictions that require their acknowledgment.</p>
169
170     <note>
171       <p>mod_mime_magic: MIME type lookup via file magic numbers<br />
172       Copyright (c) 1996-1997 Cisco Systems, Inc.</p>
173
174       <p>This software was submitted by Cisco Systems to the Apache Group
175       in July 1997. Future revisions and derivatives of this source code
176       must acknowledge Cisco Systems as the original contributor of this
177       module. All other licensing and usage conditions are those of the
178       Apache Group.</p>
179
180       <p>Some of this code is derived from the free version of the file
181       command originally posted to comp.sources.unix. Copyright info for
182       that program is included below as required.</p>
183     </note>
184
185     <note>
186       <p> - Copyright (c) Ian F. Darwin, 1987. Written by Ian F. Darwin.</p>
187
188       <p>This software is not subject to any license of the American
189       Telephone and Telegraph Company or of the Regents of the University
190       of California.</p>
191
192       <p>Permission is granted to anyone to use this software for any
193       purpose on any computer system, and to alter it and redistribute it
194       freely, subject to the following restrictions:</p>
195
196       <ol>
197         <li>The author is not responsible for the consequences of use of
198         this software, no matter how awful, even if they arise from flaws
199         in it.</li>
200
201         <li>The origin of this software must not be misrepresented, either
202         by explicit claim or by omission. Since few users ever read
203         sources, credits must appear in the documentation.</li>
204
205         <li>Altered versions must be plainly marked as such, and must not
206         be misrepresented as being the original software. Since few users
207         ever read sources, credits must appear in the documentation.</li>
208
209         <li>This notice may not be removed or altered.</li>
210       </ol>
211     </note>
212
213     <note>
214       <p>For compliance with Mr Darwin's terms: this has been very
215       significantly modified from the free "file" command.</p>
216
217       <ul>
218         <li>all-in-one file for compilation convenience when moving from
219         one version of Apache to the next.</li>
220
221         <li>Memory allocation is done through the Apache API's pool
222         structure.</li>
223
224         <li>All functions have had necessary Apache API request or server
225         structures passed to them where necessary to call other Apache API
226         routines. (<em>i.e.</em>, usually for logging, files, or memory
227         allocation in itself or a called function.)</li>
228
229         <li>struct magic has been converted from an array to a single-ended
230         linked list because it only grows one record at a time, it's only
231         accessed sequentially, and the Apache API has no equivalent of
232         <code>realloc()</code>.</li>
233
234         <li>Functions have been changed to get their parameters from the
235         server configuration instead of globals.  (It should be reentrant
236         now but has not been tested in a threaded environment.)</li>
237
238         <li>Places where it used to print results to stdout now saves them
239         in a list where they're used to set the MIME type in the Apache
240         request record.</li>
241
242         <li>Command-line flags have been removed since they will never be
243         used here.</li>
244       </ul>
245     </note>
246 </section>
247
248 <directivesynopsis>
249 <name>MimeMagicFile</name>
250 <description>Enable MIME-type determination based on file contents
251 using the specified magic file</description>
252 <syntax>MimeMagicFile <var>file-path</var></syntax>
253 <contextlist><context>server config</context><context>virtual host</context>
254 </contextlist>
255
256 <usage>
257     <p>The <directive>MimeMagicFile</directive> directive can be used to
258     enable this module, the default file is distributed at
259     <code>conf/magic</code>. Non-rooted paths are relative to the
260     <directive module="core">ServerRoot</directive>. Virtual hosts will use
261     the same file as the main server unless a more specific setting is
262     used, in which case the more specific setting overrides the main
263     server's file.</p>
264
265     <example><title>Example</title>
266       MimeMagicFile conf/magic
267     </example>
268 </usage>
269 </directivesynopsis>
270
271 </modulesynopsis>