libzypp 17.37.17
request.h
Go to the documentation of this file.
1#ifndef ZYPP_NG_MEDIA_CURL_REQUEST_H_INCLUDED
2#define ZYPP_NG_MEDIA_CURL_REQUEST_H_INCLUDED
3
5#include <zypp-curl/ng/network/TransferSettings>
7#include <zypp-core/zyppng/base/Base>
8#include <zypp-core/zyppng/core/Url>
9#include <zypp-core/zyppng/core/ByteArray>
13#include <zypp-core/ByteCount.h>
14#include <optional>
15#include <vector>
16#include <chrono>
17#include <any>
18
19namespace zypp {
20 class Digest;
21 class CheckSum;
22
23 namespace media {
24 class AuthData;
25 }
26}
27
28namespace zyppng {
29
31
32 class NetworkRequestDispatcher;
34
43 {
44 public:
45
46 using Ptr = std::shared_ptr<NetworkRequest>;
47 using WeakPtr = std::weak_ptr<NetworkRequest>;
48 using DigestPtr = std::shared_ptr<zypp::Digest>;
50
51 enum State {
52 Pending, //< waiting to be dispatched
53 Running, //< currently running
54 Finished, //< finished successfully
55 Error, //< Error, use error function to figure out the issue
56 };
57
58 enum Priority {
59 Normal, //< Requests with normal priority will be enqueued as they come in
60 High, //< Request with high priority will be moved to the front of the queue
61 Critical = 100, //< Those requests will be enqueued as fast as possible, even before High priority requests, this should be used only if requests needs to start immediately
62 };
63
64 enum FileMode {
65 WriteExclusive, //< the request will create its own file, overwriting anything that already exists
66 WriteShared //< the request will create or open the file in shared mode and only write between \a start and \a len
67 };
68
70 Default = 0x00, //< no special options, just do a normal download
71 HeadRequest = 0x01, //< only request the header part of the file
72 ConnectionTest = 0x02 //< only connect to collect connection speed information
73 };
75
77
78 struct Timings {
79 std::chrono::microseconds namelookup;
80 std::chrono::microseconds connect;
81 std::chrono::microseconds appconnect;
82 std::chrono::microseconds pretransfer;
83 std::chrono::microseconds total;
84 std::chrono::microseconds redirect;
85 };
86
93 ~NetworkRequest() override;
94
101
103
109 void setPriority ( Priority prio, bool triggerReschedule = true );
110
114 Priority priority ( ) const;
115
121 void setOptions ( Options opt );
122
126 Options options () const;
127
132 void addRequestRange ( size_t start, size_t len = 0, std::optional<zypp::Digest> &&digest = {}, CheckSumBytes expectedChkSum = CheckSumBytes(), std::any userData = std::any(), std::optional<size_t> digestCompareLen = {}, std::optional<size_t> chksumpad = {} );
133
134 void addRequestRange ( Range &&range );
135
140 bool setExpectedFileChecksum( const zypp::CheckSum &expected );
141
146 void resetRequestRanges ( );
147
148 std::vector<Range> failedRanges () const;
149 const std::vector<Range> &requestedRanges () const;
150
154 const std::string &lastRedirectInfo() const;
155
162 void *nativeHandle () const;
163
168 std::optional<Timings> timings () const;
169
174 std::vector<char> peekData ( off_t offset, size_t count ) const;
175
179 Url url () const;
180
185 void setUrl ( const Url & url );
186
190 const zypp::Pathname & targetFilePath () const;
191
196 void setTargetFilePath ( const zypp::Pathname &path );
197
201 FileMode fileOpenMode () const;
202
207 void setFileOpenMode ( FileMode mode );
208
213 std::string contentType () const;
214
221 zypp::ByteCount reportedByteCount() const;
222
226 zypp::ByteCount downloadedByteCount() const;
227
232 TransferSettings &transferSettings ();
233
237 State state () const;
238
242 NetworkRequestError error () const;
243
248 std::string extendedErrorString() const;
249
253 bool hasError () const;
254
259 bool addRequestHeader(const std::string &header );
260
264 const zypp::Pathname &cookieFile() const;
265
270 void setCookieFile( zypp::Pathname cookieFile );
271
275 SignalProxy<void ( NetworkRequest &req )> sigStarted ();
276
280 SignalProxy<void ( NetworkRequest &req, zypp::ByteCount count )> sigBytesDownloaded ();
281
287 SignalProxy<void ( NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow )> sigProgress ();
288
295 SignalProxy<void ( NetworkRequest &req, const NetworkRequestError &err)> sigFinished ( );
296
297 private:
301 };
302
303}
304ZYPP_DECLARE_OPERATORS_FOR_FLAGS(zyppng::NetworkRequest::Options);
305
306#endif
Store and operate with byte count.
Definition ByteCount.h:32
Compute Message Digests (MD5, SHA1 etc)
Definition Digest.h:38
Url manipulation class.
Definition Url.h:93
Class for handling media authentication data.
Definition authdata.h:31
void setExpectedFileSize(zypp::ByteCount expectedFileSize)
Definition request.cc:764
void setPriority(Priority prio, bool triggerReschedule=true)
Definition request.cc:774
std::shared_ptr< zypp::Digest > DigestPtr
Definition request.h:48
friend class NetworkRequestDispatcher
Definition request.h:298
std::shared_ptr< NetworkRequest > Ptr
Definition request.h:46
void setOptions(Options opt)
Definition request.cc:787
zypp::ByteCount expectedFileSize() const
Definition request.cc:769
friend class NetworkRequestDispatcherPrivate
Definition request.h:299
UByteArray CheckSumBytes
Definition request.h:49
Options options() const
Definition request.cc:792
NetworkRequest(Url url, zypp::Pathname targetFile, FileMode fMode=WriteExclusive)
Definition request.cc:751
Priority priority() const
Definition request.cc:782
void addRequestRange(size_t start, size_t len=0, std::optional< zypp::Digest > &&digest={}, CheckSumBytes expectedChkSum=CheckSumBytes(), std::any userData=std::any(), std::optional< size_t > digestCompareLen={}, std::optional< size_t > chksumpad={})
Definition request.cc:797
ZYPP_DECLARE_FLAGS(Options, OptionBits)
CurlMultiPartHandler::Range Range
Definition request.h:76
std::weak_ptr< NetworkRequest > WeakPtr
Definition request.h:47
Easy-to use interface to the ZYPP dependency resolver.
zypp::media::AuthData AuthData
Definition authdata.h:21
zypp::Url Url
Definition url.h:15
zypp::media::TransferSettings TransferSettings
std::chrono::microseconds appconnect
Definition request.h:81
std::chrono::microseconds redirect
Definition request.h:84
std::chrono::microseconds pretransfer
Definition request.h:82
std::chrono::microseconds total
Definition request.h:83
std::chrono::microseconds namelookup
Definition request.h:79
std::chrono::microseconds connect
Definition request.h:80
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
Definition Flags.h:177
#define ZYPP_DECLARE_PRIVATE(Class)
Definition zyppglobal.h:87
#define LIBZYPP_NG_EXPORT
Definition zyppglobal.h:8