root/libswish3/trunk/src/libswish3/mime_types.c

Revision 2133, 7.5 kB (checked in by karpet, 7 months ago)

make test now works under linux. this was an issue with s[n]printf

Line 
1 /*
2  * This file is part of libswish3
3  * Copyright (C) 2007 Peter Karman
4  *
5  *  libswish3 is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  libswish3 is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with libswish3; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20 /* MIME types hash based on Apache 2.0 mime.types listing
21 see <http://www.iana.org/assignments/media-types/> for official registry.
22 */
23
24 #include <err.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "libswish3.h"
29
30 extern int SWISH_DEBUG;
31
32 //should be total number of strings(NOT pairs !) below
33 #define SWISH_MIME_TABLE_COUNT  304
34
35 static char *SWISH_MIME_TABLE[] = {
36     "ai", "application/postscript",
37     "aif", "audio/x-aiff",
38     "aifc", "audio/x-aiff",
39     "aiff", "audio/x-aiff",
40     "asc", "text/plain",
41     "au", "audio/basic",
42     "avi", "video/x-msvideo",
43     "bcpio", "application/x-bcpio",
44     "bin", "application/octet-stream",
45     "bmp", "image/bmp",
46     "cdf", "application/x-netcdf",
47     "cgm", "image/cgm",
48     "class", "application/octet-stream",
49     "cpio", "application/x-cpio",
50     "cpt", "application/mac-compactpro",
51     "csh", "application/x-csh",
52     "css", "text/css",
53     "dcr", "application/x-director",
54     "dir", "application/x-director",
55     "djv", "image/vnd.djvu",
56     "djvu", "image/vnd.djvu",
57     "dll", "application/octet-stream",
58     "dmg", "application/octet-stream",
59     "dms", "application/octet-stream",
60     "doc", "application/msword",
61     "dtd", "application/xml-dtd",
62     "dvi", "application/x-dvi",
63     "dxr", "application/x-director",
64     "eps", "application/postscript",
65     "etx", "text/x-setext",
66     "exe", "application/octet-stream",
67     "ez", "application/andrew-inset",
68     "gif", "image/gif",
69     "gram", "application/srgs",
70     "grxml", "application/srgs+xml",
71     "gtar", "application/x-gtar",
72     "gz", "application/x-gzip",
73     "hdf", "application/x-hdf",
74     "hqx", "application/mac-binhex40",
75     "htm", "text/html",
76     "html", "text/html",
77     "ice", "x-conference/x-cooltalk",
78     "ico", "image/x-icon",
79     "ics", "text/calendar",
80     "ief", "image/ief",
81     "ifb", "text/calendar",
82     "iges", "model/iges",
83     "igs", "model/iges",
84     "jpe", "image/jpeg",
85     "jpeg", "image/jpeg",
86     "jpg", "image/jpeg",
87     "js", "application/x-javascript",
88     "kar", "audio/midi",
89     "latex", "application/x-latex",
90     "lha", "application/octet-stream",
91     "lzh", "application/octet-stream",
92     "m3u", "audio/x-mpegurl",
93     "m4u", "video/vnd.mpegurl",
94     "man", "application/x-troff-man",
95     "mathml", "application/mathml+xml",
96     "me", "application/x-troff-me",
97     "mesh", "model/mesh",
98     "mid", "audio/midi",
99     "midi", "audio/midi",
100     "mif", "application/vnd.mif",
101     "mov", "video/quicktime",
102     "movie", "video/x-sgi-movie",
103     "mp2", "audio/mpeg",
104     "mp3", "audio/mpeg",
105     "mpe", "video/mpeg",
106     "mpeg", "video/mpeg",
107     "mpg", "video/mpeg",
108     "mpga", "audio/mpeg",
109     "ms", "application/x-troff-ms",
110     "msh", "model/mesh",
111     "mxu", "video/vnd.mpegurl",
112     "nc", "application/x-netcdf",
113     "oda", "application/oda",
114     "ogg", "application/ogg",
115     "pbm", "image/x-portable-bitmap",
116     "pdb", "chemical/x-pdb",
117     "pdf", "application/pdf",
118     "pgm", "image/x-portable-graymap",
119     "pgn", "application/x-chess-pgn",
120     "png", "image/png",
121     "pnm", "image/x-portable-anymap",
122     "ppm", "image/x-portable-pixmap",
123     "ppt", "application/vnd.ms-powerpoint",
124     "ps", "application/postscript",
125     "qt", "video/quicktime",
126     "ra", "audio/x-pn-realaudio",
127     "ram", "audio/x-pn-realaudio",
128     "ras", "image/x-cmu-raster",
129     "rdf", "application/rdf+xml",
130     "rgb", "image/x-rgb",
131     "rm", "application/vnd.rn-realmedia",
132     "roff", "application/x-troff",
133     "rtf", "text/rtf",
134     "rtx", "text/richtext",
135     "sgm", "text/sgml",
136     "sgml", "text/sgml",
137     "sh", "application/x-sh",
138     "shar", "application/x-shar",
139     "silo", "model/mesh",
140     "sit", "application/x-stuffit",
141     "skd", "application/x-koan",
142     "skm", "application/x-koan",
143     "skp", "application/x-koan",
144     "skt", "application/x-koan",
145     "smi", "application/smil",
146     "smil", "application/smil",
147     "snd", "audio/basic",
148     "so", "application/octet-stream",
149     "spl", "application/x-futuresplash",
150     "src", "application/x-wais-source",
151     "sv4cpio", "application/x-sv4cpio",
152     "sv4crc", "application/x-sv4crc",
153     "svg", "image/svg+xml",
154     "swf", "application/x-shockwave-flash",
155     "t", "application/x-troff",
156     "tar", "application/x-tar",
157     "tcl", "application/x-tcl",
158     "tex", "application/x-tex",
159     "texi", "application/x-texinfo",
160     "texinfo", "application/x-texinfo",
161     "tif", "image/tiff",
162     "tiff", "image/tiff",
163     "tr", "application/x-troff",
164     "tsv", "text/tab-separated-values",
165     "txt", "text/plain",
166     "ustar", "application/x-ustar",
167     "vcd", "application/x-cdlink",
168     "vrml", "model/vrml",
169     "vxml", "application/voicexml+xml",
170     "wav", "audio/x-wav",
171     "wbmp", "image/vnd.wap.wbmp",
172     "wbxml", "application/vnd.wap.wbxml",
173     "wml", "text/vnd.wap.wml",
174     "wmlc", "application/vnd.wap.wmlc",
175     "wmls", "text/vnd.wap.wmlscript",
176     "wmlsc", "application/vnd.wap.wmlscriptc",
177     "wrl", "model/vrml",
178     "xbm", "image/x-xbitmap",
179     "xht", "application/xhtml+xml",
180     "xhtml", "application/xhtml+xml",
181     "xls", "application/vnd.ms-excel",
182 /* "xml",       "application/xml", */
183     "xml", "text/xml",
184     "xpm", "image/x-xpixmap",
185     "xsl", "application/xml",
186     "xslt", "application/xslt+xml",
187     "xul", "application/vnd.mozilla.xul+xml",
188     "xwd", "image/x-xwindowdump",
189     "xyz", "chemical/x-xyz",
190     "zip", "application/zip"
191 };
192
193 /* create hash of file ext => mime type */
194 xmlHashTablePtr
195 swish_mime_hash(
196 )
197 {
198     int i;
199     xmlHashTablePtr mimes;
200     mimes = swish_init_hash(SWISH_MIME_TABLE_COUNT / 2);
201
202     for (i = 0; i <= SWISH_MIME_TABLE_COUNT; i += 2) {
203         swish_hash_add(mimes, (xmlChar *)SWISH_MIME_TABLE[i],
204                        swish_xstrdup((xmlChar *)SWISH_MIME_TABLE[i + 1])
205             );
206     }
207
208     return mimes;
209 }
210
211 /* retrieve mime type from hash */
212 xmlChar *
213 swish_get_mime_type(
214     swish_Config *config,
215     xmlChar *fileext
216 )
217 {
218     xmlChar *mime;
219     mime = swish_hash_fetch(config->mimes, fileext);
220     if (mime == NULL) {
221         SWISH_WARN("No MIME type known for '%s' -- using '%s'", fileext,
222                    SWISH_DEFAULT_MIME);
223         mime = swish_xstrdup((xmlChar *)SWISH_DEFAULT_MIME);
224     }
225     return swish_xstrdup(mime);
226 }
227
228 /* returns parser type (TXT, HTML, XML) based on mime type */
229 xmlChar *
230 swish_get_parser(
231     swish_Config *config,
232     xmlChar *mime
233 )
234 {
235     xmlChar *parser;
236     xmlChar *deftype;
237
238     parser = swish_hash_fetch(config->parsers, mime);
239
240     if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO)
241         SWISH_DEBUG_MSG("using parser '%s' based on MIME '%s'", parser, mime);
242
243     deftype = swish_hash_fetch(config->parsers, (xmlChar *)SWISH_DEFAULT_PARSER);       /* error check?? */
244
245     if (parser == NULL) {
246         SWISH_WARN("No parser for MIME '%s' -- using '%s'", mime, deftype);
247         parser = deftype;
248     }
249
250     return swish_xstrdup(parser);       /* so we don't change orig value -- MUST free */
251 }
Note: See TracBrowser for help on using the browser.