summaryrefslogtreecommitdiff
path: root/src/mime/mime.c
blob: e476eea9c180044e023c83a29beee887751c6f05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260

#include "mime.h"

#include <stdlib.h>


const char* fileExtToMime( const char*ext )
{
    if( ext[0]=='7' ){
        if( ext[1]=='z' ){
            if( ext[2]=='\0' ){
                return "application/x-7z-compressed";
            }
        }
    }
    if( ext[0]=='b' ){
        if( ext[1]=='i' ){
            if( ext[2]=='n' ){
                if( ext[3]==0 ){
                    return "application/octet-stream";
                }
            }
        }
    }
    if( ext[0]=='c' ){
        if( ext[1]=='s' ){
            if( ext[2]=='s' ){
                if( ext[3]==0 ){
                    return "text/css";
                }
            }
            if( ext[2]=='v' ){
                if( ext[3]==0 ){
                    return "text/csv";
                }
            }
        }
    }
    if( ext[0]=='g' ){
        if( ext[1]=='i' ){
            if( ext[2]=='f' ){
                if( ext[3]==0 ){
                    return "image/gif";
                }
            }
        }
        if( ext[1]=='z' ){
            if( ext[2]==0 ){
                return "application/gzip";
            }
        }
    }
    if( ext[0]=='h' ){
        if( ext[1]=='t' ){
            if( ext[2]=='m' ){
                if( ext[3]==0 ){
                    return "text/html";
                }
                if( ext[3]=='l' ){
                    return "text/html";
                }
            }
        }
    }
    if( ext[0]=='i' ){
        if( ext[1]=='c' ){
            if( ext[2]=='o' ){
                if( ext[3]==0 ){
                    return "image/vnd.microsoft.icon";
                }
            }
        }
    }
    if( ext[0]=='j' ){
        if( ext[1]=='a' ){
            if( ext[2]=='r' ){
                if( ext[3]==0 ){
                    return "application/java-archive";
                }
            }
        }
        if( ext[1]=='p' ){
            if( ext[2]=='e' ){
                if( ext[3]=='g' ){
                    if( ext[4]==0 ){
                        return "image/jpeg";
                    }
                }
            }
            if( ext[2]=='g' ){
                if( ext[3]==0 ){
                    return "image/jpeg";
                }
            }
        }
    }
    if( ext[0]=='m' ){
        if( ext[1]=='p' ){
            if( ext[2]=='3' ){
                if( ext[3]==0 ){
                    return "audio/mpeg";
                }
            }
            if( ext[2]=='e' ){
                if( ext[3]=='g' ){
                    if( ext[4]==0 ){
                        return "video/mpeg";
                    }
                }
            }
        }
    }
    if( ext[0]=='o' ){
        if( ext[1]=='d' ){
            if( ext[2]=='p' ){
                if( ext[3]==0 ){
                    return "application/vnd.oasis.opendocument.presentation";
                }
            }
            if( ext[2]=='s' ){
                if( ext[3]==0 ){
                    return "application/vnd.oasis.opendocument.spreadsheet";
                }
            }
            if( ext[2]=='t' ){
                if( ext[3]==0 ){
                    return "application/vnd.oasis.opendocument.text";
                }
            }
        }
    }
    if( ext[0]=='p' ){
        if( ext[1]=='d' ){
            if( ext[2]=='f' ){
                if( ext[3]==0 ){
                    return "application/pdf";
                }
            }
        }
        if( ext[1]=='n' ){
            if( ext[2]=='g' ){
                if( ext[3]==0 ){
                    return "image/png";
                }
            }
        }
    }
    if( ext[0]=='s' ){
        if( ext[1]=='v' ){
            if( ext[2]=='g' ){
                if( ext[3]==0 ){
                    return "image/svg+xml";
                }
            }
        }
    }
    if( ext[0]=='t' ){
        if( ext[1]=='a' ){
            if( ext[2]=='r' ){
                if( ext[3]==0 ){
                    return "application/x-tar";
                }
            }
        }
        if( ext[1]=='x' ){
            if( ext[2]=='t' ){
                if( ext[3]==0 ){
                    return "text/plain";
                }
            }
        }
    }
    if( ext[0]=='j' ){
        if( ext[1]=='s' ){
            if( ext[2]==0 ){
                return "text/javascript";
            }
            if( ext[2]=='o' ){
                if( ext[3]=='n' ){
                    if( ext[4]==0 ){
                        return "application/json";
                    }
                }
            }
        }
    }
    if( ext[0]=='w' ){
        if( ext[1]=='a' ){
            if( ext[2]=='v' ){
                if( ext[3]==0 ){
                    return "audio/wav";
                }
            }
        }
        if( ext[1]=='e' ){
            if( ext[2]=='b' ){
                if( ext[3]=='a' ){
                    if( ext[4]==0 ){
                        return "audio/webm";
                    }
                }
                if( ext[3]=='m' ){
                    if( ext[4]==0 ){
                        return "video/webm";
                    }
                }
                if( ext[3]=='p' ){
                    if( ext[4]==0 ){
                        return "image/webp";
                    }
                }
            }
        }
        if( ext[1]=='o' ){
            if( ext[2]=='f' ){
                if( ext[3]=='f' ){
                    if( ext[4]=='\0' ){
                        return "font/woff";
                    }
                    if( ext[4]=='2' ){
                        if( ext[5]=='\0' ){
                            return "font/woff2";
                        }
                    }
                }
            }
        }
    }
    if( ext[0]=='x' ){
        if( ext[1]=='h' ){
            if( ext[2]=='t' ){
                if( ext[3]=='m' ){
                    if( ext[4]=='l' ){
                        if( ext[5]=='\0' ){
                            return "application/xhtml+xml";
                        }
                    }
                }
            }
        }
        if( ext[1]=='m' ){
            if( ext[2]=='l' ){
                if( ext[3]==0 ){
                    return "text/xml";
                }
            }
        }
    }
    if( ext[0]=='z' ){
        if( ext[1]=='i' ){
            if( ext[2]=='p' ){
                if( ext[3]=='\0' ){
                    return "application/zip";
                }
            }
        }
    }
    return NULL;
}