From 230cb5f01fbb9948ce5dd067e87535f9c012779c Mon Sep 17 00:00:00 2001 From: James Bursa Date: Wed, 9 Apr 2003 21:57:09 +0000 Subject: [project @ 2003-04-09 21:57:09 by bursa] Table layout fixes, allowed type list. svn path=/import/netsurf/; revision=119 --- content/content.h | 13 ++++++++++--- content/fetch.c | 31 +++++++++++++++++++++++++++++-- content/fetchcache.c | 28 ++++++++++++++++++---------- content/fetchcache.h | 4 ++-- 4 files changed, 59 insertions(+), 17 deletions(-) (limited to 'content') diff --git a/content/content.h b/content/content.h index ff0dbc6dd..e65f62fb1 100644 --- a/content/content.h +++ b/content/content.h @@ -1,5 +1,5 @@ /** - * $Id: content.h,v 1.5 2003/04/06 18:09:34 bursa Exp $ + * $Id: content.h,v 1.6 2003/04/09 21:57:09 bursa Exp $ */ #ifndef _NETSURF_DESKTOP_CONTENT_H_ @@ -26,8 +26,14 @@ * the content may be removed from the memory cache. */ -typedef enum {CONTENT_HTML, CONTENT_TEXTPLAIN, CONTENT_JPEG, CONTENT_CSS, - CONTENT_PNG, CONTENT_OTHER} content_type; +typedef enum { + CONTENT_HTML, + CONTENT_TEXTPLAIN, + CONTENT_JPEG, + CONTENT_CSS, + CONTENT_PNG, + CONTENT_OTHER +} content_type; struct box_position { @@ -72,6 +78,7 @@ struct content { struct css_stylesheet *css; unsigned int import_count; + char **import_url; struct content **import_content; } css; diff --git a/content/fetch.c b/content/fetch.c index 9314bedeb..d1c3f0e07 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -1,5 +1,5 @@ /** - * $Id: fetch.c,v 1.3 2003/03/15 15:53:20 bursa Exp $ + * $Id: fetch.c,v 1.4 2003/04/09 21:57:09 bursa Exp $ */ #include @@ -21,12 +21,14 @@ struct fetch char *url; char error_buffer[CURL_ERROR_SIZE]; void *p; + struct curl_slist *headers; }; static const char * const user_agent = "NetSurf"; static CURLM * curl_multi; static size_t fetch_curl_data(void * data, size_t size, size_t nmemb, struct fetch *f); +static size_t fetch_curl_header(void *data, size_t size, size_t nmemb, struct fetch *f); /** @@ -102,12 +104,24 @@ struct fetch * fetch_start(char *url, char *referer, assert(code == CURLE_OK); code = curl_easy_setopt(fetch->curl_handle, CURLOPT_WRITEDATA, fetch); assert(code == CURLE_OK); +/* code = curl_easy_setopt(fetch->curl_handle, CURLOPT_HEADERFUNCTION, fetch_curl_header); + assert(code == CURLE_OK); + code = curl_easy_setopt(fetch->curl_handle, CURLOPT_WRITEHEADER, fetch); + assert(code == CURLE_OK);*/ code = curl_easy_setopt(fetch->curl_handle, CURLOPT_USERAGENT, user_agent); assert(code == CURLE_OK); if (referer != 0) { code = curl_easy_setopt(fetch->curl_handle, CURLOPT_REFERER, referer); assert(code == CURLE_OK); - } + } + + /* custom request headers */ + fetch->headers = 0; + /* remove curl default headers */ + fetch->headers = curl_slist_append(fetch->headers, "Accept:"); + fetch->headers = curl_slist_append(fetch->headers, "Pragma:"); + code = curl_easy_setopt(fetch->curl_handle, CURLOPT_HTTPHEADER, fetch->headers); + assert(code == CURLE_OK); /* add to the global curl multi handle */ codem = curl_multi_add_handle(curl_multi, fetch->curl_handle); @@ -138,6 +152,7 @@ void fetch_abort(struct fetch *f) codem = curl_multi_remove_handle(curl_multi, f->curl_handle); assert(codem == CURLM_OK); curl_easy_cleanup(f->curl_handle); + curl_slist_free_all(f->headers); xfree(f->url); xfree(f); @@ -241,6 +256,18 @@ size_t fetch_curl_data(void * data, size_t size, size_t nmemb, struct fetch *f) } +/** + * fetch_curl_header -- callback function for headers + */ + +size_t fetch_curl_header(void *data, size_t size, size_t nmemb, struct fetch *f) +{ + LOG(("header '%*s'", size * nmemb, data)); + return size * nmemb; +} + + + /** * testing framework */ diff --git a/content/fetchcache.c b/content/fetchcache.c index 9adaee544..8aa81f66f 100644 --- a/content/fetchcache.c +++ b/content/fetchcache.c @@ -1,5 +1,5 @@ /** - * $Id: fetchcache.c,v 1.6 2003/04/06 18:09:34 bursa Exp $ + * $Id: fetchcache.c,v 1.7 2003/04/09 21:57:09 bursa Exp $ */ #include @@ -19,6 +19,7 @@ struct fetchcache { struct content *c; unsigned long width, height; unsigned long size; + content_type allowed; }; @@ -29,16 +30,22 @@ static void status_callback(void *p, const char *status); void fetchcache(const char *url, char *referer, void (*callback)(fetchcache_msg msg, struct content *c, void *p, const char *error), - void *p, unsigned long width, unsigned long height) + void *p, unsigned long width, unsigned long height, content_type allowed) { struct content *c; struct fetchcache *fc; c = cache_get(url); if (c != 0) { - callback(FETCHCACHE_STATUS, c, p, "Found in cache"); - content_revive(c, width, height); - callback(FETCHCACHE_OK, c, p, 0); + /* check type is allowed */ + if ((1 << c->type) & allowed) { + callback(FETCHCACHE_STATUS, c, p, "Found in cache"); + content_revive(c, width, height); + callback(FETCHCACHE_OK, c, p, 0); + } else { + callback(FETCHCACHE_BADTYPE, 0, p, ""); + cache_free(c); + } return; } @@ -51,6 +58,7 @@ void fetchcache(const char *url, char *referer, fc->width = width; fc->height = height; fc->size = 0; + fc->allowed = allowed; fc->f = fetch_start(fc->url, referer, fetchcache_callback, fc); } @@ -76,14 +84,14 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size) *semic = 0; /* remove "; charset=..." */ type = content_lookup(mime_type); LOG(("FETCH_TYPE, type %u", type)); - if (type == CONTENT_OTHER) { - fetch_abort(fc->f); - fc->callback(FETCHCACHE_BADTYPE, 0, fc->p, mime_type); - free(fc); - } else { + if ((1 << type) & fc->allowed) { fc->c = content_create(type, fc->url); fc->c->status_callback = status_callback; fc->c->status_p = fc; + } else { + fetch_abort(fc->f); + fc->callback(FETCHCACHE_BADTYPE, 0, fc->p, mime_type); + free(fc); } free(mime_type); break; diff --git a/content/fetchcache.h b/content/fetchcache.h index d8986002a..9241ddf0f 100644 --- a/content/fetchcache.h +++ b/content/fetchcache.h @@ -1,5 +1,5 @@ /** - * $Id: fetchcache.h,v 1.3 2003/03/04 11:59:35 bursa Exp $ + * $Id: fetchcache.h,v 1.4 2003/04/09 21:57:09 bursa Exp $ */ #ifndef _NETSURF_DESKTOP_FETCHCACHE_H_ @@ -11,6 +11,6 @@ typedef enum {FETCHCACHE_OK, FETCHCACHE_BADTYPE, FETCHCACHE_ERROR, FETCHCACHE_ST void fetchcache(const char *url, char *referer, void (*callback)(fetchcache_msg msg, struct content *c, void *p, const char *error), - void *p, unsigned long width, unsigned long height); + void *p, unsigned long width, unsigned long height, content_type allowed); #endif -- cgit v1.2.3