libzypp 17.37.10

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
4#include <zypp-curl/ng/network/networkrequesterror.h>
5#include <zypp-curl/ng/network/TransferSettings>
6#include <zypp-curl/ng/network/curlmultiparthandler.h>
7#include <zypp-core/zyppng/base/Base>
8#include <zypp-core/zyppng/core/Url>
9#include <zypp-core/zyppng/core/ByteArray>
10#include <zypp-core/zyppng/base/zyppglobal.h>
11#include <zypp-core/zyppng/base/signals.h>
12#include <zypp-core/base/Flags.h>
13#include <zypp-core/ByteCount.h>
14#include <optional>
15#include <vector>
16#include <chrono>
17#include <any>
18
19 namespace zypp {
20 class Digest;
21 class CheckSum;
22
23 namespace media {
24 class AuthData;
25 }
26}
27
28 namespace zyppng {
29
30 using AuthData = zypp::media::AuthData;
31
32 class NetworkRequestDispatcher;
33 class NetworkRequestPrivate;
34
42 class LIBZYPP_NG_EXPORT NetworkRequest : public Base
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>;
49 using CheckSumBytes = UByteArray;
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
69 enum OptionBits {
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 };
74 ZYPP_DECLARE_FLAGS(Options, OptionBits);
75
76 using Range = CurlMultiPartHandler::Range;
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
92 NetworkRequest(Url url, zypp::Pathname targetFile, FileMode fMode = WriteExclusive );
93 ~NetworkRequest() override;
94
100 void setExpectedFileSize ( zypp::ByteCount expectedFileSize );
101
102 zypp::ByteCount expectedFileSize() const;
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:
298 friend class NetworkRequestDispatcher;
299 friend class NetworkRequestDispatcherPrivate;
300 ZYPP_DECLARE_PRIVATE( NetworkRequest )
301 };
302
303}
304 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(zyppng::NetworkRequest::Options);
305
306#endif
zypp::ByteCount
Store and operate with byte count.
Definition ByteCount.h:32
zypp::CheckSum
Definition CheckSum.h:34
zypp::Digest
Compute Message Digests (MD5, SHA1 etc)
Definition Digest.h:38
zypp::UByteArray
Definition ByteArray.h:46
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::media::AuthData
Class for handling media authentication data.
Definition authdata.h:31
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::NetworkRequestPrivate
Definition request_p.h:35
zyppng::NetworkRequest::setExpectedFileSize
void setExpectedFileSize(zypp::ByteCount expectedFileSize)
Definition request.cc:764
zyppng::NetworkRequest::setPriority
void setPriority(Priority prio, bool triggerReschedule=true)
Definition request.cc:774
zyppng::NetworkRequest::OptionBits
OptionBits
Definition request.h:69
zyppng::NetworkRequest::HeadRequest
@ HeadRequest
Definition request.h:71
zyppng::NetworkRequest::ConnectionTest
@ ConnectionTest
Definition request.h:72
zyppng::NetworkRequest::Default
@ Default
Definition request.h:70
zyppng::NetworkRequest::State
State
Definition request.h:51
zyppng::NetworkRequest::Running
@ Running
Definition request.h:53
zyppng::NetworkRequest::Error
@ Error
Definition request.h:55
zyppng::NetworkRequest::Finished
@ Finished
Definition request.h:54
zyppng::NetworkRequest::Pending
@ Pending
Definition request.h:52
zyppng::NetworkRequest::DigestPtr
std::shared_ptr< zypp::Digest > DigestPtr
Definition request.h:48
zyppng::NetworkRequest::NetworkRequestDispatcher
friend class NetworkRequestDispatcher
Definition request.h:298
zyppng::NetworkRequest::Ptr
std::shared_ptr< NetworkRequest > Ptr
Definition request.h:46
zyppng::NetworkRequest::setOptions
void setOptions(Options opt)
Definition request.cc:787
zyppng::NetworkRequest::url
Url url() const
Definition request.cc:916
zyppng::NetworkRequest::expectedFileSize
zypp::ByteCount expectedFileSize() const
Definition request.cc:769
zyppng::NetworkRequest::NetworkRequestDispatcherPrivate
friend class NetworkRequestDispatcherPrivate
Definition request.h:299
zyppng::NetworkRequest::CheckSumBytes
UByteArray CheckSumBytes
Definition request.h:49
zyppng::NetworkRequest::options
Options options() const
Definition request.cc:792
zyppng::NetworkRequest::FileMode
FileMode
Definition request.h:64
zyppng::NetworkRequest::WriteShared
@ WriteShared
Definition request.h:66
zyppng::NetworkRequest::WriteExclusive
@ WriteExclusive
Definition request.h:65
zyppng::NetworkRequest::NetworkRequest
NetworkRequest(Url url, zypp::Pathname targetFile, FileMode fMode=WriteExclusive)
Definition request.cc:751
zyppng::NetworkRequest::priority
Priority priority() const
Definition request.cc:782
zyppng::NetworkRequest::addRequestRange
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
zyppng::NetworkRequest::ZYPP_DECLARE_FLAGS
ZYPP_DECLARE_FLAGS(Options, OptionBits)
zyppng::NetworkRequest::Range
CurlMultiPartHandler::Range Range
Definition request.h:76
zyppng::NetworkRequest::WeakPtr
std::weak_ptr< NetworkRequest > WeakPtr
Definition request.h:47
zyppng::NetworkRequest::Priority
Priority
Definition request.h:58
zyppng::NetworkRequest::High
@ High
Definition request.h:60
zyppng::NetworkRequest::Normal
@ Normal
Definition request.h:59
zyppng::NetworkRequest::Critical
@ Critical
Definition request.h:61
curlmultiparthandler.h
ztui::ProgressEnd::error
@ error
Definition Out.h:45
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::AuthData
zypp::media::AuthData AuthData
Definition authdata.h:21
zyppng::Url
zypp::Url Url
Definition url.h:15
zyppng::TransferSettings
zypp::media::TransferSettings TransferSettings
Definition transfersettings.h:20
networkrequesterror.h
signals.h
zyppng::CurlMultiPartHandler::Range
Definition curlmultiparthandler.h:104
zyppng::NetworkRequest::Timings
Definition request.h:78
zyppng::NetworkRequest::Timings::appconnect
std::chrono::microseconds appconnect
Definition request.h:81
zyppng::NetworkRequest::Timings::redirect
std::chrono::microseconds redirect
Definition request.h:84
zyppng::NetworkRequest::Timings::pretransfer
std::chrono::microseconds pretransfer
Definition request.h:82
zyppng::NetworkRequest::Timings::total
std::chrono::microseconds total
Definition request.h:83
zyppng::NetworkRequest::Timings::namelookup
std::chrono::microseconds namelookup
Definition request.h:79
zyppng::NetworkRequest::Timings::connect
std::chrono::microseconds connect
Definition request.h:80
ByteCount.h
Flags.h
ZYPP_DECLARE_OPERATORS_FOR_FLAGS
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
Definition Flags.h:177
zyppglobal.h
ZYPP_DECLARE_PRIVATE
#define ZYPP_DECLARE_PRIVATE(Class)
Definition zyppglobal.h:87
LIBZYPP_NG_EXPORT
#define LIBZYPP_NG_EXPORT
Definition zyppglobal.h:8