]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/import/pull-job.h
Merge pull request #3162 from keszybz/alias-refusal
[thirdparty/systemd.git] / src / import / pull-job.h
1 #pragma once
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2015 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <gcrypt.h>
23
24 #include "curl-util.h"
25 #include "import-compress.h"
26 #include "macro.h"
27
28 typedef struct PullJob PullJob;
29
30 typedef void (*PullJobFinished)(PullJob *job);
31 typedef int (*PullJobOpenDisk)(PullJob *job);
32 typedef int (*PullJobHeader)(PullJob *job, const char *header, size_t sz);
33 typedef void (*PullJobProgress)(PullJob *job);
34
35 typedef enum PullJobState {
36 PULL_JOB_INIT,
37 PULL_JOB_ANALYZING, /* Still reading into ->payload, to figure out what we have */
38 PULL_JOB_RUNNING, /* Writing to destination */
39 PULL_JOB_DONE,
40 PULL_JOB_FAILED,
41 _PULL_JOB_STATE_MAX,
42 _PULL_JOB_STATE_INVALID = -1,
43 } PullJobState;
44
45 #define PULL_JOB_IS_COMPLETE(j) (IN_SET((j)->state, PULL_JOB_DONE, PULL_JOB_FAILED))
46
47 struct PullJob {
48 PullJobState state;
49 int error;
50
51 char *url;
52
53 void *userdata;
54 PullJobFinished on_finished;
55 PullJobOpenDisk on_open_disk;
56 PullJobHeader on_header;
57 PullJobProgress on_progress;
58
59 CurlGlue *glue;
60 CURL *curl;
61 struct curl_slist *request_header;
62
63 char *etag;
64 char **old_etags;
65 bool etag_exists;
66
67 uint64_t content_length;
68 uint64_t written_compressed;
69 uint64_t written_uncompressed;
70
71 uint64_t uncompressed_max;
72 uint64_t compressed_max;
73
74 uint8_t *payload;
75 size_t payload_size;
76 size_t payload_allocated;
77
78 int disk_fd;
79
80 usec_t mtime;
81
82 ImportCompress compress;
83
84 unsigned progress_percent;
85 usec_t start_usec;
86 usec_t last_status_usec;
87
88 bool allow_sparse;
89
90 bool calc_checksum;
91 gcry_md_hd_t checksum_context;
92
93 char *checksum;
94
95 bool grow_machine_directory;
96 uint64_t written_since_last_grow;
97 };
98
99 int pull_job_new(PullJob **job, const char *url, CurlGlue *glue, void *userdata);
100 PullJob* pull_job_unref(PullJob *job);
101
102 int pull_job_begin(PullJob *j);
103
104 void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result);
105
106 DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref);