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);
36 typedef int (*ImportJobHeader)(ImportJob *job, const char *header, size_t sz);
37 typedef void (*ImportJobProgress)(ImportJob *job);
39 typedef enum ImportJobState {
41 IMPORT_JOB_ANALYZING, /* Still reading into ->payload, to figure out what we have */
42 IMPORT_JOB_RUNNING, /* Writing to destination */
45 _IMPORT_JOB_STATE_MAX,
46 _IMPORT_JOB_STATE_INVALID = -1,
49 #define IMPORT_JOB_STATE_IS_COMPLETE(j) (IN_SET((j)->state, IMPORT_JOB_DONE, IMPORT_JOB_FAILED))
51 typedef enum ImportJobCompression {
52 IMPORT_JOB_UNCOMPRESSED,
56 _IMPORT_JOB_COMPRESSION_MAX,
57 _IMPORT_JOB_COMPRESSION_INVALID = -1,
58 } ImportJobCompression;
67 ImportJobFinished on_finished;
68 ImportJobOpenDisk on_open_disk;
69 ImportJobHeader on_header;
70 ImportJobProgress on_progress;
74 struct curl_slist *request_header;
80 uint64_t content_length;
81 uint64_t written_compressed;
82 uint64_t written_uncompressed;
84 uint64_t uncompressed_max;
85 uint64_t compressed_max;
89 size_t payload_allocated;
95 ImportJobCompression compressed;
100 unsigned progress_percent;
102 usec_t last_status_usec;
107 gcry_md_hd_t checksum_context;
112 int import_job_new(ImportJob **job, const char *url, CurlGlue *glue, void *userdata);
113 ImportJob* import_job_unref(ImportJob *job);
115 int import_job_begin(ImportJob *j);
117 void import_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result);
119 DEFINE_TRIVIAL_CLEANUP_FUNC(ImportJob*, import_job_unref);