create table for fetcher operations and move all operations into it

This commit is contained in:
Vincent Sanders 2014-01-22 23:19:57 +00:00
parent 4684e9665d
commit 0475693394
37 changed files with 343 additions and 140 deletions

View File

@ -144,12 +144,6 @@ const char *fetch_filetype(const char *unix_path)
return mimetype;
}
char *fetch_mimetype(const char *ro_path)
{
return strdup(fetch_filetype(ro_path));
}
const char *ami_content_type_to_file_type(content_type type)
{
switch(type)

View File

@ -27,6 +27,8 @@
struct hlcache_handle;
struct ami_mime_entry;
const char *fetch_filetype(const char *unix_path);
nserror ami_mime_init(const char *mimefile);
void ami_mime_free(void);
void ami_mime_entry_free(struct ami_mime_entry *mimeentry);
@ -46,4 +48,5 @@ bool ami_mime_compare(struct hlcache_handle *c, const char *type);
/* deprecated */
const char *ami_content_type_to_file_type(content_type type);
#endif

View File

@ -5181,17 +5181,22 @@ static struct gui_window_table amiga_window_table = {
.save_link = gui_window_save_link,
};
static struct gui_fetch_table amiga_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
.get_resource_url = gui_get_resource_url,
};
static struct gui_browser_table amiga_browser_table = {
.poll = gui_poll,
.quit = gui_quit,
.set_search_ico = gui_set_search_ico,
.get_resource_url = gui_get_resource_url,
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.login = gui_401login_open,
};
@ -5211,6 +5216,7 @@ int main(int argc, char** argv)
.window = &amiga_window_table,
.clipboard = amiga_clipboard_table,
.download = amiga_download_table,
.fetch = &amiga_fetch_table,
};
/* Open popupmenu.library just to check the version.

View File

@ -26,6 +26,8 @@
#include "utils/url.h"
#include "utils/log.h"
#include "content/fetch.h"
#include "atari/filetype.h"
/**
* filetype -- determine the MIME type of a local file

2
atari/filetype.h Normal file
View File

@ -0,0 +1,2 @@
char *fetch_mimetype(const char *ro_path);
const char *fetch_filetype(const char *unix_path);

View File

@ -74,6 +74,7 @@
#include "atari/search.h"
#include "atari/deskmenu.h"
#include "atari/download.h"
#include "atari/filetype.h"
#include "cflib.h"
#define TODO() (0)/*printf("%s Unimplemented!\n", __FUNCTION__)*/
@ -1072,13 +1073,20 @@ static struct gui_clipboard_table atari_clipboard_table = {
.set = gui_set_clipboard,
};
static struct gui_browser_table atari_browser_table = {
.poll = gui_poll,
.quit = gui_quit,
.get_resource_url = gui_get_resource_url,
.cert_verify = gui_cert_verify,
static struct gui_fetch_table atari_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
.get_resource_url = gui_get_resource_url,
.mimetype = fetch_mimetype,
};
static struct gui_browser_table atari_browser_table = {
.poll = gui_poll,
.quit = gui_quit,
.cert_verify = gui_cert_verify,
.login = gui_401login_open,
};
@ -1102,6 +1110,7 @@ int main(int argc, char** argv)
.window = &atari_window_table,
.clipboard = &atari_clipboard_table,
.download = atari_download_table,
.fetch = &atari_fetch_table,
};
/* @todo logging file descriptor update belongs in a nslog_init callback */

View File

@ -135,9 +135,3 @@ const char *fetch_filetype(const char *unix_path)
return type;
}
char *fetch_mimetype(const char *unix_path)
{
return strdup(fetch_filetype(unix_path));
}

View File

@ -18,3 +18,4 @@
void beos_fetch_filetype_init(void);
void beos_fetch_filetype_fin(void);
const char *fetch_filetype(const char *unix_path);

View File

