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/>.
30 #include "curl-util.h"
32 typedef struct ImportJob ImportJob;
34 typedef void (*ImportJobFinished)(ImportJob *job);
35 typedef int (*ImportJobOpenDisk)(ImportJob *job);
37 typedef enum ImportJobState {
39 IMPORT_JOB_ANALYZING, /* Still reading into ->payload, to figure out what we have */
40 IMPORT_JOB_RUNNING, /* Writing to destination */
43 _IMPORT_JOB_STATE_MAX,
44 _IMPORT_JOB_STATE_INVALID = -1,
47 #define IMPORT_JOB_STATE_IS_COMPLETE(j) (IN_SET((j)->state, IMPORT_JOB_DONE, IMPORT_JOB_FAILED))
49 typedef enum ImportJobCompression {
50 IMPORT_JOB_UNCOMPRESSED,
54 _IMPORT_JOB_COMPRESSION_MAX,
55 _IMPORT_JOB_COMPRESSION_INVALID = -1,
56 } ImportJobCompression;
65 ImportJobFinished on_finished;
66 ImportJobOpenDisk on_open_disk;
70 struct curl_slist *request_header;
76 uint64_t content_length;
77 uint64_t written_compressed;
78 uint64_t written_uncompressed;
80 uint64_t uncompressed_max;
81 uint64_t compressed_max;
85 size_t payload_allocated;
91 ImportJobCompression compressed;
96 unsigned progress_percent;
98 usec_t last_status_usec;
103 gcry_md_hd_t checksum_context;
108 int import_job_new(ImportJob **job, const char *url, CurlGlue *glue, void *userdata);
109 ImportJob* import_job_unref(ImportJob *job);
111 int import_job_begin(ImportJob *j);
113 void import_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result);
115 DEFINE_TRIVIAL_CLEANUP_FUNC(ImportJob*, import_job_unref);