2023-07-28 09:34:18 +00:00
|
|
|
/* copyright (c) 2022 - 2023 grunfink et al. / MIT license */
|
2022-09-25 19:02:47 +00:00
|
|
|
|
|
|
|
#ifndef _XS_MIME
|
|
|
|
|
|
|
|
#define _XS_MIME
|
|
|
|
|
2023-08-14 16:02:20 +00:00
|
|
|
const char *xs_mime_by_ext(const char *file);
|
2022-09-25 19:02:47 +00:00
|
|
|
|
|
|
|
#ifdef XS_IMPLEMENTATION
|
|
|
|
|
|
|
|
/* intentionally brain-dead simple */
|
|
|
|
struct _mime_info {
|
2023-08-14 16:02:20 +00:00
|
|
|
const char *type;
|
|
|
|
const char *ext;
|
2022-09-25 19:02:47 +00:00
|
|
|
} mime_info[] = {
|
|
|
|
{ "application/json", ".json" },
|
|
|
|
{ "image/gif", ".gif" },
|
|
|
|
{ "image/jpeg", ".jpeg" },
|
|
|
|
{ "image/jpeg", ".jpg" },
|
|
|
|
{ "image/png", ".png" },
|
|
|
|
{ "image/webp", ".webp" },
|
2023-08-14 16:02:20 +00:00
|
|
|
{ "video/mp4", ".mp4" },
|
|
|
|
{ "video/mp4", ".mpg4" },
|
|
|
|
{ "video/mp4", ".m4v" },
|
|
|
|
{ "video/webm", ".webm" },
|
|
|
|
{ "video/quicktime", ".mov" },
|
|
|
|
{ "video/3gpp", ".3gp" },
|
|
|
|
{ "video/ogg", ".ogv" },
|
|
|
|
{ "video/flv", ".flv" },
|
|
|
|
{ "audio/mp3", ".mp3" },
|
|
|
|
{ "audio/ogg", ".ogg" },
|
|
|
|
{ "audio/ogg", ".oga" },
|
|
|
|
{ "audio/ogg", ".opus" },
|
|
|
|
{ "audio/flac", ".flac" },
|
|
|
|
{ "audio/wav", ".wav" },
|
|
|
|
{ "audio/wma", ".wma" },
|
|
|
|
{ "audio/aac", ".aac" },
|
|
|
|
{ "audio/aac", ".m4a" },
|
2022-09-25 19:02:47 +00:00
|
|
|
{ "text/css", ".css" },
|
|
|
|
{ "text/html", ".html" },
|
|
|
|
{ "text/plain", ".txt" },
|
|
|
|
{ "text/xml", ".xml" },
|
2023-01-17 08:50:16 +00:00
|
|
|
{ "text/markdown", ".md" },
|
|
|
|
{ "text/gemini", ".gmi" },
|
2022-09-25 19:02:47 +00:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-08-14 16:02:20 +00:00
|
|
|
const char *xs_mime_by_ext(const char *file)
|
2022-09-25 19:02:47 +00:00
|
|
|
/* returns the MIME type by file extension */
|
|
|
|
{
|
|
|
|
struct _mime_info *mi = mime_info;
|
2023-08-14 16:02:20 +00:00
|
|
|
xs *lfile = xs_tolower_i(xs_dup(file));
|
2022-09-25 19:02:47 +00:00
|
|
|
|
2023-08-14 16:02:20 +00:00
|
|
|
while (mi->type != NULL) {
|
|
|
|
if (xs_endswith(lfile, mi->ext))
|
|
|
|
return mi->type;
|
2022-09-25 19:02:47 +00:00
|
|
|
|
|
|
|
mi++;
|
|
|
|
}
|
|
|
|
|
2023-08-14 16:02:20 +00:00
|
|
|
return "application/octet-stream";
|
2022-09-25 19:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* XS_IMPLEMENTATION */
|
|
|
|
|
|
|
|
#endif /* XS_MIME */
|