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