summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2003-10-23 00:09:17 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2003-10-23 00:09:17 +0000
commitcaac2628a7b3dafd707c385a50d98a3028085b60 (patch)
tree474c5c6b8096d8271cf621266e0a3a2f884249b6
parent9fd638f098b36399e3ca7c90df3c283ab07ed08e (diff)
downloadnetsurf-caac2628a7b3dafd707c385a50d98a3028085b60.tar.gz
netsurf-caac2628a7b3dafd707c385a50d98a3028085b60.tar.bz2
[project @ 2003-10-23 00:09:16 by jmb]
Enable logging into sites which require Basic Authentication Has a couple of issues: 1) Opens the page in the first window in the list 2) Doesn't save the login details so you have to log in to each page. 3) The call to ro_gui_401login_open shouldn't be there. svn path=/import/netsurf/; revision=372
-rw-r--r--!NetSurf/Resources/CSS,f793
-rw-r--r--!NetSurf/Resources/Templates,fecbin3683 -> 4315 bytes
-rw-r--r--content/fetch.c28
-rw-r--r--desktop/401login.h18
-rw-r--r--desktop/browser.c1
-rw-r--r--riscos/401login.c140
-rw-r--r--riscos/dialog.c7
-rw-r--r--riscos/gui.c1
-rw-r--r--riscos/gui.h12
9 files changed, 206 insertions, 4 deletions
diff --git a/!NetSurf/Resources/CSS,f79 b/!NetSurf/Resources/CSS,f79
index d345a2106..54f2067e1 100644
--- a/!NetSurf/Resources/CSS,f79
+++ b/!NetSurf/Resources/CSS,f79
@@ -36,7 +36,8 @@ hr { background-color: #000; height: 1px; }
center { text-align: center; }
small { font-size: smaller; }
big { font-size: larger; }
-select, input { background-color: #eeb; color: #000; width: 10em; height: 2em; }
+select, input { background-color: #eeb; color: #000; width: 10em; height: 2em;
+ text-align: left;}
textarea { background-color: #eeb; color: #000; text-align: left; }
input[type=button], input[type=image], input[type=reset], input[type=submit],
button { background-color: #ddd; color: #000; width: auto;
diff --git a/!NetSurf/Resources/Templates,fec b/!NetSurf/Resources/Templates,fec
index f23c7fa19..8b43f7bb1 100644
--- a/!NetSurf/Resources/Templates,fec
+++ b/!NetSurf/Resources/Templates,fec
Binary files differ
diff --git a/content/fetch.c b/content/fetch.c
index 2823d6dfa..88b451523 100644
--- a/content/fetch.c
+++ b/content/fetch.c
@@ -28,6 +28,7 @@
#include "netsurf/desktop/gui.h"
#endif
#include "netsurf/desktop/options.h"
+#include "netsurf/desktop/401login.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/messages.h"
#include "netsurf/utils/utils.h"
@@ -50,6 +51,7 @@ struct fetch {
char *host; /**< Host part of URL. */
char *location; /**< Response Location header, or 0. */
unsigned long content_length; /**< Response Content-Length, or 0. */
+ char *realm; /**< HTTP Auth Realm */
struct fetch *queue; /**< Next fetch for this host. */
struct fetch *prev; /**< Previous active fetch in ::fetch_list. */
struct fetch *next; /**< Next active fetch in ::fetch_list. */
@@ -251,6 +253,14 @@ struct fetch * fetch_start(char *url, char *referer,
assert(code == CURLE_OK);
}
+ /* HTTP auth */
+ code = curl_easy_setopt(fetch->curl_handle, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
+ assert(code == CURLE_OK);
+
+ if (LOGIN.string != NULL) {
+ code = curl_easy_setopt(fetch->curl_handle, CURLOPT_USERPWD, LOGIN.string);
+ assert(code == CURLE_OK);
+ }
/* add to the global curl multi handle */
codem = curl_multi_add_handle(curl_multi, fetch->curl_handle);
@@ -335,6 +345,7 @@ void fetch_abort(struct fetch *f)
free(f->host);
free(f->referer);
free(f->location);
+ free(f->realm);
xfree(f);
}
@@ -455,6 +466,12 @@ size_t fetch_curl_header(char * data, size_t size, size_t nmemb, struct fetch *f
;
if ('0' <= data[i] && data[i] <= '9')
f->content_length = atol(data + i);
+ } else if (16 < size && strncasecmp(data, "WWW-Authenticate",16) == 0) {
+ /* extract Realm from WWW-Authenticate header */
+ f->realm = xcalloc(size, 1);
+ for (i=16;i!=strlen(data);i++)
+ if(data[i]=='=')break;
+ strncpy(f->realm, data+i+2, size-i-5);
}
return size;
}
@@ -475,7 +492,7 @@ bool fetch_process_headers(struct fetch *f)
f->had_headers = true;
code = curl_easy_getinfo(f->curl_handle, CURLINFO_HTTP_CODE, &http_code);
- assert(code == CURLE_OK);
+ assert(code == CURLE_OK);
LOG(("HTTP status code %li", http_code));
/* handle HTTP redirects (3xx response codes) */
@@ -485,6 +502,15 @@ bool fetch_process_headers(struct fetch *f)
return true;
}
+ /* handle HTTP 401 (Authentication errors) */
+ if (http_code == 401) {
+ /* this shouldn't be here... */
+ ro_gui_401login_open(xstrdup(f->host), xstrdup(f->realm),
+ xstrdup(f->url));
+ f->callback(FETCH_ERROR, f->p, "",0);
+ return true;
+ }
+
/* handle HTTP errors (non 2xx response codes) */
if (f->only_2xx && strncmp(f->url, "http", 4) == 0 &&
(http_code < 200 || 299 < http_code)) {
diff --git a/desktop/401login.h b/desktop/401login.h
new file mode 100644
index 000000000..f9a999ebd
--- /dev/null
+++ b/desktop/401login.h
@@ -0,0 +1,18 @@
+/*
+ * 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>
+ */
+
+#ifndef NETSURF_DESKTOP_401LOGIN_H
+#define NETSURF_DESKTOP_401LOGIN_H
+
+struct login {
+
+ char *string;
+};
+
+extern struct login LOGIN;
+
+#endif
diff --git a/desktop/browser.c b/desktop/browser.c
index f3b403a80..1eb881f1c 100644
--- a/desktop/browser.c
+++ b/desktop/browser.c
@@ -363,6 +363,7 @@ 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);
diff --git a/riscos/401login.c b/riscos/401login.c
new file mode 100644
index 000000000..0ab0ffbea
--- /dev/null
+++ b/riscos/401login.c
@@ -0,0 +1,140 @@
+/*
+ * 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 "oslib/wimp.h"
+#include "netsurf/desktop/401login.h"
+#include "netsurf/desktop/gui.h"
+#include "netsurf/riscos/gui.h"
+#include "netsurf/utils/log.h"
+#include "netsurf/utils/messages.h"
+#include "netsurf/utils/utils.h"
+
+static void get_unamepwd(void);
+static void do_thing(void);
+
+static wimp_window *dialog_401;
+extern wimp_w dialog_401li;
+
+struct login LOGIN;
+
+static char *uname;
+static char* url;
+static char *pwd;
+
+/**
+ * Load the 401 login window template.
+ */
+
+void ro_gui_401login_init(void)
+{
+ char name[] = "dialog_401li";
+ int context, window_size, data_size;
+ char *data;
+
+ /* find required buffer sizes */
+ context = wimp_load_template(wimp_GET_SIZE, 0, 0, wimp_NO_FONTS,
+ name, 0, &window_size, &data_size);
+ assert(context != 0);
+
+ dialog_401 = xcalloc((unsigned int) window_size, 1);
+ data = xcalloc((unsigned int) data_size, 1);
+
+ /* load */
+ wimp_load_template(dialog_401, data, data + data_size,
+ wimp_NO_FONTS, name, 0, 0, 0);
+}
+
+/**
+ * Open a 401 login window.
+ */
+
+void ro_gui_401login_open(char *host, char* realm, char *fetchurl)
+{
+ url = xstrdup(fetchurl);
+ uname = xstrdup("");
+ pwd = xstrdup("");
+
+ /* fill in download window icons */
+ dialog_401->icons[ICON_401LOGIN_HOST].data.indirected_text.text =
+ host;
+ dialog_401->icons[ICON_401LOGIN_HOST].data.indirected_text.size =
+ strlen(host) + 1;
+ dialog_401->icons[ICON_401LOGIN_REALM].data.indirected_text.text =
+ realm;
+ dialog_401->icons[ICON_401LOGIN_REALM].data.indirected_text.size =
+ strlen(realm) + 1;
+ dialog_401->icons[ICON_401LOGIN_USERNAME].data.indirected_text.text =
+ uname;
+ dialog_401->icons[ICON_401LOGIN_PASSWORD].data.indirected_text.text =
+ pwd;
+
+ /* create and open the window */
+ dialog_401li = wimp_create_window(dialog_401);
+ ro_gui_dialog_open(dialog_401li);
+ wimp_set_caret_position(dialog_401li, ICON_401LOGIN_USERNAME,0,0,0,0);
+}
+
+/* Login Clicked -> create a new fetch request, specifying uname & pwd
+ * CURLOPT_USERPWD takes a string "username:password"
+ */
+void ro_gui_401login_click(wimp_pointer *pointer) {
+
+ if (pointer->buttons == wimp_CLICK_MENU) return;
+
+ switch (pointer->i) {
+ case ICON_401LOGIN_LOGIN:
+ if (pointer->buttons == wimp_CLICK_SELECT) {
+ LOG(("here"));
+ get_unamepwd();
+ ro_gui_dialog_close(dialog_401li);
+ do_thing();
+ LOGIN.string = 0; /* TODO: keep the details until we
+ * access a new site */
+ }
+ else
+ ro_gui_dialog_close(dialog_401li);
+ break;
+ case ICON_401LOGIN_CANCEL:
+ if (pointer->buttons == wimp_CLICK_SELECT)
+ ro_gui_dialog_close(dialog_401li);
+ else {
+ get_unamepwd();
+ ro_gui_dialog_close(dialog_401li);
+ do_thing();
+ LOGIN.string = 0; /* TODO: keep the details until we
+ * access a new site */
+ }
+ break;
+ default: break;
+ }
+}
+
+void get_unamepwd() {
+
+ LOGIN.string = xcalloc(strlen(uname)+strlen(pwd)+2, sizeof(char));
+
+ sprintf(LOGIN.string, "%s:%s", uname, pwd);
+ LOG(("%s", LOGIN.string));
+}
+
+void do_thing() {
+
+ struct gui_window *gw;
+
+ /* TODO: fix this. For now we just open the page in the
+ * first window in the list. */
+ for (gw=window_list; gw!=NULL; gw=gw->next) {
+ if (gw->type == GUI_BROWSER_WINDOW /*&&
+ (strcasecmp(gw->url, url)==0 ||
+ strcasecmp(gw->data.browser.bw->url, url)==0)*/)
+ break;
+ }
+ if (gw != NULL)
+ browser_window_open_location_historical(gw->data.browser.bw, url);
+}
diff --git a/riscos/dialog.c b/riscos/dialog.c
index f8df58bb0..5dd170dc6 100644
--- a/riscos/dialog.c
+++ b/riscos/dialog.c
@@ -25,7 +25,8 @@
wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br,
- dialog_config_prox, dialog_config_th, download_template;
+ dialog_config_prox, dialog_config_th, download_template,
+ dialog_401li;
wimp_menu* theme_menu = NULL;
static struct ro_choices choices;
@@ -121,7 +122,7 @@ void ro_gui_dialog_open(wimp_w w)
screen_x, screen_y, dx, dy;
wimp_window_state open;
- /* find screen centre in os units */
+ /* find screen centre in os units */
os_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XEIG_FACTOR, &xeig_factor);
os_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_YEIG_FACTOR, &yeig_factor);
os_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XWIND_LIMIT, &xwind_limit);
@@ -160,6 +161,8 @@ void ro_gui_dialog_click(wimp_pointer *pointer)
ro_gui_dialog_click_config_prox(pointer);
else if (pointer->w == dialog_config_th)
ro_gui_dialog_click_config_th(pointer);
+ else if (pointer->w == dialog_401li)
+ ro_gui_401login_click(pointer);
}
diff --git a/riscos/gui.c b/riscos/gui.c
index 4fca50964..ca21c4e83 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -609,6 +609,7 @@ void gui_init(int argc, char** argv)
ro_gui_dialog_init();
ro_gui_download_init();
ro_gui_menus_init();
+ ro_gui_401login_init();
wimp_close_template();
}
diff --git a/riscos/gui.h b/riscos/gui.h
index 83cb15a2a..3ad54ed0a 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -120,6 +120,11 @@ void ro_gui_start_selection(wimp_pointer *pointer, wimp_window_state *state,
gui_window *g);
void ro_gui_drag_end(wimp_dragged* drag);
+/* in 401login.c */
+void ro_gui_401login_init(void);
+void ro_gui_401login_open(char* host, char * realm, char* fetchurl);
+void ro_gui_401login_click(wimp_pointer *pointer);
+
/* icon numbers */
#define ICON_CONFIG_SAVE 0
#define ICON_CONFIG_CANCEL 1
@@ -159,4 +164,11 @@ void ro_gui_drag_end(wimp_dragged* drag);
#define ICON_DOWNLOAD_PATH 3
#define ICON_DOWNLOAD_ABORT 4
+#define ICON_401LOGIN_LOGIN 0
+#define ICON_401LOGIN_CANCEL 1
+#define ICON_401LOGIN_HOST 2
+#define ICON_401LOGIN_REALM 3
+#define ICON_401LOGIN_USERNAME 4
+#define ICON_401LOGIN_PASSWORD 5
+
#endif