• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

MimeTable.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   MimeTableEntry and MimeTable definitions
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #include "libts.h"        /* MAGIC_EDITING_TAG */
00025 
00026 MimeTableEntry
00027   MimeTable::m_table[] = {
00028   {"ai", "application/postscript", "8bit", "text"},
00029   {"aif", "audio/x-aiff", "binary", "sound"},
00030   {"aifc", "audio/x-aiff", "binary", "sound"},
00031   {"aiff", "audio/x-aiff", "binary", "sound"},
00032   {"arj", "application/x-arj-compressed", "binary", "binary"},
00033   {"au", "audio/basic", "binary", "sound"},
00034   {"avi", "video/x-msvideo", "binary", "movie"},
00035   {"bcpio", "application/x-bcpio", "binary", "binary"},
00036   {"bin", "application/macbinary", "macbinary", "binary"},
00037   {"c", "text/plain", "7bit", "text"},
00038   {"cc", "text/plain", "7bit", "text"},
00039   {"cdf", "application/x-netcdf", "binary", "binary"},
00040   {"cpio", "application/x-cpio", "binary", "binary"},
00041   {"csh", "application/x-csh", "7bit", "text"},
00042   {"doc", "application/msword", "binary", "binary"},
00043   {"dvi", "application/x-dvi", "binary", "binary"},
00044   {"eps", "application/postscript", "8bit", "text"},
00045   {"etx", "text/x-setext", "7bit", "text"},
00046   {"exe", "application/octet-stream", "binary", "binary"},
00047   {"f90", "text/plain", "7bit", "text"},
00048   {"gif", "image/gif", "binary", "image"},
00049   {"gtar", "application/x-gtar", "binary", "binary"},
00050   {"gz", "application/x-gzip", "x-gzip", "binary"},
00051   {"h", "text/plain", "7bit", "text"},
00052   {"hdf", "application/x-hdf", "binary", "binary"},
00053   {"hh", "text/plain", "7bit", "text"},
00054   {"hqx", "application/mac-binhex40", "mac-binhex40", "binary"},
00055   {"htm", "text/html", "8bit", "text"},
00056   {"html", "text/html", "8bit", "text"},
00057   {"ief", "image/ief", "binary", "image"},
00058   {"jpe", "image/jpeg", "binary", "image"},
00059   {"jpeg", "image/jpeg", "binary", "image"},
00060   {"jpg", "image/jpeg", "binary", "image"},
00061   {"latex", "application/x-latex", "8bit", "text"},
00062   {"lha", "application/x-lha-compressed", "binary", "binary"},
00063   {"lsm", "text/plain", "7bit", "text"},
00064   {"lzh", "application/x-lha-compressed", "binary", "binary"},
00065   {"m", "text/plain", "7bit", "text"},
00066   {"man", "application/x-troff-man", "7bit", "text"},
00067   {"me", "application/x-troff-me", "7bit", "text"},
00068   {"mif", "application/x-mif", "binary", "binary"},
00069   {"mime", "www/mime", "8bit", "text"},
00070   {"mov", "video/quicktime", "binary", "movie"},
00071   {"movie", "video/x-sgi-movie", "binary", "movie"},
00072   {"mp2", "audio/mpeg", "binary", "sound"},
00073   {"mp3", "audio/mpeg", "binary", "sound"},
00074   {"mpe", "video/mpeg", "binary", "movie"},
00075   {"mpeg", "video/mpeg", "binary", "movie"},
00076   {"mpg", "video/mpeg", "binary", "movie"},
00077   {"ms", "application/x-troff-ms", "7bit", "text"},
00078   {"msw", "application/msword", "binary", "binary"},
00079   {"mwrt", "application/macwriteii", "binary", "binary"},
00080   {"nc", "application/x-netcdf", "binary", "binary"},
00081   {"oda", "application/oda", "binary", "binary"},
00082   {"pbm", "image/x-portable-bitmap", "binary", "image"},
00083   {"pdf", "application/pdf", "binary", "binary"},
00084   {"pgm", "image/x-portable-graymap", "binary", "image"},
00085   {"pic", "application/pict", "binary", "image"},
00086   {"pict", "application/pict", "binary", "image"},
00087   {"pnm", "image/x-portable-anymap", "binary", "image"},
00088   {"ppm", "image/x-portable-pixmap", "binary", "image"},
00089   {"ps", "application/postscript", "8bit", "text"},
00090   {"qt", "video/quicktime", "binary", "movie"},
00091   {"ras", "image/cmu-raster", "binary", "image"},
00092   {"rgb", "image/x-rgb", "binary", "image"},
00093   {"roff", "application/x-troff", "7bit", "text"},
00094   {"rpm", "application/x-rpm", "binary", "binary"},
00095   {"rtf", "application/x-rtf", "7bit", "binary"},
00096   {"rtx", "text/richtext", "7bit", "text"},
00097   {"sh", "application/x-sh", "7bit", "text"},
00098   {"shar", "application/x-shar", "8bit", "text"},
00099   {"sit", "application/stuffit", "binary", "binary"},
00100   {"snd", "audio/basic", "binary", "sound"},
00101   {"src", "application/x-wais-source", "7bit", "text"},
00102   {"sv4cpio", "application/x-sv4cpio", "binary", "binary"},
00103   {"sv4crc", "application/x-sv4crc", "binary", "binary"},
00104   {"t", "application/x-troff", "7bit", "text"},
00105   {"tar", "application/x-tar", "binary", "binary"},
00106   {"tcl", "application/x-tcl", "7bit", "text"},
00107   {"tex", "application/x-tex", "8bit", "text"},
00108   {"texi", "application/x-texinfo", "7bit", "text"},
00109   {"texinfo", "application/x-texinfo", "7bit", "text"},
00110   {"tgz", "application/x-tar", "x-gzip", "binary"},
00111   {"tif", "image/tiff", "binary", "image"},
00112   {"tiff", "image/tiff", "binary", "image"},
00113   {"tr", "application/x-troff", "7bit", "text"},
00114   {"tsv", "text/tab-separated-values", "7bit", "text"},
00115   {"txt", "text/plain", "7bit", "text"},
00116   {"ustar", "application/x-ustar", "binary", "binary"},
00117   {"wav", "audio/x-wav", "binary", "sound"},
00118   {"xbm", "image/x-xbitmap", "binary", "image"},
00119   {"xpm", "image/x-xpixmap", "binary", "image"},
00120   {"xwd", "image/x-xwindowdump", "binary", "image"},
00121   {"Z", "application/x-compressed", "x-compress", "binary"},
00122   {"zip", "application/x-zip-compressed", "zip", "binary"}
00123 };
00124 int
00125   MimeTable::m_table_size = (sizeof(MimeTable::m_table)) / (sizeof(MimeTable::m_table[0]));
00126 MimeTableEntry
00127 MimeTable::m_unknown = { "unknown", "application/x-unknown-content-type", "binary", "unknown" };
00128 MimeTable
00129   mimeTable;
00130 ////////////////////////////////////////////////////////////////
00131 //
00132 //  class MimeTable
00133 //
00134 ////////////////////////////////////////////////////////////////
00135 ////////////////////////////////////////////////////////////////
00136 //
00137 //  MimeTable::get_entry_path()
00138 //
00139 ////////////////////////////////////////////////////////////////
00140 MimeTableEntry *
00141 MimeTable::get_entry_path(const char *path)
00142 {
00143   const char *p = strrchr(path, '.');
00144   MimeTableEntry *e = 0;
00145 
00146   if (p)
00147     e = get_entry(p + 1);
00148   else {
00149     /////////////////////////////////////////
00150     // file has no extension. make a best  //
00151     // guess, or return null for unknown   //
00152     /////////////////////////////////////////
00153     if (ParseRules::strcasestr(path, "index") ||
00154         ParseRules::strcasestr(path, "README") ||
00155         ParseRules::strcasestr(path, "ls-lR") ||
00156         ParseRules::strcasestr(path, "config") || (path[0] == '\0') || (path[strlen(path) - 1] == '/'))
00157       e = get_entry("txt");
00158   }
00159   if (e == 0)
00160     e = &m_unknown;
00161 
00162   return (e);
00163 }
00164 
00165 ////////////////////////////////////////////////////////////////
00166 //
00167 //  MimeTable::get_entry()
00168 //
00169 ////////////////////////////////////////////////////////////////
00170 MimeTableEntry *
00171 MimeTable::get_entry(const char *name)
00172 {
00173   MimeTableEntry key;
00174 
00175   key.name = name;
00176 
00177   // do a binary search. extensions are unique
00178   int low = 0;
00179   int high = m_table_size - 1;
00180   int mid = ((high - low) / 2) + low;
00181   int found = -1;
00182 
00183   if (!name[0])
00184     return (0);
00185 
00186 
00187   while (1) {
00188     if (m_table[mid] == key) {
00189       found = mid;
00190       break;
00191     } else if (m_table[mid] < key) {
00192       if (mid == high) {
00193         found = -1;
00194         break;
00195       } else {
00196         low = mid + 1;
00197         mid = ((high - low) / 2) + low;
00198       }
00199     } else {
00200       if (mid == low) {
00201         found = -1;
00202         break;
00203       } else {
00204         high = mid - 1;
00205         mid = ((high - low) / 2) + low;
00206       }
00207     }
00208   }
00209 
00210   return ((found >= 0) ? (&m_table[found]) : 0);
00211 }

Generated by  doxygen 1.7.1