37 lines1.3 KBC
1/*
2download.h: one file from dl.ps3.world to disk, streamed, resumable, checked.
3
4dest.part holds what's arrived and dest.part.sha the sha256 it's meant to
5end with. A download that stops (network, quitting the app, pause) leaves
6them, and the next try of the same file asks for the rest with Range. The
7finished file is checked against the size and sha256 and only then renamed
8to dest; one that doesn't match is deleted.
9*/
10#ifndef DOWNLOAD_H
11#define DOWNLOAD_H
12
13enum { DL_WAITING, DL_CHECKING, DL_RUNNING, DL_VERIFYING, DL_DONE, DL_FAILED, DL_CANCELLED, DL_PAUSED };
14enum { ERR_NONE, ERR_NETWORK, ERR_TLS, ERR_NOT_FOUND, ERR_HTTP, ERR_CHECKSUM, ERR_DISK_FULL, ERR_WRITE };
15
16typedef struct {
17 // in
18 char url[1024];
19 char dest[512];
20 long long size;
21 unsigned char sha256[32];
22 // set by the UI: cancel deletes what's arrived, pause keeps it for later
23 volatile int cancel, pause;
24 // out (written by the worker; the UI reads them)
25 volatile int state;
26 volatile long long got; // bytes of the file on disk so far (resumed ones included)
27 long long resumed_from; // 0, or where Range started
28 int err_kind;
29 char err[200];
30} download_t;
31
32void download_run(download_t *d); // blocking: on a worker thread
33
34// the reason for a failed request, from http_ps3.c's message and the status
35int download_error_kind(const char *http_err, int status);
36
37#endif