libzypp: zypp/media/MediaCurl.h Source File

libzypp 17.36.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>
16#include <zypp/ZYppCallbacks.h>
17#include <zypp/media/MediaNetworkCommonHandler.h>
18
19#include <curl/curl.h>
20
21namespace zypp {
22 namespace media {
23
25//
26// CLASS NAME : MediaCurl
31 class MediaCurl : public MediaNetworkCommonHandler
32{
33 public:
34 enum RequestOption
35 {
37 OPTION_NONE = 0x0,
39 OPTION_RANGE = 0x1,
41 OPTION_HEAD = 0x02,
43 OPTION_NO_IFMODSINCE = 0x04,
45 OPTION_NO_REPORT_START = 0x08,
46 };
47 ZYPP_DECLARE_FLAGS(RequestOptions,RequestOption);
48
49 protected:
50
51 Url clearQueryString(const Url &url) const;
52
53 void attachTo (bool next = false) override;
54 void releaseFrom( const std::string & ejectDev ) override;
55 void getFile( const OnMediaLocation & file ) const override;
56 void getDir( const Pathname & dirname, bool recurse_r ) const override;
57 void getDirInfo( std::list<std::string> & retlist,
58 const Pathname & dirname, bool dots = true ) const override;
59 void getDirInfo( filesystem::DirContent & retlist,
60 const Pathname & dirname, bool dots = true ) const override;
66 bool getDoesFileExist( const Pathname & filename ) const override;
67
71 virtual bool doGetDoesFileExist( const Pathname & filename ) const;
72
78 void disconnectFrom() override;
84 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 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 ~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;
164 static Pathname _cookieFile;
165 char _curlError[ CURL_ERROR_SIZE ];
166
167 mutable std::string _lastRedirect;
168
169 protected:
170 CURL *_curl;
171 curl_slist *_customHeaders;
172
173 const char* curlError() const { return _curlError; };
174 void setCurlError(const char* error);
175};
176 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions);
177
179
180 } // namespace media
181} // namespace zypp
182
183#endif // ZYPP_MEDIA_MEDIACURL_H
MediaNetworkCommonHandler.h
ZYppCallbacks.h
zypp::ByteCount
Store and operate with byte count.
Definition ByteCount.h:32
zypp::OnMediaLocation
Describes a resource file located on a medium.
Definition onmedialocation.h:37
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::media::MediaCurl::Callbacks
Definition MediaCurl.h:106
zypp::media::MediaCurl::Callbacks::~Callbacks
virtual ~Callbacks()
Definition MediaCurl.cc:1444
zypp::media::MediaCurl::Callbacks::progress
virtual bool progress(int percent)=0
zypp::media::MediaCurl::setupEasy
virtual void setupEasy()
initializes the curl easy handle with the data from the url
Definition MediaCurl.cc:286
zypp::media::MediaCurl::setCookieFile
static void setCookieFile(const Pathname &)
Definition MediaCurl.cc:247
zypp::media::MediaCurl::getDoesFileExist
bool getDoesFileExist(const Pathname &filename) const override
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly,...
Definition MediaCurl.cc:671
zypp::media::MediaCurl::RequestOption
RequestOption
Definition MediaCurl.h:35
zypp::media::MediaCurl::OPTION_RANGE
@ OPTION_RANGE
retrieve only a range of the file
Definition MediaCurl.h:39
zypp::media::MediaCurl::OPTION_NO_IFMODSINCE
@ OPTION_NO_IFMODSINCE
to not add a IFMODSINCE header if target exists
Definition MediaCurl.h:43
zypp::media::MediaCurl::OPTION_NO_REPORT_START
@ OPTION_NO_REPORT_START
do not send a start ProgressReport
Definition MediaCurl.h:45
zypp::media::MediaCurl::OPTION_HEAD
@ OPTION_HEAD
only issue a HEAD (or equivalent) request
Definition MediaCurl.h:41
zypp::media::MediaCurl::OPTION_NONE
@ OPTION_NONE
Defaults.
Definition MediaCurl.h:37
zypp::media::MediaCurl::getFile
void getFile(const OnMediaLocation &file) const override
Call concrete handler to provide file below attach point.
Definition MediaCurl.cc:600
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:1268
zypp::media::MediaCurl::_currentCookieFile
std::string _currentCookieFile
Definition MediaCurl.h:163
zypp::media::MediaCurl::_cookieFile
static Pathname _cookieFile
Definition MediaCurl.h:164
zypp::media::MediaCurl::progressCallback
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:1225
zypp::media::MediaCurl::getFileCopy
void getFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename) const override
Definition MediaCurl.cc:609
zypp::media::MediaCurl::doGetFileCopy
virtual void doGetFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename, callback::SendReport< DownloadProgressReport > &_report, RequestOptions options=OPTION_NONE) const
Definition MediaCurl.cc:952
zypp::media::MediaCurl::_lastRedirect
std::string _lastRedirect
to log/report redirections
Definition MediaCurl.h:167
zypp::media::MediaCurl::clearQueryString
Url clearQueryString(const Url &url) const
Definition MediaCurl.cc:242
zypp::media::MediaCurl::attachTo
void attachTo(bool next=false) override
Call concrete handler to attach the media.
Definition MediaCurl.cc:532
zypp::media::MediaCurl::getDirInfo
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:1195
zypp::media::MediaCurl::_curlError
char _curlError[CURL_ERROR_SIZE]
Definition MediaCurl.h:165
zypp::media::MediaCurl::doGetFileCopyFile
void doGetFileCopyFile(const OnMediaLocation &srcFile, const Pathname &dest, FILE *file, callback::SendReport< DownloadProgressReport > &report, RequestOptions options=OPTION_NONE) const
Definition MediaCurl.cc:1062
zypp::media::MediaCurl::checkProtocol
void checkProtocol(const Url &url) const
check the url is supported by the curl library
Definition MediaCurl.cc:261
zypp::media::MediaCurl::MediaCurl
MediaCurl(const Url &url_r, const Pathname &attach_point_hint_r)
Definition MediaCurl.cc:207
zypp::media::MediaCurl::~MediaCurl
~MediaCurl() override
Definition MediaCurl.h:101
zypp::media::MediaCurl::executeCurl
CURLcode executeCurl() const
Definition MediaCurl.cc:1281
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:702
zypp::media::MediaCurl::curlError
const char * curlError() const
Definition MediaCurl.h:173
zypp::media::MediaCurl::_curl
CURL * _curl
Definition MediaCurl.h:170
zypp::media::MediaCurl::checkAttachPoint
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:567
zypp::media::MediaCurl::getDir
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:1162
zypp::media::MediaCurl::setCurlError
void setCurlError(const char *error)
Definition MediaCurl.cc:252
zypp::media::MediaCurl::authenticate
bool authenticate(const std::string &availAuthTypes, bool firstTry) const
Definition MediaCurl.cc:1342
zypp::media::MediaCurl::progressCallback_getcurl
static CURL * progressCallback_getcurl(void *clientp)
Definition MediaCurl.cc:1241
zypp::media::MediaCurl::releaseFrom
void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition MediaCurl.cc:593
zypp::media::MediaCurl::aliveCallback
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:1211
zypp::media::MediaCurl::disconnectFrom
void disconnectFrom() override
Definition MediaCurl.cc:574
zypp::media::MediaCurl::doGetDoesFileExist
virtual bool doGetDoesFileExist(const Pathname &filename) const
Definition MediaCurl.cc:843
zypp::media::MediaCurl::_customHeaders
curl_slist * _customHeaders
Definition MediaCurl.h:171
zypp::media::MediaCurl::getAuthHint
std::string getAuthHint() const
Return a comma separated list of available authentication methods supported by server.
Definition MediaCurl.cc:1249
zypp::media::MediaCurl::ZYPP_DECLARE_FLAGS
ZYPP_DECLARE_FLAGS(RequestOptions, RequestOption)
zypp::media::MediaHandler::url
Url url() const
Url used.
Definition MediaHandler.h:503
zypp::media::MediaHandler::release
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
Definition MediaHandler.cc:704
zypp::media::MediaNetworkCommonHandler::MediaNetworkCommonHandler
MediaNetworkCommonHandler(const Url &url_r, const Pathname &attach_point_r, const Pathname &urlpath_below_attachpoint_r, const bool does_download_r)
Definition MediaNetworkCommonHandler.h:33
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition PathInfo.h:526
zypp::media
Definition MediaCD.cc:47
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::callback::SendReport
Definition Callback.h:237
ZYPP_DECLARE_OPERATORS_FOR_FLAGS
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
Definition Flags.h:177
Flags.h