| 1 | /* |
| 2 | download.h: one file from dl.ps3.world to disk, streamed, resumable, checked. |
| 3 |
|
| 4 | dest.part holds what's arrived and dest.part.sha the sha256 it's meant to |
| 5 | end with. A download that stops (network, quitting the app, pause) leaves |
| 6 | them, and the next try of the same file asks for the rest with Range. The |
| 7 | finished file is checked against the size and sha256 and only then renamed |
| 8 | to dest; one that doesn't match is deleted. |
| 9 | */ |
| 10 | #ifndef DOWNLOAD_H |
| 11 | #define DOWNLOAD_H |
| 12 |
|
| 13 | enum { DL_WAITING, DL_CHECKING, DL_RUNNING, DL_VERIFYING, DL_DONE, DL_FAILED, DL_CANCELLED, DL_PAUSED }; |
| 14 | enum { ERR_NONE, ERR_NETWORK, ERR_TLS, ERR_NOT_FOUND, ERR_HTTP, ERR_CHECKSUM, ERR_DISK_FULL, ERR_WRITE }; |
| 15 |
|
| 16 | typedef 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 |
|
| 32 | void 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 |
| 35 | int download_error_kind(const char *http_err, int status); |
| 36 |
|
| 37 | #endif |