mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-03 17:54:33 +03:00
[project @ 2004-06-22 17:37:51 by bursa]
Fix aborting of fetches. svn path=/import/netsurf/; revision=990
This commit is contained in:
parent
1fa1786d83
commit
fdaf72417a
@ -376,7 +376,8 @@ void content_set_status(struct content *c, const char *status_message, ...)
|
|||||||
* possibly reported
|
* possibly reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool content_process_data(struct content *c, char *data, unsigned int size)
|
bool content_process_data(struct content *c, const char *data,
|
||||||
|
unsigned int size)
|
||||||
{
|
{
|
||||||
char *source_data;
|
char *source_data;
|
||||||
union content_msg_data msg_data;
|
union content_msg_data msg_data;
|
||||||
@ -400,7 +401,8 @@ bool content_process_data(struct content *c, char *data, unsigned int size)
|
|||||||
c->size += size;
|
c->size += size;
|
||||||
|
|
||||||
if (handler_map[c->type].process_data) {
|
if (handler_map[c->type].process_data) {
|
||||||
if (!handler_map[c->type].process_data(c, data, size)) {
|
if (!handler_map[c->type].process_data(c,
|
||||||
|
source_data + c->source_size - size, size)) {
|
||||||
c->status = CONTENT_STATUS_ERROR;
|
c->status = CONTENT_STATUS_ERROR;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,8 @@ struct content * content_get(const char *url);
|
|||||||
bool content_set_type(struct content *c, content_type type,
|
bool content_set_type(struct content *c, content_type type,
|
||||||
const char *mime_type, const char *params[]);
|
const char *mime_type, const char *params[]);
|
||||||
void content_set_status(struct content *c, const char *status_message, ...);
|
void content_set_status(struct content *c, const char *status_message, ...);
|
||||||
bool content_process_data(struct content *c, char *data, unsigned int size);
|
bool content_process_data(struct content *c, const char *data,
|
||||||
|
unsigned int size);
|
||||||
void content_convert(struct content *c, int width, int height);
|
void content_convert(struct content *c, int width, int height);
|
||||||
void content_reformat(struct content *c, int width, int height);
|
void content_reformat(struct content *c, int width, int height);
|
||||||
void content_clean(void);
|
void content_clean(void);
|
||||||
|
@ -49,11 +49,11 @@ bool fetch_active; /**< Fetches in progress, please call fetch_poll(). */
|
|||||||
/** Information for a single fetch. */
|
/** Information for a single fetch. */
|
||||||
struct fetch {
|
struct fetch {
|
||||||
CURL * curl_handle; /**< cURL handle if being fetched, or 0. */
|
CURL * curl_handle; /**< cURL handle if being fetched, or 0. */
|
||||||
void (*callback)(fetch_msg msg, void *p, char *data, unsigned long size);
|
void (*callback)(fetch_msg msg, void *p, const char *data,
|
||||||
|
unsigned long size);
|
||||||
/**< Callback function. */
|
/**< Callback function. */
|
||||||
bool had_headers; /**< Headers have been processed. */
|
bool had_headers; /**< Headers have been processed. */
|
||||||
int locked; /**< Lock count. */
|
bool abort; /**< Abort requested. */
|
||||||
bool aborting; /**< Abort requested in callback. */
|
|
||||||
bool stopped; /**< Download stopped on purpose. */
|
bool stopped; /**< Download stopped on purpose. */
|
||||||
bool only_2xx; /**< Only HTTP 2xx responses acceptable. */
|
bool only_2xx; /**< Only HTTP 2xx responses acceptable. */
|
||||||
bool cookies; /**< Send & accept cookies. */
|
bool cookies; /**< Send & accept cookies. */
|
||||||
@ -82,9 +82,12 @@ static char fetch_error_buffer[CURL_ERROR_SIZE]; /**< Error buffer for cURL. */
|
|||||||
|
|
||||||
static CURLcode fetch_set_options(struct fetch *f);
|
static CURLcode fetch_set_options(struct fetch *f);
|
||||||
static void fetch_free(struct fetch *f);
|
static void fetch_free(struct fetch *f);
|
||||||
|
static void fetch_stop(struct fetch *f);
|
||||||
static void fetch_done(CURL *curl_handle, CURLcode result);
|
static void fetch_done(CURL *curl_handle, CURLcode result);
|
||||||
static size_t fetch_curl_data(void * data, size_t size, size_t nmemb, struct fetch *f);
|
static size_t fetch_curl_data(void *data, size_t size, size_t nmemb,
|
||||||
static size_t fetch_curl_header(char * data, size_t size, size_t nmemb, struct fetch *f);
|
struct fetch *f);
|
||||||
|
static size_t fetch_curl_header(char *data, size_t size, size_t nmemb,
|
||||||
|
struct fetch *f);
|
||||||
static bool fetch_process_headers(struct fetch *f);
|
static bool fetch_process_headers(struct fetch *f);
|
||||||
#ifdef WITH_POST
|
#ifdef WITH_POST
|
||||||
static struct curl_httppost *fetch_post_convert(struct form_successful_control *control);
|
static struct curl_httppost *fetch_post_convert(struct form_successful_control *control);
|
||||||
@ -208,7 +211,7 @@ void fetch_quit(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
struct fetch * fetch_start(char *url, char *referer,
|
struct fetch * fetch_start(char *url, char *referer,
|
||||||
void (*callback)(fetch_msg msg, void *p, char *data,
|
void (*callback)(fetch_msg msg, void *p, const char *data,
|
||||||
unsigned long size),
|
unsigned long size),
|
||||||
void *p, bool only_2xx, char *post_urlenc,
|
void *p, bool only_2xx, char *post_urlenc,
|
||||||
struct form_successful_control *post_multipart, bool cookies)
|
struct form_successful_control *post_multipart, bool cookies)
|
||||||
@ -232,8 +235,7 @@ struct fetch * fetch_start(char *url, char *referer,
|
|||||||
fetch->curl_handle = 0;
|
fetch->curl_handle = 0;
|
||||||
fetch->callback = callback;
|
fetch->callback = callback;
|
||||||
fetch->had_headers = false;
|
fetch->had_headers = false;
|
||||||
fetch->locked = 0;
|
fetch->abort = false;
|
||||||
fetch->aborting = false;
|
|
||||||
fetch->stopped = false;
|
fetch->stopped = false;
|
||||||
fetch->only_2xx = only_2xx;
|
fetch->only_2xx = only_2xx;
|
||||||
fetch->cookies = cookies;
|
fetch->cookies = cookies;
|
||||||
@ -387,25 +389,31 @@ CURLcode fetch_set_options(struct fetch *f)
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop a fetch.
|
* Abort a fetch.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fetch_abort(struct fetch *f)
|
void fetch_abort(struct fetch *f)
|
||||||
|
{
|
||||||
|
assert(f);
|
||||||
|
LOG(("fetch %p, url '%s'", f, f->url));
|
||||||
|
f->abort = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up a fetch and start any queued fetch for the same host.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void fetch_stop(struct fetch *f)
|
||||||
{
|
{
|
||||||
CURLcode code;
|
CURLcode code;
|
||||||
CURLMcode codem;
|
CURLMcode codem;
|
||||||
struct fetch *fetch;
|
struct fetch *fetch;
|
||||||
struct fetch *next_fetch;
|
struct fetch *next_fetch;
|
||||||
|
|
||||||
assert(f != 0);
|
assert(f);
|
||||||
LOG(("fetch %p, url '%s'", f, f->url));
|
LOG(("fetch %p, url '%s'", f, f->url));
|
||||||
|
|
||||||
if (f->locked) {
|
|
||||||
LOG(("locked: will abort later"));
|
|
||||||
f->aborting = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* remove from list of fetches */
|
/* remove from list of fetches */
|
||||||
if (f->prev == 0)
|
if (f->prev == 0)
|
||||||
fetch_list = f->next;
|
fetch_list = f->next;
|
||||||
@ -446,10 +454,8 @@ void fetch_abort(struct fetch *f)
|
|||||||
} else {
|
} else {
|
||||||
/* destroy all queued fetches for this host */
|
/* destroy all queued fetches for this host */
|
||||||
do {
|
do {
|
||||||
fetch->locked++;
|
|
||||||
fetch->callback(FETCH_ERROR, fetch->p,
|
fetch->callback(FETCH_ERROR, fetch->p,
|
||||||
(char*)messages_get("FetchError"), 0);
|
messages_get("FetchError"), 0);
|
||||||
fetch->locked--;
|
|
||||||
next_fetch = fetch->queue_next;
|
next_fetch = fetch->queue_next;
|
||||||
fetch_free(fetch);
|
fetch_free(fetch);
|
||||||
fetch = next_fetch;
|
fetch = next_fetch;
|
||||||
@ -538,7 +544,7 @@ void fetch_done(CURL *curl_handle, CURLcode result)
|
|||||||
bool error = false;
|
bool error = false;
|
||||||
struct fetch *f;
|
struct fetch *f;
|
||||||
void *p;
|
void *p;
|
||||||
void (*callback)(fetch_msg msg, void *p, char *data,
|
void (*callback)(fetch_msg msg, void *p, const char *data,
|
||||||
unsigned long size);
|
unsigned long size);
|
||||||
CURLcode code;
|
CURLcode code;
|
||||||
|
|
||||||
@ -562,10 +568,10 @@ void fetch_done(CURL *curl_handle, CURLcode result)
|
|||||||
else
|
else
|
||||||
error = true;
|
error = true;
|
||||||
|
|
||||||
/* clean up fetch */
|
/* clean up fetch and start any queued fetch for this host */
|
||||||
fetch_abort(f);
|
fetch_stop(f);
|
||||||
|
|
||||||
/* postponed until after abort so that queue fetches are started */
|
/* postponed until after stop so that queue fetches are started */
|
||||||
if (finished)
|
if (finished)
|
||||||
callback(FETCH_FINISHED, p, 0, 0);
|
callback(FETCH_FINISHED, p, 0, 0);
|
||||||
else if (error)
|
else if (error)
|
||||||
@ -577,14 +583,12 @@ void fetch_done(CURL *curl_handle, CURLcode result)
|
|||||||
* Callback function for cURL.
|
* Callback function for cURL.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
size_t fetch_curl_data(void * data, size_t size, size_t nmemb, struct fetch *f)
|
size_t fetch_curl_data(void *data, size_t size, size_t nmemb,
|
||||||
|
struct fetch *f)
|
||||||
{
|
{
|
||||||
f->locked++;
|
|
||||||
|
|
||||||
LOG(("fetch %p, size %u", f, size * nmemb));
|
LOG(("fetch %p, size %u", f, size * nmemb));
|
||||||
|
|
||||||
if (!f->had_headers && fetch_process_headers(f)) {
|
if (f->abort || (!f->had_headers && fetch_process_headers(f))) {
|
||||||
f->locked--;
|
|
||||||
f->stopped = true;
|
f->stopped = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -592,13 +596,12 @@ size_t fetch_curl_data(void * data, size_t size, size_t nmemb, struct fetch *f)
|
|||||||
/* send data to the caller */
|
/* send data to the caller */
|
||||||
LOG(("FETCH_DATA"));
|
LOG(("FETCH_DATA"));
|
||||||
f->callback(FETCH_DATA, f->p, data, size * nmemb);
|
f->callback(FETCH_DATA, f->p, data, size * nmemb);
|
||||||
if (f->aborting) {
|
|
||||||
f->locked--;
|
if (f->abort) {
|
||||||
f->stopped = true;
|
f->stopped = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
f->locked--;
|
|
||||||
return size * nmemb;
|
return size * nmemb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,7 +610,8 @@ size_t fetch_curl_data(void * data, size_t size, size_t nmemb, struct fetch *f)
|
|||||||
* Callback function for headers.
|
* Callback function for headers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
size_t fetch_curl_header(char * data, size_t size, size_t nmemb, struct fetch *f)
|
size_t fetch_curl_header(char *data, size_t size, size_t nmemb,
|
||||||
|
struct fetch *f)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
size *= nmemb;
|
size *= nmemb;
|
||||||
@ -675,7 +679,6 @@ bool fetch_process_headers(struct fetch *f)
|
|||||||
const char *type;
|
const char *type;
|
||||||
CURLcode code;
|
CURLcode code;
|
||||||
|
|
||||||
f->locked++;
|
|
||||||
f->had_headers = true;
|
f->had_headers = true;
|
||||||
|
|
||||||
code = curl_easy_getinfo(f->curl_handle, CURLINFO_HTTP_CODE, &http_code);
|
code = curl_easy_getinfo(f->curl_handle, CURLINFO_HTTP_CODE, &http_code);
|
||||||
@ -686,7 +689,6 @@ bool fetch_process_headers(struct fetch *f)
|
|||||||
if (300 <= http_code && http_code < 400 && f->location != 0) {
|
if (300 <= http_code && http_code < 400 && f->location != 0) {
|
||||||
LOG(("FETCH_REDIRECT, '%s'", f->location));
|
LOG(("FETCH_REDIRECT, '%s'", f->location));
|
||||||
f->callback(FETCH_REDIRECT, f->p, f->location, 0);
|
f->callback(FETCH_REDIRECT, f->p, f->location, 0);
|
||||||
f->locked--;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -694,7 +696,6 @@ bool fetch_process_headers(struct fetch *f)
|
|||||||
#ifdef WITH_AUTH
|
#ifdef WITH_AUTH
|
||||||
if (http_code == 401) {
|
if (http_code == 401) {
|
||||||
f->callback(FETCH_AUTH, f->p, f->realm,0);
|
f->callback(FETCH_AUTH, f->p, f->realm,0);
|
||||||
f->locked--;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -702,8 +703,7 @@ bool fetch_process_headers(struct fetch *f)
|
|||||||
/* handle HTTP errors (non 2xx response codes) */
|
/* handle HTTP errors (non 2xx response codes) */
|
||||||
if (f->only_2xx && strncmp(f->url, "http", 4) == 0 &&
|
if (f->only_2xx && strncmp(f->url, "http", 4) == 0 &&
|
||||||
(http_code < 200 || 299 < http_code)) {
|
(http_code < 200 || 299 < http_code)) {
|
||||||
f->callback(FETCH_ERROR, f->p, (char*)messages_get("Not2xx"), 0);
|
f->callback(FETCH_ERROR, f->p, messages_get("Not2xx"), 0);
|
||||||
f->locked--;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -727,9 +727,8 @@ bool fetch_process_headers(struct fetch *f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG(("FETCH_TYPE, '%s'", type));
|
LOG(("FETCH_TYPE, '%s'", type));
|
||||||
f->callback(FETCH_TYPE, f->p, (char*)type, f->content_length);
|
f->callback(FETCH_TYPE, f->p, type, f->content_length);
|
||||||
f->locked--;
|
if (f->abort)
|
||||||
if (f->aborting)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -36,7 +36,8 @@ extern bool fetch_active;
|
|||||||
|
|
||||||
void fetch_init(void);
|
void fetch_init(void);
|
||||||
struct fetch * fetch_start(char *url, char *referer,
|
struct fetch * fetch_start(char *url, char *referer,
|
||||||
void (*callback)(fetch_msg msg, void *p, char *data, unsigned long size),
|
void (*callback)(fetch_msg msg, void *p, const char *data,
|
||||||
|
unsigned long size),
|
||||||
void *p, bool only_2xx
|
void *p, bool only_2xx
|
||||||
#ifdef WITH_POST
|
#ifdef WITH_POST
|
||||||
, char *post_urlenc,
|
, char *post_urlenc,
|
||||||
|
@ -29,8 +29,9 @@
|
|||||||
|
|
||||||
static char error_page[1000];
|
static char error_page[1000];
|
||||||
static regex_t re_content_type;
|
static regex_t re_content_type;
|
||||||
static void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size);
|
static void fetchcache_callback(fetch_msg msg, void *p, const char *data,
|
||||||
static char *fetchcache_parse_type(char *s, char **params[]);
|
unsigned long size);
|
||||||
|
static char *fetchcache_parse_type(const char *s, char **params[]);
|
||||||
static void fetchcache_error_page(struct content *c, const char *error);
|
static void fetchcache_error_page(struct content *c, const char *error);
|
||||||
|
|
||||||
|
|
||||||
@ -193,7 +194,8 @@ void fetchcache_go(struct content *content, char *referer,
|
|||||||
* This is called when the status of a fetch changes.
|
* This is called when the status of a fetch changes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size)
|
void fetchcache_callback(fetch_msg msg, void *p, const char *data,
|
||||||
|
unsigned long size)
|
||||||
{
|
{
|
||||||
bool res;
|
bool res;
|
||||||
struct content *c = p;
|
struct content *c = p;
|
||||||
@ -317,7 +319,7 @@ void fetchcache_init(void)
|
|||||||
|
|
||||||
#define MAX_ATTRS 10
|
#define MAX_ATTRS 10
|
||||||
|
|
||||||
char *fetchcache_parse_type(char *s, char **params[])
|
char *fetchcache_parse_type(const char *s, char **params[])
|
||||||
{
|
{
|
||||||
char *type;
|
char *type;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
Loading…
Reference in New Issue
Block a user