]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
56ebfaf1 LP |
2 | #pragma once |
3 | ||
4 | /*** | |
56ebfaf1 | 5 | Copyright 2015 Lennart Poettering |
56ebfaf1 LP |
6 | ***/ |
7 | ||
85dbc41d | 8 | #include <gcrypt.h> |
56ebfaf1 | 9 | |
56ebfaf1 | 10 | #include "curl-util.h" |
3e2cda69 | 11 | #include "import-compress.h" |
71d35b6b | 12 | #include "macro.h" |
56ebfaf1 | 13 | |
dc2c282b LP |
14 | typedef struct PullJob PullJob; |
15 | ||
16 | typedef void (*PullJobFinished)(PullJob *job); | |
17 | typedef int (*PullJobOpenDisk)(PullJob *job); | |
18 | typedef int (*PullJobHeader)(PullJob *job, const char *header, size_t sz); | |
19 | typedef void (*PullJobProgress)(PullJob *job); | |
20 | ||
21 | typedef enum PullJobState { | |
22 | PULL_JOB_INIT, | |
23 | PULL_JOB_ANALYZING, /* Still reading into ->payload, to figure out what we have */ | |
24 | PULL_JOB_RUNNING, /* Writing to destination */ | |
25 | PULL_JOB_DONE, | |
26 | PULL_JOB_FAILED, | |
27 | _PULL_JOB_STATE_MAX, | |
28 | _PULL_JOB_STATE_INVALID = -1, | |
29 | } PullJobState; | |
30 | ||
697be0be TB |
31 | typedef enum VerificationStyle { |
32 | VERIFICATION_STYLE_UNSET, | |
33 | VERIFICATION_PER_FILE, /* SuSE-style ".sha256" files with inline signature */ | |
34 | VERIFICATION_PER_DIRECTORY, /* Ubuntu-style SHA256SUM files with detach SHA256SUM.gpg signatures */ | |
35 | } VerificationStyle; | |
36 | ||
9854730b | 37 | #define PULL_JOB_IS_COMPLETE(j) (IN_SET((j)->state, PULL_JOB_DONE, PULL_JOB_FAILED)) |
dc2c282b | 38 | |
dc2c282b LP |
39 | struct PullJob { |
40 | PullJobState state; | |
56ebfaf1 LP |
41 | int error; |
42 | ||
43 | char *url; | |
44 | ||
45 | void *userdata; | |
dc2c282b LP |
46 | PullJobFinished on_finished; |
47 | PullJobOpenDisk on_open_disk; | |
48 | PullJobHeader on_header; | |
49 | PullJobProgress on_progress; | |
56ebfaf1 LP |
50 | |
51 | CurlGlue *glue; | |
52 | CURL *curl; | |
53 | struct curl_slist *request_header; | |
54 | ||
55 | char *etag; | |
56 | char **old_etags; | |
85dbc41d | 57 | bool etag_exists; |
56ebfaf1 LP |
58 | |
59 | uint64_t content_length; | |
60 | uint64_t written_compressed; | |
61 | uint64_t written_uncompressed; | |
62 | ||
63 | uint64_t uncompressed_max; | |
64 | uint64_t compressed_max; | |
65 | ||
66 | uint8_t *payload; | |
67 | size_t payload_size; | |
68 | size_t payload_allocated; | |
69 | ||
70 | int disk_fd; | |
71 | ||
72 | usec_t mtime; | |
73 | ||
3e2cda69 | 74 | ImportCompress compress; |
56ebfaf1 LP |
75 | |
76 | unsigned progress_percent; | |
77 | usec_t start_usec; | |
78 | usec_t last_status_usec; | |
79 | ||
80 | bool allow_sparse; | |
85dbc41d | 81 | |
98c38001 LP |
82 | bool calc_checksum; |
83 | gcry_md_hd_t checksum_context; | |
85dbc41d | 84 | |
98c38001 | 85 | char *checksum; |
26166c88 LP |
86 | |
87 | bool grow_machine_directory; | |
88 | uint64_t written_since_last_grow; | |
697be0be TB |
89 | |
90 | VerificationStyle style; | |
56ebfaf1 LP |
91 | }; |
92 | ||
dc2c282b LP |
93 | int pull_job_new(PullJob **job, const char *url, CurlGlue *glue, void *userdata); |
94 | PullJob* pull_job_unref(PullJob *job); | |
56ebfaf1 | 95 | |
dc2c282b | 96 | int pull_job_begin(PullJob *j); |
56ebfaf1 | 97 | |
dc2c282b | 98 | void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result); |
98c38001 | 99 | |
dc2c282b | 100 | DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref); |