NetSurf
|
Core download context implementation. More...
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "content/llcache.h"
#include "utils/corestrings.h"
#include "utils/http.h"
#include "utils/utils.h"
#include "utils/log.h"
#include "desktop/download.h"
#include "netsurf/download.h"
#include "desktop/gui_internal.h"
Go to the source code of this file.
Data Structures | |
struct | download_context |
A context for a download. More... | |
Functions | |
static char * | download_parse_filename (const char *filename) |
Parse a filename parameter value. More... | |
static char * | download_default_filename (nsurl *url) |
Compute a default filename for a download. More... | |
static nserror | download_context_process_headers (download_context *ctx) |
Process fetch headers for a download context. More... | |
static nserror | download_callback (llcache_handle *handle, const llcache_event *event, void *pw) |
Callback for low-level cache events. More... | |
nserror | download_context_create (llcache_handle *llcache, struct gui_window *parent) |
Create a download context. More... | |
void | download_context_destroy (download_context *ctx) |
Destroy a download context. More... | |
void | download_context_abort (download_context *ctx) |
Abort a download fetch. More... | |
nsurl * | download_context_get_url (const download_context *ctx) |
Retrieve the URL for a download. More... | |
const char * | download_context_get_mime_type (const download_context *ctx) |
Retrieve the MIME type for a download. More... | |
unsigned long long int | download_context_get_total_length (const download_context *ctx) |
Retrieve total byte length of download. More... | |
const char * | download_context_get_filename (const download_context *ctx) |
Retrieve the filename for a download. More... | |
Core download context implementation.
Definition in file download.c.
|
static |
Callback for low-level cache events.
handle | Low-level cache handle |
event | Event object |
pw | Our context |
Definition at line 178 of file download.c.
References llcache_event::buf, gui_download_window::ctx, llcache_event::data, gui_download_table::data, gui_download_table::done, netsurf_table::download, download_context_destroy(), download_context_process_headers(), llcache_event::error, gui_download_window::error, gui_download_table::error, guit, llcache_event::len, LLCACHE_EVENT_DONE, LLCACHE_EVENT_ERROR, LLCACHE_EVENT_GOT_CERTS, LLCACHE_EVENT_HAD_DATA, LLCACHE_EVENT_HAD_HEADERS, LLCACHE_EVENT_PROGRESS, LLCACHE_EVENT_REDIRECT, llcache_handle_abort(), llcache_event::msg, NSERROR_OK, llcache_event::type, and download_context::window.
Referenced by download_context_create().
void download_context_abort | ( | download_context * | ctx | ) |
Abort a download fetch.
ctx | Context to abort |
Called by the frontend to abort a download. The context must be destroyed independently.
Definition at line 285 of file download.c.
References gui_download_window::ctx, download_context::llcache, and llcache_handle_abort().
Referenced by ami_download_window_abort(), gui_download_window_data(), gui_download_window_destroy(), nsgtk_download_store_cancel_item(), ro_gui_download_save(), ro_gui_download_window_destroy(), and NSDownloadWindow::~NSDownloadWindow().
nserror download_context_create | ( | struct llcache_handle * | llcache, |
struct gui_window * | parent | ||
) |
Create a download context.
llcache | Low-level cache handle for download |
parent | Parent window, for UI |
This must only be called by the core browser window fetch infrastructure. Ownership of the download context object created is passed to the frontend.
Definition at line 248 of file download.c.
References gui_download_window::ctx, download_callback(), download_context::filename, llcache, download_context::llcache, llcache_handle_change_callback(), download_context::mime_type, NSERROR_NOMEM, NSERROR_OK, download_context::parent, parent, download_context::total_length, and download_context::window.
Referenced by browser_window_convert_to_download(), and browser_window_download().
void download_context_destroy | ( | download_context * | ctx | ) |
Destroy a download context.
ctx | Context to destroy |
Called by the frontend when it has finished with a download context
Definition at line 270 of file download.c.
References gui_download_window::ctx, download_context::filename, download_context::llcache, llcache_handle_release(), and download_context::mime_type.
Referenced by download_callback(), gui_download_window_destroy(), gui_download_window_done(), gui_download_window_error(), nsgtk_download_store_clear_item(), ro_gui_download_window_destroy(), and NSDownloadWindow::~NSDownloadWindow().
const char * download_context_get_filename | ( | const download_context * | ctx | ) |
Retrieve the filename for a download.
ctx | Context to retrieve filename from |
Definition at line 310 of file download.c.
References gui_download_window::ctx, and download_context::filename.
Referenced by gui_download_window_create(), NSDownloadWindow::NSDownloadWindow(), and nsgtk_download_store_cancel_item().
const char * download_context_get_mime_type | ( | const download_context * | ctx | ) |
Retrieve the MIME type for a download.
ctx | Context to retrieve MIME type from |
Definition at line 297 of file download.c.
References gui_download_window::ctx, and download_context::mime_type.
Referenced by download_ro_filetype().
unsigned long long int download_context_get_total_length | ( | const download_context * | ctx | ) |
Retrieve total byte length of download.
ctx | Context to retrieve byte length from |
Definition at line 304 of file download.c.
References gui_download_window::ctx, and download_context::total_length.
Referenced by gui_download_window_create(), and NSDownloadWindow::NSDownloadWindow().
nsurl * download_context_get_url | ( | const download_context * | ctx | ) |
Retrieve the URL for a download.
The caller is borrowing the url reference from the underlying low level cache object. If it is used beyond the immediate scope of the caller an additional reference should be made.
ctx | Context to retrieve URL from |
Definition at line 291 of file download.c.
References gui_download_window::ctx, download_context::llcache, and llcache_handle_get_url().
Referenced by download_ro_filetype(), and gui_download_window_create().
|
static |
Process fetch headers for a download context.
Extracts MIME type, total length, and creates gui_download_window
ctx | Context to process |
Definition at line 93 of file download.c.
References gui_download_table::create, gui_download_window::ctx, netsurf_table::download, download_default_filename(), download_parse_filename(), gui_download_window::error, download_context::filename, guit, http_content_disposition_destroy(), http_content_type_destroy(), http_parameter_list_find_item(), http_parse_content_disposition(), http_parse_content_type(), download_context::llcache, llcache_handle_get_header(), llcache_handle_get_url(), download_context::mime_type, NSERROR_NOMEM, NSERROR_OK, http_content_disposition::parameters, download_context::parent, strtoull(), download_context::total_length, and download_context::window.
Referenced by download_callback().
|
static |
Compute a default filename for a download.
url | URL of item being fetched |
Definition at line 75 of file download.c.
References NSERROR_OK, nsurl_nice(), and gui_download_window::url.
Referenced by download_context_process_headers().
|
static |
Parse a filename parameter value.
filename | Value to parse |
Definition at line 57 of file download.c.
References gui_download_window::filename.
Referenced by download_context_process_headers().