Debian Codegraph @

src/import/pull-job.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <curl/curl.h>
5 #include <sys/stat.h>
6 #include <sys/uio.h>
7
8 #include "shared-forward.h"
9
10 typedef struct PullJob PullJob;
11
12 typedef void (*PullJobFinished)(PullJob *job);
13 typedef int (*PullJobOpenDisk)(PullJob *job);
14 typedef int (*PullJobHeader)(PullJob *job, const char *header, size_t sz);
15 typedef void (*PullJobProgress)(PullJob *job);
16 typedef int (*PullJobNotFound)(PullJob *job, char **ret_new_url);
17
18 typedef enum PullJobState {
19 PULL_JOB_INIT,
20 PULL_JOB_ANALYZING, /* Still reading into ->payload, to figure out what we have */
21 PULL_JOB_RUNNING, /* Writing to destination */
22 PULL_JOB_DONE,
23 PULL_JOB_FAILED,
24 _PULL_JOB_STATE_MAX,
25 _PULL_JOB_STATE_INVALID = -EINVAL,
26 } PullJobState;
27
28 #define PULL_JOB_IS_COMPLETE(j) (IN_SET((j)->state, PULL_JOB_DONE, PULL_JOB_FAILED))
29
30 typedef struct PullJob {
31 PullJobState state;
32 int error;
33
34 char *url;
35
36 void *userdata;
37 free_func_t free_userdata;
38
39 char *description;
40
41 PullJobFinished on_finished;
42 PullJobOpenDisk on_open_disk;
43 PullJobHeader on_header;
44 PullJobProgress on_progress;
45 PullJobNotFound on_not_found;
46
47 CurlGlue *glue;
48 CurlSlot *slot;
49 struct curl_slist *request_header;
50
51 char *etag;
52 char **old_etags;
53 bool etag_exists;
54
55 uint64_t content_length;
56 uint64_t written_compressed;
57 uint64_t written_uncompressed;
58 uint64_t offset;
59
60 uint64_t uncompressed_max;
61 uint64_t compressed_max;
62
63 uint64_t expected_content_length;
64
65 struct iovec payload;
66
67 int disk_fd;
68 bool close_disk_fd;
69 struct stat disk_stat;
70
71 usec_t mtime;
72 char *content_type;
73
74 Compressor *compress;
75
76 unsigned progress_percent;
77 usec_t start_usec;
78 usec_t last_status_usec;
79
80 bool calc_checksum;
81 EVP_MD_CTX *checksum_ctx;
82
83 struct iovec checksum;
84 struct iovec expected_checksum;
85
86 bool sync;
87 bool force_memory;
88
89 char *authentication_challenge;
90 } PullJob;
91
92 int pull_job_new(PullJob **ret, const char *url, CurlGlue *glue, void *userdata);
93 PullJob* pull_job_unref(PullJob *job);
94
95 int pull_job_begin(PullJob *j);
96
97 void pull_job_close_disk_fd(PullJob *j);
98
99 int pull_job_add_request_header(PullJob *j, const char *hdr);
100 int pull_job_set_accept(PullJob *j, char * const *l);
101 int pull_job_set_bearer_token(PullJob *j, const char *token);
102
103 int pull_job_restart(PullJob *j, const char *new_url);
104
105 DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref);