NetSurf
fetch.c
Go to the documentation of this file.
1/*
2 * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/** \file
20 * Interfaces for fetch table.
21 */
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <limits.h>
27
28#include "utils/nsurl.h"
29#include "utils/log.h"
30#include "utils/filepath.h"
31#include "utils/file.h"
32#include "netsurf/fetch.h"
33
35#include "framebuffer/fetch.h"
36
37
38/**
39 * Translate resource to full url.
40 *
41 * Transforms a resource: path into a full URL. The returned URL
42 * is used as the target for a redirect. The caller takes ownership of
43 * the returned nsurl including unrefing it when finished with it.
44 *
45 * \param path The path of the resource to locate.
46 * \return A string containing the full URL of the target object or
47 * NULL if no suitable resource can be found.
48 */
49static nsurl *get_resource_url(const char *path)
50{
51 char buf[PATH_MAX];
52 nsurl *url = NULL;
53
54 if (strcmp(path, "favicon.ico") == 0)
55 path = "favicon.png";
56
58
59 return url;
60}
61
62/**
63 * filetype -- determine the MIME type of a local file
64 */
65static const char *fetch_filetype(const char *unix_path)
66{
67 int l;
68 NSLOG(netsurf, INFO, "unix path %s", unix_path);
69 l = strlen(unix_path);
70 if (2 < l && strcasecmp(unix_path + l - 3, "css") == 0)
71 return "text/css";
72 if (2 < l && strcasecmp(unix_path + l - 3, "f79") == 0)
73 return "text/css";
74 if (2 < l && strcasecmp(unix_path + l - 3, "jpg") == 0)
75 return "image/jpeg";
76 if (3 < l && strcasecmp(unix_path + l - 4, "jpeg") == 0)
77 return "image/jpeg";
78 if (2 < l && strcasecmp(unix_path + l - 3, "gif") == 0)
79 return "image/gif";
80 if (2 < l && strcasecmp(unix_path + l - 3, "png") == 0)
81 return "image/png";
82 if (2 < l && strcasecmp(unix_path + l - 3, "b60") == 0)
83 return "image/png";
84 if (2 < l && strcasecmp(unix_path + l - 3, "jng") == 0)
85 return "image/jng";
86 if (2 < l && strcasecmp(unix_path + l - 3, "svg") == 0)
87 return "image/svg";
88 if (2 < l && strcasecmp(unix_path + l - 3, "bmp") == 0)
89 return "image/bmp";
90 return "text/html";
91}
92
93/* table for fetch operations */
96
97 .get_resource_url = get_resource_url,
98};
99
#define PATH_MAX
Definition: gui.h:31
char * filepath_sfind(char **respathv, char *filepath, const char *filename)
Searches an array of resource paths for a file.
Definition: filepath.c:109
Utility routines to obtain paths to file resources.
static struct gui_fetch_table fetch_table
Definition: fetch.c:94
static nsurl * get_resource_url(const char *path)
Translate resource to full url.
Definition: fetch.c:49
struct gui_fetch_table * framebuffer_fetch_table
Definition: fetch.c:100
static const char * fetch_filetype(const char *unix_path)
filetype – determine the MIME type of a local file
Definition: fetch.c:65
char ** respaths
resource search path vector
Definition: findfile.c:28
Interface to platform-specific fetcher operations.
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
NetSurf URL handling (interface).
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
Interface to utility string handling.
function table for fetcher operations.
Definition: fetch.h:33
const char *(* filetype)(const char *unix_path)
Determine the MIME type of a local file.
Definition: fetch.h:45
nserror netsurf_path_to_nsurl(const char *path, struct nsurl **url)
Create a nsurl from a path.
Definition: file.c:307
Default operations table for files.
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
Definition: plot.c:821