]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/import/pull-job.h
8e416d51badc4bf8ec0a863c45f03c55494f612b
[thirdparty/systemd.git] / src / import / pull-job.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
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 typedef int (*PullJobNotFound)(PullJob *job, char **ret_new_url);
17
18 typedef enum PullJobState {
19 PULL_JOB_INIT,
20 PULL_JOB_ANALYZING, /* Still reading into ->payload, to figure out what we have */
21 PULL_JOB_RUNNING, /* Writing to destination */
22 PULL_JOB_DONE,
23 PULL_JOB_FAILED,
24 _PULL_JOB_STATE_MAX,
25 _PULL_JOB_STATE_INVALID = -EINVAL,
26 } PullJobState;
27
28 #define PULL_JOB_IS_COMPLETE(j) (IN_SET((j)->state, PULL_JOB_DONE, PULL_JOB_FAILED))
29
30 struct PullJob {
31 PullJobState state;
32 int error;
33
34 char *url;
35
36 void *userdata;
37 PullJobFinished on_finished;
38 PullJobOpenDisk on_open_disk;
39 PullJobHeader on_header;
40 PullJobProgress on_progress;
41 PullJobNotFound on_not_found;
42
43 CurlGlue *glue;
44 CURL *curl;
45 struct curl_slist *request_header;
46
47 char *etag;
48 char **old_etags;
49 bool etag_exists;
50
51 uint64_t content_length;
52 uint64_t written_compressed;
53 uint64_t written_uncompressed;
54
55 uint64_t uncompressed_max;
56 uint64_t compressed_max;
57
58 uint8_t *payload;
59 size_t payload_size;
60 size_t payload_allocated;
61
62 int disk_fd;
63
64 usec_t mtime;
65
66 ImportCompress compress;
67
68 unsigned progress_percent;
69 usec_t start_usec;
70 usec_t last_status_usec;
71
72 bool allow_sparse;
73
74 bool calc_checksum;
75 gcry_md_hd_t checksum_context;
76
77 char *checksum;
78 };
79
80 int pull_job_new(PullJob **job, const char *url, CurlGlue *glue, void *userdata);
81 PullJob* pull_job_unref(PullJob *job);
82
83 int pull_job_begin(PullJob *j);
84
85 void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result);
86
87 DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref);