From 047569339406f2be1637ae4cee5dd0c9a9c2328f Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 22 Jan 2014 23:19:57 +0000 Subject: [PATCH] create table for fetcher operations and move all operations into it --- amiga/filetype.c | 6 --- amiga/filetype.h | 3 ++ amiga/gui.c | 12 +++-- atari/filetype.c | 2 + atari/filetype.h | 2 + atari/gui.c | 19 +++++-- beos/filetype.cpp | 6 --- beos/filetype.h | 1 + beos/gui.cpp | 17 ++++-- cocoa/NetsurfApp.m | 1 + cocoa/fetch.h | 19 +++++++ cocoa/fetch.m | 8 +-- cocoa/gui.h | 1 + cocoa/gui.m | 17 ++++-- content/fetch.h | 5 -- content/fetchers/curl.c | 4 +- content/fetchers/file.c | 8 +-- content/fetchers/resource.c | 2 +- desktop/gui.h | 102 +++++++++++++++++++++++++----------- desktop/gui_factory.c | 61 +++++++++++++++------ desktop/save_complete.c | 6 +-- framebuffer/filetype.c | 2 + framebuffer/filetype.h | 25 +++++++++ framebuffer/gui.c | 16 ++++-- gtk/filetype.c | 5 -- gtk/filetype.h | 1 + gtk/gui.c | 14 +++-- monkey/filetype.c | 14 ++--- monkey/filetype.h | 5 +- monkey/main.c | 39 ++++++++------ riscos/gui.c | 14 +++-- riscos/gui.h | 2 + windows/filetype.c | 2 + windows/filetype.h | 25 +++++++++ windows/gui.c | 15 +++++- windows/gui.h | 1 + windows/main.c | 1 + 37 files changed, 343 insertions(+), 140 deletions(-) create mode 100644 atari/filetype.h create mode 100644 cocoa/fetch.h create mode 100644 framebuffer/filetype.h create mode 100644 windows/filetype.h diff --git a/amiga/filetype.c b/amiga/filetype.c index 39e874ab0..0cb4ac454 100644 --- a/amiga/filetype.c +++ b/amiga/filetype.c @@ -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) diff --git a/amiga/filetype.h b/amiga/filetype.h index 851dddf36..e99f5950c 100644 --- a/amiga/filetype.h +++ b/amiga/filetype.h @@ -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 diff --git a/amiga/gui.c b/amiga/gui.c index b7ee133fa..6bad1dbee 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -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. diff --git a/atari/filetype.c b/atari/filetype.c index 99daf470c..9b73a0508 100755 --- a/atari/filetype.c +++ b/atari/filetype.c @@ -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 diff --git a/atari/filetype.h b/atari/filetype.h new file mode 100644 index 000000000..54d915bf5 --- /dev/null +++ b/atari/filetype.h @@ -0,0 +1,2 @@ +char *fetch_mimetype(const char *ro_path); +const char *fetch_filetype(const char *unix_path); diff --git a/atari/gui.c b/atari/gui.c index b2ac6f715..0267148d2 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -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 */ diff --git a/beos/filetype.cpp b/beos/filetype.cpp index 7975041ac..d5bd3d77b 100644 --- a/beos/filetype.cpp +++ b/beos/filetype.cpp @@ -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)); -} - diff --git a/beos/filetype.h b/beos/filetype.h index ab0ef410f..72252dbd0 100644 --- a/beos/filetype.h +++ b/beos/filetype.h @@ -18,3 +18,4 @@ void beos_fetch_filetype_init(void); void beos_fetch_filetype_fin(void); +const char *fetch_filetype(const char *unix_path); diff --git a/beos/gui.cpp b/beos/gui.cpp index feac53a29..ca176c83f 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -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) { diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index 158c195e6..5643efd6c 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -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(); diff --git a/cocoa/fetch.h b/cocoa/fetch.h new file mode 100644 index 000000000..4a50b6e8d --- /dev/null +++ b/cocoa/fetch.h @@ -0,0 +1,19 @@ +/* + * Copyright 2011 Sven Weidauer + * + * 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 . + */ + +const char *fetch_filetype(const char *unix_path); diff --git a/cocoa/fetch.m b/cocoa/fetch.m index ff1496246..b1c7aea9e 100644 --- a/cocoa/fetch.m +++ b/cocoa/fetch.m @@ -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 ) ); -} diff --git a/cocoa/gui.h b/cocoa/gui.h index 757140030..55b69072e 100644 --- a/cocoa/gui.h +++ b/cocoa/gui.h @@ -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; diff --git a/cocoa/gui.m b/cocoa/gui.m index 4d43fe4f0..2a97df39d 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -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; - - diff --git a/content/fetch.h b/content/fetch.h index 09b7c8d44..f20b4f2d2 100644 --- a/content/fetch.h +++ b/content/fetch.h @@ -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. * diff --git a/content/fetchers/curl.c b/content/fetchers/curl.c index bc6b2c338..f3a8385a1 100644 --- a/content/fetchers/curl.c +++ b/content/fetchers/curl.c @@ -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, diff --git a/content/fetchers/file.c b/content/fetchers/file.c index 26ef9069b..83c408e5a 100644 --- a/content/fetchers/file.c +++ b/content/fetchers/file.c @@ -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)); diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c index d1b21b741..cce816aa5 100644 --- a/content/fetchers/resource.c +++ b/content/fetchers/resource.c @@ -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 { diff --git a/desktop/gui.h b/desktop/gui.h index 5252737f9..724355d10 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -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; }; diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 104f4906d..06b5383ba 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -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 */ diff --git a/desktop/save_complete.c b/desktop/save_complete.c index bd2ed4dea..da87a65fe 100644 --- a/desktop/save_complete.c +++ b/desktop/save_complete.c @@ -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; diff --git a/framebuffer/filetype.c b/framebuffer/filetype.c index 84e286d0c..ce71e337a 100644 --- a/framebuffer/filetype.c +++ b/framebuffer/filetype.c @@ -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 */ diff --git a/framebuffer/filetype.h b/framebuffer/filetype.h new file mode 100644 index 000000000..d11aacb5b --- /dev/null +++ b/framebuffer/filetype.h @@ -0,0 +1,25 @@ +/* + * Copyright 2014 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 . + */ + +#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 diff --git a/framebuffer/gui.c b/framebuffer/gui.c index d89315957..82af56d9e 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1,5 +1,5 @@ /* - * Copyright 2008 Vincent Sanders + * Copyright 2008, 2014 Vincent Sanders * * 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); diff --git a/gtk/filetype.c b/gtk/filetype.c index 2ae59d867..a949b14d5 100644 --- a/gtk/filetype.c +++ b/gtk/filetype.c @@ -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[]) diff --git a/gtk/filetype.h b/gtk/filetype.h index 8bf98db7c..68bb9c0ff 100644 --- a/gtk/filetype.h +++ b/gtk/filetype.h @@ -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); diff --git a/gtk/gui.c b/gtk/gui.c index 39dc885da..d6d35029d 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -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 */ diff --git a/monkey/filetype.c b/monkey/filetype.c index f89f2358c..db9c49ab4 100644 --- a/monkey/filetype.c +++ b/monkey/filetype.c @@ -26,14 +26,15 @@ #include #include -#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[]) diff --git a/monkey/filetype.h b/monkey/filetype.h index 8bf98db7c..6c16db01b 100644 --- a/monkey/filetype.h +++ b/monkey/filetype.h @@ -17,5 +17,6 @@ * along with this program. If not, see . */ -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); diff --git a/monkey/main.c b/monkey/main.c index b6f5c434d..1135f0e53 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -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)); diff --git a/riscos/gui.c b/riscos/gui.c index 6160956c7..8495dd6aa 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -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 diff --git a/riscos/gui.h b/riscos/gui.h index c3dce1cb8..3eeb56273 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -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); diff --git a/windows/filetype.c b/windows/filetype.c index 7ad862b8b..5c6485659 100644 --- a/windows/filetype.c +++ b/windows/filetype.c @@ -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 */ diff --git a/windows/filetype.h b/windows/filetype.h new file mode 100644 index 000000000..e5017eaf4 --- /dev/null +++ b/windows/filetype.h @@ -0,0 +1,25 @@ +/* + * Copyright 2014 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 . + */ + +#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 diff --git a/windows/gui.c b/windows/gui.c index f476c5ae9..a6b2facaf 100644 --- a/windows/gui.c +++ b/windows/gui.c @@ -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; diff --git a/windows/gui.h b/windows/gui.h index 3372dcc21..1ff849d73 100644 --- a/windows/gui.h +++ b/windows/gui.h @@ -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; diff --git a/windows/main.c b/windows/main.c index 8dc9d45cb..ac5231e07 100644 --- a/windows/main.c +++ b/windows/main.c @@ -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;