libzypp  17.28.8
MediaCurl.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_MEDIA_MEDIACURL_H
13 #define ZYPP_MEDIA_MEDIACURL_H
14 
15 #include <zypp/base/Flags.h>
16 #include <zypp/ZYppCallbacks.h>
18 
19 #include <curl/curl.h>
20 namespace zypp {
21  namespace media {
22 
24 //
25 // CLASS NAME : MediaCurl
31 {
32  public:
34  {
36  OPTION_NONE = 0x0,
38  OPTION_RANGE = 0x1,
40  OPTION_HEAD = 0x02,
45  };
47 
48  protected:
49 
50  Url clearQueryString(const Url &url) const;
51 
52  virtual void attachTo (bool next = false) override;
53  virtual void releaseFrom( const std::string & ejectDev ) override;
54  virtual void getFile( const OnMediaLocation & file ) const override;
55  virtual void getDir( const Pathname & dirname, bool recurse_r ) const override;
56  virtual void getDirInfo( std::list<std::string> & retlist,
57  const Pathname & dirname, bool dots = true ) const override;
58  virtual void getDirInfo( filesystem::DirContent & retlist,
59  const Pathname & dirname, bool dots = true ) const override;
65  virtual bool getDoesFileExist( const Pathname & filename ) const override;
66 
70  virtual bool doGetDoesFileExist( const Pathname & filename ) const;
71 
77  virtual void disconnectFrom() override;
83  virtual void getFileCopy( const OnMediaLocation& srcFile, const Pathname & targetFilename ) const override;
84 
90  virtual void doGetFileCopy( const OnMediaLocation &srcFile, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
91 
92 
93  virtual bool checkAttachPoint(const Pathname &apoint) const override;
94 
95  public:
96 
97  MediaCurl( const Url & url_r,
98  const Pathname & attach_point_hint_r );
99 
100  virtual ~MediaCurl() override { try { release(); } catch(...) {} }
101 
102  static void setCookieFile( const Pathname & );
103 
104  class Callbacks
105  {
106  public:
107  virtual ~Callbacks();
108  virtual bool progress( int percent ) = 0;
109  };
110 
111  protected:
112 // /** Callback sending just an alive trigger to the UI, without stats (e.g. during metalink download). */
113  static int aliveCallback( void *clientp, double dltotal, double dlnow, double ultotal, double ulnow );
115  static int progressCallback( void *clientp, double dltotal, double dlnow, double ultotal, double ulnow );
116  static CURL *progressCallback_getcurl( void *clientp );
121  void checkProtocol(const Url &url) const;
122 
127  virtual void setupEasy();
132  Url getFileUrl(const Pathname & filename) const;
133 
146  void evaluateCurlCode(const zypp::Pathname &filename, CURLcode code, bool timeout) const;
147 
148  void doGetFileCopyFile( const OnMediaLocation & srcFile, const Pathname & dest, FILE *file, callback::SendReport<DownloadProgressReport> & report, RequestOptions options = OPTION_NONE ) const;
149 
150  static void resetExpectedFileSize ( void *clientp, const ByteCount &expectedFileSize );
151 
152  private:
157  std::string getAuthHint() const;
158 
159  bool authenticate(const std::string & availAuthTypes, bool firstTry) const;
160 
161  bool detectDirIndex() const;
162 
163  private:
165 
166  std::string _currentCookieFile;
168 
169  mutable std::string _lastRedirect;
170 
171  protected:
172  CURL *_curl;
173  char _curlError[ CURL_ERROR_SIZE ];
174  curl_slist *_customHeaders;
175 };
176 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions);
177 
179 
180  } // namespace media
181 } // namespace zypp
182 
183 #endif // ZYPP_MEDIA_MEDIACURL_H
Store and operate with byte count.
Definition: ByteCount.h:31
Describes a resource file located on a medium.
Url manipulation class.
Definition: Url.h:92
virtual bool progress(int percent)=0
Implementation class for FTP, HTTP and HTTPS MediaHandler.
Definition: MediaCurl.h:31
virtual void setupEasy()
initializes the curl easy handle with the data from the url
Definition: MediaCurl.cc:139
Url getFileUrl(const Pathname &filename) const
concatenate the attach url and the filename to a complete download url
Definition: MediaCurl.cc:464
static void setCookieFile(const Pathname &)
Definition: MediaCurl.cc:107
virtual bool getDoesFileExist(const Pathname &filename) const override
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly,...
Definition: MediaCurl.cc:538
@ OPTION_RANGE
retrieve only a range of the file
Definition: MediaCurl.h:38
@ OPTION_NO_IFMODSINCE
to not add a IFMODSINCE header if target exists
Definition: MediaCurl.h:42
@ OPTION_NO_REPORT_START
do not send a start ProgressReport
Definition: MediaCurl.h:44
@ OPTION_HEAD
only issue a HEAD (or equivalent) request
Definition: MediaCurl.h:40
@ OPTION_NONE
Defaults.
Definition: MediaCurl.h:36
virtual void getFile(const OnMediaLocation &file) const override
Call concrete handler to provide file below attach point.
Definition: MediaCurl.cc:480
static void resetExpectedFileSize(void *clientp, const ByteCount &expectedFileSize)
MediaMultiCurl needs to reset the expected filesize in case a metalink file is downloaded otherwise t...
Definition: MediaCurl.cc:1219
std::string _currentCookieFile
Definition: MediaCurl.h:166
static int aliveCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
Definition: MediaCurl.cc:1162
static Pathname _cookieFile
Definition: MediaCurl.h:167
static int progressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
Callback reporting download progress.
Definition: MediaCurl.cc:1176
virtual void getFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename) const override
Definition: MediaCurl.cc:489
virtual void doGetFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename, callback::SendReport< DownloadProgressReport > &_report, RequestOptions options=OPTION_NONE) const
Definition: MediaCurl.cc:896
std::string _lastRedirect
to log/report redirections
Definition: MediaCurl.h:169
Url clearQueryString(const Url &url) const
Definition: MediaCurl.cc:102
virtual void attachTo(bool next=false) override
Call concrete handler to attach the media.
Definition: MediaCurl.cc:400
virtual 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: MediaCurl.cc:1146
char _curlError[CURL_ERROR_SIZE]
Definition: MediaCurl.h:173
void doGetFileCopyFile(const OnMediaLocation &srcFile, const Pathname &dest, FILE *file, callback::SendReport< DownloadProgressReport > &report, RequestOptions options=OPTION_NONE) const
Definition: MediaCurl.cc:1006
void checkProtocol(const Url &url) const
check the url is supported by the curl library
Definition: MediaCurl.cc:114
virtual ~MediaCurl() override
Definition: MediaCurl.h:100
MediaCurl(const Url &url_r, const Pathname &attach_point_hint_r)
Definition: MediaCurl.cc:66
bool detectDirIndex() const
void evaluateCurlCode(const zypp::Pathname &filename, CURLcode code, bool timeout) const
Evaluates a curl return code and throws the right MediaException filename Filename being downloaded c...
Definition: MediaCurl.cc:569
virtual bool checkAttachPoint(const Pathname &apoint) const override
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
Definition: MediaCurl.cc:435
virtual void getDir(const Pathname &dirname, bool recurse_r) const override
Call concrete handler to provide directory content (not recursive!) below attach point.
Definition: MediaCurl.cc:1113
bool authenticate(const std::string &availAuthTypes, bool firstTry) const
Definition: MediaCurl.cc:1229
static CURL * progressCallback_getcurl(void *clientp)
Definition: MediaCurl.cc:1192
virtual void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition: MediaCurl.cc:459
virtual void disconnectFrom() override
Definition: MediaCurl.cc:442
virtual bool doGetDoesFileExist(const Pathname &filename) const
Definition: MediaCurl.cc:710
curl_slist * _customHeaders
Definition: MediaCurl.h:174
std::string getAuthHint() const
Return a comma separated list of available authentication methods supported by server.
Definition: MediaCurl.cc:1200
ZYPP_DECLARE_FLAGS(RequestOptions, RequestOption)
Url url() const
Url used.
Definition: MediaHandler.h:503
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
Common baseclass for MediaCurl and MediaNetwork.
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:518
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions)
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2