/* * Copyright 2021 Vincent Sanders * * This file is part of NetSurf, http://www.netsurf-browser.org/ * * NetSurf is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * NetSurf is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file * Implementation of netsurf fetch for fltk. */ #include #include #include #include extern "C" { #include "utils/errors.h" #include "utils/log.h" #include "utils/filepath.h" #include "utils/file.h" #include "netsurf/fetch.h" } #include "fltk/fetch.h" #include "fltk/resources.h" /** * Determine the MIME type of a local file. * * @note used in file fetcher * * \param unix_path Unix style path to file on disk * \return Pointer to MIME type string (should not be freed) - * invalidated on next call to fetch_filetype. */ static const char *nsfltk_fetch_filetype(const char *unix_path) { int l; char * res = (char*)"text/html"; l = strlen(unix_path); NSLOG(netsurf, INFO, "unix path: %s", unix_path); if (2 < l && strcasecmp(unix_path + l - 3, "f79") == 0) res = (char*)"text/css"; else if (2 < l && strcasecmp(unix_path + l - 3, "css") == 0) res = (char*)"text/css"; else if (2 < l && strcasecmp(unix_path + l - 3, "jpg") == 0) res = (char*)"image/jpeg"; else if (3 < l && strcasecmp(unix_path + l - 4, "jpeg") == 0) res = (char*)"image/jpeg"; else if (2 < l && strcasecmp(unix_path + l - 3, "gif") == 0) res = (char*)"image/gif"; else if (2 < l && strcasecmp(unix_path + l - 3, "png") == 0) res = (char*)"image/png"; else if (2 < l && strcasecmp(unix_path + l - 3, "jng") == 0) res = (char*)"image/jng"; else if (2 < l && strcasecmp(unix_path + l - 3, "svg") == 0) res = (char*)"image/svg"; else if (2 < l && strcasecmp(unix_path + l - 3, "txt") == 0) res = (char*)"text/plain"; NSLOG(netsurf, INFO, "mime type: %s", res); return res; } /** * Translate resource path to full url. * * @note Only used in resource protocol fetcher * * Transforms a resource protocol path into a full URL. The returned URL * is used as the target for a redirect. The caller takes ownership of * the returned nsurl including unrefing it when finished with it. * * \param path The path of the resource to locate. * \return A netsurf url object containing the full URL of the resource path * or NULL if a suitable resource URL can not be generated. */ static nsurl *nsfltk_get_resource_url(const char *path) { char buf[PATH_MAX]; nsurl *url = NULL; netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url); return url; } static struct gui_fetch_table fetch_table = { .filetype = nsfltk_fetch_filetype, .get_resource_url = nsfltk_get_resource_url, .get_resource_data = NULL, .release_resource_data = NULL, .mimetype = NULL, }; struct gui_fetch_table *nsfltk_fetch_table = &fetch_table;