]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/import/pull-job.h
Merge pull request #7388 from keszybz/doc-tweak
[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 typedef enum VerificationStyle {
46 VERIFICATION_STYLE_UNSET,
47 VERIFICATION_PER_FILE, /* SuSE-style ".sha256" files with inline signature */
48 VERIFICATION_PER_DIRECTORY, /* Ubuntu-style SHA256SUM files with detach SHA256SUM.gpg signatures */
49 } VerificationStyle;
50
51 #define PULL_JOB_IS_COMPLETE(j) (IN_SET((j)->state, PULL_JOB_DONE, PULL_JOB_FAILED))
52
53 struct PullJob {
54 PullJobState state;
55 int error;
56
57 char *url;
58
59 void *userdata;
60 PullJobFinished on_finished;
61 PullJobOpenDisk on_open_disk;
62 PullJobHeader on_header;
63 PullJobProgress on_progress;
64
65 CurlGlue *glue;
66 CURL *curl;
67 struct curl_slist *request_header;
68
69 char *etag;
70 char **old_etags;
71 bool etag_exists;
72
73 uint64_t content_length;
74 uint64_t written_compressed;
75 uint64_t written_uncompressed;
76
77 uint64_t uncompressed_max;
78 uint64_t compressed_max;
79
80 uint8_t *payload;
81 size_t payload_size;
82 size_t payload_allocated;
83
84 int disk_fd;
85
86 usec_t mtime;
87
88 ImportCompress compress;
89
90 unsigned progress_percent;
91 usec_t start_usec;
92 usec_t last_status_usec;
93
94 bool allow_sparse;
95
96 bool calc_checksum;
97 gcry_md_hd_t checksum_context;
98
99 char *checksum;
100
101 bool grow_machine_directory;
102 uint64_t written_since_last_grow;
103
104 VerificationStyle style;
105 };
106
107 int pull_job_new(PullJob **job, const char *url, CurlGlue *glue, void *userdata);
108 PullJob* pull_job_unref(PullJob *job);
109
110 int pull_job_begin(PullJob *j);
111
112 void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result);
113
114 DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref);