From 3b93e10a47628c7ba6ff17f25cba17a6a688e227 Mon Sep 17 00:00:00 2001 From: dgaudet Date: Mon, 7 Jul 1997 18:18:40 +0000 Subject: [PATCH] Added mod_mime_magic. Submitted by: Ian Kluft git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@78553 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/mod/directives.html | 1 + docs/manual/mod/index.html | 4 +- docs/manual/mod/mod_mime_magic.html | 251 ++++++++++++++++++++++++++++ 3 files changed, 255 insertions(+), 1 deletion(-) create mode 100644 docs/manual/mod/mod_mime_magic.html diff --git a/docs/manual/mod/directives.html b/docs/manual/mod/directives.html index 8ce065e131..d65e005614 100644 --- a/docs/manual/mod/directives.html +++ b/docs/manual/mod/directives.html @@ -115,6 +115,7 @@
  • MaxSpareServers
  • MetaDir
  • MetaSuffix +
  • MimeMagicFile
  • MinSpareServers
  • NoCache
  • Options diff --git a/docs/manual/mod/index.html b/docs/manual/mod/index.html index 4bacd90aab..98c48cb03f 100644 --- a/docs/manual/mod/index.html +++ b/docs/manual/mod/index.html @@ -83,7 +83,9 @@ mod_log_config module in Apache 1.2 and up
    mod_log_referer
    Logging of document references.
    mod_mime -
    Determining document types. +
    Determining document types using file extensions. +
    mod_mime_magic +
    Determining document types using "magic numbers".
    mod_negotiation
    Content negotiation.
    mod_rewrite Apache 1.2 and up diff --git a/docs/manual/mod/mod_mime_magic.html b/docs/manual/mod/mod_mime_magic.html new file mode 100644 index 0000000000..56fade8486 --- /dev/null +++ b/docs/manual/mod/mod_mime_magic.html @@ -0,0 +1,251 @@ + + + + Apache module mod_mime_magic + + + +

    Module mod_mime_magic

    + + This module is an optional extension to the Apache HTTPD server. + The current version can be obtained from + + http://www.employees.org/~ikluft/apache/mod_mime_magic/. + +

    Summary

    + + This module is derived from a free version of the file(1) + command for Unix, + which uses "magic numbers" and other hints from a file's contents to + figure out what the contents are. + In the case of this module, + it tries to figure out the MIME type of the file. +

    + This module is only active if the magic file exists and + was successfully opened at server-configuration time. + The magic file can be named by the + MimeMagicFile + directive or defaults to conf/magic. +

    + The contents of the file are plain ASCII text in 4-5 columns. + Blank lines are allowed but ignored. + Commented lines use a hash mark "#". + The remaining lines are parsed for the following columns: + + + + + + + + + + + + + + + + + + + + + +
    ColumnDescription
    1byte number to begin checking from +
    + ">" indicates a dependency upon the previous non-">" line
    2type of data to match + + + + + + + + + + + + +
    bytesingle character
    shortmachine-order 16-bit integer
    longmachine-order 32-bit integer
    stringarbitrary-length string
    datelong integer date + (seconds since Unix epoch/1970)
    beshortbig-endian 16-bit integer
    belongbig-endian 32-bit integer
    bedatebig-endian 32-bit integer date
    leshortlittle-endian 16-bit integer
    lelonglittle-endian 32-bit integer
    ledatelittle-endian 32-bit integer date
    +
    3contents of data to match
    4MIME type if matched
    5MIME encoding if matched (optional)
    + +

    + For example, the following magic file lines + would recognize some audio formats. + +

    +# Sun/NeXT audio data
    +0       string          .snd
    +>12     belong          1               audio/basic
    +>12     belong          2               audio/basic
    +>12     belong          3               audio/basic
    +>12     belong          4               audio/basic
    +>12     belong          5               audio/basic
    +>12     belong          6               audio/basic
    +>12     belong          7               audio/basic
    +>12     belong          23              audio/x-adpcm
    +
    + + Or these would recognize the difference between "*.doc" files containing + Microsoft Word or FrameMaker documents. (These are incompatible file + formats which use the same file suffix.) + +
    +# Frame
    +0       string          \<MakerFile     application/x-frame
    +0       string          \<MIFFile       application/x-frame
    +0       string          \<MakerDictionary       application/x-frame
    +0       string          \<MakerScreenFon        application/x-frame
    +0       string          \<MML           application/x-frame
    +0       string          \<Book          application/x-frame
    +0       string          \<Maker         application/x-frame
    +
    +# MS-Word
    +0       string          \376\067\0\043                  application/msword
    +0       string          \320\317\021\340\241\261        application/msword
    +0       string          \333\245-\0\0\0                 application/msword
    +
    + + An optional MIME encoding can be included as a fifth column. + For example, this can recognize gzipped files and set the encoding + for them. + +
    +# gzip (GNU zip, not to be confused with [Info-ZIP/PKWARE] zip archiver)
    +0       string          \037\213        application/octet-stream        x-gzip
    +
    + +

    Performance Issues

    + + This module is not for every system. If your system is barely keeping + up with its load or if you're performing a web server benchmark, + you may not want to enable this because the processing is not free. +

    + However, an effort was made to improve the performance of the original + file(1) code to make it fit in a busy web server. + It was designed for a server where there are thousands of users who + publish their own documents. + This is probably very common on intranets. + Many times, it's helpful + if the server can make more intelligent decisions about a file's + contents than the file name allows + ...even if just to reduce the "why doesn't my page work" calls + when users improperly name their own files. + You have to decide if the extra work suits your environment. +

    + When compiling an Apache server, this module should be at or near the + top of the list of modules in the Configuration file. The modules are + listed in increasing priority so that will mean this one is used only + as a last resort, just like it was designed to. + +

    Directives

    +

    +

    +

    +
    +

    + MimeMagicFile +

    +

    + Syntax: MimeMagicFile magic-file-name +
    + Default: conf/magic +
    + Context: server config, virtual host +
    + Status: Extension +
    + Module: mod_mime_magic +

    + + The MimeMagicFile directive can be used to change the location of the + magic file from its default location at conf/magic. + Non-rooted paths are relative to the ServerRoot. +

    +


    + +

    Notes

    + + Patches and suggestions for mod_mime_magic should be sent to + Ian Kluft <ikluft@cisco.com>. + Note that enhancements are done on a volunteer basis so no timetable can + be committed for any particular request. + Obviously, patches are given much higher priority over plain requests. +

    + The following notes apply to the mod_mime_magic module and are + included here for compliance with contributors' copyright restrictions + that require their acknowledgement. + +

    +/*
    + * mod_mime_magic: MIME type lookup via file magic numbers
    + * Copyright (c) 1996-1997 Cisco Systems, Inc.
    + *
    + * This software was submitted by Cisco Systems to the Apache Group in July
    + * 1997.  Future revisions and derivatives of this source code must
    + * acknowledge Cisco Systems as the original contributor of this module.
    + * All other licensing and usage conditions are those of the Apache Group.
    + *
    + * Some of this code is derived from the free version of the file command
    + * originally posted to comp.sources.unix.  Copyright info for that program
    + * is included below as required.
    + * ---------------------------------------------------------------------------
    + * - Copyright (c) Ian F. Darwin, 1987. Written by Ian F. Darwin.
    + *
    + * This software is not subject to any license of the American Telephone and
    + * Telegraph Company or of the Regents of the University of California.
    + *
    + * Permission is granted to anyone to use this software for any purpose on any
    + * computer system, and to alter it and redistribute it freely, subject to
    + * the following restrictions:
    + *
    + * 1. The author is not responsible for the consequences of use of this
    + * software, no matter how awful, even if they arise from flaws in it.
    + *
    + * 2. The origin of this software must not be misrepresented, either by
    + * explicit claim or by omission.  Since few users ever read sources, credits
    + * must appear in the documentation.
    + *
    + * 3. Altered versions must be plainly marked as such, and must not be
    + * misrepresented as being the original software.  Since few users ever read
    + * sources, credits must appear in the documentation.
    + *
    + * 4. This notice may not be removed or altered.
    + * -------------------------------------------------------------------------
    + *
    + * For complicance with Mr Darwin's terms: this has been very significantly
    + * modified from the free "file" command.
    + * - all-in-one file for compilation convenience when moving from one
    + *   version of Apache to the next.
    + * - Memory allocation is done through the Apache API's pool structure.
    + * - All functions have had necessary Apache API request or server
    + *   structures passed to them where necessary to call other Apache API
    + *   routines.  (i.e. usually for logging, files, or memory allocation in
    + *   itself or a called function.)
    + * - struct magic has been converted from an array to a single-ended linked
    + *   list because it only grows one record at a time, it's only accessed
    + *   sequentially, and the Apache API has no equivalent of realloc().
    + * - Functions have been changed to get their parameters from the server
    + *   configuration instead of globals.  (It should be reentrant now but has
    + *   not been tested in a threaded environment.)
    + * - Places where it used to print results to stdout now saves them in a
    + *   list where they're used to set the MIME type in the Apache request
    + *   record.
    + * - Command-line flags have been removed since they will never be used here.
    + *
    + */
    +
    + + + -- 2.40.0