summaryrefslogtreecommitdiff
path: root/content
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 /content
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
Diffstat (limited to 'content')
-rw-r--r--content/fetch.c28
1 files changed, 27 insertions, 1 deletions
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)) {