libzypp: zypp/media/MediaCurl.h Source File

libzypp 17.25.10

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/media/TransferSettings.h>
17 #include <zypp/media/MediaHandler.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:
35 enum RequestOption
36 {
38 OPTION_NONE = 0x0,
40 OPTION_RANGE = 0x1,
42 OPTION_HEAD = 0x02,
44 OPTION_NO_IFMODSINCE = 0x04,
46 OPTION_NO_REPORT_START = 0x08,
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) override;
55 virtual void releaseFrom( const std::string & ejectDev ) override;
56 virtual void getFile( const Pathname & filename, const ByteCount &expectedFileSize_r ) const override;
57 virtual void getDir( const Pathname & dirname, bool recurse_r ) const override;
58 virtual void getDirInfo( std::list<std::string> & retlist,
59 const Pathname & dirname, bool dots = true ) const override;
60 virtual void getDirInfo( filesystem::DirContent & retlist,
61 const Pathname & dirname, bool dots = true ) const override;
67 virtual bool getDoesFileExist( const Pathname & filename ) const override;
68
72 virtual bool doGetDoesFileExist( const Pathname & filename ) const;
73
79 virtual void disconnectFrom() override;
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 override;
96
97 public:
98
99 MediaCurl( const Url & url_r,
100 const Pathname & attach_point_hint_r );
101
102 virtual ~MediaCurl() override { try { release(); } catch(...) {} }
103
104 TransferSettings & settings();
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:
168 long _curlDebug;
169
170 std::string _currentCookieFile;
171 static Pathname _cookieFile;
172
173 mutable std::string _lastRedirect;
174
175 protected:
176 CURL *_curl;
177 char _curlError[ CURL_ERROR_SIZE ];
178 curl_slist *_customHeaders;
179 TransferSettings _settings;
180 };
181 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions);
182
184
185 } // namespace media
186 } // namespace zypp
187
188 #endif // ZYPP_MEDIA_MEDIACURL_H
Flags.h
timeout
time_t timeout
Definition: MediaCurl.cc:67
MediaHandler.h
TransferSettings.h
ZYppCallbacks.h
zypp::ByteCount
Store and operate with byte count.
Definition: ByteCount.h:31
zypp::Url
Url manipulation class.
Definition: Url.h:92
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::media::MediaCurl::Callbacks
Definition: MediaCurl.h:109
zypp::media::MediaCurl::Callbacks::~Callbacks
virtual ~Callbacks()
Definition: MediaCurl.cc:1452
zypp::media::MediaCurl::Callbacks::progress
virtual bool progress(int percent)=0
zypp::media::MediaCurl
Implementation class for FTP, HTTP and HTTPS MediaHandler.
Definition: MediaCurl.h:33
zypp::media::MediaCurl::setupEasy
virtual void setupEasy()
initializes the curl easy handle with the data from the url
Definition: MediaCurl.cc:260
zypp::media::MediaCurl::getFileUrl
Url getFileUrl(const Pathname &filename) const
concatenate the attach url and the filename to a complete download url
Definition: MediaCurl.cc:588
zypp::media::MediaCurl::setCookieFile
static void setCookieFile(const Pathname &)
Definition: MediaCurl.cc:228
zypp::media::MediaCurl::getDoesFileExist
virtual bool getDoesFileExist(const Pathname &filename) const override
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly,...
Definition: MediaCurl.cc:659
zypp::media::MediaCurl::RequestOption
RequestOption
Definition: MediaCurl.h:36
zypp::media::MediaCurl::OPTION_RANGE
@ OPTION_RANGE
retrieve only a range of the file
Definition: MediaCurl.h:40
zypp::media::MediaCurl::OPTION_NO_IFMODSINCE
@ OPTION_NO_IFMODSINCE
to not add a IFMODSINCE header if target exists
Definition: MediaCurl.h:44
zypp::media::MediaCurl::OPTION_NO_REPORT_START
@ OPTION_NO_REPORT_START
do not send a start ProgressReport
Definition: MediaCurl.h:46
zypp::media::MediaCurl::OPTION_HEAD
@ OPTION_HEAD
only issue a HEAD (or equivalent) request
Definition: MediaCurl.h:42
zypp::media::MediaCurl::OPTION_NONE
@ OPTION_NONE
Defaults.
Definition: MediaCurl.h:38
zypp::media::MediaCurl::_curlDebug
long _curlDebug
Definition: MediaCurl.h:168
zypp::media::MediaCurl::resetExpectedFileSize
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:1340
zypp::media::MediaCurl::_currentCookieFile
std::string _currentCookieFile
Definition: MediaCurl.h:170
zypp::media::MediaCurl::aliveCallback
static int aliveCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
Definition: MediaCurl.cc:1283
zypp::media::MediaCurl::_cookieFile
static Pathname _cookieFile
Definition: MediaCurl.h:171
zypp::media::MediaCurl::progressCallback
static int progressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
Callback reporting download progress.
Definition: MediaCurl.cc:1297
zypp::media::MediaCurl::_lastRedirect
std::string _lastRedirect
to log/report redirections
Definition: MediaCurl.h:173
zypp::media::MediaCurl::clearQueryString
Url clearQueryString(const Url &url) const
Definition: MediaCurl.cc:217
zypp::media::MediaCurl::attachTo
virtual void attachTo(bool next=false) override
Call concrete handler to attach the media.
Definition: MediaCurl.cc:524
zypp::media::MediaCurl::getDirInfo
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:1267
zypp::media::MediaCurl::_curlError
char _curlError[CURL_ERROR_SIZE]
Definition: MediaCurl.h:177
zypp::media::MediaCurl::checkProtocol
void checkProtocol(const Url &url) const
check the url is supported by the curl library
Definition: MediaCurl.cc:235
zypp::media::MediaCurl::~MediaCurl
virtual ~MediaCurl() override
Definition: MediaCurl.h:102
zypp::media::MediaCurl::MediaCurl
MediaCurl(const Url &url_r, const Pathname &attach_point_hint_r)
Definition: MediaCurl.cc:181
zypp::media::MediaCurl::getFileCopy
virtual void getFileCopy(const Pathname &srcFilename, const Pathname &targetFilename, const ByteCount &expectedFileSize_r) const override
Definition: MediaCurl.cc:613
zypp::media::MediaCurl::detectDirIndex
bool detectDirIndex() const
zypp::media::MediaCurl::evaluateCurlCode
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:690
zypp::media::MediaCurl::_settings
TransferSettings _settings
Definition: MediaCurl.h:179
zypp::media::MediaCurl::doGetFileCopy
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:1017
zypp::media::MediaCurl::_curl
CURL * _curl
Definition: MediaCurl.h:176
zypp::media::MediaCurl::checkAttachPoint
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:559
zypp::media::MediaCurl::getDir
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:1234
zypp::media::MediaCurl::settings
TransferSettings & settings()
Definition: MediaCurl.cc:222
zypp::media::MediaCurl::authenticate
bool authenticate(const std::string &availAuthTypes, bool firstTry) const
Definition: MediaCurl.cc:1350
zypp::media::MediaCurl::getFile
virtual void getFile(const Pathname &filename, const ByteCount &expectedFileSize_r) const override
Call concrete handler to provide file below attach point.
Definition: MediaCurl.cc:604
zypp::media::MediaCurl::progressCallback_getcurl
static CURL * progressCallback_getcurl(void *clientp)
Definition: MediaCurl.cc:1313
zypp::media::MediaCurl::releaseFrom
virtual void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition: MediaCurl.cc:583
zypp::media::MediaCurl::doGetFileCopyFile
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:1127
zypp::media::MediaCurl::disconnectFrom
virtual void disconnectFrom() override
Definition: MediaCurl.cc:566
zypp::media::MediaCurl::doGetDoesFileExist
virtual bool doGetDoesFileExist(const Pathname &filename) const
Definition: MediaCurl.cc:831
zypp::media::MediaCurl::_customHeaders
curl_slist * _customHeaders
Definition: MediaCurl.h:178
zypp::media::MediaCurl::getAuthHint
std::string getAuthHint() const
Return a comma separated list of available authentication methods supported by server.
Definition: MediaCurl.cc:1321
zypp::media::MediaCurl::ZYPP_DECLARE_FLAGS
ZYPP_DECLARE_FLAGS(RequestOptions, RequestOption)
zypp::media::MediaHandler
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:45
zypp::media::MediaHandler::url
Url url() const
Url used.
Definition: MediaHandler.h:507
zypp::media::MediaHandler::release
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
Definition: MediaHandler.cc:740
zypp::media::TransferSettings
Holds transfer setting.
Definition: TransferSettings.h:21
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
zypp::media::ZYPP_DECLARE_OPERATORS_FOR_FLAGS
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions)
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::callback::SendReport
Definition: Callback.h:237