diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-01-20 01:36:11 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-01-20 15:06:58 +0100 |
commit | 56ebfaf1ca185a93ffb372b6e1a1fa3a957d93cd (patch) | |
tree | 247317cdedacfbbc7771e450076e91f08c8ce115 /src/import/import-job.h | |
parent | a2e0337875addaf08225fbf9b231435ba12a88b5 (diff) |
import: add support for pulling raw tar balls as containers
Ubuntu provides their cloud images optionally as tarball, hence also
support downloading those.
Diffstat (limited to 'src/import/import-job.h')
-rw-r--r-- | src/import/import-job.h | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/import/import-job.h b/src/import/import-job.h new file mode 100644 index 0000000000..843daa217c --- /dev/null +++ b/src/import/import-job.h @@ -0,0 +1,101 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2015 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include <lzma.h> +#include <zlib.h> + +#include "macro.h" +#include "curl-util.h" + +typedef struct ImportJob ImportJob; + +typedef void (*ImportJobFinished)(ImportJob *job); +typedef int (*ImportJobOpenDisk)(ImportJob *job); + +typedef enum ImportJobState { + IMPORT_JOB_INIT, + IMPORT_JOB_ANALYZING, /* Still reading into ->payload, to figure out what we have */ + IMPORT_JOB_RUNNING, /* Writing to destination */ + IMPORT_JOB_DONE, + IMPORT_JOB_FAILED, + _IMPORT_JOB_STATE_MAX, + _IMPORT_JOB_STATE_INVALID = -1, +} ImportJobState; + +typedef enum ImportJobCompression { + IMPORT_JOB_UNCOMPRESSED, + IMPORT_JOB_XZ, + IMPORT_JOB_GZIP, + _IMPORT_JOB_COMPRESSION_MAX, + _IMPORT_JOB_COMPRESSION_INVALID = -1, +} ImportJobCompression; + +struct ImportJob { + ImportJobState state; + int error; + + char *url; + + void *userdata; + ImportJobFinished on_finished; + ImportJobOpenDisk on_open_disk; + + CurlGlue *glue; + CURL *curl; + struct curl_slist *request_header; + + char *etag; + char **old_etags; + + uint64_t content_length; + uint64_t written_compressed; + uint64_t written_uncompressed; + + uint64_t uncompressed_max; + uint64_t compressed_max; + + uint8_t *payload; + size_t payload_size; + size_t payload_allocated; + + int disk_fd; + + usec_t mtime; + + ImportJobCompression compressed; + lzma_stream xz; + z_stream gzip; + + unsigned progress_percent; + usec_t start_usec; + usec_t last_status_usec; + + bool allow_sparse; +}; + +int import_job_new(ImportJob **job, const char *url, CurlGlue *glue, void *userdata); +ImportJob* import_job_unref(ImportJob *job); + +int import_job_begin(ImportJob *j); + +void import_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result); |