libzypp  17.36.7
MediaCurl2.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_MEDIA_MEDIACURL2_H
13 #define ZYPP_MEDIA_MEDIACURL2_H
14 
16 #include <zypp/base/Flags.h>
17 #include <zypp/ZYppCallbacks.h>
19 
20 #include <curl/curl.h>
21 
22 namespace zyppng {
24  ZYPP_FWD_DECL_TYPE_WITH_REFS (NetworkRequestDispatcher);
26 }
27 
28 namespace zypp {
29  namespace media {
30 
31  class CredentialManager;
32 
34 //
35 // CLASS NAME : MediaCurl2
41 {
42  public:
44  {
46  OPTION_NONE = 0x0,
48  OPTION_RANGE = 0x1,
50  OPTION_HEAD = 0x02,
55  };
56  ZYPP_DECLARE_FLAGS(RequestOptions,RequestOption);
57 
58  protected:
59 
60  Url clearQueryString(const Url &url) const;
61 
62  void attachTo (bool next = false) override;
63  void releaseFrom( const std::string & ejectDev ) override;
64  void getFile( const OnMediaLocation & file ) const override;
65  void getDir( const Pathname & dirname, bool recurse_r ) const override;
66  void getDirInfo( std::list<std::string> & retlist,
67  const Pathname & dirname, bool dots = true ) const override;
68  void getDirInfo( filesystem::DirContent & retlist,
69  const Pathname & dirname, bool dots = true ) const override;
75  bool getDoesFileExist( const Pathname & filename ) const override;
76 
82  void disconnectFrom() override;
88  void getFileCopy( const OnMediaLocation& srcFile, const Pathname & targetFilename ) const override;
89 
95  virtual void doGetFileCopy( const OnMediaLocation &srcFile, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
96 
97 
98  bool checkAttachPoint(const Pathname &apoint) const override;
99 
100  public:
101 
102  MediaCurl2( const Url & url_r,
103  const Pathname & attach_point_hint_r );
104 
105  ~MediaCurl2() override { try { release(); } catch(...) {} }
106 
107  // standard auth procedure, shared with CommitPackagePreloader
108  static bool authenticate( const Url &url, CredentialManager &cm, TransferSettings &settings, const std::string & availAuthTypes, bool firstTry);
109 
110  protected:
115  void checkProtocol(const Url &url) const;
116 
121  void setupEasy();
122 
123  private:
124  void executeRequest( zyppng::NetworkRequestRef req, callback::SendReport<DownloadProgressReport> *report = nullptr );
125 
126  bool authenticate(const std::string & availAuthTypes, bool firstTry);
127 
128  bool tryZchunk( zyppng::NetworkRequestRef req, const OnMediaLocation &srcFile , const Pathname & target, callback::SendReport<DownloadProgressReport> & report );
129 
130  private:
131  zyppng::EventDispatcherRef _evDispatcher; //< keep the ev dispatcher alive as long as MediaCurl2 is
132  zyppng::NetworkRequestDispatcherRef _nwDispatcher; //< keep the dispatcher alive as well
133  TransferSettings _effectiveSettings; // use another level of indirection, _settings contains the user modified settings
134 };
135 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl2::RequestOptions);
136 
138 
139  } // namespace media
140 } // namespace zypp
141 
142 #endif // ZYPP_MEDIA_MEDIACURL2_H
zyppng::EventDispatcherRef _evDispatcher
Definition: MediaCurl2.h:131
Implementation class for FTP, HTTP and HTTPS MediaHandler.
Definition: MediaCurl2.h:40
Describes a resource file located on a medium.
bool getDoesFileExist(const Pathname &filename) const override
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly, or user cancels the operation.
Definition: MediaCurl2.cc:258
void setupEasy()
initializes the curl easy handle with the data from the url
Definition: MediaCurl2.cc:129
void getFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename) const override
Definition: MediaCurl2.cc:224
void executeRequest(zyppng::NetworkRequestRef req, callback::SendReport< DownloadProgressReport > *report=nullptr)
Definition: MediaCurl2.cc:535
Holds transfer setting.
bool tryZchunk(zyppng::NetworkRequestRef req, const OnMediaLocation &srcFile, const Pathname &target, callback::SendReport< DownloadProgressReport > &report)
Definition: MediaCurl2.cc:414
void disconnectFrom() override
Definition: MediaCurl2.cc:200
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:526
MediaCurl2(const Url &url_r, const Pathname &attach_point_hint_r)
Definition: MediaCurl2.cc:75
ZYPP_DECLARE_FLAGS(RequestOptions, RequestOption)
TransferSettings _effectiveSettings
Definition: MediaCurl2.h:133
zyppng::NetworkRequestDispatcherRef _nwDispatcher
Definition: MediaCurl2.h:132
do not send a start ProgressReport
Definition: MediaCurl2.h:54
bool checkAttachPoint(const Pathname &apoint) const override
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
Definition: MediaCurl2.cc:195
void getDirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const override
Call concrete handler to provide a content list of directory on media via retlist.
Definition: MediaCurl2.cc:521
to not add a IFMODSINCE header if target exists
Definition: MediaCurl2.h:52
only issue a HEAD (or equivalent) request
Definition: MediaCurl2.h:50
void getDir(const Pathname &dirname, bool recurse_r) const override
Call concrete handler to provide directory content (not recursive!) below attach point.
Definition: MediaCurl2.cc:488
void attachTo(bool next=false) override
Call concrete handler to attach the media.
Definition: MediaCurl2.cc:170
Url url() const
Url used.
Definition: MediaHandler.h:503
ZYPP_FWD_DECL_TYPE_WITH_REFS(EventDispatcher)
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions)
Url clearQueryString(const Url &url) const
Definition: MediaCurl2.cc:111
retrieve only a range of the file
Definition: MediaCurl2.h:48
static bool authenticate(const Url &url, CredentialManager &cm, TransferSettings &settings, const std::string &availAuthTypes, bool firstTry)
Definition: MediaCurl2.cc:682
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
virtual void doGetFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename, callback::SendReport< DownloadProgressReport > &_report, RequestOptions options=OPTION_NONE) const
Definition: MediaCurl2.cc:302
void checkProtocol(const Url &url) const
check the url is supported by the curl library
Definition: MediaCurl2.cc:118
Url manipulation class.
Definition: Url.h:92
void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition: MediaCurl2.cc:208
void getFile(const OnMediaLocation &file) const override
Call concrete handler to provide file below attach point.
Definition: MediaCurl2.cc:215