~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to lib/ts/MimeTable.cc

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  MimeTableEntry and MimeTable definitions
 
4
 
 
5
  @section license License
 
6
 
 
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
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
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.
 
22
 */
 
23
 
 
24
#include "libts.h"        /* MAGIC_EDITING_TAG */
 
25
 
 
26
MimeTableEntry
 
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"}
 
123
};
 
124
int
 
125
  MimeTable::m_table_size = (sizeof(MimeTable::m_table)) / (sizeof(MimeTable::m_table[0]));
 
126
MimeTableEntry
 
127
MimeTable::m_unknown = { "unknown", "application/x-unknown-content-type", "binary", "unknown" };
 
128
MimeTable
 
129
  mimeTable;
 
130
////////////////////////////////////////////////////////////////
 
131
//
 
132
//  class MimeTable
 
133
//
 
134
////////////////////////////////////////////////////////////////
 
135
////////////////////////////////////////////////////////////////
 
136
//
 
137
//  MimeTable::get_entry_path()
 
138
//
 
139
////////////////////////////////////////////////////////////////
 
140
MimeTableEntry *
 
141
MimeTable::get_entry_path(const char *path)
 
142
{
 
143
  const char *p = strrchr(path, '.');
 
144
  MimeTableEntry *e = 0;
 
145
 
 
146
  if (p)
 
147
    e = get_entry(p + 1);
 
148
  else {
 
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");
 
158
  }
 
159
  if (e == 0)
 
160
    e = &m_unknown;
 
161
 
 
162
  return (e);
 
163
}
 
164
 
 
165
////////////////////////////////////////////////////////////////
 
166
//
 
167
//  MimeTable::get_entry()
 
168
//
 
169
////////////////////////////////////////////////////////////////
 
170
MimeTableEntry *
 
171
MimeTable::get_entry(const char *name)
 
172
{
 
173
  MimeTableEntry key;
 
174
 
 
175
  key.name = name;
 
176
 
 
177
  // do a binary search. extensions are unique
 
178
  int low = 0;
 
179
  int high = m_table_size - 1;
 
180
  int mid = ((high - low) / 2) + low;
 
181
  int found = -1;
 
182
 
 
183
  if (!name[0])
 
184
    return (0);
 
185
 
 
186
 
 
187
  while (1) {
 
188
    if (m_table[mid] == key) {
 
189
      found = mid;
 
190
      break;
 
191
    } else if (m_table[mid] < key) {
 
192
      if (mid == high) {
 
193
        found = -1;
 
194
        break;
 
195
      } else {
 
196
        low = mid + 1;
 
197
        mid = ((high - low) / 2) + low;
 
198
      }
 
199
    } else {
 
200
      if (mid == low) {
 
201
        found = -1;
 
202
        break;
 
203
      } else {
 
204
        high = mid - 1;
 
205
        mid = ((high - low) / 2) + low;
 
206
      }
 
207
    }
 
208
  }
 
209
 
 
210
  return ((found >= 0) ? (&m_table[found]) : 0);
 
211
}