libzypp  17.37.5
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>
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 
31 
32  class NetworkRequestDispatcher;
33  class NetworkRequestPrivate;
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 
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 
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;
301  };
302 
303 }
304 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(zyppng::NetworkRequest::Options);
305 
306 #endif
std::chrono::microseconds connect
Definition: request.h:80
std::weak_ptr< Base > WeakPtr
Definition: base.h:66
Store and operate with byte count.
Definition: ByteCount.h:31
std::chrono::microseconds pretransfer
Definition: request.h:82
std::chrono::microseconds appconnect
Definition: request.h:81
Request the standard behavior (as defined in zypp.conf or &#39;Job&#39;)
std::chrono::microseconds namelookup
Definition: request.h:79
zypp::media::AuthData AuthData
Definition: authdata.h:21
zypp::media::TransferSettings TransferSettings
zypp::UByteArray UByteArray
Definition: bytearray.h:22
zypp::Url Url
Definition: url.h:15
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(zyppng::NetworkRequest::Options)
#define ZYPP_DECLARE_FLAGS(Name, Enum)
Definition: Flags.h:174
#define ZYPP_DECLARE_PRIVATE(Class)
Definition: zyppglobal.h:87
std::chrono::microseconds total
Definition: request.h:83
#define LIBZYPP_NG_EXPORT
Definition: zyppglobal.h:8
std::chrono::microseconds redirect
Definition: request.h:84
std::shared_ptr< zypp::Digest > DigestPtr
Definition: request.h:48
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
Url manipulation class.
Definition: Url.h:92
std::shared_ptr< Base > Ptr
Definition: base.h:65