libzypp: zypp-curl/ng/network/request.h Source File

libzypp 17.38.6

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/ng/base/Base>
8#include <zypp-core/ng/core/Url>
9#include <zypp-core/ng/core/ByteArray>
10#include <zypp-core/ng/base/zyppglobal.h>
11#include <zypp-core/ng/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
19namespace zypp {
20 class Digest;
21 class CheckSum;
22
23 namespace media {
24 class AuthData;
25 }
26}
27
28namespace zyppng {
29
30 using AuthData = zypp::media::AuthData;
31
32 class NetworkRequestDispatcher;
33 class NetworkRequestPrivate;
34
42 class 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
ByteCount.h
Flags.h
ZYPP_DECLARE_OPERATORS_FOR_FLAGS
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
relates: Flags
Definition Flags.h:177
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:48
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::setExpectedFileChecksum
bool setExpectedFileChecksum(const zypp::CheckSum &expected)
Definition request.cc:822
zyppng::NetworkRequest::reportedByteCount
zypp::ByteCount reportedByteCount() const
Returns the number of bytes that are reported from the backend as the full download size,...
Definition request.cc:966
zyppng::NetworkRequest::targetFilePath
const zypp::Pathname & targetFilePath() const
Returns the target filename path.
Definition request.cc:932
zyppng::NetworkRequest::downloadedByteCount
zypp::ByteCount downloadedByteCount() const
Returns the number of already downloaded bytes as reported by the backend.
Definition request.cc:980
zyppng::NetworkRequest::resetRequestRanges
void resetRequestRanges()
Definition request.cc:839
zyppng::NetworkRequest::setUrl
void setUrl(const Url &url)
This will change the URL of the request.
Definition request.cc:923
zyppng::NetworkRequest::setExpectedFileSize
void setExpectedFileSize(zypp::ByteCount expectedFileSize)
Definition request.cc:766
zyppng::NetworkRequest::setPriority
void setPriority(Priority prio, bool triggerReschedule=true)
Definition request.cc:776
zyppng::NetworkRequest::peekData
std::vector< char > peekData(off_t offset, size_t count) const
Definition request.cc:907
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::contentType
std::string contentType() const
Returns the content type as reported from the server.
Definition request.cc:958
zyppng::NetworkRequest::setFileOpenMode
void setFileOpenMode(FileMode mode)
Sets the file open mode to mode.
Definition request.cc:950
zyppng::NetworkRequest::DigestPtr
std::shared_ptr< zypp::Digest > DigestPtr
Definition request.h:48
zyppng::NetworkRequest::addRequestHeader
bool addRequestHeader(const std::string &header)
Definition request.cc:1040
zyppng::NetworkRequest::NetworkRequestDispatcher
friend class NetworkRequestDispatcher
Definition request.h:298
zyppng::NetworkRequest::~NetworkRequest
~NetworkRequest() override
Definition request.cc:758
zyppng::NetworkRequest::Ptr
std::shared_ptr< NetworkRequest > Ptr
Definition request.h:46
zyppng::NetworkRequest::setOptions
void setOptions(Options opt)
Definition request.cc:789
zyppng::NetworkRequest::url
Url url() const
Definition request.cc:918
zyppng::NetworkRequest::fileOpenMode
FileMode fileOpenMode() const
Returns the currently configured file open mode.
Definition request.cc:945
zyppng::NetworkRequest::expectedFileSize
zypp::ByteCount expectedFileSize() const
Definition request.cc:771
zyppng::NetworkRequest::hasError
bool hasError() const
Checks if there was a error with the request.
Definition request.cc:1035
zyppng::NetworkRequest::state
State state() const
Returns the current state the HttpDownloadRequest is in.
Definition request.cc:1000
zyppng::NetworkRequest::NetworkRequestDispatcherPrivate
friend class NetworkRequestDispatcherPrivate
Definition request.h:299
zyppng::NetworkRequest::sigFinished
SignalProxy< void(NetworkRequest &req, const NetworkRequestError &err)> sigFinished()
Signals that the download finished.
Definition request.cc:1079
zyppng::NetworkRequest::CheckSumBytes
UByteArray CheckSumBytes
Definition request.h:49
zyppng::NetworkRequest::options
Options options() const
Definition request.cc:794
zyppng::NetworkRequest::sigBytesDownloaded
SignalProxy< void(NetworkRequest &req, zypp::ByteCount count)> sigBytesDownloaded()
Signals that new data has been downloaded, this is only the payload and does not include control data...
Definition request.cc:1069
zyppng::NetworkRequest::timings
std::optional< Timings > timings() const
After the request is finished query the timings that were collected during download.
Definition request.cc:879
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::extendedErrorString
std::string extendedErrorString() const
In some cases, curl can provide extended error information collected at runtime.
Definition request.cc:1027
zyppng::NetworkRequest::NetworkRequest
NetworkRequest(Url url, zypp::Pathname targetFile, FileMode fMode=WriteExclusive)
Definition request.cc:753
zyppng::NetworkRequest::priority
Priority priority() const
Definition request.cc:784
zyppng::NetworkRequest::error
NetworkRequestError error() const
Returns the last set Error.
Definition request.cc:1019
zyppng::NetworkRequest::setTargetFilePath
void setTargetFilePath(const zypp::Pathname &path)
Changes the target file path of the download.
Definition request.cc:937
zyppng::NetworkRequest::cookieFile
const zypp::Pathname & cookieFile() const
Definition request.cc:1054
zyppng::NetworkRequest::nativeHandle
void * nativeHandle() const
Definition request.cc:874
zyppng::NetworkRequest::setCookieFile
void setCookieFile(zypp::Pathname cookieFile)
Definition request.cc:1059
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:799
zyppng::NetworkRequest::failedRanges
std::vector< Range > failedRanges() const
Definition request.cc:847
zyppng::NetworkRequest::requestedRanges
const std::vector< Range > & requestedRanges() const
Definition request.cc:864
zyppng::NetworkRequest::sigStarted
SignalProxy< void(NetworkRequest &req)> sigStarted()
Signals that the dispatcher dequeued the request and actually starts downloading data.
Definition request.cc:1064
zyppng::NetworkRequest::sigProgress
SignalProxy< void(NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow)> sigProgress()
Signals if there was data read from the download.
Definition request.cc:1074
zyppng::NetworkRequest::transferSettings
TransferSettings & transferSettings()
Definition request.cc:995
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::lastRedirectInfo
const std::string & lastRedirectInfo() const
Definition request.cc:869
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
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
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
zyppglobal.h
ZYPP_DECLARE_PRIVATE
#define ZYPP_DECLARE_PRIVATE(Class)
Definition zyppglobal.h:80