16ced9245SJulian Harnath/*
26ced9245SJulian Harnath	Copyright 1999-2001, Be Incorporated.   All Rights Reserved.
36ced9245SJulian Harnath	This file may be used under the terms of the Be Sample Code License.
46ced9245SJulian Harnath*/
56ced9245SJulian Harnath
66ced9245SJulian Harnath#include <SupportDefs.h>
76ced9245SJulian Harnath
86ced9245SJulian Harnath#include <string.h>
96ced9245SJulian Harnath
106ced9245SJulian Harnath#include <file_systems/mime_ext_table.h>
116ced9245SJulian Harnath
126ced9245SJulian Harnath
136ced9245SJulian Harnathstruct ext_mime {
146ced9245SJulian Harnath	char *extension;
156ced9245SJulian Harnath	char *mime;
166ced9245SJulian Harnath};
176ced9245SJulian Harnath
186ced9245SJulian Harnathstatic struct ext_mime mimes[] = {
196ced9245SJulian Harnath	{ "gz", "application/x-gzip" },
206ced9245SJulian Harnath	{ "hqx", "application/x-binhex40" },
216ced9245SJulian Harnath	{ "lha", "application/x-lharc" },
226ced9245SJulian Harnath	{ "pcl", "application/x-pcl" },
236ced9245SJulian Harnath	{ "pdf", "application/pdf" },
246ced9245SJulian Harnath	{ "ps", "application/postscript" },
256ced9245SJulian Harnath	{ "sit", "application/x-stuff-it" },
266ced9245SJulian Harnath	{ "tar", "application/x-tar" },
276ced9245SJulian Harnath	{ "tgz", "application/x-gzip" },
286ced9245SJulian Harnath	{ "uue", "application/x-uuencode" },
296ced9245SJulian Harnath	{ "z", "application/x-compress" },
306ced9245SJulian Harnath	{ "zip", "application/zip" },
316ced9245SJulian Harnath	{ "zoo", "application/x-zoo" },
326ced9245SJulian Harnath	{ "rar", "application/x-rar" },
336ced9245SJulian Harnath	{ "pkg", "application/x-scode-UPkg" },
346ced9245SJulian Harnath	{ "7z", "application/x-7z-compressed" },
356ced9245SJulian Harnath	{ "bz2", "application/x-bzip2" },
366ced9245SJulian Harnath	{ "xz", "application/x-xz" },
376ced9245SJulian Harnath
386ced9245SJulian Harnath	{ "jar", "application/x-jar" },
396ced9245SJulian Harnath
406ced9245SJulian Harnath	{ "aif", "audio/x-aiff" },
416ced9245SJulian Harnath	{ "aiff", "audio/x-aiff" },
426ced9245SJulian Harnath	{ "au", "audio/basic" },
436ced9245SJulian Harnath	{ "mid", "audio/x-midi" },
446ced9245SJulian Harnath	{ "midi", "audio/x-midi" },
456ced9245SJulian Harnath	{ "mod", "audio/mod" },
466ced9245SJulian Harnath	{ "ra", "audio/x-real-audio" },
476ced9245SJulian Harnath	{ "wav", "audio/x-wav" },
486ced9245SJulian Harnath	{ "mp3", "audio/x-mpeg" },
496ced9245SJulian Harnath	{ "ogg", "audio/x-vorbis" },
506ced9245SJulian Harnath	{ "flac", "audio/x-flac" },
516ced9245SJulian Harnath	{ "wma", "audio/x-ms-wma" },
526ced9245SJulian Harnath
536ced9245SJulian Harnath	{ "avi", "video/x-msvideo" },
546ced9245SJulian Harnath	{ "mov", "video/quicktime" },
556ced9245SJulian Harnath	{ "qt", "video/quicktime" },
566ced9245SJulian Harnath	{ "mpg", "video/mpeg" },
576ced9245SJulian Harnath	{ "mpeg", "video/mpeg" },
586ced9245SJulian Harnath	{ "flv", "video/x-flv" },
596ced9245SJulian Harnath	{ "mp4", "video/mp4" },
606ced9245SJulian Harnath	{ "mkv", "video/x-matroska" },
616ced9245SJulian Harnath	{ "asf", "application/x-asf" },
626ced9245SJulian Harnath	{ "rm", "video/vnd.rn-realvideo" },
636ced9245SJulian Harnath	{ "wmv", "video/x-ms-wmv" },
646ced9245SJulian Harnath
656ced9245SJulian Harnath	{ "bmp", "image/x-bmp" },
666ced9245SJulian Harnath	{ "fax", "image/g3fax" },
676ced9245SJulian Harnath	{ "gif", "image/gif" },
686ced9245SJulian Harnath	{ "iff", "image/x-iff" },
696ced9245SJulian Harnath	{ "jpg", "image/jpeg" },
706ced9245SJulian Harnath	{ "jpeg", "image/jpeg" },
716ced9245SJulian Harnath	{ "pbm", "image/x-portable-bitmap" },
726ced9245SJulian Harnath	{ "pcx", "image/x-pcx" },
736ced9245SJulian Harnath	{ "pgm", "image/x-portable-graymap" },
746ced9245SJulian Harnath	{ "png", "image/png" },
756ced9245SJulian Harnath	{ "ppm", "image/x-portable-pixmap" },
766ced9245SJulian Harnath	{ "rgb", "image/x-rgb" },
776ced9245SJulian Harnath	{ "tga", "image/x-targa" },
786ced9245SJulian Harnath	{ "tif", "image/tiff" },
796ced9245SJulian Harnath	{ "tiff", "image/tiff" },
806ced9245SJulian Harnath	{ "xbm", "image/x-xbitmap" },
816ced9245SJulian Harnath	{ "djvu", "image/x-djvu" },
826ced9245SJulian Harnath	{ "svg", "image/svg+xml" },
836ced9245SJulian Harnath	{ "ico", "image/vnd.microsoft.icon" },
846ced9245SJulian Harnath
856ced9245SJulian Harnath	{ "doc", "application/msword" },
866ced9245SJulian Harnath	{ "xls", "application/vnd.ms-excel" },
876ced9245SJulian Harnath	{ "xls", "application/vnd.ms-excel" },
886ced9245SJulian Harnath	{ "xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" },
896ced9245SJulian Harnath	{ "docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
906ced9245SJulian Harnath	{ "ppt", "application/vnd.ms-powerpoint" },
916ced9245SJulian Harnath	{ "pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation" },
926ced9245SJulian Harnath	{ "chm", "application/x-chm" },
936ced9245SJulian Harnath
946ced9245SJulian Harnath	{ "txt", "text/plain" },
956ced9245SJulian Harnath	{ "xml", "text/plain" },
966ced9245SJulian Harnath	{ "htm", "text/html" },
976ced9245SJulian Harnath	{ "html", "text/html" },
986ced9245SJulian Harnath	{ "rtf", "text/rtf" },
996ced9245SJulian Harnath	{ "c", "text/x-source-code" },
1006ced9245SJulian Harnath	{ "cc", "text/x-source-code" },
1016ced9245SJulian Harnath	{ "c++", "text/x-source-code" },
1026ced9245SJulian Harnath	{ "h", "text/x-source-code" },
1036ced9245SJulian Harnath	{ "hh", "text/x-source-code" },
1046ced9245SJulian Harnath	{ "hpp", "text/x-source-code" },
1056ced9245SJulian Harnath	{ "cxx", "text/x-source-code" },
1066ced9245SJulian Harnath	{ "cpp", "text/x-source-code" },
1076ced9245SJulian Harnath	{ "S", "text/x-source-code" },
1086ced9245SJulian Harnath	{ "java", "text/x-source-code" },
1096ced9245SJulian Harnath	{ "ini", "text/plain" },
1106ced9245SJulian Harnath	{ "inf", "text/plain" },
1116ced9245SJulian Harnath
1126ced9245SJulian Harnath	{ "ttf", "application/x-truetype" },
1136ced9245SJulian Harnath
1146ced9245SJulian Harnath	{ NULL, NULL }
1156ced9245SJulian Harnath};
1166ced9245SJulian Harnath
1176ced9245SJulian Harnath
1186ced9245SJulian Harnathconst char* kAttrMimeTypeName = "BEOS:TYPE";
1196ced9245SJulian Harnath
1206ced9245SJulian Harnathstatic const char* kFailBackMime = "application/octet-stream";
1216ced9245SJulian Harnathstatic const char* kDirectoryMime = "application/x-vnd.Be-directory";
1226ced9245SJulian Harnath
1236ced9245SJulian Harnath
1246ced9245SJulian Harnathstatus_t
1256ced9245SJulian Harnathset_mime(const char** mime, const char* filename)
1266ced9245SJulian Harnath{
1276ced9245SJulian Harnath	struct ext_mime *p;
1286ced9245SJulian Harnath	int32 namelen;
1296ced9245SJulian Harnath	int32 ext_len;
1306ced9245SJulian Harnath	*mime = NULL;
1316ced9245SJulian Harnath
1326ced9245SJulian Harnath	if (filename == NULL) {
1336ced9245SJulian Harnath		*mime = kDirectoryMime;
1346ced9245SJulian Harnath		return B_NO_ERROR;
1356ced9245SJulian Harnath	}
1366ced9245SJulian Harnath	namelen = strlen(filename);
1376ced9245SJulian Harnath
1386ced9245SJulian Harnath	for (p = mimes; p->extension; p++) {
1396ced9245SJulian Harnath		ext_len = strlen(p->extension);
1406ced9245SJulian Harnath
1416ced9245SJulian Harnath		if (namelen <= ext_len)
1426ced9245SJulian Harnath			continue;
1436ced9245SJulian Harnath
1446ced9245SJulian Harnath		if (filename[namelen-ext_len-1] != '.')
1456ced9245SJulian Harnath			continue;
1466ced9245SJulian Harnath
1476ced9245SJulian Harnath		if (!strcasecmp(filename + namelen - ext_len, p->extension))
1486ced9245SJulian Harnath			break;
1496ced9245SJulian Harnath	}
1506ced9245SJulian Harnath	if(p->mime == NULL)
1516ced9245SJulian Harnath		*mime = kFailBackMime;
1526ced9245SJulian Harnath	else
1536ced9245SJulian Harnath		*mime = p->mime;
1546ced9245SJulian Harnath
1556ced9245SJulian Harnath	return B_NO_ERROR;
1566ced9245SJulian Harnath}
157