NetSurf
fetch.c
Go to the documentation of this file.
1/*
2 * Copyright 2018 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/**
20 * \file
21 * Fetch operation implementation for win32
22 */
23
24#include <stdlib.h>
25#include <string.h>
26
27#include "utils/log.h"
28#include "utils/file.h"
29#include "utils/filepath.h"
30#include "content/fetch.h"
31#include "netsurf/fetch.h"
32
33#include "windows/fetch.h"
34#include "windows/gui.h"
35
36/**
37 * determine the MIME type of a local file.
38 *
39 * \param unix_path The unix style path to the file.
40 * \return The mime type of the file.
41 */
42static const char *fetch_filetype(const char *unix_path)
43{
44 int l;
45 NSLOG(netsurf, INFO, "unix path %s", unix_path);
46 l = strlen(unix_path);
47 if (2 < l && strcasecmp(unix_path + l - 3, "css") == 0)
48 return "text/css";
49 if (2 < l && strcasecmp(unix_path + l - 3, "jpg") == 0)
50 return "image/jpeg";
51 if (3 < l && strcasecmp(unix_path + l - 4, "jpeg") == 0)
52 return "image/jpeg";
53 if (2 < l && strcasecmp(unix_path + l - 3, "gif") == 0)
54 return "image/gif";
55 if (2 < l && strcasecmp(unix_path + l - 3, "png") == 0)
56 return "image/png";
57 if (2 < l && strcasecmp(unix_path + l - 3, "jng") == 0)
58 return "image/jng";
59 if (2 < l && strcasecmp(unix_path + l - 3, "svg") == 0)
60 return "image/svg";
61 if (2 < l && strcasecmp(unix_path + l - 3, "bmp") == 0)
62 return "image/x-ms-bmp";
63 return "text/html";
64}
65
66/**
67 * Translate resource to full win32 url.
68 *
69 * Transforms a resource: path into a full URL. The returned URL
70 * is used as the target for a redirect. The caller takes ownership of
71 * the returned nsurl including unrefing it when finished with it.
72 *
73 * \param path The path of the resource to locate.
74 * \return A string containing the full URL of the target object or
75 * NULL if no suitable resource can be found.
76 */
77static nsurl *nsw32_get_resource_url(const char *path)
78{
79 char buf[PATH_MAX];
80 nsurl *url = NULL;
81
83
84 return url;
85}
86
87
88/* exported interface documented in windows/fetch.h */
91 const uint8_t **data_out,
92 size_t *data_len_out)
93{
94 HRSRC reshandle;
95 HGLOBAL datahandle;
96 uint8_t *data;
97 DWORD data_len;
98
99 reshandle = FindResource(NULL, path, "USER");
100 if (reshandle == NULL) {
101 return NSERROR_NOT_FOUND;
102 }
103
104 data_len = SizeofResource(NULL, reshandle);
105 if (data_len == 0) {
106 return NSERROR_NOT_FOUND;
107 }
108
109 datahandle = LoadResource(NULL, reshandle);
110 if (datahandle == NULL) {
111 return NSERROR_NOT_FOUND;
112 }
113 data = LockResource(datahandle);
114 if (data == NULL) {
115 return NSERROR_NOT_FOUND;
116 }
117
118 *data_out = data;
119 *data_len_out = data_len;
120
121 return NSERROR_OK;
122}
123
124
125/** win32 fetch operation table */
128
129 .get_resource_url = nsw32_get_resource_url,
130 .get_resource_data = nsw32_get_resource_data,
131};
132
#define PATH_MAX
Definition: gui.h:31
Fetching of data from a URL (interface).
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOT_FOUND
Requested item not found.
Definition: errors.h:34
@ NSERROR_OK
No error.
Definition: errors.h:30
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.
const char * fetch_filetype(const char *unix_path)
filetype – determine the MIME type of a local file
Definition: fetch.c:184
static struct gui_fetch_table fetch_table
win32 fetch operation table
Definition: fetch.c:126
static nsurl * nsw32_get_resource_url(const char *path)
Translate resource to full win32 url.
Definition: fetch.c:77
nserror nsw32_get_resource_data(const char *path, const uint8_t **data_out, size_t *data_len_out)
Translate resource to win32 resource data.
Definition: fetch.c:90
struct gui_fetch_table * win32_fetch_table
win32 API fetch operation table
Definition: fetch.c:133
Interface to platform-specific fetcher operations.
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
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.
char ** G_resource_pathv
resource search path vector.
Definition: gui.c:48
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