libzypp  17.36.3
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 
32 //
33 // CLASS NAME : MediaCurl2
39 {
40  public:
42  {
44  OPTION_NONE = 0x0,
46  OPTION_RANGE = 0x1,
48  OPTION_HEAD = 0x02,
53  };
54  ZYPP_DECLARE_FLAGS(RequestOptions,RequestOption);
55 
56  protected:
57 
58  Url clearQueryString(const Url &url) const;
59 
60  void attachTo (bool next = false) override;
61  void releaseFrom( const std::string & ejectDev ) override;
62  void getFile( const OnMediaLocation & file ) const override;
63  void getDir( const Pathname & dirname, bool recurse_r ) const override;
64  void getDirInfo( std::list<std::string> & retlist,
65  const Pathname & dirname, bool dots = true ) const override;
66  void getDirInfo( filesystem::DirContent & retlist,
67  const Pathname & dirname, bool dots = true ) const override;
73  bool getDoesFileExist( const Pathname & filename ) const override;
74 
80  void disconnectFrom() override;
86  void getFileCopy( const OnMediaLocation& srcFile, const Pathname & targetFilename ) const override;
87 
93  virtual void doGetFileCopy( const OnMediaLocation &srcFile, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
94 
95 
96  bool checkAttachPoint(const Pathname &apoint) const override;
97 
98  public:
99 
100  MediaCurl2( const Url & url_r,
101  const Pathname & attach_point_hint_r );
102 
103  ~MediaCurl2() override { try { release(); } catch(...) {} }
104 
105  static void setCookieFile( const Pathname & );
106 
107  protected:
112  void checkProtocol(const Url &url) const;
113 
118  void setupEasy();
119 
120  private:
121  void executeRequest( zyppng::NetworkRequestRef req, callback::SendReport<DownloadProgressReport> *report = nullptr );
122 
123  bool authenticate(const std::string & availAuthTypes, bool firstTry);
124 
125  bool tryZchunk( zyppng::NetworkRequestRef req, const OnMediaLocation &srcFile , const Pathname & target, callback::SendReport<DownloadProgressReport> & report );
126 
127  private:
128  zyppng::EventDispatcherRef _evDispatcher; //< keep the ev dispatcher alive as long as MediaCurl2 is
129  zyppng::NetworkRequestDispatcherRef _nwDispatcher; //< keep the dispatcher alive as well
130  TransferSettings _effectiveSettings; // use another level of indirection, _settings contains the user modified settings
131 };
132 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl2::RequestOptions);
133 
135 
136  } // namespace media
137 } // namespace zypp
138 
139 #endif // ZYPP_MEDIA_MEDIACURL2_H
zyppng::EventDispatcherRef _evDispatcher
Definition: MediaCurl2.h:128
Implementation class for FTP, HTTP and HTTPS MediaHandler.
Definition: MediaCurl2.h:38
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:311
void setupEasy()
initializes the curl easy handle with the data from the url
Definition: MediaCurl2.cc:182
void getFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename) const override
Definition: MediaCurl2.cc:277
void executeRequest(zyppng::NetworkRequestRef req, callback::SendReport< DownloadProgressReport > *report=nullptr)
Definition: MediaCurl2.cc:588
Holds transfer setting.
bool tryZchunk(zyppng::NetworkRequestRef req, const OnMediaLocation &srcFile, const Pathname &target, callback::SendReport< DownloadProgressReport > &report)
Definition: MediaCurl2.cc:467
void disconnectFrom() override
Definition: MediaCurl2.cc:253
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:526
bool authenticate(const std::string &availAuthTypes, bool firstTry)
Definition: MediaCurl2.cc:729
MediaCurl2(const Url &url_r, const Pathname &attach_point_hint_r)
Definition: MediaCurl2.cc:128
ZYPP_DECLARE_FLAGS(RequestOptions, RequestOption)
TransferSettings _effectiveSettings
Definition: MediaCurl2.h:130
zyppng::NetworkRequestDispatcherRef _nwDispatcher
Definition: MediaCurl2.h:129
do not send a start ProgressReport
Definition: MediaCurl2.h:52
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:248
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:574
to not add a IFMODSINCE header if target exists
Definition: MediaCurl2.h:50
only issue a HEAD (or equivalent) request
Definition: MediaCurl2.h:48
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:541
void attachTo(bool next=false) override
Call concrete handler to attach the media.
Definition: MediaCurl2.cc:223
Url url() const
Url used.
Definition: MediaHandler.h:503
ZYPP_FWD_DECL_TYPE_WITH_REFS(EventDispatcher)
static void setCookieFile(const Pathname &)
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions)
Url clearQueryString(const Url &url) const
Definition: MediaCurl2.cc:164
retrieve only a range of the file
Definition: MediaCurl2.h:46
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:355
void checkProtocol(const Url &url) const
check the url is supported by the curl library
Definition: MediaCurl2.cc:171
Url manipulation class.
Definition: Url.h:92
void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition: MediaCurl2.cc:261
void getFile(const OnMediaLocation &file) const override
Call concrete handler to provide file below attach point.
Definition: MediaCurl2.cc:268