diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2003-12-27 23:49:31 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2003-12-27 23:49:31 +0000 |
commit | 9ec88eb91f752c2d4487f66e614925ba69d8fe6c (patch) | |
tree | f7ff1f82cf22ed4ad11d43a4442a1ed4039fdd12 | |
parent | ce0d5294d5898b6100269bd39d38c0884d5fd4b4 (diff) | |
download | netsurf-9ec88eb91f752c2d4487f66e614925ba69d8fe6c.tar.gz netsurf-9ec88eb91f752c2d4487f66e614925ba69d8fe6c.tar.bz2 |
[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
-rw-r--r-- | !NetSurf/About/About,faf | 8 | ||||
-rw-r--r-- | desktop/browser.c | 1 | ||||
-rw-r--r-- | riscos/about.c | 80 | ||||
-rw-r--r-- | riscos/about.h | 2 | ||||
-rw-r--r-- | riscos/constdata.c | 1 | ||||
-rw-r--r-- | riscos/constdata.h | 1 | ||||
-rw-r--r-- | riscos/gui.c | 1 | ||||
-rw-r--r-- | riscos/window.c | 46 | ||||
-rw-r--r-- | 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 @@ <!-- Browser specific information --> +<div style="float: left; width: 15%; background-color: #ddddee"> +<h4>Quick Links</h4> +<ul> +<li><a href="about:cookies">List Cookies</a></li> +<li><a href="help:">User Manual</a></li> +</ul> +</div> +<div style="float: right"> <strong><i>NetSurf makes use of the following libraries:</i></strong><br> <br> <table border="0" cellspacing="2" width="100%"> <tr valign="top"> 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 <string.h> #include <stdlib.h> #include <stdio.h> +#include <time.h> #include <unixlib/local.h> /* for __unixify */ #include "netsurf/desktop/netsurf.h" @@ -28,13 +29,13 @@ #include "oslib/osfind.h" #include "oslib/osfscontrol.h" -static const char *pabouthdr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/transitional.dtd\"><html><head><title>About NetSurf</title></head><body bgcolor=\"#f3f3ff\"><!-- About header --><table border=\"0\" width=\"100%%\" bgcolor=\"#94adff\" cellspacing=\"2\"><tr><td><a href=\"http://netsurf.sf.net\"><img src=\"file:///%%3CNetSurf$Dir%%3E/About/nslogo\" alt=\"Netsurf logo\"></a><td><table bgcolor=\"#94adff\" border=\"0\"><tr><td> <tr><td align=\"center\"><h2>NetSurf %s</h2><tr><td align=\"center\"><h5>Copyright © 2002, 2003 NetSurf Developers.</h5><tr><td> </table></table><hr>"; /**< About page header */ +static const char *pabouthdr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/transitional.dtd\"><html><head><title>%s</title></head><body bgcolor=\"#f3f3ff\"><!-- About header --><table border=\"0\" width=\"100%%\" bgcolor=\"#94adff\" cellspacing=\"2\"><tr><td><a href=\"http://netsurf.sf.net\"><img src=\"file:///%%3CNetSurf$Dir%%3E/About/nslogo\" alt=\"Netsurf logo\"></a><td><table bgcolor=\"#94adff\" border=\"0\"><tr><td> <tr><td align=\"center\"><h2>NetSurf %s</h2><tr><td align=\"center\"><h5>Copyright © 2002, 2003 NetSurf Developers.</h5><tr><td> </table></table><hr>"; /**< About page header */ static const char *pabtplghd = "<!-- Plugin information --><strong><i>The following plugins are installed on your system:</i></strong><br> <br><table border=\"0\" cellspacing=\"2\" width=\"100%\">"; /**< Plugin table header */ static const char *paboutpl1 = "<tr valign=\"top\"><td width=\"30%%\"><font size=\"2\"><strong>%s</strong></font></td><td width=\"70%%\"><font size=\"2\">%s</font></td></tr><tr><td colspan=\"2\" bgcolor=\"#dddddd\" height=\"1\"></td></tr>"; /**< Plugin entry without image */ static const char *paboutpl2 = "<tr valign=\"top\"><td width=\"30%%\"><font size=\"2\"><strong>%s</strong></font><br><img src=\"%s\" alt=\"%s\"></td><td width=\"70%%\"><font size=\"2\">%s</font></td></tr><tr><td colspan=\"2\" bgcolor=\"#dddddd\" height=\"1\"></td></tr>";/**< Plugin entry with image (filename=nn) */ static const char *paboutpl3 = "<tr valign=\"top\"><td width=\"30%%\"><font size=\"2\"><strong>%s</strong></font><br><img src=\"%s\" alt=\"%s\" width=\"%d\" height=\"%d\"></td><td width=\"70%%\"><font size=\"2\">%s</font></td></tr><tr><td colspan=\"2\" bgcolor=\"#dddddd\" height=\"1\"></td></tr>"; /**< Plugin entry with image (filename=nnwwwwhhhh) */ static const char *pabtplgft = "</table>"; /**< Plugin table footer */ -static const char *paboutftr = "</body></html>"; /**< Page footer */ +static const char *paboutftr = "</div></body></html>"; /**< 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 <Wimp$ScrapDir>.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("<Wimp$ScrapDir>.WWW", 77); + xosfile_create_dir("<Wimp$ScrapDir>.WWW.NetSurf", 77); + fp = fopen("<Wimp$ScrapDir>.WWW.NetSurf.Cookies", "w+"); + if (!fp) { + xfree(cookies); + LOG(("Failed to create file")); + return; + } + fprintf(fp, pabouthdr, "About NetSurf - Cookies", netsurf_version); + fprintf(fp, "<strong><i>The following cookies are stored on your system:</i></strong><div align=\"center\"><table cellspacing=\"2\" cellpadding=\"2\" width=\"100%%\"><strong><thead><td nowrap>Domain:</td><td nowrap>Flag:</td><td nowrap>Path:</td><td nowrap>Secure:</td><td nowrap>Expiration:</td><td nowrap>Name:</td><td nowrap>Value:</td></thead></strong><tbody>"); + 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, "<tr%s><td nowrap>%s</td><td nowrap>%s</td><td nowrap>%s</td><td nowrap>%s</td><td nowrap>%s</td><td nowrap>%s</td><td nowrap>%s</td></tr>", (count%2 == 0 ? " bgcolor=\"#ddddee\"" : ""), domain, flag, path, secure, + (expiry == 0 ? "Expires on exit" : ctime((time_t*)&expiry)), name, val); + count++; + } + + fprintf(fp, "</tbody></table></div></body></html>"); + fclose(fp); + xosfile_set_type("<Wimp$ScrapDir>.WWW.NetSurf.Cookies", 0xfaf); + xfree(cookies); + return; +} + +/** + * Clean up created files + */ +void about_quit(void) { + + xosfile_delete("<Wimp$ScrapDir>.WWW.NetSurf.About", 0, 0, 0, 0, 0); + xosfile_delete("<Wimp$ScrapDir>.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 <regex.h> #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)), |