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