]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/import/pull-job.h
build-sys: drop gitignore patterns for in-tree builds
[thirdparty/systemd.git] / src / import / pull-job.h
CommitLineData
56ebfaf1
LP
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
85dbc41d 22#include <gcrypt.h>
56ebfaf1 23
56ebfaf1 24#include "curl-util.h"
3e2cda69 25#include "import-compress.h"
71d35b6b 26#include "macro.h"
56ebfaf1 27
dc2c282b
LP
28typedef struct PullJob PullJob;
29
30typedef void (*PullJobFinished)(PullJob *job);
31typedef int (*PullJobOpenDisk)(PullJob *job);
32typedef int (*PullJobHeader)(PullJob *job, const char *header, size_t sz);
33typedef void (*PullJobProgress)(PullJob *job);
34
35typedef 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
697be0be
TB
45typedef 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
9854730b 51#define PULL_JOB_IS_COMPLETE(j) (IN_SET((j)->state, PULL_JOB_DONE, PULL_JOB_FAILED))
dc2c282b 52
dc2c282b
LP
53struct PullJob {
54 PullJobState state;
56ebfaf1
LP
55 int error;
56
57 char *url;
58
59 void *userdata;
dc2c282b
LP
60 PullJobFinished on_finished;
61 PullJobOpenDisk on_open_disk;
62 PullJobHeader on_header;
63 PullJobProgress on_progress;
56ebfaf1
LP
64
65 CurlGlue *glue;
66 CURL *curl;
67 struct curl_slist *request_header;
68
69 char *etag;
70 char **old_etags;
85dbc41d 71 bool etag_exists;
56ebfaf1
LP
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
3e2cda69 88 ImportCompress compress;
56ebfaf1
LP
89
90 unsigned progress_percent;
91 usec_t start_usec;
92 usec_t last_status_usec;
93
94 bool allow_sparse;
85dbc41d 95
98c38001
LP
96 bool calc_checksum;
97 gcry_md_hd_t checksum_context;
85dbc41d 98
98c38001 99 char *checksum;
26166c88
LP
100
101 bool grow_machine_directory;
102 uint64_t written_since_last_grow;
697be0be
TB
103
104 VerificationStyle style;
56ebfaf1
LP
105};
106
dc2c282b
LP
107int pull_job_new(PullJob **job, const char *url, CurlGlue *glue, void *userdata);
108PullJob* pull_job_unref(PullJob *job);
56ebfaf1 109
dc2c282b 110int pull_job_begin(PullJob *j);
56ebfaf1 111
dc2c282b 112void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result);
98c38001 113
dc2c282b 114DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref);