libzypp  15.28.6
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"
18 #include "zypp/ZYppCallbacks.h"
19 
20 #include <curl/curl.h>
21 
22 namespace zypp {
23  namespace media {
24 
26 //
27 // CLASS NAME : MediaCurl
32 class MediaCurl : public MediaHandler
33 {
34  public:
36  {
38  OPTION_NONE = 0x0,
40  OPTION_RANGE = 0x1,
42  OPTION_HEAD = 0x02,
47  };
48  ZYPP_DECLARE_FLAGS(RequestOptions,RequestOption);
49 
50  protected:
51 
52  Url clearQueryString(const Url &url) const;
53 
54  virtual void attachTo (bool next = false);
55  virtual void releaseFrom( const std::string & ejectDev );
56  virtual void getFile( const Pathname & filename, const ByteCount &expectedFileSize_r ) const override;
57  virtual void getDir( const Pathname & dirname, bool recurse_r ) const;
58  virtual void getDirInfo( std::list<std::string> & retlist,
59  const Pathname & dirname, bool dots = true ) const;
60  virtual void getDirInfo( filesystem::DirContent & retlist,
61  const Pathname & dirname, bool dots = true ) const;
67  virtual bool getDoesFileExist( const Pathname & filename ) const;
68 
72  virtual bool doGetDoesFileExist( const Pathname & filename ) const;
73 
79  virtual void disconnectFrom();
85  virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, const ByteCount &expectedFileSize_r) const override;
86 
92  virtual void doGetFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report, const ByteCount &expectedFileSize_r, RequestOptions options = OPTION_NONE ) const;
93 
94 
95  virtual bool checkAttachPoint(const Pathname &apoint) const;
96 
97  public:
98 
99  MediaCurl( const Url & url_r,
100  const Pathname & attach_point_hint_r );
101 
102  virtual ~MediaCurl() { try { release(); } catch(...) {} }
103 
105 
106  static void setCookieFile( const Pathname & );
107 
108  class Callbacks
109  {
110  public:
111  virtual ~Callbacks() {}
112  virtual bool progress( int percent ) = 0;
113  };
114 
115  protected:
116 // /** Callback sending just an alive trigger to the UI, without stats (e.g. during metalink download). */
117  static int aliveCallback( void *clientp, double dltotal, double dlnow, double ultotal, double ulnow );
119  static int progressCallback( void *clientp, double dltotal, double dlnow, double ultotal, double ulnow );
120  static CURL *progressCallback_getcurl( void *clientp );
125  void checkProtocol(const Url &url) const;
126 
131  virtual void setupEasy();
136  Url getFileUrl(const Pathname & filename) const;
137 
150  void evaluateCurlCode(const zypp::Pathname &filename, CURLcode code, bool timeout) const;
151 
152  void doGetFileCopyFile( const Pathname & srcFilename, const Pathname & dest, FILE *file, callback::SendReport<DownloadProgressReport> & _report, const ByteCount &expectedFileSize_r, RequestOptions options = OPTION_NONE ) const;
153 
154  static void resetExpectedFileSize ( void *clientp, const ByteCount &expectedFileSize );
155 
156  private:
161  std::string getAuthHint() const;
162 
163  bool authenticate(const std::string & availAuthTypes, bool firstTry) const;
164 
165  bool detectDirIndex() const;
166 
167  private:
169 
170  std::string _currentCookieFile;
171  static Pathname _cookieFile;
172 
173  protected:
174  CURL *_curl;
175  char _curlError[ CURL_ERROR_SIZE ];
176  curl_slist *_customHeaders;
178 };
179 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions);
180 
182 
183  } // namespace media
184 } // namespace zypp
185 
186 #endif // ZYPP_MEDIA_MEDIACURL_H
void checkProtocol(const Url &url) const
check the url is supported by the curl library
Definition: MediaCurl.cc:612
bool authenticate(const std::string &availAuthTypes, bool firstTry) const
Definition: MediaCurl.cc:1689
virtual void releaseFrom(const std::string &ejectDev)
Call concrete handler to release the media.
Definition: MediaCurl.cc:934
Implementation class for FTP, HTTP and HTTPS MediaHandler.
Definition: MediaCurl.h:32
Store and operate with byte count.
Definition: ByteCount.h:30
to not add a IFMODSINCE header if target exists
Definition: MediaCurl.h:44
TransferSettings & settings()
Definition: MediaCurl.cc:599
Holds transfer setting.
Url clearQueryString(const Url &url) const
Definition: MediaCurl.cc:574
static int progressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
Callback reporting download progress.
Definition: MediaCurl.cc:1636
static int aliveCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
Callback sending just an alive trigger to the UI, without stats (e.g.
Definition: MediaCurl.cc:1622
virtual void setupEasy()
initializes the curl easy handle with the data from the url
Definition: MediaCurl.cc:637
std::string _currentCookieFile
Definition: MediaCurl.h:170
MediaCurl(const Url &url_r, const Pathname &attach_point_hint_r)
Definition: MediaCurl.cc:538
static void setCookieFile(const Pathname &)
Definition: MediaCurl.cc:605
std::string getAuthHint() const
Return a comma separated list of available authentication methods supported by server.
Definition: MediaCurl.cc:1660
virtual bool progress(int percent)=0
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:1679
virtual void doGetFileCopy(const Pathname &srcFilename, const Pathname &targetFilename, callback::SendReport< DownloadProgressReport > &_report, const ByteCount &expectedFileSize_r, RequestOptions options=OPTION_NONE) const
Definition: MediaCurl.cc:1357
time_t timeout
Definition: MediaCurl.cc:181
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:45
virtual bool getDoesFileExist(const Pathname &filename) const
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly, or user cancels the operation.
Definition: MediaCurl.cc:1005
virtual void getFileCopy(const Pathname &srcFilename, const Pathname &targetFilename, const ByteCount &expectedFileSize_r) const override
Definition: MediaCurl.cc:964
do not send a start ProgressReport
Definition: MediaCurl.h:46
only issue a HEAD (or equivalent) request
Definition: MediaCurl.h:42
TransferSettings _settings
Definition: MediaCurl.h:177
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
ZYPP_DECLARE_FLAGS(RequestOptions, RequestOption)
virtual void getFile(const Pathname &filename, const ByteCount &expectedFileSize_r) const override
Call concrete handler to provide file below attach point.
Definition: MediaCurl.cc:955
virtual bool checkAttachPoint(const Pathname &apoint) const
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
Definition: MediaCurl.cc:910
virtual void getDir(const Pathname &dirname, bool recurse_r) const
Call concrete handler to provide directory content (not recursive!) below attach point.
Definition: MediaCurl.cc:1573
virtual void disconnectFrom()
Definition: MediaCurl.cc:917
bool detectDirIndex() const
retrieve only a range of the file
Definition: MediaCurl.h:40
curl_slist * _customHeaders
Definition: MediaCurl.h:176
Url getFileUrl(const Pathname &filename) const
concatenate the attach url and the filename to a complete download url
Definition: MediaCurl.cc:939
virtual void getDirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Call concrete handler to provide a content list of directory on media via retlist.
Definition: MediaCurl.cc:1606
void doGetFileCopyFile(const Pathname &srcFilename, const Pathname &dest, FILE *file, callback::SendReport< DownloadProgressReport > &_report, const ByteCount &expectedFileSize_r, RequestOptions options=OPTION_NONE) const
Definition: MediaCurl.cc:1467
static CURL * progressCallback_getcurl(void *clientp)
Definition: MediaCurl.cc:1652
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions)
virtual void attachTo(bool next=false)
Call concrete handler to attach the media.
Definition: MediaCurl.cc:870
static Pathname _cookieFile
Definition: MediaCurl.h:171
virtual bool doGetDoesFileExist(const Pathname &filename) const
Definition: MediaCurl.cc:1172
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
char _curlError[CURL_ERROR_SIZE]
Definition: MediaCurl.h:175
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:1036
Url url() const
Url used.
Definition: MediaHandler.h:506
Url manipulation class.
Definition: Url.h:87