]> git.ipfire.org Git - pakfire.git/blame - src/libpakfire/include/pakfire/xfer.h
xfer: Translate any errors into our own error codes
[pakfire.git] / src / libpakfire / include / pakfire / xfer.h
CommitLineData
c26aca37
MT
1/*#############################################################################
2# #
3# Pakfire - The IPFire package management system #
4# Copyright (C) 2021 Pakfire development team #
5# #
6# This program is free software: you can redistribute it and/or modify #
7# it under the terms of the GNU General Public License as published by #
8# the Free Software Foundation, either version 3 of the License, or #
9# (at your option) any later version. #
10# #
11# This program is distributed in the hope that it will be useful, #
12# but WITHOUT ANY WARRANTY; without even the implied warranty of #
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14# GNU General Public License for more details. #
15# #
16# You should have received a copy of the GNU General Public License #
17# along with this program. If not, see <http://www.gnu.org/licenses/>. #
18# #
19#############################################################################*/
20
21#ifndef PAKFIRE_XFER_H
22#define PAKFIRE_XFER_H
23
24#ifdef PAKFIRE_PRIVATE
25
26#include <curl/curl.h>
27
3fcf86a0
MT
28#include <json.h>
29
c26aca37
MT
30struct pakfire_xfer;
31
32#include <pakfire/ctx.h>
10db1fae 33#include <pakfire/httpclient.h>
c26aca37
MT
34#include <pakfire/mirrorlist.h>
35#include <pakfire/progress.h>
36
6aed39be
MT
37typedef enum pakfire_xfer_error_code {
38 PAKFIRE_XFER_OK = 0,
39
40 // General/Unknown Failure
41 PAKFIRE_XFER_FAILED,
42
43 // An unsupported protocol was requested
44 PAKFIRE_XFER_UNSUPPORTED,
45
46 // Invalid URL
47 PAKFIRE_XFER_INVALID_URL,
48
49 // The server responded with something weird
50 PAKFIRE_XFER_INVALID_RESPONSE,
51
52 // DNS Problem
53 PAKFIRE_XFER_DNS_ERROR,
54
55 // Authentication
56 PAKFIRE_XFER_AUTH_ERROR,
57 PAKFIRE_XFER_ACCESS_DENIED,
58
59 // Some connection problem
60 PAKFIRE_XFER_TRANSPORT_ERROR,
61
62 // Timeout
63 PAKFIRE_XFER_TIMEOUT,
64
65 // Local operation errors
66 PAKFIRE_XFER_WRITE_ERROR,
67 PAKFIRE_XFER_READ_ERROR,
68 PAKFIRE_XFER_ABORTED,
69
70 // Digest Mismatch
71 PAKFIRE_XFER_DIGEST_MISMATCH,
72} pakfire_xfer_error_code_t;
73
c26aca37
MT
74typedef enum pakfire_xfer_flags {
75 PAKFIRE_XFER_NO_PROGRESS = (1 << 0),
c26aca37
MT
76} pakfire_xfer_flags_t;
77
78typedef enum pakfire_transfer_method {
79 PAKFIRE_METHOD_DELETE,
80} pakfire_xfer_method_t;
81
82int pakfire_xfer_create(struct pakfire_xfer** transfer, struct pakfire_ctx* ctx,
10db1fae 83 struct pakfire_httpclient* httpclient, const char* url);
c26aca37
MT
84
85struct pakfire_xfer* pakfire_xfer_ref(struct pakfire_xfer* xfer);
86struct pakfire_xfer* pakfire_xfer_unref(struct pakfire_xfer* xfer);
87
88CURL* pakfire_xfer_handle(struct pakfire_xfer* xfer);
89
90int pakfire_xfer_set_method(struct pakfire_xfer* xfer,
91 const pakfire_xfer_method_t method);
92
93// Title
94const char* pakfire_xfer_get_title(struct pakfire_xfer* xfer);
95int pakfire_xfer_set_title(struct pakfire_xfer* xfer, const char* title);
96
97int pakfire_xfer_set_baseurl(struct pakfire_xfer* xfer, const char* baseurl);
98const char* pakfire_xfer_get_effective_url(struct pakfire_xfer* xfer);
99
100int pakfire_xfer_set_mirrorlist(struct pakfire_xfer* xfer, struct pakfire_mirrorlist* mirrors);
101
102size_t pakfire_xfer_get_size(struct pakfire_xfer* xfer);
103int pakfire_xfer_set_size(struct pakfire_xfer* xfer, size_t size);
104
105int pakfire_xfer_verify_digest(struct pakfire_xfer* xfer, const enum pakfire_digest_types md,
106 const unsigned char* expected_digest, const size_t expected_digest_length);
107
108int pakfire_xfer_add_param(struct pakfire_xfer* xfer,
109 const char* key, const char* format, ...) __attribute__((format(printf, 3, 4)));
110
111// Output
112int pakfire_xfer_set_output(struct pakfire_xfer* xfer, FILE* f);
113int pakfire_xfer_set_output_buffer(struct pakfire_xfer* xfer, char** buffer, size_t* length);
90a6b8e4 114int pakfire_xfer_set_output_path(struct pakfire_xfer* xfer, const char* path);
c26aca37
MT
115
116// Input
117int pakfire_xfer_set_input(struct pakfire_xfer* xfer, FILE* f);
118
c26aca37
MT
119// Authentication
120int pakfire_xfer_auth(struct pakfire_xfer* xfer);
121
122int pakfire_xfer_prepare(struct pakfire_xfer* xfer, struct pakfire_progress* progress, int flags);
6aed39be
MT
123pakfire_xfer_error_code_t pakfire_xfer_done(struct pakfire_xfer* xfer, int code);
124int pakfire_xfer_fail(struct pakfire_xfer* xfer);
c26aca37 125
6aed39be
MT
126pakfire_xfer_error_code_t pakfire_xfer_run(struct pakfire_xfer* xfer, int flags);
127pakfire_xfer_error_code_t pakfire_xfer_run_api_request(
128 struct pakfire_xfer* xfer, struct json_object** response);
c26aca37
MT
129
130#endif /* PAKFIRE_PRIVATE */
131#endif /* PAKFIRE_XFER_H */