vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / file_systems / shared / mime_ext_table.c
blob6c6e926b0e1f715b934c94a2ff5c8532e8d5320b
1 /*
2 Copyright 1999-2001, Be Incorporated. All Rights Reserved.
3 This file may be used under the terms of the Be Sample Code License.
4 */
6 #include <SupportDefs.h>
8 #include <string.h>
10 #include <file_systems/mime_ext_table.h>
13 struct ext_mime {
14 char *extension;
15 char *mime;
18 static struct ext_mime mimes[] = {
19 { "gz", "application/x-gzip" },
20 { "hqx", "application/x-binhex40" },
21 { "lha", "application/x-lharc" },
22 { "pcl", "application/x-pcl" },
23 { "pdf", "application/pdf" },
24 { "ps", "application/postscript" },
25 { "sit", "application/x-stuff-it" },
26 { "tar", "application/x-tar" },
27 { "tgz", "application/x-gzip" },
28 { "uue", "application/x-uuencode" },
29 { "z", "application/x-compress" },
30 { "zip", "application/zip" },
31 { "zoo", "application/x-zoo" },
32 { "rar", "application/x-rar" },
33 { "pkg", "application/x-scode-UPkg" },
34 { "7z", "application/x-7z-compressed" },
35 { "bz2", "application/x-bzip2" },
36 { "xz", "application/x-xz" },
38 { "jar", "application/x-jar" },
40 { "aif", "audio/x-aiff" },
41 { "aiff", "audio/x-aiff" },
42 { "au", "audio/basic" },
43 { "mid", "audio/x-midi" },
44 { "midi", "audio/x-midi" },
45 { "mod", "audio/mod" },
46 { "ra", "audio/x-real-audio" },
47 { "wav", "audio/x-wav" },
48 { "mp3", "audio/x-mpeg" },
49 { "ogg", "audio/x-vorbis" },
50 { "flac", "audio/x-flac" },
51 { "wma", "audio/x-ms-wma" },
53 { "avi", "video/x-msvideo" },
54 { "mov", "video/quicktime" },
55 { "qt", "video/quicktime" },
56 { "mpg", "video/mpeg" },
57 { "mpeg", "video/mpeg" },
58 { "flv", "video/x-flv" },
59 { "mp4", "video/mp4" },
60 { "mkv", "video/x-matroska" },
61 { "asf", "application/x-asf" },
62 { "rm", "video/vnd.rn-realvideo" },
63 { "wmv", "video/x-ms-wmv" },
65 { "bmp", "image/x-bmp" },
66 { "fax", "image/g3fax" },
67 { "gif", "image/gif" },
68 { "iff", "image/x-iff" },
69 { "jpg", "image/jpeg" },
70 { "jpeg", "image/jpeg" },
71 { "pbm", "image/x-portable-bitmap" },
72 { "pcx", "image/x-pcx" },
73 { "pgm", "image/x-portable-graymap" },
74 { "png", "image/png" },
75 { "ppm", "image/x-portable-pixmap" },
76 { "rgb", "image/x-rgb" },
77 { "tga", "image/x-targa" },
78 { "tif", "image/tiff" },
79 { "tiff", "image/tiff" },
80 { "xbm", "image/x-xbitmap" },
81 { "djvu", "image/x-djvu" },
82 { "svg", "image/svg+xml" },
83 { "ico", "image/vnd.microsoft.icon" },
85 { "doc", "application/msword" },
86 { "xls", "application/vnd.ms-excel" },
87 { "xls", "application/vnd.ms-excel" },
88 { "xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" },
89 { "docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
90 { "ppt", "application/vnd.ms-powerpoint" },
91 { "pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation" },
92 { "chm", "application/x-chm" },
94 { "txt", "text/plain" },
95 { "xml", "text/plain" },
96 { "htm", "text/html" },
97 { "html", "text/html" },
98 { "rtf", "text/rtf" },
99 { "c", "text/x-source-code" },
100 { "cc", "text/x-source-code" },
101 { "c++", "text/x-source-code" },
102 { "h", "text/x-source-code" },
103 { "hh", "text/x-source-code" },
104 { "hpp", "text/x-source-code" },
105 { "cxx", "text/x-source-code" },
106 { "cpp", "text/x-source-code" },
107 { "S", "text/x-source-code" },
108 { "java", "text/x-source-code" },
109 { "ini", "text/plain" },
110 { "inf", "text/plain" },
112 { "ttf", "application/x-truetype" },
114 { NULL, NULL }
118 const char* kAttrMimeTypeName = "BEOS:TYPE";
120 static const char* kFailBackMime = "application/octet-stream";
121 static const char* kDirectoryMime = "application/x-vnd.Be-directory";
124 status_t
125 set_mime(const char** mime, const char* filename)
127 struct ext_mime *p;
128 int32 namelen;
129 int32 ext_len;
130 *mime = NULL;
132 if (filename == NULL) {
133 *mime = kDirectoryMime;
134 return B_NO_ERROR;
136 namelen = strlen(filename);
138 for (p = mimes; p->extension; p++) {
139 ext_len = strlen(p->extension);
141 if (namelen <= ext_len)
142 continue;
144 if (filename[namelen-ext_len-1] != '.')
145 continue;
147 if (!strcasecmp(filename + namelen - ext_len, p->extension))
148 break;
150 if(p->mime == NULL)
151 *mime = kFailBackMime;
152 else
153 *mime = p->mime;
155 return B_NO_ERROR;