libzypp  17.22.0
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/zyppng/media/network/TransferSettings>
6 #include <zypp/zyppng/base/Base>
7 #include <zypp/zyppng/core/Url>
10 #include <zypp/base/Flags.h>
11 #include <vector>
12 
13 namespace zypp {
14  class Digest;
15 
16  namespace media {
17  class AuthData;
18  }
19 }
20 
21 namespace zyppng {
22 
24 
25  class NetworkRequestDispatcher;
26  class NetworkRequestPrivate;
27 
36  {
37  public:
38 
39  using Ptr = std::shared_ptr<NetworkRequest>;
40  using WeakPtr = std::weak_ptr<NetworkRequest>;
41 
42  enum State {
43  Pending, //< waiting to be dispatched
44  Running, //< currently running
45  Finished, //< finished successfully
46  Error, //< Error, use error function to figure out the issue
47  };
48 
49  enum Priority {
50  Normal, //< Requests with normal priority will be enqueued at the end
51  High //< Request with high priority will be moved to the front of the queue
52  };
53 
54  enum FileMode {
55  WriteExclusive, //< the request will create its own file, overwriting anything that already exists
56  WriteShared //< the request will create or open the file in shared mode and only write between \a start and \a len
57  };
58 
59  enum OptionBits {
60  HeadRequest = 0x01 //< only request the header part of the file
61  };
62  ZYPP_DECLARE_FLAGS(Options, OptionBits);
63 
71  NetworkRequest( Url url, zypp::Pathname targetFile, off_t start = -1, off_t len = 0, FileMode fMode = WriteExclusive );
72  virtual ~NetworkRequest();
73 
79  void setPriority ( Priority prio );
80 
84  Priority priority ( ) const;
85 
91  void setOptions ( Options opt );
92 
96  Options options () const;
97 
104  void setRequestRange ( off_t start = -1, off_t len = 0 );
105 
109  const std::string &lastRedirectInfo() const;
110 
117  void *nativeHandle () const;
118 
123  std::vector<char> peekData ( off_t offset, size_t count ) const;
124 
128  Url url () const;
129 
134  void setUrl ( const Url & url );
135 
139  const zypp::Pathname & targetFilePath () const;
140 
145  std::string contentType () const;
146 
150  off_t downloadOffset () const;
151 
156  off_t reportedByteCount () const;
157 
162  off_t expectedByteCount () const;
163 
167  off_t downloadedByteCount () const;
168 
173  void setDigest ( std::shared_ptr<zypp::Digest> dig );
174 
178  std::shared_ptr<zypp::Digest> digest () const;
179 
186  void setExpectedChecksum (std::vector<unsigned char> checksum );
187 
188 
193  TransferSettings &transferSettings ();
194 
198  State state () const;
199 
203  const NetworkRequestError &error () const;
204 
209  std::string extendedErrorString() const;
210 
214  bool hasError () const;
215 
220  bool addRequestHeader(const std::string &header );
221 
226 
231 
239 
240  private:
241  friend class NetworkRequestDispatcher;
244  };
245 
246 }
247 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(zyppng::NetworkRequest::Options);
248 
249 #endif
std::weak_ptr< Base > WeakPtr
Definition: base.h:39
Holds transfer setting.
Url url
Definition: MediaCurl.cc:65
The NetworkRequestError class Represents a error that occured in.
zypp::media::AuthData AuthData
Definition: authdata.h:21
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(zyppng::NetworkRequest::Options)
#define ZYPP_DECLARE_PRIVATE(Class)
Definition: zyppglobal.h:21
#define ZYPP_DECLARE_FLAGS(Name, Enum)
Definition: Flags.h:174
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
Definition: PathInfo.cc:1004
#define LIBZYPP_NG_EXPORT
Definition: zyppglobal.h:7
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
Url manipulation class.
Definition: Url.h:87
std::shared_ptr< Base > Ptr
Definition: base.h:38