mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 04:02:34 +03:00
Merge cookies changes into head - unvalidated transactions and a UI
still need implementing. svn path=/trunk/netsurf/; revision=2632
This commit is contained in:
parent
cc226c0293
commit
4f249f9d0a
@ -70,6 +70,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 *cookie_string; /**< Cookie string for this fetch */
|
||||
char *realm; /**< HTTP Auth Realm */
|
||||
char *post_urlenc; /**< Url encoded POST string, or 0. */
|
||||
struct curl_httppost *post_multipart; /**< Multipart post data, or 0. */
|
||||
@ -356,6 +357,7 @@ struct fetch * fetch_start(char *url, char *referer,
|
||||
fetch->host = host;
|
||||
fetch->location = 0;
|
||||
fetch->content_length = 0;
|
||||
fetch->cookie_string = 0;
|
||||
fetch->realm = 0;
|
||||
fetch->post_urlenc = 0;
|
||||
fetch->post_multipart = 0;
|
||||
@ -635,13 +637,9 @@ CURLcode fetch_set_options(struct fetch *f)
|
||||
SETOPT(CURLOPT_HTTPGET, 1L);
|
||||
}
|
||||
if (f->cookies) {
|
||||
if (option_cookie_file)
|
||||
SETOPT(CURLOPT_COOKIEFILE, option_cookie_file);
|
||||
if (option_cookie_jar)
|
||||
SETOPT(CURLOPT_COOKIEJAR, option_cookie_jar);
|
||||
} else {
|
||||
SETOPT(CURLOPT_COOKIEFILE, 0);
|
||||
SETOPT(CURLOPT_COOKIEJAR, 0);
|
||||
f->cookie_string = urldb_get_cookie(f->url, f->referer);
|
||||
if (f->cookie_string)
|
||||
SETOPT(CURLOPT_COOKIE, f->cookie_string);
|
||||
}
|
||||
#ifdef WITH_AUTH
|
||||
if ((auth = urldb_get_auth_details(f->url)) != NULL) {
|
||||
@ -771,6 +769,7 @@ void fetch_free(struct fetch *f)
|
||||
free(f->host);
|
||||
free(f->referer);
|
||||
free(f->location);
|
||||
free(f->cookie_string);
|
||||
free(f->realm);
|
||||
if (f->headers)
|
||||
curl_slist_free_all(f->headers);
|
||||
@ -1175,6 +1174,10 @@ size_t fetch_curl_header(char *data, size_t size, size_t nmemb,
|
||||
f->cachedata.last_modified =
|
||||
curl_getdate(&data[i], NULL);
|
||||
}
|
||||
} else if (11 < size && strncasecmp(data, "Set-Cookie:", 11) == 0) {
|
||||
/* extract Set-Cookie header */
|
||||
SKIP_ST(11);
|
||||
urldb_set_cookie(&data[i], f->url);
|
||||
}
|
||||
|
||||
return size;
|
||||
|
990
content/urldb.c
990
content/urldb.c
File diff suppressed because it is too large
Load Diff
@ -25,6 +25,9 @@ struct url_data {
|
||||
|
||||
struct bitmap;
|
||||
|
||||
/* Initialisation */
|
||||
void urldb_init(void);
|
||||
|
||||
/* Persistence support */
|
||||
void urldb_load(const char *filename);
|
||||
void urldb_save(const char *filename);
|
||||
@ -66,4 +69,10 @@ void urldb_iterate_entries(bool (*callback)(const char *url,
|
||||
/* Debug */
|
||||
void urldb_dump(void);
|
||||
|
||||
/* Cookies */
|
||||
bool urldb_set_cookie(const char *header, const char *url);
|
||||
char *urldb_get_cookie(const char *url, const char *referer);
|
||||
void urldb_load_cookies(const char *filename);
|
||||
void urldb_save_cookies(const char *filename);
|
||||
|
||||
#endif
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "netsurf/utils/config.h"
|
||||
#include "netsurf/content/fetch.h"
|
||||
#include "netsurf/content/fetchcache.h"
|
||||
#include "netsurf/content/urldb.h"
|
||||
#include "netsurf/desktop/netsurf.h"
|
||||
#include "netsurf/desktop/browser.h"
|
||||
#include "netsurf/desktop/gui.h"
|
||||
@ -77,6 +78,7 @@ void netsurf_init(int argc, char** argv)
|
||||
|
||||
lib_init();
|
||||
url_init();
|
||||
urldb_init();
|
||||
gui_init(argc, argv);
|
||||
setlocale(LC_ALL, "");
|
||||
fetch_init();
|
||||
|
@ -367,6 +367,7 @@ void gui_init(int argc, char** argv)
|
||||
|
||||
bitmap_initialise_memory();
|
||||
urldb_load(option_url_path);
|
||||
urldb_load_cookies(option_cookie_file);
|
||||
|
||||
nsdir_temp = getenv("NetSurf$Dir");
|
||||
if (!nsdir_temp)
|
||||
@ -724,6 +725,7 @@ void gui_init2(int argc, char** argv)
|
||||
void gui_quit(void)
|
||||
{
|
||||
bitmap_quit();
|
||||
urldb_save_cookies(option_cookie_jar);
|
||||
urldb_save(option_url_save);
|
||||
ro_gui_window_quit();
|
||||
ro_gui_global_history_save();
|
||||
|
52
utils/url.c
52
utils/url.c
@ -676,6 +676,58 @@ url_func_result url_plq(const char *url, char **result)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract path segment from an URL
|
||||
*
|
||||
* \param url an absolute URL
|
||||
* \param result pointer to pointer to buffer to hold result
|
||||
* \return URL_FUNC_OK on success
|
||||
*/
|
||||
|
||||
url_func_result url_path(const char *url, char **result)
|
||||
{
|
||||
int m, path_len = 0;
|
||||
regmatch_t match[10];
|
||||
|
||||
(*result) = 0;
|
||||
|
||||
m = regexec(&url_re, url, 10, match, 0);
|
||||
if (m) {
|
||||
LOG(("url '%s' failed to match regex", url));
|
||||
return URL_FUNC_FAILED;
|
||||
}
|
||||
if (match[URL_RE_SCHEME].rm_so == -1 ||
|
||||
match[URL_RE_AUTHORITY].rm_so == -1)
|
||||
return URL_FUNC_FAILED;
|
||||
|
||||
if (match[URL_RE_PATH].rm_so != -1)
|
||||
path_len = match[URL_RE_PATH].rm_eo -
|
||||
match[URL_RE_PATH].rm_so;
|
||||
|
||||
(*result) = malloc((path_len ? path_len : 1) + 1);
|
||||
if (!(*result)) {
|
||||
LOG(("malloc failed"));
|
||||
return URL_FUNC_NOMEM;
|
||||
}
|
||||
|
||||
m = 0;
|
||||
if (path_len > 1) {
|
||||
strncpy((*result), url + match[URL_RE_PATH].rm_so,
|
||||
path_len);
|
||||
for (; path_len != 0 && (*result)[m + path_len - 1] != '/';
|
||||
path_len--)
|
||||
/* do nothing */;
|
||||
m += path_len;
|
||||
}
|
||||
else
|
||||
(*result)[m++] = '/';
|
||||
|
||||
(*result)[m] = '\0';
|
||||
|
||||
return URL_FUNC_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to find a nice filename for a URL.
|
||||
*
|
||||
|
@ -30,6 +30,7 @@ url_func_result url_escape(const char *unescaped, char **result);
|
||||
url_func_result url_canonical_root(const char *url, char **result);
|
||||
url_func_result url_strip_lqf(const char *url, char **result);
|
||||
url_func_result url_plq(const char *url, char **result);
|
||||
url_func_result url_path(const char *url, char **result);
|
||||
|
||||
char *path_to_url(const char *path);
|
||||
char *url_to_path(const char *url);
|
||||
|
Loading…
Reference in New Issue
Block a user