@ -1067,13 +1067,18 @@ static struct gui_clipboard_table beos_clipboard_table = {
gui_set_clipboard,
};
static struct gui_fetch_table beos_fetch_table = {
filename_from_path,
path_add_part,
fetch_filetype,
gui_get_resource_url,
NULL //fetch_mimetype
};
static struct gui_browser_table beos_browser_table = {
gui_poll,
filename_from_path,
path_add_part,
gui_quit,
NULL, //set_search_ico
gui_get_resource_url,
gui_launch_url,
NULL, //create_form_select_menu
NULL, //cert_verify
@ -1090,7 +1095,8 @@ int main(int argc, char** argv)
&beos_browser_table,
beos_window_table,
beos_download_table,
&beos_clipboard_table
&beos_clipboard_table,
&beos_fetch_table
};
if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) {
@ -1141,7 +1147,8 @@ int gui_init_replicant(int argc, char** argv)
&beos_browser_table,
beos_window_table,
beos_download_table,
&beos_clipboard_table
&beos_clipboard_table,
&beos_fetch_table
};
if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) {

View File

@ -190,6 +190,7 @@ int main( int argc, char **argv )
.window = cocoa_window_table,
.clipboard = cocoa_clipboard_table,
.download = cocoa_download_table,
.fetch = cocoa_fetch_table,
};
cocoa_autorelease();

19
cocoa/fetch.h Normal file
View File

