summaryrefslogtreecommitdiff
path: root/content/fetchers
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@netsurf-browser.org>2010-03-28 12:56:39 +0000
committerDaniel Silverstone <dsilvers@netsurf-browser.org>2010-03-28 12:56:39 +0000
commit270ef59a98d34fef418fb6cd27e46f3edc912948 (patch)
tree9d363b42d441640e1d2dbff3ba548a2cdf8d67a9 /content/fetchers
parent21da4f5bdf74c6654730c32dfcc1c6b3d24da4b4 (diff)
downloadnetsurf-270ef59a98d34fef418fb6cd27e46f3edc912948.tar.gz
netsurf-270ef59a98d34fef418fb6cd27e46f3edc912948.tar.bz2
Merge jmb/new-cache; r=dsilvers,rs=vince
svn path=/trunk/netsurf/; revision=10180
Diffstat (limited to 'content/fetchers')
-rw-r--r--content/fetchers/fetch_curl.c110
-rw-r--r--content/fetchers/fetch_data.c32
2 files changed, 75 insertions, 67 deletions
diff --git a/content/fetchers/fetch_curl.c b/content/fetchers/fetch_curl.c
index ca2d86845..9ac3ad7b3 100644
--- a/content/fetchers/fetch_curl.c
+++ b/content/fetchers/fetch_curl.c
@@ -30,6 +30,7 @@
#include <assert.h>
#include <errno.h>
+#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
@@ -43,7 +44,6 @@
#include "content/urldb.h"
#include "desktop/netsurf.h"
#include "desktop/options.h"
-#include "render/form.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/url.h"
@@ -104,7 +104,7 @@ static bool fetch_curl_initialise(const char *scheme);
static void fetch_curl_finalise(const char *scheme);
static void * fetch_curl_setup(struct fetch *parent_fetch, const char *url,
bool only_2xx, const char *post_urlenc,
- struct form_successful_control *post_multipart,
+ struct fetch_multipart_data *post_multipart,
const char **headers);
static bool fetch_curl_start(void *vfetch);
static bool fetch_curl_initiate_fetch(struct curl_fetch_info *fetch,
@@ -132,7 +132,7 @@ static size_t fetch_curl_header(char *data, size_t size, size_t nmemb,
void *_f);
static bool fetch_curl_process_headers(struct curl_fetch_info *f);
static struct curl_httppost *fetch_curl_post_convert(
- struct form_successful_control *control);
+ struct fetch_multipart_data *control);
static int fetch_curl_verify_callback(int preverify_ok,
X509_STORE_CTX *x509_ctx);
static int fetch_curl_cert_verify_callback(X509_STORE_CTX *x509_ctx,
@@ -294,7 +294,7 @@ void fetch_curl_finalise(const char *scheme)
void * fetch_curl_setup(struct fetch *parent_fetch, const char *url,
bool only_2xx, const char *post_urlenc,
- struct form_successful_control *post_multipart,
+ struct fetch_multipart_data *post_multipart,
const char **headers)
{
char *host;
@@ -1108,10 +1108,7 @@ size_t fetch_curl_header(char *data, size_t size, size_t nmemb,
bool fetch_curl_process_headers(struct curl_fetch_info *f)
{
long http_code;
- const char *type;
CURLcode code;
- struct stat s;
- char *url_path = 0;
f->had_headers = true;
@@ -1142,7 +1139,7 @@ bool fetch_curl_process_headers(struct curl_fetch_info *f)
/* handle HTTP 401 (Authentication errors) */
if (http_code == 401) {
- fetch_send_callback(FETCH_AUTH, f->fetch_handle, f->realm,0,
+ fetch_send_callback(FETCH_AUTH, f->fetch_handle, f->realm, 0,
FETCH_ERROR_AUTHENTICATION);
return true;
}
@@ -1156,49 +1153,64 @@ bool fetch_curl_process_headers(struct curl_fetch_info *f)
return true;
}
- /* find MIME type from headers or filetype for local files */
- code = curl_easy_getinfo(f->curl_handle, CURLINFO_CONTENT_TYPE, &type);
- assert(code == CURLE_OK);
-
- if (strncmp(f->url, "file:///", 8) == 0)
- url_path = curl_unescape(f->url + 7,
- (int) strlen(f->url) - 7);
-
- if (url_path && stat(url_path, &s) == 0) {
- /* file: URL and file exists */
- /* create etag */
- char etag_buf[20];
- snprintf(etag_buf, sizeof etag_buf,
- "ETag: \"%10d\"", (int) s.st_mtime);
- /* And send it to the header handler */
- fetch_send_callback(FETCH_HEADER, f->fetch_handle, etag_buf,
- strlen(etag_buf), FETCH_ERROR_NO_ERROR);
-
- /* don't set last modified time so as to ensure that local
- * files are revalidated at all times. */
-
- /* If performed a conditional request and unmodified ... */
- if (f->last_modified && f->file_etag &&
- f->last_modified > s.st_mtime &&
- f->file_etag == s.st_mtime) {
- fetch_send_callback(FETCH_NOTMODIFIED, f->fetch_handle,
- 0, 0, FETCH_ERROR_NO_ERROR);
- curl_free(url_path);
- return true;
- }
- }
-
- if (type == 0) {
- type = "text/plain";
- if (url_path) {
+ /* find MIME type from filetype for local files */
+ if (strncmp(f->url, "file:///", 8) == 0) {
+ struct stat s;
+ char *url_path = curl_unescape(f->url + 7,
+ (int) strlen(f->url + 7));
+
+ if (url_path != NULL && stat(url_path, &s) == 0) {
+ /* file: URL and file exists */
+ char header[64];
+ const char *type;
+
+ /* create etag */
+ snprintf(header, sizeof header,
+ "ETag: \"%10" PRId64 "\"",
+ (int64_t) s.st_mtime);
+ /* And send it to the header handler */
+ fetch_send_callback(FETCH_HEADER, f->fetch_handle,
+ header, strlen(header),
+ FETCH_ERROR_NO_ERROR);
+
+ /* create Content-Type */
type = fetch_filetype(url_path);
+ snprintf(header, sizeof header,
+ "Content-Type: %s", type);
+ /* Send it to the header handler */
+ fetch_send_callback(FETCH_HEADER, f->fetch_handle,
+ header, strlen(header),
+ FETCH_ERROR_NO_ERROR);
+
+ /* create Content-Length */
+ type = fetch_filetype(url_path);
+ snprintf(header, sizeof header,
+ "Content-Length: %" PRId64,
+ (int64_t) s.st_size);
+ /* Send it to the header handler */
+ fetch_send_callback(FETCH_HEADER, f->fetch_handle,
+ header, strlen(header),
+ FETCH_ERROR_NO_ERROR);
+
+ /* don't set last modified time so as to ensure that
+ * local files are revalidated at all times. */
+
+ /* Report not modified, if appropriate */
+ if (f->last_modified && f->file_etag &&
+ f->last_modified > s.st_mtime &&
+ f->file_etag == s.st_mtime) {
+ fetch_send_callback(FETCH_NOTMODIFIED,
+ f->fetch_handle, 0, 0,
+ FETCH_ERROR_NO_ERROR);
+ curl_free(url_path);
+ return true;
+ }
}
- }
- curl_free(url_path);
+ if (url_path != NULL)
+ curl_free(url_path);
+ }
- LOG(("FETCH_TYPE, '%s'", type));
- fetch_send_callback(FETCH_TYPE, f->fetch_handle, type, f->content_length, FETCH_ERROR_NO_ERROR);
if (f->abort)
return true;
@@ -1207,11 +1219,11 @@ bool fetch_curl_process_headers(struct curl_fetch_info *f)
/**
- * Convert a list of struct ::form_successful_control to a list of
+ * Convert a list of struct ::fetch_multipart_data to a list of
* struct curl_httppost for libcurl.
*/
struct curl_httppost *
-fetch_curl_post_convert(struct form_successful_control *control)
+fetch_curl_post_convert(struct fetch_multipart_data *control)
{
struct curl_httppost *post = 0, *last = 0;
CURLFORMcode code;
diff --git a/content/fetchers/fetch_data.c b/content/fetchers/fetch_data.c
index f2a90c50d..1790de56f 100644
--- a/content/fetchers/fetch_data.c
+++ b/content/fetchers/fetch_data.c
@@ -35,7 +35,6 @@
#include "content/urldb.h"
#include "desktop/netsurf.h"
#include "desktop/options.h"
-#include "render/form.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/url.h"
@@ -78,7 +77,7 @@ static void fetch_data_finalise(const char *scheme)
static void *fetch_data_setup(struct fetch *parent_fetch, const char *url,
bool only_2xx, const char *post_urlenc,
- struct form_successful_control *post_multipart,
+ struct fetch_multipart_data *post_multipart,
const char **headers)
{
struct fetch_data_context *ctx = calloc(1, sizeof(*ctx));
@@ -232,20 +231,9 @@ static bool fetch_data_process(struct fetch_data_context *c)
static void fetch_data_poll(const char *scheme)
{
struct fetch_data_context *c, *next;
- struct cache_data cachedata;
if (ring == NULL) return;
- cachedata.req_time = time(NULL);
- cachedata.res_time = time(NULL);
- cachedata.date = 0;
- cachedata.expires = 0;
- cachedata.age = INVALID_AGE;
- cachedata.max_age = 0;
- cachedata.no_cache = true;
- cachedata.etag = NULL;
- cachedata.last_modified = 0;
-
/* Iterate over ring, processing each pending fetch */
c = ring;
do {
@@ -265,6 +253,8 @@ static void fetch_data_poll(const char *scheme)
/* Only process non-aborted fetches */
if (!c->aborted && fetch_data_process(c) == true) {
+ char header[64];
+
fetch_set_http_code(c->parent_fetch, 200);
LOG(("setting data: MIME type to %s, length to %zd",
c->mimetype, c->datalen));
@@ -272,9 +262,16 @@ static void fetch_data_poll(const char *scheme)
* Therefore, we _must_ check for this after _every_
* call to fetch_data_send_callback().
*/
- fetch_data_send_callback(FETCH_TYPE,
- c, c->mimetype, c->datalen,
- FETCH_ERROR_NO_ERROR);
+ snprintf(header, sizeof header, "Content-Type: %s",
+ c->mimetype);
+ fetch_data_send_callback(FETCH_HEADER, c, header,
+ strlen(header), FETCH_ERROR_NO_ERROR);
+
+ snprintf(header, sizeof header, "Content-Length: %zd",
+ c->datalen);
+ fetch_data_send_callback(FETCH_HEADER, c, header,
+ strlen(header), FETCH_ERROR_NO_ERROR);
+
if (!c->aborted) {
fetch_data_send_callback(FETCH_DATA,
c, c->data, c->datalen,
@@ -282,8 +279,7 @@ static void fetch_data_poll(const char *scheme)
}
if (!c->aborted) {
fetch_data_send_callback(FETCH_FINISHED,
- c, &cachedata, 0,
- FETCH_ERROR_NO_ERROR);
+ c, 0, 0, FETCH_ERROR_NO_ERROR);
}
} else {
LOG(("Processing of %s failed!", c->url));