/*
- * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Copyright (C) 2016, 2017, 2018 "IoT.bzh"
* Author: José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
const char *extension = strrchr(filename, '.');
if (extension) {
static const char *const known[][2] = {
- { ".js", "text/javascript" },
- { ".json", "application/json" },
- { ".html", "text/html" },
+ /* keep it sorted for dichotomic search */
{ ".css", "text/css" },
+ { ".gif", "image/gif" },
+ { ".html", "text/html" },
+ { ".htm", "text/html" },
{ ".ico", "image/x-icon"},
- /* TODO: CHECK ME { ".ico", "image/vnd.microsoft.icon" }, */
+ { ".jpeg", "image/jpeg" },
{ ".jpg", "image/jpeg" },
+ { ".js", "text/javascript" },
+ { ".json", "application/json" },
+ { ".mp3", "audio/mpeg" },
{ ".png", "image/png" },
{ ".svg", "image/svg+xml" },
{ ".ttf", "application/x-font-ttf"},
- { ".htm", "text/html" },
- { ".xml", "application/xml" },
{ ".txt", "text/plain" },
{ ".wav", "audio/x-wav" },
- { ".xhtml", "application/xhtml+xml" },
{ ".xht", "application/xhtml+xml" },
- { ".gif", "image/gif" },
- { ".png", "image/png" },
- { ".mp3", "audio/mpeg" },
- { NULL, NULL }
+ { ".xhtml", "application/xhtml+xml" },
+ { ".xml", "application/xml" }
};
- int i = 0;
- while (known[i][0]) {
- if (!strcasecmp(extension, known[i][0])) {
+ int i, c, l = 0, u = sizeof known / sizeof *known;
+ while (l < u) {
+ i = (l + u) >> 1;
+ c = strcasecmp(extension, known[i][0]);
+ if (!c) {
result = known[i][1];
break;
}
- i++;
+ if (c < 0)
+ u = i;
+ else
+ l = i + 1;
}
}
#endif