2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2015-01-20 01:36:11 +01:00
|
|
|
#pragma once
|
|
|
|
|
2015-01-20 15:06:34 +01:00
|
|
|
#include <gcrypt.h>
|
2015-01-20 01:36:11 +01:00
|
|
|
|
|
|
|
#include "curl-util.h"
|
2015-03-04 18:53:37 +01:00
|
|
|
#include "import-compress.h"
|
2015-11-18 22:46:33 +01:00
|
|
|
#include "macro.h"
|
2015-01-20 01:36:11 +01:00
|
|
|
|
2015-03-04 17:07:12 +01:00
|
|
|
typedef struct PullJob PullJob;
|
|
|
|
|
|
|
|
typedef void (*PullJobFinished)(PullJob *job);
|
|
|
|
typedef int (*PullJobOpenDisk)(PullJob *job);
|
|
|
|
typedef int (*PullJobHeader)(PullJob *job, const char *header, size_t sz);
|
|
|
|
typedef void (*PullJobProgress)(PullJob *job);
|
|
|
|
|
|
|
|
typedef enum PullJobState {
|
|
|
|
PULL_JOB_INIT,
|
|
|
|
PULL_JOB_ANALYZING, /* Still reading into ->payload, to figure out what we have */
|
|
|
|
PULL_JOB_RUNNING, /* Writing to destination */
|
|
|
|
PULL_JOB_DONE,
|
|
|
|
PULL_JOB_FAILED,
|
|
|
|
_PULL_JOB_STATE_MAX,
|
|
|
|
_PULL_JOB_STATE_INVALID = -1,
|
|
|
|
} PullJobState;
|
|
|
|
|
2017-04-24 20:37:11 +02:00
|
|
|
typedef enum VerificationStyle {
|
|
|
|
VERIFICATION_STYLE_UNSET,
|
|
|
|
VERIFICATION_PER_FILE, /* SuSE-style ".sha256" files with inline signature */
|
|
|
|
VERIFICATION_PER_DIRECTORY, /* Ubuntu-style SHA256SUM files with detach SHA256SUM.gpg signatures */
|
|
|
|
} VerificationStyle;
|
|
|
|
|
2015-09-08 18:25:56 +02:00
|
|
|
#define PULL_JOB_IS_COMPLETE(j) (IN_SET((j)->state, PULL_JOB_DONE, PULL_JOB_FAILED))
|
2015-03-04 17:07:12 +01:00
|
|
|
|
|
|
|
struct PullJob {
|
|
|
|
PullJobState state;
|
2015-01-20 01:36:11 +01:00
|
|
|
int error;
|
|
|
|
|
|
|
|
char *url;
|
|
|
|
|
|
|
|
void *userdata;
|
2015-03-04 17:07:12 +01:00
|
|
|
PullJobFinished on_finished;
|
|
|
|
PullJobOpenDisk on_open_disk;
|
|
|
|
PullJobHeader on_header;
|
|
|
|
PullJobProgress on_progress;
|
2015-01-20 01:36:11 +01:00
|
|
|
|
|
|
|
CurlGlue *glue;
|
|
|
|
CURL *curl;
|
|
|
|
struct curl_slist *request_header;
|
|
|
|
|
|
|
|
char *etag;
|
|
|
|
char **old_etags;
|
2015-01-20 15:06:34 +01:00
|
|
|
bool etag_exists;
|
2015-01-20 01:36:11 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2015-03-04 18:53:37 +01:00
|
|
|
ImportCompress compress;
|
2015-01-20 01:36:11 +01:00
|
|
|
|
|
|
|
unsigned progress_percent;
|
|
|
|
usec_t start_usec;
|
|
|
|
usec_t last_status_usec;
|
|
|
|
|
|
|
|
bool allow_sparse;
|
2015-01-20 15:06:34 +01:00
|
|
|
|
2015-01-21 03:46:01 +01:00
|
|
|
bool calc_checksum;
|
|
|
|
gcry_md_hd_t checksum_context;
|
2015-01-20 15:06:34 +01:00
|
|
|
|
2015-01-21 03:46:01 +01:00
|
|
|
char *checksum;
|
2015-03-03 00:13:12 +01:00
|
|
|
|
2017-04-24 20:37:11 +02:00
|
|
|
VerificationStyle style;
|
2015-01-20 01:36:11 +01:00
|
|
|
};
|
|
|
|
|
2015-03-04 17:07:12 +01:00
|
|
|
int pull_job_new(PullJob **job, const char *url, CurlGlue *glue, void *userdata);
|
|
|
|
PullJob* pull_job_unref(PullJob *job);
|
2015-01-20 01:36:11 +01:00
|
|
|
|
2015-03-04 17:07:12 +01:00
|
|
|
int pull_job_begin(PullJob *j);
|
2015-01-20 01:36:11 +01:00
|
|
|
|
2015-03-04 17:07:12 +01:00
|
|
|
void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result);
|
2015-01-21 03:46:01 +01:00
|
|
|
|
2015-03-04 17:07:12 +01:00
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref);
|