NetSurf
Data Structures | Functions
download.c File Reference

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"
Include dependency graph for download.c:

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...
 
nsurldownload_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...
 

Detailed Description

Core download context implementation.

Definition in file download.c.

Function Documentation

◆ download_callback()

static nserror download_callback ( llcache_handle handle,
const llcache_event event,
void *  pw 
)
static

Callback for low-level cache events.

Parameters
handleLow-level cache handle
eventEvent object
pwOur context
Returns
NSERROR_OK on success, appropriate error otherwise
Todo:
Lose ugly cast

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_context_abort()

void download_context_abort ( download_context ctx)

Abort a download fetch.

Parameters
ctxContext 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_context_create()

nserror download_context_create ( struct llcache_handle llcache,
struct gui_window parent 
)

Create a download context.

Parameters
llcacheLow-level cache handle for download
parentParent window, for UI
Returns
NSERROR_OK on success, appropriate error otherwise

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_context_destroy()

void download_context_destroy ( download_context ctx)

Destroy a download context.

Parameters
ctxContext 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_context_get_filename()

const char * download_context_get_filename ( const download_context ctx)

Retrieve the filename for a download.

Parameters
ctxContext to retrieve filename from
Returns
Filename string

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().

Here is the caller graph for this function:

◆ download_context_get_mime_type()

const char * download_context_get_mime_type ( const download_context ctx)

Retrieve the MIME type for a download.

Parameters
ctxContext to retrieve MIME type from
Returns
MIME type string

Definition at line 297 of file download.c.

References gui_download_window::ctx, and download_context::mime_type.

Referenced by download_ro_filetype().

Here is the caller graph for this function:

◆ download_context_get_total_length()

unsigned long long int download_context_get_total_length ( const download_context ctx)

Retrieve total byte length of download.

Parameters
ctxContext to retrieve byte length from
Returns
Total length, in bytes, or 0 if unknown

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().

Here is the caller graph for this function:

◆ download_context_get_url()

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.

Parameters
ctxContext to retrieve URL from
Returns
URL object

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_context_process_headers()

static nserror download_context_process_headers ( download_context ctx)
static

Process fetch headers for a download context.

Extracts MIME type, total length, and creates gui_download_window

Parameters
ctxContext to process
Returns
NSERROR_OK on success, appropriate error otherwise

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_default_filename()

static char * download_default_filename ( nsurl url)
static

Compute a default filename for a download.

Parameters
urlURL of item being fetched
Returns
Default filename, or NULL on memory exhaustion

Definition at line 75 of file download.c.

References NSERROR_OK, nsurl_nice(), and gui_download_window::url.

Referenced by download_context_process_headers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ download_parse_filename()

static char * download_parse_filename ( const char *  filename)
static

Parse a filename parameter value.

Parameters
filenameValue to parse
Returns
Sanitised filename, or NULL on memory exhaustion

Definition at line 57 of file download.c.

References gui_download_window::filename.

Referenced by download_context_process_headers().

Here is the caller graph for this function: