summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
Diffstat (limited to 'desktop')
-rw-r--r--desktop/401login.h14
-rw-r--r--desktop/browser.c15
-rw-r--r--desktop/loginlist.c137
3 files changed, 163 insertions, 3 deletions
diff --git a/desktop/401login.h b/desktop/401login.h
index f9a999ebd..d9262c54c 100644
--- a/desktop/401login.h
+++ b/desktop/401login.h
@@ -8,11 +8,21 @@
#ifndef NETSURF_DESKTOP_401LOGIN_H
#define NETSURF_DESKTOP_401LOGIN_H
+#include "netsurf/content/content.h"
+#include "netsurf/desktop/browser.h"
+
struct login {
- char *string;
+ char *host; /**< hostname */
+ char *logindetails; /**< string containing "username:password" */
+ struct login *next; /**< next in list */
+ struct login *prev; /**< previous in list */
};
-extern struct login LOGIN;
+void gui_401login_open(struct browser_window *bw, struct content *c,
+ char *realm);
+void login_list_add(char *host, char *logindets);
+struct login *login_list_get(char *host);
+void login_list_remove(char *host);
#endif
diff --git a/desktop/browser.c b/desktop/browser.c
index 16fc03126..8e311eee8 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -18,6 +18,7 @@
#include "netsurf/content/cache.h"
#include "netsurf/content/fetchcache.h"
#include "netsurf/css/css.h"
+#include "netsurf/desktop/401login.h"
#include "netsurf/desktop/browser.h"
#include "netsurf/render/box.h"
#include "netsurf/render/font.h"
@@ -208,6 +209,7 @@ void browser_window_destroy(struct browser_window* bw)
if (bw->current_content->status == CONTENT_STATUS_DONE)
content_remove_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state);
content_remove_user(bw->current_content, browser_window_callback, bw, 0);
+ login_list_remove(bw->current_content->url);
}
if (bw->loading_content != NULL) {
content_remove_user(bw->loading_content, browser_window_callback, bw, 0);
@@ -248,10 +250,18 @@ void browser_window_open_location_historical(struct browser_window* bw,
const char* url, char *post_urlenc,
struct form_successful_control *post_multipart)
{
+ struct login *li;
LOG(("bw = %p, url = %s", bw, url));
assert(bw != 0 && url != 0);
+ if ((li = login_list_get(url)) == NULL) {
+
+ if (bw->current_content != NULL) {
+ login_list_remove(bw->current_content->url);
+ }
+ }
+
browser_window_set_status(bw, "Opening page...");
browser_window_start_throbber(bw);
bw->time0 = clock();
@@ -376,7 +386,6 @@ void browser_window_callback(content_msg msg, struct content *c,
case CONTENT_MSG_REDIRECT:
bw->loading_content = 0;
- bw->url = xstrdup(error);
browser_window_set_status(bw, "Redirecting");
/* error actually holds the new URL */
browser_window_open_location(bw, error);
@@ -386,6 +395,10 @@ void browser_window_callback(content_msg msg, struct content *c,
browser_window_reformat(bw, 0);
break;
+ case CONTENT_MSG_AUTH:
+ gui_401login_open(bw, c, error);
+ break;
+
default:
assert(0);
}
diff --git a/desktop/loginlist.c b/desktop/loginlist.c
new file mode 100644
index 000000000..08b1822c1
--- /dev/null
+++ b/desktop/loginlist.c
@@ -0,0 +1,137 @@
+/*
+ * 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 <jmb202@ecs.soton.ac.uk>
+ */
+
+#include <assert.h>
+#include <string.h>
+#include "netsurf/desktop/401login.h"
+#include "netsurf/utils/log.h"
+#include "netsurf/utils/utils.h"
+
+#define NDEBUG
+
+void login_list_dump(void);
+
+/**
+ * Pointer into the linked list
+ */
+static struct login login = {0, 0, &login, &login};
+static struct login *loginlist = &login;
+
+/**
+ * Adds an item to the list of login details
+ */
+void login_list_add(char *host, char* logindets) {
+
+ struct login *nli = xcalloc(1, sizeof(*nli));
+ char *temp = xstrdup(host);
+ char *i;
+
+ /* Go back to the path base ie strip the document name
+ * eg. http://www.blah.com/blah/test.htm becomes
+ * http://www.blah.com/blah/
+ * This does, however, mean that directories MUST have a '/' at the end
+ */
+ if (temp[strlen(temp)-1] != '/') {
+ i = strrchr(temp, '/');
+ temp[(i-temp)+1] = 0;
+ }
+
+ nli->host = xstrdup(temp);
+ nli->logindetails = xstrdup(logindets);
+ nli->prev = loginlist->prev;
+ nli->next = loginlist;
+ loginlist->prev->next = nli;
+ loginlist->prev = nli;
+
+ LOG(("Adding %s : %s", temp, logindets));
+#ifndef NDEBUG
+ login_list_dump();
+#endif
+ xfree(temp);
+}
+
+/**
+ * Retrieves an element from the login list
+ */
+struct login *login_list_get(char *host) {
+
+ struct login *nli;
+ char *temp, *temphost;
+ char* i;
+
+ if (host == NULL)
+ return NULL;
+
+ temphost = get_host_from_url(host);
+ temp = xstrdup(host);
+
+ /* Work backwards through the path, directory at at time.
+ * Finds the closest match.
+ * eg. http://www.blah.com/moo/ matches the url
+ * http://www.blah.com/moo/test/index.htm
+ * This allows multiple realms (and login details) per host.
+ * Only one set of login details per realm are allowed.
+ */
+ while (strcasecmp(temp, temphost) != 0) {
+
+ LOG(("%s, %d", temp, strlen(temp)));
+
+ for (nli = loginlist->next; nli != loginlist &&
+ (strcasecmp(nli->host, temp)!=0);
+ nli = nli->next) ;
+
+ if (temp[strlen(temp)-1] == '/') {
+ temp[strlen(temp)-1] = 0;
+ }
+
+ i = strrchr(temp, '/');
+
+ temp[(i-temp)+1] = 0;
+
+ if (nli != loginlist) {
+ LOG(("Got %s", nli->host));
+ xfree(temphost);
+ return nli;
+ }
+ }
+
+ xfree(temphost);
+ return NULL;
+}
+
+/**
+ * Remove a realm's login details from the list
+ */
+void login_list_remove(char *host) {
+
+ struct login *nli = login_list_get(host);
+
+ if (nli != NULL) {
+ nli->prev->next = nli->next;
+ nli->next->prev = nli->prev;
+ xfree(nli->logindetails);
+ xfree(nli->host);
+ xfree(nli);
+ }
+
+ LOG(("Removing %s", host));
+#ifndef NDEBUG
+ login_list_dump();
+#endif
+}
+
+/**
+ * Dumps the list of login details (base paths only)
+ */
+void login_list_dump(void) {
+
+ struct login *nli;
+
+ for (nli = loginlist->next; nli != loginlist; nli = nli->next) {
+ LOG(("%s", nli->host));
+ }
+}