]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
56ebfaf1 LP |
2 | #pragma once |
3 | ||
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2015 Lennart Poettering | |
56ebfaf1 LP |
8 | ***/ |
9 | ||
85dbc41d | 10 | #include <gcrypt.h> |
56ebfaf1 | 11 | |
56ebfaf1 | 12 | #include "curl-util.h" |
3e2cda69 | 13 | #include "import-compress.h" |
71d35b6b | 14 | #include "macro.h" |
56ebfaf1 | 15 | |
dc2c282b LP |
16 | typedef struct PullJob PullJob; |
17 | ||
18 | typedef void (*PullJobFinished)(PullJob *job); | |
19 | typedef int (*PullJobOpenDisk)(PullJob *job); | |
20 | typedef int (*PullJobHeader)(PullJob *job, const char *header, size_t sz); | |
21 | typedef void (*PullJobProgress)(PullJob *job); | |
22 | ||
23 | typedef enum PullJobState { | |
24 | PULL_JOB_INIT, | |
25 | PULL_JOB_ANALYZING, /* Still reading into ->payload, to figure out what we have */ | |
26 | PULL_JOB_RUNNING, /* Writing to destination */ | |
27 | PULL_JOB_DONE, | |
28 | PULL_JOB_FAILED, | |
29 | _PULL_JOB_STATE_MAX, | |
30 | _PULL_JOB_STATE_INVALID = -1, | |
31 | } PullJobState; | |
32 | ||
697be0be TB |
33 | typedef enum VerificationStyle { |
34 | VERIFICATION_STYLE_UNSET, | |
35 | VERIFICATION_PER_FILE, /* SuSE-style ".sha256" files with inline signature */ | |
36 | VERIFICATION_PER_DIRECTORY, /* Ubuntu-style SHA256SUM files with detach SHA256SUM.gpg signatures */ | |
37 | } VerificationStyle; | |
38 | ||
9854730b | 39 | #define PULL_JOB_IS_COMPLETE(j) (IN_SET((j)->state, PULL_JOB_DONE, PULL_JOB_FAILED)) |
dc2c282b | 40 | |
dc2c282b LP |
41 | struct PullJob { |
42 | PullJobState state; | |
56ebfaf1 LP |
43 | int error; |
44 | ||
45 | char *url; | |
46 | ||
47 | void *userdata; | |
dc2c282b LP |
48 | PullJobFinished on_finished; |
49 | PullJobOpenDisk on_open_disk; | |
50 | PullJobHeader on_header; | |
51 | PullJobProgress on_progress; | |
56ebfaf1 LP |
52 | |
53 | CurlGlue *glue; | |
54 | CURL *curl; | |
55 | struct curl_slist *request_header; | |
56 | ||
57 | char *etag; | |
58 | char **old_etags; | |
85dbc41d | 59 | bool etag_exists; |
56ebfaf1 LP |
60 | |
61 | uint64_t content_length; | |
62 | uint64_t written_compressed; | |
63 | uint64_t written_uncompressed; | |
64 | ||
65 | uint64_t uncompressed_max; | |
66 | uint64_t compressed_max; | |
67 | ||
68 | uint8_t *payload; | |
69 | size_t payload_size; | |
70 | size_t payload_allocated; | |
71 | ||
72 | int disk_fd; | |
73 | ||
74 | usec_t mtime; | |
75 | ||
3e2cda69 | 76 | ImportCompress compress; |
56ebfaf1 LP |
77 | |
78 | unsigned progress_percent; | |
79 | usec_t start_usec; | |
80 | usec_t last_status_usec; | |
81 | ||
82 | bool allow_sparse; | |
85dbc41d | 83 | |
98c38001 LP |
84 | bool calc_checksum; |
85 | gcry_md_hd_t checksum_context; | |
85dbc41d | 86 | |
98c38001 | 87 | char *checksum; |
26166c88 LP |
88 | |
89 | bool grow_machine_directory; | |
90 | uint64_t written_since_last_grow; | |
697be0be TB |
91 | |
92 | VerificationStyle style; | |
56ebfaf1 LP |
93 | }; |
94 | ||
dc2c282b LP |
95 | int pull_job_new(PullJob **job, const char *url, CurlGlue *glue, void *userdata); |
96 | PullJob* pull_job_unref(PullJob *job); | |
56ebfaf1 | 97 | |
dc2c282b | 98 | int pull_job_begin(PullJob *j); |
56ebfaf1 | 99 | |
dc2c282b | 100 | void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result); |
98c38001 | 101 | |
dc2c282b | 102 | DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref); |