libzypp  17.31.31
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 
21 namespace zypp {
22  namespace media {
23 
25 //
26 // CLASS NAME : MediaCurl
32 {
33  public:
35  {
37  OPTION_NONE = 0x0,
39  OPTION_RANGE = 0x1,
41  OPTION_HEAD = 0x02,
46  };
47  ZYPP_DECLARE_FLAGS(RequestOptions,RequestOption);
48 
49  protected:
50 
51  Url clearQueryString(const Url &url) const;
52 
53  virtual void attachTo (bool next = false) override;
54  virtual void releaseFrom( const std::string & ejectDev ) override;
55  virtual void getFile( const OnMediaLocation & file ) const override;
56  virtual void getDir( const Pathname & dirname, bool recurse_r ) const override;
57  virtual void getDirInfo( std::list<std::string> & retlist,
58  const Pathname & dirname, bool dots = true ) const override;
59  virtual void getDirInfo( filesystem::DirContent & retlist,
60  const Pathname & dirname, bool dots = true ) const override;
66  virtual bool getDoesFileExist( const Pathname & filename ) const override;
67 
71  virtual bool doGetDoesFileExist( const Pathname & filename ) const;
72 
78  virtual void disconnectFrom() override;
84  virtual void getFileCopy( const OnMediaLocation& srcFile, const Pathname & targetFilename ) const override;
85 
91  virtual void doGetFileCopy( const OnMediaLocation &srcFile, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
92 
93 
94  virtual bool checkAttachPoint(const Pathname &apoint) const override;
95 
96  public:
97 
98  MediaCurl( const Url & url_r,
99  const Pathname & attach_point_hint_r );
100 
101  virtual ~MediaCurl() override { try { release(); } catch(...) {} }
102 
103  static void setCookieFile( const Pathname & );
104 
105  class Callbacks
106  {
107  public:
108  virtual ~Callbacks();
109  virtual bool progress( int percent ) = 0;
110  };
111 
112  protected:
114  static int aliveCallback( void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow );
116  static int progressCallback( void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow );
117  static CURL *progressCallback_getcurl( void *clientp );
122  void checkProtocol(const Url &url) const;
123 
128  virtual void setupEasy();
129 
142  void evaluateCurlCode(const zypp::Pathname &filename, CURLcode code, bool timeout) const;
143 
144  void doGetFileCopyFile( const OnMediaLocation & srcFile, const Pathname & dest, FILE *file, callback::SendReport<DownloadProgressReport> & report, RequestOptions options = OPTION_NONE ) const;
145 
146  static void resetExpectedFileSize ( void *clientp, const ByteCount &expectedFileSize );
147 
148  private:
149 
150  CURLcode executeCurl() const;
151 
156  std::string getAuthHint() const;
157 
158  bool authenticate(const std::string & availAuthTypes, bool firstTry) const;
159 
160  bool detectDirIndex() const;
161 
162  private:
163  std::string _currentCookieFile;
165 
166  mutable std::string _lastRedirect;
167 
168  protected:
169  CURL *_curl;
170  char _curlError[ CURL_ERROR_SIZE ];
171  curl_slist *_customHeaders;
172 };
173 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions);
174 
176 
177  } // namespace media
178 } // namespace zypp
179 
180 #endif // ZYPP_MEDIA_MEDIACURL_H
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:688
virtual ~MediaCurl() override
Definition: MediaCurl.h:101
Describes a resource file located on a medium.
void checkProtocol(const Url &url) const
check the url is supported by the curl library
Definition: MediaCurl.cc:384
bool authenticate(const std::string &availAuthTypes, bool firstTry) const
Definition: MediaCurl.cc:1468
Implementation class for FTP, HTTP and HTTPS MediaHandler.
Definition: MediaCurl.h:31
Store and operate with byte count.
Definition: ByteCount.h:30
to not add a IFMODSINCE header if target exists
Definition: MediaCurl.h:43
virtual void getFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename) const override
Definition: MediaCurl.cc:730
virtual void setupEasy()
initializes the curl easy handle with the data from the url
Definition: MediaCurl.cc:409
CURLcode executeCurl() const
Definition: MediaCurl.cc:1407
std::string _currentCookieFile
Definition: MediaCurl.h:163
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:1288
virtual void getFile(const OnMediaLocation &file) const override
Call concrete handler to provide file below attach point.
Definition: MediaCurl.cc:721
MediaCurl(const Url &url_r, const Pathname &attach_point_hint_r)
Definition: MediaCurl.cc:337
static void setCookieFile(const Pathname &)
Definition: MediaCurl.cc:377
virtual bool progress(int percent)=0
virtual void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition: MediaCurl.cc:714
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:1394
bool detectDirIndex() const
Url clearQueryString(const Url &url) const
Definition: MediaCurl.cc:372
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:823
do not send a start ProgressReport
Definition: MediaCurl.h:45
only issue a HEAD (or equivalent) request
Definition: MediaCurl.h:41
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:518
ZYPP_DECLARE_FLAGS(RequestOptions, RequestOption)
static int progressCallback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
Callback reporting download progress.
Definition: MediaCurl.cc:1351
virtual bool doGetDoesFileExist(const Pathname &filename) const
Definition: MediaCurl.cc:971
virtual void attachTo(bool next=false) override
Call concrete handler to attach the media.
Definition: MediaCurl.cc:653
Common baseclass for MediaCurl and MediaNetwork.
virtual bool getDoesFileExist(const Pathname &filename) const override
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly, or user cancels the operation.
Definition: MediaCurl.cc:792
void doGetFileCopyFile(const OnMediaLocation &srcFile, const Pathname &dest, FILE *file, callback::SendReport< DownloadProgressReport > &report, RequestOptions options=OPTION_NONE) const
Definition: MediaCurl.cc:1188
retrieve only a range of the file
Definition: MediaCurl.h:39
curl_slist * _customHeaders
Definition: MediaCurl.h:171
std::string _lastRedirect
to log/report redirections
Definition: MediaCurl.h:166
Url url() const
Url used.
Definition: MediaHandler.h:503
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:1321
virtual void disconnectFrom() override
Definition: MediaCurl.cc:695
static CURL * progressCallback_getcurl(void *clientp)
Definition: MediaCurl.cc:1367
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions)
static Pathname _cookieFile
Definition: MediaCurl.h:164
std::string getAuthHint() const
Return a comma separated list of available authentication methods supported by server.
Definition: MediaCurl.cc:1375
virtual void doGetFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename, callback::SendReport< DownloadProgressReport > &_report, RequestOptions options=OPTION_NONE) const
Definition: MediaCurl.cc:1078
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
char _curlError[CURL_ERROR_SIZE]
Definition: MediaCurl.h:170
static int aliveCallback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
Callback sending just an alive trigger to the UI, without stats (e.g.
Definition: MediaCurl.cc:1337
Url manipulation class.
Definition: Url.h:91