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