1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2015 Lennart Poettering
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.
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.
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/>.
27 #include "curl-util.h"
28 #include "import-compress.h"
30 typedef struct PullJob PullJob;
32 typedef void (*PullJobFinished)(PullJob *job);
33 typedef int (*PullJobOpenDisk)(PullJob *job);
34 typedef int (*PullJobHeader)(PullJob *job, const char *header, size_t sz);
35 typedef void (*PullJobProgress)(PullJob *job);
37 typedef enum PullJobState {
39 PULL_JOB_ANALYZING, /* Still reading into ->payload, to figure out what we have */
40 PULL_JOB_RUNNING, /* Writing to destination */
44 _PULL_JOB_STATE_INVALID = -1,
47 #define PULL_JOB_STATE_IS_COMPLETE(j) (IN_SET((j)->state, PULL_JOB_DONE, PULL_JOB_FAILED))
49 typedef enum PullJobCompression {
50 PULL_JOB_UNCOMPRESSED,
54 _PULL_JOB_COMPRESSION_MAX,
55 _PULL_JOB_COMPRESSION_INVALID = -1,
65 PullJobFinished on_finished;
66 PullJobOpenDisk on_open_disk;
67 PullJobHeader on_header;
68 PullJobProgress on_progress;
72 struct curl_slist *request_header;
78 uint64_t content_length;
79 uint64_t written_compressed;
80 uint64_t written_uncompressed;
82 uint64_t uncompressed_max;
83 uint64_t compressed_max;
87 size_t payload_allocated;
93 ImportCompress compress;
95 unsigned progress_percent;
97 usec_t last_status_usec;
102 gcry_md_hd_t checksum_context;
106 bool grow_machine_directory;
107 uint64_t written_since_last_grow;
110 int pull_job_new(PullJob **job, const char *url, CurlGlue *glue, void *userdata);
111 PullJob* pull_job_unref(PullJob *job);
113 int pull_job_begin(PullJob *j);
115 void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result);
117 DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref);