summaryrefslogtreecommitdiff
path: root/content/hlcache.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2010-04-05 21:35:38 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2010-04-05 21:35:38 +0000
commit2748fe4f6483f8cfb3c4f91a01e8d897b7d1ac47 (patch)
tree0647010a17aee4237d125e42cc8bd726ec0573ae /content/hlcache.c
parent89daef932a9bbc46e276f6d306b0aabf109806f9 (diff)
downloadnetsurf-2748fe4f6483f8cfb3c4f91a01e8d897b7d1ac47.tar.gz
netsurf-2748fe4f6483f8cfb3c4f91a01e8d897b7d1ac47.tar.bz2
Make downloads work again.
svn path=/trunk/netsurf/; revision=10243
Diffstat (limited to 'content/hlcache.c')
-rw-r--r--content/hlcache.c52
1 files changed, 41 insertions, 11 deletions
diff --git a/content/hlcache.c b/content/hlcache.c
index 298fe8151..bbe0cd753 100644
--- a/content/hlcache.c
+++ b/content/hlcache.c
@@ -40,6 +40,8 @@ struct hlcache_retrieval_ctx {
hlcache_handle *handle; /**< High-level handle for object */
+ uint32_t flags; /**< Retrieval flags */
+
const content_type *accepted_types; /**< Accepted types, or NULL */
hlcache_child_context child; /**< Child context */
@@ -67,7 +69,8 @@ static hlcache_entry *hlcache_content_list;
static nserror hlcache_llcache_callback(llcache_handle *handle,
const llcache_event *event, void *pw);
static bool hlcache_type_is_acceptable(llcache_handle *llcache,
- const content_type *accepted_types);
+ const content_type *accepted_types,
+ content_type *computed_type);
static nserror hlcache_find_content(hlcache_retrieval_ctx *ctx);
static void hlcache_content_callback(struct content *c,
content_msg msg, union content_msg_data data, void *pw);
@@ -104,6 +107,7 @@ nserror hlcache_handle_retrieve(const char *url, uint32_t flags,
ctx->child.quirks = child->quirks;
}
+ ctx->flags = flags;
ctx->accepted_types = accepted_types;
ctx->handle->cb = cb;
@@ -227,10 +231,28 @@ nserror hlcache_llcache_callback(llcache_handle *handle,
switch (event->type) {
case LLCACHE_EVENT_HAD_HEADERS:
- if (hlcache_type_is_acceptable(handle, ctx->accepted_types)) {
+ {
+ content_type type;
+
+ if (hlcache_type_is_acceptable(handle,
+ ctx->accepted_types, &type)) {
error = hlcache_find_content(ctx);
if (error != NSERROR_OK)
return error;
+ } else if (type == CONTENT_OTHER &&
+ ctx->flags & HLCACHE_RETRIEVE_MAY_DOWNLOAD) {
+ /* Unknown type, and we can download, so convert */
+ llcache_handle_force_stream(handle);
+
+ if (ctx->handle->cb != NULL) {
+ hlcache_event hlevent;
+
+ hlevent.type = CONTENT_MSG_DOWNLOAD;
+ hlevent.data.download = handle;
+
+ ctx->handle->cb(ctx->handle, &hlevent,
+ ctx->handle->pw);
+ }
} else {
/* Unacceptable type: abort fetch and report error */
llcache_handle_abort(handle);
@@ -249,6 +271,7 @@ nserror hlcache_llcache_callback(llcache_handle *handle,
/* No longer require retrieval context */
free(ctx);
+ }
break;
case LLCACHE_EVENT_HAD_DATA:
/* fall through */
@@ -277,19 +300,18 @@ nserror hlcache_llcache_callback(llcache_handle *handle,
*
* \param llcache Low-level cache object to consider
* \param accepted_types Array of acceptable types, or NULL for any
+ * \param computed_type Pointer to location to receive computed type of object
* \return True if the type is acceptable, false otherwise
*/
bool hlcache_type_is_acceptable(llcache_handle *llcache,
- const content_type *accepted_types)
+ const content_type *accepted_types, content_type *computed_type)
{
const char *content_type_header;
char *mime_type;
http_parameter *params;
content_type type;
nserror error;
-
- if (accepted_types == NULL)
- return true;
+ bool acceptable;
content_type_header =
llcache_handle_get_header(llcache, "Content-Type");
@@ -306,14 +328,22 @@ bool hlcache_type_is_acceptable(llcache_handle *llcache,
free(mime_type);
http_parameter_list_destroy(params);
- while (*accepted_types != CONTENT_UNKNOWN) {
- if (*accepted_types == type)
- break;
+ if (accepted_types == NULL) {
+ acceptable = type != CONTENT_OTHER;
+ } else {
+ while (*accepted_types != CONTENT_UNKNOWN) {
+ if (*accepted_types == type)
+ break;
+
+ accepted_types++;
+ }
- accepted_types++;
+ acceptable = *accepted_types == type;
}
- return *accepted_types == type;
+ *computed_type = type;
+
+ return acceptable;
}
/**