@ -0,0 +1,19 @@
/*
* Copyright 2011 Sven Weidauer <sven.weidauer@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
const char *fetch_filetype(const char *unix_path);

View File

@ -21,6 +21,8 @@
#import "utils/log.h"
#import "content/fetch.h"
#import "cocoa/fetch.h"
static char cocoafiletype[200];
static const struct mimemap_s {
@ -91,9 +93,3 @@ const char *fetch_filetype(const char *unix_path)
return cocoafiletype;
}
char *fetch_mimetype(const char *ro_path)
{
return strdup( fetch_filetype( ro_path ) );
}

View File

@ -20,6 +20,7 @@
extern struct gui_window_table *cocoa_window_table;
extern struct gui_clipboard_table *cocoa_clipboard_table;
extern struct gui_fetch_table *cocoa_fetch_table;
extern struct gui_browser_table *cocoa_browser_table;
extern NSString * const kCookiesFileOption;

View File

@ -24,6 +24,7 @@
#import "cocoa/BrowserViewController.h"
#import "cocoa/BrowserWindowController.h"
#import "cocoa/FormSelectMenu.h"
#import "cocoa/fetch.h"
#import "desktop/gui.h"
#import "desktop/netsurf.h"
@ -311,16 +312,22 @@ static struct gui_window_table window_table = {
struct gui_window_table *cocoa_window_table = &window_table;
static struct gui_fetch_table fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
.get_resource_url = gui_get_resource_url,
};
struct gui_fetch_table *cocoa_fetch_table = &fetch_table;
static struct gui_browser_table browser_table = {
.poll = gui_poll,
.get_resource_url = gui_get_resource_url,
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
};
struct gui_browser_table *cocoa_browser_table = &browser_table;

View File

@ -99,11 +99,6 @@ extern bool fetch_active;
typedef void (*fetch_callback)(const fetch_msg *msg, void *p);
/** @todo these calls should be in a file_table in gui_factory */
const char *fetch_filetype(const char *unix_path);
char *fetch_mimetype(const char *ro_path);
/**
* Initialise the fetcher.
*

View File

@ -1267,7 +1267,7 @@ fetch_curl_post_convert(const struct fetch_multipart_data *control)
if (control->file) {
char *leafname = 0;
leafname = guit->browser->filename_from_path(control->value);
leafname = guit->fetch->filename_from_path(control->value);
if (leafname == NULL)
continue;
@ -1297,7 +1297,7 @@ fetch_curl_post_convert(const struct fetch_multipart_data *control)
LOG(("curl_formadd: %d (%s)",
code, control->name));
} else {
char *mimetype = fetch_mimetype(control->value);
char *mimetype = guit->fetch->mimetype(control->value);
code = curl_formadd(&post, &last,
CURLFORM_COPYNAME, control->name,
CURLFORM_FILE, control->rawfile,

View File

@ -305,7 +305,7 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx,
/* content type */
if (fetch_file_send_header(ctx, "Content-Type: %s",
fetch_filetype(ctx->path)))
guit->fetch->filetype(ctx->path)))
goto fetch_file_process_aborted;
/* content length */
@ -385,7 +385,7 @@ fetch_file_process_aborted:
/* content type */
if (fetch_file_send_header(ctx, "Content-Type: %s",
fetch_filetype(ctx->path)))
guit->fetch->filetype(ctx->path)))
goto fetch_file_process_aborted;
/* content length */
@ -575,7 +575,7 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
continue;
strncpy(urlpath, ctx->path, sizeof urlpath);
if (guit->browser->path_add_part(urlpath, sizeof urlpath,
if (guit->fetch->path_add_part(urlpath, sizeof urlpath,
ent->d_name) == false)
continue;
@ -608,7 +608,7 @@ static void fetch_file_process_dir(struct fetch_file_context *ctx,
false,
path,
ent->d_name,
fetch_filetype(urlpath),
guit->fetch->filetype(urlpath),
ent_stat.st_size,
datebuf, timebuf,
buffer, sizeof(buffer));

View File

@ -207,7 +207,7 @@ static bool fetch_resource_initialise(lwc_string *scheme)
}
}
e->url = guit->browser->get_resource_url(fetch_resource_paths[i]);
e->url = guit->fetch->get_resource_url(fetch_resource_paths[i]);
if (e->url == NULL) {
lwc_string_unref(e->path);
} else {

View File

@ -280,6 +280,75 @@ struct gui_clipboard_table {
void (*set)(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles);
};
/**
* function table for fetcher operations
*/
struct gui_fetch_table {
/* Mandantory entries */
/**
* Return the filename part of a full path
*
* @note used in curl fetcher
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
char *(*filename_from_path)(char *path);
/**
* Add a path component/filename to an existing path
*
* @note used in save complete and file fetcher
*
* \param path buffer containing path + free space
* \param length length of buffer "path"
* \param newpart string containing path component to add to path
* \return true on success
*/
bool (*path_add_part)(char *path, int length, const char *newpart);
/**
* 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.
*/
const char *(*filetype)(const char *unix_path);
/* Optional entries */
/**
* Callback to translate resource to full url.
*
* @note used in resource fetcher
*
* Transforms a resource: 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 string containing the full URL of the target object or
* NULL if no suitable resource can be found.
*/
nsurl* (*get_resource_url)(const char *path);
/**
* Find a MIME type for a local file
*
* @note used in file fetcher
*
* \param ro_path RISC OS style path to file on disk
* \return MIME type string (on heap, caller should free), or NULL
*/
char *(*mimetype)(const char *ro_path);
};
/** Graphical user interface browser misc function table
*
* function table implementing GUI interface to miscelaneous browser
@ -294,23 +363,6 @@ struct gui_browser_table {
*/
void (*poll)(bool active);
/**
* Return the filename part of a full path
*
* \param path full path and filename
* \return filename (will be freed with free())
*/
char *(*filename_from_path)(char *path);
/**
* Add a path component/filename to an existing path
*
* \param path buffer containing path + free space
* \param length length of buffer "path"
* \param newpart string containing path component to add to path
* \return true on success
*/
bool (*path_add_part)(char *path, int length, const char *newpart);
/* Optional entries */
@ -326,19 +378,6 @@ struct gui_browser_table {
*/
void (*set_search_ico)(hlcache_handle *ico);
/**
* Callback to translate resource to full url.
*
* Transforms a resource: 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 string containing the full URL of the target object or
* NULL if no suitable resource can be found.
*/
nsurl* (*get_resource_url)(const char *path);
/**
* core has no fetcher for url
*/
@ -380,6 +419,9 @@ struct gui_table {
/** Clipboard table */
struct gui_clipboard_table *clipboard;
/** Fetcher table */
struct gui_fetch_table *fetch;
};

View File

@ -289,6 +289,46 @@ static nserror verify_clipboard_register(struct gui_clipboard_table *gct)
return NSERROR_OK;
}
static nsurl *gui_default_get_resource_url(const char *path)
{
return NULL;
}
static char *gui_default_mimetype(const char *path)
{
return strdup(guit->fetch->filetype(path));
}
/** verify fetch table is valid */
static nserror verify_fetch_register(struct gui_fetch_table *gft)
{
/* check table is present */
if (gft == NULL) {
return NSERROR_BAD_PARAMETER;
}
/* check the mandantory fields are set */
if (gft->filename_from_path == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (gft->path_add_part == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (gft->filetype == NULL) {
return NSERROR_BAD_PARAMETER;
}
/* fill in the optional entries with defaults */
if (gft->get_resource_url == NULL) {
gft->get_resource_url = gui_default_get_resource_url;
}
if (gft->mimetype == NULL) {
gft->mimetype = gui_default_mimetype;
}
return NSERROR_OK;
}
static void gui_default_quit(void)
{
@ -298,11 +338,6 @@ static void gui_default_set_search_ico(hlcache_handle *ico)
{
}
static nsurl *gui_default_get_resource_url(const char *path)
{
return NULL;
}
static void gui_default_launch_url(const char *url)
{
}
@ -340,13 +375,6 @@ static nserror verify_browser_register(struct gui_browser_table *gbt)
if (gbt->poll == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (gbt->filename_from_path == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (gbt->path_add_part == NULL) {
return NSERROR_BAD_PARAMETER;
}
/* fill in the optional entries with defaults */
if (gbt->quit == NULL) {
@ -355,9 +383,6 @@ static nserror verify_browser_register(struct gui_browser_table *gbt)
if (gbt->set_search_ico == NULL) {
gbt->set_search_ico = gui_default_set_search_ico;
}
if (gbt->get_resource_url == NULL) {
gbt->get_resource_url = gui_default_get_resource_url;
}
if (gbt->launch_url == NULL) {
gbt->launch_url = gui_default_launch_url;
}
@ -414,6 +439,12 @@ nserror gui_factory_register(struct gui_table *gt)
return err;
}
/* fetch table */
err = verify_fetch_register(gt->fetch);
if (err != NSERROR_OK) {
return err;
}
/* download table */
if (gt->download == NULL) {
/* set default download table */

View File

@ -148,7 +148,7 @@ static bool save_complete_save_buffer(save_complete_ctx *ctx,
char fullpath[PATH_MAX];
strncpy(fullpath, ctx->path, sizeof fullpath);
error = guit->browser->path_add_part(fullpath, sizeof fullpath, leafname);
error = guit->fetch->path_add_part(fullpath, sizeof fullpath, leafname);
if (error == false) {
warn_user("NoMemory", NULL);
return false;
@ -1049,7 +1049,7 @@ static bool save_complete_save_html_document(save_complete_ctx *ctx,
else
snprintf(filename, sizeof filename, "%p", c);
error = guit->browser->path_add_part(fullpath, sizeof fullpath, filename);
error = guit->fetch->path_add_part(fullpath, sizeof fullpath, filename);
if (error == false) {
warn_user("NoMemory", NULL);
return false;
@ -1126,7 +1126,7 @@ static bool save_complete_inventory(save_complete_ctx *ctx)
char fullpath[PATH_MAX];
strncpy(fullpath, ctx->path, sizeof fullpath);
error = guit->browser->path_add_part(fullpath, sizeof fullpath, "Inventory");
error = guit->fetch->path_add_part(fullpath, sizeof fullpath, "Inventory");
if (error == false) {
warn_user("NoMemory", NULL);
return false;

View File

@ -22,6 +22,8 @@
#include "utils/log.h"
#include "utils/utils.h"
#include "framebuffer/filetype.h"
/**
* filetype -- determine the MIME type of a local file
*/

25
framebuffer/filetype.h Normal file
View File

@ -0,0 +1,25 @@
/*
* Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef NETSURF_FB_FILETYPE_H
#define NETSURF_FB_FILETYPE_H
const char *fetch_filetype(const char *unix_path);
char *fetch_mimetype(const char *ro_path);
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright 2008 Vincent Sanders <vince@simtec.co.uk>
* Copyright 2008, 2014 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@ -55,6 +55,7 @@
#include "framebuffer/image_data.h"
#include "framebuffer/font.h"
#include "framebuffer/clipboard.h"
#include "framebuffer/filetype.h"
#include "content/urldb.h"
#include "desktop/local_history.h"
@ -1824,13 +1825,19 @@ static struct gui_window_table framebuffer_window_table = {
.stop_throbber = gui_window_stop_throbber,
};
static struct gui_browser_table framebuffer_browser_table = {
.poll = gui_poll,
static struct gui_fetch_table framebuffer_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
.get_resource_url = gui_get_resource_url,
.mimetype = fetch_mimetype,
};
static struct gui_browser_table framebuffer_browser_table = {
.poll = gui_poll,
.quit = gui_quit,
.get_resource_url = gui_get_resource_url,
};
/** Entry point from OS.
@ -1852,6 +1859,7 @@ main(int argc, char** argv)
.browser = &framebuffer_browser_table,
.window = &framebuffer_window_table,
.clipboard = framebuffer_clipboard_table,
.fetch = &framebuffer_fetch_table,
};
respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH);

View File

@ -207,11 +207,6 @@ const char *fetch_filetype(const char *unix_path)
return type != NULL ? type : "text/plain";
}
char *fetch_mimetype(const char *unix_path)
{
return strdup(fetch_filetype(unix_path));
}
#ifdef TEST_RIG
int main(int argc, char *argv[])

View File

@ -19,3 +19,4 @@
void gtk_fetch_filetype_init(const char *mimefile);
void gtk_fetch_filetype_fin(void);
const char *fetch_filetype(const char *unix_path);

View File

@ -1133,16 +1133,23 @@ static struct gui_clipboard_table nsgtk_clipboard_table = {
.set = gui_set_clipboard,
};
static struct gui_fetch_table nsgtk_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
.get_resource_url = gui_get_resource_url,
};
static struct gui_browser_table nsgtk_browser_table = {
.poll = gui_poll,
.quit = gui_quit,
.set_search_ico = gui_set_search_ico,
.get_resource_url = gui_get_resource_url,
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.login = gui_401login_open,
};
@ -1159,6 +1166,7 @@ int main(int argc, char** argv)
.window = nsgtk_window_table,
.clipboard = &nsgtk_clipboard_table,
.download = nsgtk_download_table,
.fetch = &nsgtk_fetch_table,
};
/* check home directory is available */

View File

@ -26,14 +26,15 @@
#include <sys/stat.h>
#include <unistd.h>
#include "gtk/filetype.h"
#include "content/fetch.h"
#include "utils/log.h"
#include "utils/hashtable.h"
#include "monkey/filetype.h"
static struct hash_table *mime_hash = NULL;
void gtk_fetch_filetype_init(const char *mimefile)
void monkey_fetch_filetype_init(const char *mimefile)
{
struct stat statbuf;
FILE *fh = NULL;
@ -143,12 +144,12 @@ void gtk_fetch_filetype_init(const char *mimefile)
fclose(fh);
}
void gtk_fetch_filetype_fin(void)
void monkey_fetch_filetype_fin(void)
{
hash_destroy(mime_hash);
}
const char *fetch_filetype(const char *unix_path)
const char *monkey_fetch_filetype(const char *unix_path)
{
struct stat statbuf;
char *ext;
@ -195,11 +196,6 @@ const char *fetch_filetype(const char *unix_path)
return type != NULL ? type : "text/plain";
}
char *fetch_mimetype(const char *unix_path)
{
return strdup(fetch_filetype(unix_path));
}
#ifdef TEST_RIG
int main(int argc, char *argv[])

View File

@ -17,5 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
void gtk_fetch_filetype_init(const char *mimefile);
void gtk_fetch_filetype_fin(void);
void monkey_fetch_filetype_init(const char *mimefile);
void monkey_fetch_filetype_fin(void);
const char *monkey_fetch_filetype(const char *unix_path);

View File

@ -63,7 +63,7 @@ static void monkey_quit(void)
urldb_save(nsoption_charp(url_file));
free(nsoption_charp(cookie_file));
free(nsoption_charp(cookie_jar));
gtk_fetch_filetype_fin();
monkey_fetch_filetype_fin();
}
static nsurl *gui_get_resource_url(const char *path)
@ -124,15 +124,15 @@ static bool nslog_stream_configure(FILE *fptr)
static char *filename_from_path(char *path)
{
char *leafname;
char *leafname;
leafname = strrchr(path, '/');
if (!leafname)
leafname = path;
else
leafname += 1;
leafname = strrchr(path, '/');
if (!leafname)
leafname = path;
else
leafname += 1;
return strdup(leafname);
return strdup(leafname);
}
/**
@ -146,22 +146,28 @@ static char *filename_from_path(char *path)
static bool path_add_part(char *path, int length, const char *newpart)
{
if(path[strlen(path) - 1] != '/')
strncat(path, "/", length);
if(path[strlen(path) - 1] != '/')
strncat(path, "/", length);
strncat(path, newpart, length);
strncat(path, newpart, length);
return true;
return true;
}
static struct gui_fetch_table monkey_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = monkey_fetch_filetype,
.get_resource_url = gui_get_resource_url,
};
static struct gui_browser_table monkey_browser_table = {
.poll = monkey_poll,
.quit = monkey_quit,
.get_resource_url = gui_get_resource_url,
.launch_url = gui_launch_url,
.cert_verify = gui_cert_verify,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.login = gui_401login_open,
};
@ -176,6 +182,7 @@ main(int argc, char **argv)
.browser = &monkey_browser_table,
.window = monkey_window_table,
.download = monkey_download_table,
.fetch = &monkey_fetch_table,
};
/* Unbuffer stdin/out/err */
@ -210,7 +217,7 @@ main(int argc, char **argv)
}
filepath_sfinddef(respaths, buf, "mime.types", "/etc/");
gtk_fetch_filetype_init(buf);
monkey_fetch_filetype_init(buf);
urldb_load(nsoption_charp(url_file));
urldb_load_cookies(nsoption_charp(cookie_file));

View File

@ -2353,15 +2353,22 @@ static struct gui_clipboard_table riscos_clipboard_table = {
.set = gui_set_clipboard,
};
static struct gui_fetch_table riscos_fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
.get_resource_url = gui_get_resource_url,
.mimetype = fetch_mimetype,
};
static struct gui_browser_table riscos_browser_table = {
.poll = gui_poll,
.quit = gui_quit,
.get_resource_url = gui_get_resource_url,
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.login = gui_401login_open,
};
@ -2381,6 +2388,7 @@ int main(int argc, char** argv)
.window = riscos_window_table,
.clipboard = &riscos_clipboard_table,
.download = riscos_download_table,
.fetch = &riscos_fetch_table,
};
/* Consult NetSurf$Logging environment variable to decide if logging

View File

@ -167,6 +167,8 @@ void ro_gui_history_open(struct browser_window *bw, struct history *history,
bool pointer);
/* in filetype.c */
const char *fetch_filetype(const char *unix_path);
char *fetch_mimetype(const char *ro_path);
int ro_content_filetype(struct hlcache_handle *c);
int ro_content_native_type(struct hlcache_handle *c);
int ro_content_filetype_from_mime_type(lwc_string *mime_type);

View File

@ -22,6 +22,8 @@
#include "utils/log.h"
#include "utils/utils.h"
#include "windows/filetype.h"
/**
* filetype -- determine the MIME type of a local file
*/

25
windows/filetype.h Normal file
View File

@ -0,0 +1,25 @@
/*
* Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _NETSURF_WINDOWS_FILETYPE_H_
#define _NETSURF_WINDOWS_FILETYPE_H_
const char *fetch_filetype(const char *unix_path);
char *fetch_mimetype(const char *ro_path);
#endif

View File

@ -56,6 +56,7 @@
#include "windows/schedule.h"
#include "windows/findfile.h"
#include "windows/windbg.h"
#include "windows/filetype.h"
HINSTANCE hInstance; /** win32 application instance handle. */
@ -1868,6 +1869,7 @@ static struct gui_window_table window_table = {
struct gui_window_table *win32_window_table = &window_table;
static struct gui_clipboard_table clipboard_table = {
.get = gui_get_clipboard,
.set = gui_set_clipboard,
@ -1875,10 +1877,19 @@ static struct gui_clipboard_table clipboard_table = {
struct gui_clipboard_table *win32_clipboard_table = &clipboard_table;
static struct gui_browser_table browser_table = {
.poll = gui_poll,
static struct gui_fetch_table fetch_table = {
.filename_from_path = filename_from_path,
.path_add_part = path_add_part,
.filetype = fetch_filetype,
.mimetype = fetch_mimetype,
};
struct gui_fetch_table *win32_fetch_table = &fetch_table;
static struct gui_browser_table browser_table = {
.poll = gui_poll,
};
struct gui_browser_table *win32_browser_table = &browser_table;

View File

@ -26,6 +26,7 @@
extern struct gui_window_table *win32_window_table;
extern struct gui_clipboard_table *win32_clipboard_table;
extern struct gui_fetch_table *win32_fetch_table;
extern struct gui_browser_table *win32_browser_table;
extern HINSTANCE hInstance;

View File

@ -110,6 +110,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
.window = win32_window_table,
.clipboard = win32_clipboard_table,
.download = win32_download_table,
.fetch = win32_fetch_table,
};
win32_browser_table->get_resource_url = gui_get_resource_url;