NetSurf
download.c
Go to the documentation of this file.
1/*
2 * Copyright 2011 Daniel Silverstone <dsilvers@digital-scurf.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <stdio.h>
20#include <stdint.h>
21#include <stdlib.h>
22
23#include "utils/errors.h"
24#include "utils/ring.h"
25#include "netsurf/download.h"
26#include "desktop/download.h"
27
28#include "monkey/output.h"
29#include "monkey/browser.h"
30
31static uint32_t dwin_ctr = 0;
32
36 struct gui_window *g;
38 uint32_t dwin_num;
39 char *host; /* ignore */
40};
41
42static struct gui_download_window *dw_ring = NULL;
43
44static struct gui_download_window *
46 struct gui_window *parent)
47{
48 struct gui_download_window *ret = calloc(1, sizeof(*ret));
49 if (ret == NULL)
50 return NULL;
51 ret->g = parent;
52 ret->dwin_num = dwin_ctr++;
53 ret->dlctx = ctx;
54
55 RING_INSERT(dw_ring, ret);
56
57 moutf(MOUT_DOWNLOAD, "CREATE DWIN %u WIN %u",
58 ret->dwin_num, parent->win_num);
59
60 return ret;
61}
62
63static nserror
65 const char *data, unsigned int size)
66{
67 moutf(MOUT_DOWNLOAD, "DATA DWIN %u SIZE %u DATA %s",
68 dw->dwin_num, size, data);
69 return NSERROR_OK;
70}
71
72static void
74 const char *error_msg)
75{
76 moutf(MOUT_DOWNLOAD, "ERROR DWIN %u ERROR %s", dw->dwin_num, error_msg);
77}
78
79static void
81{
82 moutf(MOUT_DOWNLOAD, "DONE DWIN %u", dw->dwin_num);
85 free(dw);
86}
87
93};
94
void download_context_destroy(download_context *ctx)
Destroy a download context.
Definition: download.c:270
Core download context (interface)
wimp_w parent
Definition: dialog.c:88
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
static struct gui_download_table download_table
Definition: download.c:88
static nserror gui_download_window_data(struct gui_download_window *dw, const char *data, unsigned int size)
Definition: download.c:64
static void gui_download_window_error(struct gui_download_window *dw, const char *error_msg)
Definition: download.c:73
struct gui_download_table * monkey_download_table
Definition: download.c:95
static uint32_t dwin_ctr
Definition: download.c:31
static void gui_download_window_done(struct gui_download_window *dw)
Definition: download.c:80
static struct gui_download_window * dw_ring
Definition: download.c:42
static struct gui_download_window * gui_download_window_create(download_context *ctx, struct gui_window *parent)
Definition: download.c:45
Interface to platform-specific download operations.
int moutf(enum monkey_output_type mout_type, const char *fmt,...)
Definition: output.c:39
@ MOUT_DOWNLOAD
Definition: output.h:29
Ring list structure.
#define RING_REMOVE(ring, element)
Remove the given element from the specified ring.
Definition: ring.h:53
#define RING_INSERT(ring, element)
Insert the given item into the specified ring.
Definition: ring.h:40
A context for a download.
Definition: download.c:40
function table for download windows.
Definition: download.h:34
struct gui_download_window *(* create)(struct download_context *ctx, struct gui_window *parent)
Definition: download.h:35
context for each download.
Definition: download.c:91
struct gui_download_window * r_next
Definition: download.c:34
download_context * dlctx
Definition: download.c:37
struct download_context * ctx
Associated context, or 0 if the fetch has completed or aborted.
Definition: download.c:101
uint32_t dwin_num
Definition: download.c:38
struct gui_window * g
Definition: download.c:36
struct gui_download_window * r_prev
Definition: download.c:35
first entry in window list
Definition: gui.c:297