eris

Very small inetd http server
git clone https://git.woozle.org/neale/eris.git

Neale Pickett  ·  2014-12-19

mime.c

 1#include <stdio.h>
 2#include <string.h>
 3#include "mime.h"
 4
 5static struct mimeentry {
 6    const char     *name,
 7                   *type;
 8} mimetab[] = {
 9    {
10    "html", "text/html; charset=UTF-8"}, {
11    "htm", "text/html; charset=UTF-8"}, {
12    "txt", "text/plain; charset=UTF-8"}, {
13    "css", "text/css"}, {
14    "ps", "application/postscript"}, {
15    "pdf", "application/pdf"}, {
16    "js", "application/javascript"}, {
17    "gif", "image/gif"}, {
18    "png", "image/png"}, {
19    "jpeg", "image/jpeg"}, {
20    "jpg", "image/jpeg"}, {
21    "svg", "image/svg+xml"}, {
22	"webm", "video/webm"}, {
23    "mpeg", "video/mpeg"}, {
24    "mpg", "video/mpeg"}, {
25    "avi", "video/x-msvideo"}, {
26    "mov", "video/quicktime"}, {
27    "qt", "video/quicktime"}, {
28    "mp3", "audio/mpeg"}, {
29    "ogg", "audio/ogg"}, {
30    "wav", "audio/x-wav"}, {
31    "epub", "application/epub+zip"}, {
32    "dvi", "application/x-dvi"}, {
33    "pac", "application/x-ns-proxy-autoconfig"}, {
34    "sig", "application/pgp-signature"}, {
35    "swf", "application/x-shockwave-flash"}, {
36    "torrent", "application/x-bittorrent"}, {
37    "tar", "application/x-tar"}, {
38    "zip", "application/zip"}, {
39    "dtd", "text/xml"}, {
40    "xml", "text/xml"}, {
41    "xbm", "image/x-xbitmap"}, {
42    "xpm", "image/x-xpixmap"}, {
43    "xwd", "image/x-xwindowdump"}, {
44    "ico", "image/x-icon"}, {
45    0, 0}};
46
47static const char *default_mimetype = "application/octet-stream";
48
49/*
50 * Determine MIME type from file extension
51 */
52const char *
53getmimetype(char *url)
54{
55    char *ext = strrchr(url, '.');
56
57
58    if (ext) {
59        int             i;
60
61        ext++;
62        for (i = 0; mimetab[i].name; ++i) {
63            if (!strcmp(mimetab[i].name, ext)) {
64                return mimetab[i].type;
65            }
66        }
67    }
68    return default_mimetype;
69}
70