From 1c85bf04293cfba663c5170bbe762825b7e72af1 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Tue, 2 Mar 2004 18:02:41 +0000 Subject: [project @ 2004-03-02 18:02:17 by bursa] Add new url functions and modify to use them. svn path=/import/netsurf/; revision=578 --- riscos/401login.c | 3 +- riscos/about.c | 128 ++++++++++++++++--------------------------------- riscos/gui.c | 8 +--- riscos/save_complete.c | 50 +------------------ riscos/url.c | 127 ------------------------------------------------ riscos/url.h | 15 ------ riscos/url_protocol.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ riscos/url_protocol.h | 15 ++++++ riscos/window.c | 23 +++------ 9 files changed, 195 insertions(+), 301 deletions(-) delete mode 100644 riscos/url.c delete mode 100644 riscos/url.h create mode 100644 riscos/url_protocol.c create mode 100644 riscos/url_protocol.h (limited to 'riscos') diff --git a/riscos/401login.c b/riscos/401login.c index b46d115d0..c96fcd2c1 100644 --- a/riscos/401login.c +++ b/riscos/401login.c @@ -17,6 +17,7 @@ #include "netsurf/riscos/gui.h" #include "netsurf/utils/log.h" #include "netsurf/utils/messages.h" +#include "netsurf/utils/url.h" #include "netsurf/utils/utils.h" #ifdef WITH_AUTH @@ -65,7 +66,7 @@ void gui_401login_open(struct browser_window *bw, struct content *c, char *realm char *murl, *host; murl = c->url; - host = get_host_from_url(murl); + host = url_host(murl); assert(host); bwin = bw; diff --git a/riscos/about.c b/riscos/about.c index cfec2733a..89f39506c 100644 --- a/riscos/about.c +++ b/riscos/about.c @@ -16,20 +16,18 @@ #include #include #include /* for __unixify */ - -#include "netsurf/utils/config.h" -#include "netsurf/desktop/netsurf.h" -#include "netsurf/riscos/about.h" -#include "netsurf/utils/log.h" -#include "netsurf/utils/messages.h" -#include "netsurf/utils/utils.h" - #include "oslib/fileswitch.h" #include "oslib/osargs.h" #include "oslib/osfile.h" #include "oslib/osfind.h" #include "oslib/osfscontrol.h" #include "oslib/osgbpb.h" +#include "netsurf/utils/config.h" +#include "netsurf/desktop/browser.h" +#include "netsurf/desktop/netsurf.h" +#include "netsurf/utils/log.h" +#include "netsurf/utils/messages.h" +#include "netsurf/utils/utils.h" #ifdef WITH_ABOUT @@ -41,81 +39,53 @@ static const char *paboutpl3 = "details = 0; - np->details = details; - - np->next = pd; - return np; -} - -/** - * Creates the about page and stores it in .WWW.Netsurf - */ -void about_create(void) { - - struct about_page *abt; - struct plugd *temp; +struct content *about_create(const char *url, + void (*callback)(content_msg msg, struct content *c, void *p1, + void *p2, const char *error), + void *p1, void *p2, unsigned long width, unsigned long height) +{ + struct content *c = 0; FILE *fp; char *buf, *val, var[20], *ptype, *pdetails, *fname, *furl; int i, nofiles, j, w, h, size; fileswitch_object_type fot; os_error *e; + const char *params[] = { 0 }; - abt = (struct about_page*)xcalloc(1, sizeof(*abt)); - abt->plugd = 0; + c = content_create(url); + c->width = width; + c->height = height; + content_add_user(c, callback, p1, p2); + content_set_type(c, CONTENT_HTML, "text/html", params); /* Page header */ buf = xcalloc(strlen(pabouthdr) + 50, sizeof(char)); snprintf(buf, strlen(pabouthdr) + 50, pabouthdr, "About NetSurf", netsurf_version); - abt->header = xstrdup(buf); - xfree(buf); + content_process_data(c, buf, strlen(buf)); + free(buf); /* browser details */ - xosfile_read_stamped_no_path(".About.About",0,0,0,&i,0,0); - fp = fopen(".About.About", "r"); - buf = xcalloc((unsigned int)i + 10, sizeof(char)); - fread(buf, sizeof(char), (unsigned int)i, fp); - fclose(fp); - abt->browser = xstrdup(buf); - xfree(buf); + buf = load(".About.About"); + content_process_data(c, buf, strlen(buf)); + free(buf); /* plugin header */ - abt->plghead = xstrdup(pabtplghd); - - /* plugin footer */ - abt->plgfoot = xstrdup(pabtplgft); - - /* Page footer */ - abt->footer = xstrdup(paboutftr); + content_process_data(c, pabtplghd, strlen(pabtplghd)); /* plugins registered */ for (i=0; i!=4096; i++) { @@ -172,7 +142,7 @@ void about_create(void) { furl = xcalloc(strlen(paboutpl1) + strlen(ptype) + strlen(pdetails) + 10, sizeof(char)); sprintf(furl, paboutpl1, ptype, pdetails); LOG(("furl: %s", furl)); - abt->plugd = new_plugin(abt->plugd, furl); + content_process_data(c, furl, strlen(furl)); xfree(pdetails); continue; } @@ -214,7 +184,7 @@ void about_create(void) { furl = xcalloc(strlen(paboutpl3) + strlen(ptype) + strlen(buf) + strlen(pdetails) + 10, sizeof(char)); sprintf(furl, paboutpl3, ptype, buf, ptype, w, h, pdetails); - abt->plugd = new_plugin(abt->plugd, furl); + content_process_data(c, furl, strlen(furl)); xfree(pdetails); continue; } @@ -230,7 +200,7 @@ void about_create(void) { furl = xcalloc(strlen(paboutpl2) + strlen(ptype) + strlen(fname) + strlen(pdetails) + 10, sizeof(char)); sprintf(furl, paboutpl2, ptype, fname, ptype, pdetails); - abt->plugd = new_plugin(abt->plugd, furl); + content_process_data(c, furl, strlen(furl)); xfree(fname); xfree(pdetails); } @@ -241,29 +211,15 @@ void about_create(void) { } } - /* write file */ - xosfile_create_dir(".WWW", 77); - xosfile_create_dir(".WWW.NetSurf", 77); - - fp = fopen(".WWW.Netsurf.About", "w+"); - fprintf(fp, "%s", abt->header); - fprintf(fp, "%s", abt->browser); - fprintf(fp, "%s", abt->plghead); - while (abt->plugd != 0) { - fprintf(fp, "%s", abt->plugd->details); - temp = abt->plugd; - abt->plugd = abt->plugd->next; - xfree(temp); - } - fprintf(fp, "%s", abt->plgfoot); - fprintf(fp, "%s", abt->footer); - fclose(fp); + /* plugin footer */ + content_process_data(c, pabtplgft, strlen(pabtplgft)); - xosfile_set_type(".WWW.NetSurf.About", 0xfaf); + /* Page footer */ + content_process_data(c, paboutftr, strlen(paboutftr)); - xfree(abt); + content_convert(c, c->width, c->height); - return; + return c; } #ifdef WITH_COOKIES diff --git a/riscos/gui.c b/riscos/gui.c index dd976ee4e..a325aebf2 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -29,9 +29,6 @@ #include "netsurf/render/font.h" #include "netsurf/render/form.h" #include "netsurf/render/html.h" -#ifdef WITH_ABOUT -#include "netsurf/riscos/about.h" -#endif #include "netsurf/riscos/constdata.h" #include "netsurf/riscos/gui.h" #include "netsurf/riscos/options.h" @@ -43,7 +40,7 @@ #include "netsurf/riscos/uri.h" #endif #ifdef WITH_URL -#include "netsurf/riscos/url.h" +#include "netsurf/riscos/url_protocol.h" #endif #include "netsurf/utils/log.h" #include "netsurf/utils/messages.h" @@ -257,9 +254,6 @@ void ro_gui_icon_bar_create(void) void gui_quit(void) { -#ifdef WITH_ABOUT - about_quit(); -#endif ro_gui_history_quit(); wimp_close_down(task_handle); xhourglass_off(); diff --git a/riscos/save_complete.c b/riscos/save_complete.c index a97465679..08baffbd8 100644 --- a/riscos/save_complete.c +++ b/riscos/save_complete.c @@ -6,13 +6,8 @@ */ #include - #include /* for __riscosify */ - -#include /* possibly just have accessor methods in utils.c */ - #include "oslib/osfile.h" - #include "netsurf/utils/config.h" #include "netsurf/content/content.h" #include "netsurf/css/css.h" @@ -30,7 +25,6 @@ */ void save_imported_sheets(struct content *c, int parent, int level, char *p, char* fn); -char* get_filename(char * url); /* this is temporary. */ const char * const SAVE_PATH = ".savetest."; @@ -46,7 +40,7 @@ void save_complete(struct content *c) { return; } - fname = get_filename(c->data.html.base_url); + fname = "test"; /*get_filename(c->data.html.base_url);*/ if (!fname) { /* no path -> exit */ return; @@ -135,46 +129,4 @@ void save_imported_sheets(struct content *c, int parent, int level, char *p, cha } } -char* get_filename(char * url) { - - char *ret = 0, *offs; - uri_t *uri; - - uri = uri_alloc(url, (int)strlen(url)); - - if (!uri) { - return 0; - } - - if (uri->path) { - /* Two possible cases here: - * a) no page name given (eg http://www.blah.com/) -> index.html - * b) page name given - */ - /* case a */ - if (strlen(uri->path) == 0) { - ret = xstrdup("index.html"); - } - /* case b */ - else { - offs = strrchr(uri->path, '/'); - if (!offs) { - ret = xstrdup(uri->path); - } - else { - ret = xstrdup(offs+1); - } - } - } - - uri_free(uri); - - offs = xcalloc(strlen(ret)+1, sizeof(char)); - - __riscosify(ret, 0, 0, offs, strlen(ret)+1, 0); - - xfree(ret); - - return offs; -} #endif diff --git a/riscos/url.c b/riscos/url.c deleted file mode 100644 index e1ee94d47..000000000 --- a/riscos/url.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * This file is part of NetSurf, http://netsurf.sourceforge.net/ - * Licensed under the GNU General Public License, - * http://www.opensource.org/licenses/gpl-license - * Copyright 2003 John M Bell - * Shamelessly hacked from Rob Jackson's URI handler (see uri.c) - */ - -#include -#include -#include "oslib/inetsuite.h" -#include "oslib/wimp.h" -#include "netsurf/utils/config.h" -#include "netsurf/desktop/browser.h" -#include "netsurf/riscos/theme.h" -#include "netsurf/desktop/gui.h" -#include "netsurf/riscos/gui.h" -#include "netsurf/riscos/url.h" -#include "netsurf/utils/log.h" -#include "netsurf/utils/utils.h" - -/* Define this to allow posting of data to an URL */ -#undef ALLOW_POST - -static char *read_string_value(os_string_value string, char *msg); - -void ro_url_message_received(wimp_message* message) -{ - char* uri_requested = NULL; -#ifdef ALLOW_POST - char* filename = NULL, *mimetype = NULL; - bool post=false; -#endif - struct browser_window* bw; - inetsuite_message_open_url *url_message = (inetsuite_message_open_url*)&message->data; - - /* If the url_message->indirect.tag is non-zero, - * then the message data is contained within the message block. - */ - if (url_message->indirect.tag != 0) { - uri_requested = xstrdup(url_message->url); - LOG(("%s", url_message->url)); - } - else { - /* Get URL */ - if (read_string_value(url_message->indirect.url, - (char*)url_message) != 0) { - uri_requested = xstrdup(read_string_value(url_message->indirect.url, - (char*)url_message)); - } - else { - return; - } - LOG(("%s", uri_requested)); - -#ifdef ALLOW_POST - /* Get filename */ - if (read_string_value(url_message->indirect.body_file, - (char*)url_message) != 0) { - filename = xstrdup(read_string_value(url_message->indirect.body_file, - (char*)url_message)); - } - /* We ignore the target window. Just open a new window. */ - /* Get mimetype */ - if (url_message->indirect.flags & inetsuite_USE_MIME_TYPE) { - if (read_string_value(url_message->indirect.body_mimetype, - (char*)url_message) != 0) { - mimetype = xstrdup(read_string_value(url_message->indirect.body_mimetype, - (char*)url_message)); - } - else { - mimetype = xstrdup("application/x-www-form-urlencoded"); - } - } - else { - mimetype = xstrdup("application/x-www-form-urlencoded"); - } - - /* Indicate a post request */ - if (filename && message->size > 28) - post = true; -#endif - } - - if ( (strspn(uri_requested, "http://") != strlen("http://")) && - (strspn(uri_requested, "https://") != strlen("https://")) && - (strspn(uri_requested, "file:/") != strlen("file:/")) ) { -#ifdef ALLOW_POST - xfree(filename); - xfree(mimetype); -#endif - xfree(uri_requested); - return; - } - - /* send ack */ - message->your_ref = message->my_ref; - xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE, message, - message->sender); - - /* create new browser window */ - browser_window_create(uri_requested); - -#if 0 - if (post) { - /* TODO - create urlencoded data from file contents. - * Delete the file when finished with it. - */ - browser_window_open_location_historical(bw, uri_requested, /*data*/0, 0); - } -#endif - -#ifdef ALLOW_POST - xfree(filename); - xfree(mimetype); -#endif - xfree(uri_requested); - - return; -} - -char *read_string_value(os_string_value string, char *msg) { - - if(string.offset == 0) return NULL; - if(string.offset > 256) return string.pointer; - return &msg[string.offset]; -} diff --git a/riscos/url.h b/riscos/url.h deleted file mode 100644 index 01b99b7c1..000000000 --- a/riscos/url.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * This file is part of NetSurf, http://netsurf.sourceforge.net/ - * Licensed under the GNU General Public License, - * http://www.opensource.org/licenses/gpl-license - * Copyright 2003 John M Bell - */ - -#ifndef _NETSURF_RISCOS_URL_H_ -#define _NETSURF_RISCOS_URL_H_ - -#include "oslib/wimp.h" - -void ro_url_message_received(wimp_message *message); - -#endif diff --git a/riscos/url_protocol.c b/riscos/url_protocol.c new file mode 100644 index 000000000..1553d17ac --- /dev/null +++ b/riscos/url_protocol.c @@ -0,0 +1,127 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2003 John M Bell + * Shamelessly hacked from Rob Jackson's URI handler (see uri.c) + */ + +#include +#include +#include "oslib/inetsuite.h" +#include "oslib/wimp.h" +#include "netsurf/utils/config.h" +#include "netsurf/desktop/browser.h" +#include "netsurf/riscos/theme.h" +#include "netsurf/desktop/gui.h" +#include "netsurf/riscos/gui.h" +#include "netsurf/riscos/url_protocol.h" +#include "netsurf/utils/log.h" +#include "netsurf/utils/utils.h" + +/* Define this to allow posting of data to an URL */ +#undef ALLOW_POST + +static char *read_string_value(os_string_value string, char *msg); + +void ro_url_message_received(wimp_message* message) +{ + char* uri_requested = NULL; +#ifdef ALLOW_POST + char* filename = NULL, *mimetype = NULL; + bool post=false; +#endif + struct browser_window* bw; + inetsuite_message_open_url *url_message = (inetsuite_message_open_url*)&message->data; + + /* If the url_message->indirect.tag is non-zero, + * then the message data is contained within the message block. + */ + if (url_message->indirect.tag != 0) { + uri_requested = xstrdup(url_message->url); + LOG(("%s", url_message->url)); + } + else { + /* Get URL */ + if (read_string_value(url_message->indirect.url, + (char*)url_message) != 0) { + uri_requested = xstrdup(read_string_value(url_message->indirect.url, + (char*)url_message)); + } + else { + return; + } + LOG(("%s", uri_requested)); + +#ifdef ALLOW_POST + /* Get filename */ + if (read_string_value(url_message->indirect.body_file, + (char*)url_message) != 0) { + filename = xstrdup(read_string_value(url_message->indirect.body_file, + (char*)url_message)); + } + /* We ignore the target window. Just open a new window. */ + /* Get mimetype */ + if (url_message->indirect.flags & inetsuite_USE_MIME_TYPE) { + if (read_string_value(url_message->indirect.body_mimetype, + (char*)url_message) != 0) { + mimetype = xstrdup(read_string_value(url_message->indirect.body_mimetype, + (char*)url_message)); + } + else { + mimetype = xstrdup("application/x-www-form-urlencoded"); + } + } + else { + mimetype = xstrdup("application/x-www-form-urlencoded"); + } + + /* Indicate a post request */ + if (filename && message->size > 28) + post = true; +#endif + } + + if ( (strspn(uri_requested, "http://") != strlen("http://")) && + (strspn(uri_requested, "https://") != strlen("https://")) && + (strspn(uri_requested, "file:/") != strlen("file:/")) ) { +#ifdef ALLOW_POST + xfree(filename); + xfree(mimetype); +#endif + xfree(uri_requested); + return; + } + + /* send ack */ + message->your_ref = message->my_ref; + xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE, message, + message->sender); + + /* create new browser window */ + browser_window_create(uri_requested); + +#if 0 + if (post) { + /* TODO - create urlencoded data from file contents. + * Delete the file when finished with it. + */ + browser_window_open_location_historical(bw, uri_requested, /*data*/0, 0); + } +#endif + +#ifdef ALLOW_POST + xfree(filename); + xfree(mimetype); +#endif + xfree(uri_requested); + + return; +} + +char *read_string_value(os_string_value string, char *msg) { + + if(string.offset == 0) return NULL; + if(string.offset > 256) return string.pointer; + return &msg[string.offset]; +} diff --git a/riscos/url_protocol.h b/riscos/url_protocol.h new file mode 100644 index 000000000..01b99b7c1 --- /dev/null +++ b/riscos/url_protocol.h @@ -0,0 +1,15 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2003 John M Bell + */ + +#ifndef _NETSURF_RISCOS_URL_H_ +#define _NETSURF_RISCOS_URL_H_ + +#include "oslib/wimp.h" + +void ro_url_message_received(wimp_message *message); + +#endif diff --git a/riscos/window.c b/riscos/window.c index 80cd80b02..fa8b2e1d7 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -27,6 +27,7 @@ #include "netsurf/riscos/theme.h" #include "netsurf/riscos/thumbnail.h" #include "netsurf/utils/log.h" +#include "netsurf/utils/url.h" #include "netsurf/utils/utils.h" gui_window *window_list = 0; @@ -676,6 +677,7 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar) struct content *content = g->data.browser.bw->current_content; wimp_window_state state; int y; + char *url; assert(g->type == GUI_BROWSER_WINDOW); @@ -744,22 +746,11 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar) case wimp_KEY_RETURN: if (!toolbar) break; - else { - char *url = xcalloc(1, 10 + strlen(g->url)); - char *url2; - if (g->url[strspn(g->url, "abcdefghijklmnopqrstuvwxyz")] != ':') { - strcpy(url, "http://"); - strcpy(url + 7, g->url); - } else { - strcpy(url, g->url); - } - url2 = url_join(url, 0); - free(url); - if (url2) { - gui_window_set_url(g, url2); - browser_window_go(g->data.browser.bw, url2); - free(url2); - } + url = url_normalize(g->url); + if (url) { + gui_window_set_url(g, url); + browser_window_go(g->data.browser.bw, url); + free(url); } return true; -- cgit v1.2.3