]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/import/pull-job.h
tree-wide: drop space between variable and an increment/decrement
[thirdparty/systemd.git] / src / import / pull-job.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
56ebfaf1
LP
2#pragma once
3
c40d82ab 4#include <sys/stat.h>
56ebfaf1 5
56ebfaf1 6#include "curl-util.h"
3e2cda69 7#include "import-compress.h"
71d35b6b 8#include "macro.h"
6214d42b 9#include "openssl-util.h"
c40d82ab 10#include "pull-common.h"
56ebfaf1 11
dc2c282b
LP
12typedef struct PullJob PullJob;
13
14typedef void (*PullJobFinished)(PullJob *job);
15typedef int (*PullJobOpenDisk)(PullJob *job);
16typedef int (*PullJobHeader)(PullJob *job, const char *header, size_t sz);
17typedef void (*PullJobProgress)(PullJob *job);
f14717a7 18typedef int (*PullJobNotFound)(PullJob *job, char **ret_new_url);
dc2c282b
LP
19
20typedef enum PullJobState {
21 PULL_JOB_INIT,
22 PULL_JOB_ANALYZING, /* Still reading into ->payload, to figure out what we have */
7d41de2e 23 PULL_JOB_RUNNING, /* Writing to destination */
dc2c282b
LP
24 PULL_JOB_DONE,
25 PULL_JOB_FAILED,
26 _PULL_JOB_STATE_MAX,
2d93c20e 27 _PULL_JOB_STATE_INVALID = -EINVAL,
dc2c282b
LP
28} PullJobState;
29
9854730b 30#define PULL_JOB_IS_COMPLETE(j) (IN_SET((j)->state, PULL_JOB_DONE, PULL_JOB_FAILED))
dc2c282b 31
dc2c282b
LP
32struct PullJob {
33 PullJobState state;
56ebfaf1
LP
34 int error;
35
36 char *url;
37
38 void *userdata;
dc2c282b
LP
39 PullJobFinished on_finished;
40 PullJobOpenDisk on_open_disk;
41 PullJobHeader on_header;
42 PullJobProgress on_progress;
f14717a7 43 PullJobNotFound on_not_found;
56ebfaf1
LP
44
45 CurlGlue *glue;
46 CURL *curl;
47 struct curl_slist *request_header;
48
49 char *etag;
50 char **old_etags;
85dbc41d 51 bool etag_exists;
56ebfaf1
LP
52
53 uint64_t content_length;
54 uint64_t written_compressed;
55 uint64_t written_uncompressed;
c40d82ab 56 uint64_t offset;
56ebfaf1
LP
57
58 uint64_t uncompressed_max;
59 uint64_t compressed_max;
60
61 uint8_t *payload;
62 size_t payload_size;
56ebfaf1
LP
63
64 int disk_fd;
c40d82ab
LP
65 bool close_disk_fd;
66 struct stat disk_stat;
56ebfaf1
LP
67
68 usec_t mtime;
69
3e2cda69 70 ImportCompress compress;
56ebfaf1
LP
71
72 unsigned progress_percent;
73 usec_t start_usec;
74 usec_t last_status_usec;
75
98c38001 76 bool calc_checksum;
6214d42b 77 hash_context_t checksum_ctx;
85dbc41d 78
98c38001 79 char *checksum;
c40d82ab
LP
80 bool sync;
81 bool force_memory;
56ebfaf1
LP
82};
83
dc2c282b
LP
84int pull_job_new(PullJob **job, const char *url, CurlGlue *glue, void *userdata);
85PullJob* pull_job_unref(PullJob *job);
56ebfaf1 86
dc2c282b 87int pull_job_begin(PullJob *j);
56ebfaf1 88
dc2c282b 89void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result);
98c38001 90
c40d82ab
LP
91void pull_job_close_disk_fd(PullJob *j);
92
dc2c282b 93DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref);