]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
56ebfaf1 LP |
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 | ||
85dbc41d | 23 | #include <gcrypt.h> |
56ebfaf1 | 24 | |
56ebfaf1 | 25 | #include "curl-util.h" |
3e2cda69 | 26 | #include "import-compress.h" |
71d35b6b | 27 | #include "macro.h" |
56ebfaf1 | 28 | |
dc2c282b LP |
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 | ||
697be0be TB |
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 | ||
9854730b | 52 | #define PULL_JOB_IS_COMPLETE(j) (IN_SET((j)->state, PULL_JOB_DONE, PULL_JOB_FAILED)) |
dc2c282b | 53 | |
dc2c282b LP |
54 | struct PullJob { |
55 | PullJobState state; | |
56ebfaf1 LP |
56 | int error; |
57 | ||
58 | char *url; | |
59 | ||
60 | void *userdata; | |
dc2c282b LP |
61 | PullJobFinished on_finished; |
62 | PullJobOpenDisk on_open_disk; | |
63 | PullJobHeader on_header; | |
64 | PullJobProgress on_progress; | |
56ebfaf1 LP |
65 | |
66 | CurlGlue *glue; | |
67 | CURL *curl; | |
68 | struct curl_slist *request_header; | |
69 | ||
70 | char *etag; | |
71 | char **old_etags; | |
85dbc41d | 72 | bool etag_exists; |
56ebfaf1 LP |
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 | ||
3e2cda69 | 89 | ImportCompress compress; |
56ebfaf1 LP |
90 | |
91 | unsigned progress_percent; | |
92 | usec_t start_usec; | |
93 | usec_t last_status_usec; | |
94 | ||
95 | bool allow_sparse; | |
85dbc41d | 96 | |
98c38001 LP |
97 | bool calc_checksum; |
98 | gcry_md_hd_t checksum_context; | |
85dbc41d | 99 | |
98c38001 | 100 | char *checksum; |
26166c88 LP |
101 | |
102 | bool grow_machine_directory; | |
103 | uint64_t written_since_last_grow; | |
697be0be TB |
104 | |
105 | VerificationStyle style; | |
56ebfaf1 LP |
106 | }; |
107 | ||
dc2c282b LP |
108 | int pull_job_new(PullJob **job, const char *url, CurlGlue *glue, void *userdata); |
109 | PullJob* pull_job_unref(PullJob *job); | |
56ebfaf1 | 110 | |
dc2c282b | 111 | int pull_job_begin(PullJob *j); |
56ebfaf1 | 112 | |
dc2c282b | 113 | void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result); |
98c38001 | 114 | |
dc2c282b | 115 | DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref); |