X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-hreq.c;h=012debbd5d6b4f469bb7a38ecb69b58c2d692ea9;hb=c8558c8a28966110aa3a356f95d3c60afe32b64a;hp=a8aae40d8d6aa88f25c5aeeab80bbfa0103858cc;hpb=7ac6622e9175764e0ce1eeaeed9a26acee26e42a;p=src%2Fapp-framework-binder.git diff --git a/src/afb-hreq.c b/src/afb-hreq.c index a8aae40d..012debbd 100644 --- a/src/afb-hreq.c +++ b/src/afb-hreq.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 "IoT.bzh" + * Copyright (C) 2016, 2017, 2018 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -271,34 +271,38 @@ static const char *mimetype_fd_name(int fd, const char *filename) 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