From 9ec88eb91f752c2d4487f66e614925ba69d8fe6c Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 27 Dec 2003 23:49:31 +0000 Subject: [project @ 2003-12-27 23:49:31 by jmb] Add about:cookies. Tidy special URL handling code (it's now been moved into url_join in utils.c). svn path=/import/netsurf/; revision=461 --- !NetSurf/About/About,faf | 8 +++++ desktop/browser.c | 1 - riscos/about.c | 80 +++++++++++++++++++++++++++++++++++++++++++++--- riscos/about.h | 2 ++ riscos/constdata.c | 1 + riscos/constdata.h | 1 + riscos/gui.c | 1 + riscos/window.c | 46 ++++++++++++---------------- utils/utils.c | 29 +++++++++++++++++- 9 files changed, 137 insertions(+), 32 deletions(-) diff --git a/!NetSurf/About/About,faf b/!NetSurf/About/About,faf index b74abd47a..a6fb904a9 100644 --- a/!NetSurf/About/About,faf +++ b/!NetSurf/About/About,faf @@ -1,4 +1,12 @@ +
+

Quick Links

+ +
+
NetSurf makes use of the following libraries:
 
diff --git a/desktop/browser.c b/desktop/browser.c index 7a8884518..67f43cba2 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1073,7 +1073,6 @@ void browser_window_input_callback(struct browser_window *bw, char key, void *p) /* Return/Enter hit */ if (form) browser_form_submit(bw, form, 0); - /*TODO: remove caret from new page */ } else if (key == 9) { /* Tab */ /* TODO: tabbing between inputs */ diff --git a/riscos/about.c b/riscos/about.c index 09e9f7e7b..27b154ca6 100644 --- a/riscos/about.c +++ b/riscos/about.c @@ -14,6 +14,7 @@ #include #include #include +#include #include /* for __unixify */ #include "netsurf/desktop/netsurf.h" @@ -28,13 +29,13 @@ #include "oslib/osfind.h" #include "oslib/osfscontrol.h" -static const char *pabouthdr = "About NetSurf
\"Netsurf
 

NetSurf %s

Copyright © 2002, 2003 NetSurf Developers.
 

"; /**< About page header */ +static const char *pabouthdr = "%s
\"Netsurf
 

NetSurf %s

Copyright © 2002, 2003 NetSurf Developers.
 

"; /**< About page header */ static const char *pabtplghd = "The following plugins are installed on your system:
 
"; /**< Plugin table header */ static const char *paboutpl1 = ""; /**< Plugin entry without image */ static const char *paboutpl2 = "";/**< Plugin entry with image (filename=nn) */ static const char *paboutpl3 = ""; /**< Plugin entry with image (filename=nnwwwwhhhh) */ static const char *pabtplgft = "
%s%s
%s
\"%s\"
%s
%s
\"%s\"
%s
"; /**< Plugin table footer */ -static const char *paboutftr = ""; /**< Page footer */ +static const char *paboutftr = "
"; /**< Page footer */ /** The about page */ struct about_page { @@ -88,8 +89,9 @@ void about_create(void) { abt->plugd = 0; /* Page header */ - buf = xcalloc(strlen(pabouthdr) + 40, sizeof(char)); - snprintf(buf, strlen(pabouthdr) + 40, pabouthdr, netsurf_version); + buf = xcalloc(strlen(pabouthdr) + 50, sizeof(char)); + snprintf(buf, strlen(pabouthdr) + 50, pabouthdr, "About NetSurf", + netsurf_version); abt->header = xstrdup(buf); xfree(buf); @@ -252,3 +254,73 @@ void about_create(void) { return; } +/** + * Creates the cookie list and stores it in .WWW.Netsurf + */ +void cookie_create(void) { + + FILE *fp; + int len, count=0; + char *cookies = 0, *pos; + char domain[256], flag[10], path[256], secure[10], + exp[50], name[256], val[256]; + unsigned int expiry; + + fp = fopen("Choices:WWW.NetSurf.Cookies", "r"); + if (!fp) { + LOG(("Failed to open cookie jar")); + return; + } + + /* read file length */ + fseek(fp, 0, SEEK_END); + len = ftell(fp); + fseek(fp, 0, SEEK_SET); + + cookies = xcalloc((unsigned int)len, sizeof(char)); + fread(cookies, (unsigned int)len, sizeof(char), fp); + fclose(fp); + + xosfile_create_dir(".WWW", 77); + xosfile_create_dir(".WWW.NetSurf", 77); + fp = fopen(".WWW.NetSurf.Cookies", "w+"); + if (!fp) { + xfree(cookies); + LOG(("Failed to create file")); + return; + } + fprintf(fp, pabouthdr, "About NetSurf - Cookies", netsurf_version); + fprintf(fp, "The following cookies are stored on your system:
"); + pos = cookies; + while (pos != (cookies+len-1)) { + if (*pos == '#') { + for (; *pos != '\n'; pos++); + pos += 1; + continue; + } + sscanf(pos, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", domain, flag, path, secure, + exp, name, val); + pos += (strlen(domain) + strlen(flag) + strlen(path) + strlen(secure) + + strlen(exp) + strlen(name) +strlen(val) + 7); + sscanf(exp, "%u", &expiry); + fprintf(fp, "", (count%2 == 0 ? " bgcolor=\"#ddddee\"" : ""), domain, flag, path, secure, + (expiry == 0 ? "Expires on exit" : ctime((time_t*)&expiry)), name, val); + count++; + } + + fprintf(fp, "
Domain:Flag:Path:Secure:Expiration:Name:Value:
%s%s%s%s%s%s%s
"); + fclose(fp); + xosfile_set_type(".WWW.NetSurf.Cookies", 0xfaf); + xfree(cookies); + return; +} + +/** + * Clean up created files + */ +void about_quit(void) { + + xosfile_delete(".WWW.NetSurf.About", 0, 0, 0, 0, 0); + xosfile_delete(".WWW.NetSurf.Cookies", 0, 0, 0, 0, 0); +} + diff --git a/riscos/about.h b/riscos/about.h index cdcdcc885..e3ed66a69 100644 --- a/riscos/about.h +++ b/riscos/about.h @@ -9,6 +9,8 @@ #define _NETSURF_RISCOS_ABOUT_H_ void about_create(void); +void cookie_create(void); +void about_quit(void); #endif diff --git a/riscos/constdata.c b/riscos/constdata.c index e40ddc0c7..a7f573789 100644 --- a/riscos/constdata.c +++ b/riscos/constdata.c @@ -10,6 +10,7 @@ #include "netsurf/riscos/constdata.h" const char * const ABOUT_URL = "file:///%3CWimp$ScrapDir%3E/WWW/NetSurf/About"; +const char * const COOKIE_URL = "file:///%3CWimp$ScrapDir%3E/WWW/NetSurf/Cookies"; const char * const GESTURES_URL = "file:///%3CNetSurf$Dir%3E/Resources/gestures"; const char * const HOME_URL = "file:///%3CNetSurf$Dir%3E/Docs/en/intro"; const char * const HELP_URL = "file:///%3CNetSurf$Dir%3E/Docs/en/index"; diff --git a/riscos/constdata.h b/riscos/constdata.h index ff1cf0433..f5a6d47aa 100644 --- a/riscos/constdata.h +++ b/riscos/constdata.h @@ -11,6 +11,7 @@ #define _NETSURF_RISCOS_CONSTDATA_H_ extern const char * const ABOUT_URL; +extern const char * const COOKIE_URL; extern const char * const GESTURES_URL; extern const char * const HOME_URL; extern const char * const HELP_URL; diff --git a/riscos/gui.c b/riscos/gui.c index a00857c64..d2b77f0b2 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -162,6 +162,7 @@ void ro_gui_icon_bar_create(void) void gui_quit(void) { + about_quit(); ro_gui_history_quit(); wimp_close_down(task_handle); } diff --git a/riscos/window.c b/riscos/window.c index e2f6e17ae..8774f31e3 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -16,7 +16,6 @@ #include "oslib/wimp.h" #include "oslib/wimpspriteop.h" #include "netsurf/css/css.h" -#include "netsurf/riscos/about.h" #include "netsurf/riscos/constdata.h" #include "netsurf/riscos/gui.h" #include "netsurf/riscos/theme.h" @@ -309,6 +308,13 @@ void gui_window_set_url(gui_window *g, char *url) { strncpy(g->url, url, 255); wimp_set_icon_state(g->data.browser.toolbar, ICON_TOOLBAR_URL, 0, 0); + /* Move the caret to the url bar. + * It's ok to do this as this only gets + * called when fetching a new page . + */ + wimp_set_caret_position(g->data.browser.toolbar, + ICON_TOOLBAR_URL, + 0,0,-1, (int) strlen(g->url) - 1); } @@ -702,32 +708,20 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar) case wimp_KEY_RETURN: if (!toolbar) break; - if (strcasecmp(g->url, "about:") == 0) { - about_create(); - browser_window_open_location(g->data.browser.bw, - ABOUT_URL); - } else if (strcasecmp(g->url, "help:") == 0) { - browser_window_open_location(g->data.browser.bw, - HELP_URL); - } else if (strcasecmp(g->url, "home:") == 0) { - browser_window_open_location(g->data.browser.bw, - HOME_URL); + 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 { - 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_open_location(g->data.browser.bw, url2); - free(url2); - } + strcpy(url, g->url); + } + url2 = url_join(url, 0); + free(url); + if (url2) { + gui_window_set_url(g, url2); + browser_window_open_location(g->data.browser.bw, url2); + free(url2); } return true; diff --git a/utils/utils.c b/utils/utils.c index cb331a55f..260c1f7ea 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -17,6 +17,10 @@ #include #include "libxml/encoding.h" #include "libxml/uri.h" +#ifdef riscos +#include "netsurf/riscos/about.h" +#include "netsurf/riscos/constdata.h" +#endif #include "netsurf/utils/log.h" #include "netsurf/utils/messages.h" #include "netsurf/utils/utils.h" @@ -172,7 +176,7 @@ char *squash_tolat1(xmlChar *s) /** * Calculate a URL from a relative and base URL. * - * base may be 0 for a new URL, in which case the URL is cannonicalized and + * base may be 0 for a new URL, in which case the URL is canonicalized and * returned. Returns 0 in case of error. */ @@ -183,6 +187,29 @@ char *url_join(char *rel_url, char *base_url) LOG(("rel_url = %s, base_url = %s", rel_url, base_url)); +#ifdef riscos + /* hacky, hacky, hacky... + * It is, however, best to do this here as it avoids + * duplicating code for clicking links and url bar handling. + * It simplifies the code it the other places too (they just + * call this as usual, then we handle it here). + */ + if (strcasecmp(rel_url, "about:") == 0) { + about_create(); + return xstrdup(ABOUT_URL); + } + else if (strcasecmp(rel_url, "about:cookies") == 0) { + cookie_create(); + return xstrdup(COOKIE_URL); + } + else if (strcasecmp(rel_url, "help:") == 0) { + return xstrdup(HELP_URL); + } + else if (strcasecmp(rel_url, "home:") == 0) { + return xstrdup(HOME_URL); + } +#endif + if (!base_url) { res = uri_cannonicalize_string(rel_url, (int)(strlen(rel_url)), -- cgit v1.2.3