libzypp: zypp/media/MediaCurl.h Source File

libzypp 17.38.7

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-core/base/Flags.h>
16#include <zypp/ZYppCallbacks.h>
17#include <zypp/media/MediaNetworkCommonHandler.h>
18#include <zypp-curl/private/curlhelper_p.h>
19
20#include <curl/curl.h>
21
22namespace zypp {
23 namespace media {
24
26//
27// CLASS NAME : MediaCurl
32 class MediaCurl : public MediaNetworkCommonHandler, public internal::CurlPollHelper::CurlPoll
33{
34 struct RequestData {
35 int mirror = -1;
36 CURL *curl = nullptr;
37 };
38
39 protected:
40
41 void releaseFrom( const std::string & ejectDev ) override;
42
48 bool getDoesFileExist( const Pathname & filename ) const override;
49
53 bool doGetDoesFileExist( const int mirror, const Pathname & filename );
54
60 void disconnectFrom() override;
66 void getFileCopy( const OnMediaLocation& srcFile, const Pathname & target ) const override;
67
68 void getFileCopyFromMirror(const int mirror, const OnMediaLocation& srcFile, const Pathname & target );
69
70 public:
71
72 MediaCurl( const MirroredOrigin &origin_r,
73 const Pathname &attach_point_hint_r );
74
75 ~MediaCurl() override;
76
77 static void setCookieFile( const Pathname & );
78
79 protected:
81 static int aliveCallback( void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow );
83 static int progressCallback( void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow );
85 static size_t writeCallback( char *ptr, size_t size, size_t nmemb, void *userdata );
86
87 void checkProtocol(const Url &url) const override;
88
93 void setupEasy(RequestData &rData, TransferSettings &settings );
94
107 void evaluateCurlCode( RequestData &rData, const zypp::Pathname &fileName, CURLcode code, bool timeout ) const;
108
109 static void resetExpectedFileSize ( void *clientp, const ByteCount &expectedFileSize );
110
111 private:
112
113 CURLcode executeCurl( RequestData &rData );
114
119 std::string getAuthHint(CURL *curl) const;
120
121 //bool authenticate(const std::string & availAuthTypes, bool firstTry) const;
122
123 bool detectDirIndex() const;
124
125 private:
126 std::string _currentCookieFile;
127 static Pathname _cookieFile;
128 char _curlError[ CURL_ERROR_SIZE ];
129
130 mutable std::string _lastRedirect;
131 curl_slist *_customHeaders;
132
133 const char* curlError() const { return _curlError; };
134 void setCurlError(const char* error);
135};
136
138
139 } // namespace media
140} // namespace zypp
141
142#endif // ZYPP_MEDIA_MEDIACURL_H
Flags.h
MediaNetworkCommonHandler.h
ZYppCallbacks.h
zypp::ByteCount
Store and operate with byte count.
Definition ByteCount.h:32
zypp::MirroredOrigin
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Definition MirroredOrigin.h:170
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:48
zypp::media::MediaCurl::doGetDoesFileExist
bool doGetDoesFileExist(const int mirror, const Pathname &filename)
Definition MediaCurl.cc:1020
zypp::media::MediaCurl::writeCallback
static size_t writeCallback(char *ptr, size_t size, size_t nmemb, void *userdata)
Callback writing the data into our file.
Definition MediaCurl.cc:1155
zypp::media::MediaCurl::checkProtocol
void checkProtocol(const Url &url) const override
check the url is supported by the curl library
Definition MediaCurl.cc:288
zypp::media::MediaCurl::setCookieFile
static void setCookieFile(const Pathname &)
Definition MediaCurl.cc:274
zypp::media::MediaCurl::getDoesFileExist
bool getDoesFileExist(const Pathname &filename) const override
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly,...
Definition MediaCurl.cc:844
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:1185
zypp::media::MediaCurl::_currentCookieFile
std::string _currentCookieFile
Definition MediaCurl.h:126
zypp::media::MediaCurl::_cookieFile
static Pathname _cookieFile
Definition MediaCurl.h:127
zypp::media::MediaCurl::getAuthHint
std::string getAuthHint(CURL *curl) const
Return a comma separated list of available authentication methods supported by server.
Definition MediaCurl.cc:1166
zypp::media::MediaCurl::getFileCopyFromMirror
void getFileCopyFromMirror(const int mirror, const OnMediaLocation &srcFile, const Pathname &target)
Definition MediaCurl.cc:579
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:1139
zypp::media::MediaCurl::_lastRedirect
std::string _lastRedirect
to log/report redirections
Definition MediaCurl.h:130
zypp::media::MediaCurl::_curlError
char _curlError[CURL_ERROR_SIZE]
Definition MediaCurl.h:128
zypp::media::MediaCurl::~MediaCurl
~MediaCurl() override
Definition MediaCurl.cc:267
zypp::media::MediaCurl::evaluateCurlCode
void evaluateCurlCode(RequestData &rData, 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:877
zypp::media::MediaCurl::detectDirIndex
bool detectDirIndex() const
zypp::media::MediaCurl::executeCurl
CURLcode executeCurl(RequestData &rData)
Definition MediaCurl.cc:1198
zypp::media::MediaCurl::curlError
const char * curlError() const
Definition MediaCurl.h:133
zypp::media::MediaCurl::MediaCurl
MediaCurl(const MirroredOrigin &origin_r, const Pathname &attach_point_hint_r)
Definition MediaCurl.cc:231
zypp::media::MediaCurl::setCurlError
void setCurlError(const char *error)
Definition MediaCurl.cc:279
zypp::media::MediaCurl::releaseFrom
void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition MediaCurl.cc:544
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:1125
zypp::media::MediaCurl::disconnectFrom
void disconnectFrom() override
Definition MediaCurl.cc:531
zypp::media::MediaCurl::setupEasy
void setupEasy(RequestData &rData, TransferSettings &settings)
initializes the curl easy handle with the data from the url
Definition MediaCurl.cc:313
zypp::media::MediaCurl::_customHeaders
curl_slist * _customHeaders
Definition MediaCurl.h:131
zypp::media::MediaCurl::getFileCopy
void getFileCopy(const OnMediaLocation &srcFile, const Pathname &target) const override
Definition MediaCurl.cc:551
zypp::media::MediaHandler::url
Url url() const
Primary Url used.
Definition MediaHandler.h:507
zypp::media::MediaNetworkCommonHandler::MediaNetworkCommonHandler
MediaNetworkCommonHandler(const MirroredOrigin &origin_r, const Pathname &attach_point_r, const Pathname &urlpath_below_attachpoint_r, const bool does_download_r)
Definition MediaNetworkCommonHandler.cc:36
zypp::media::TransferSettings
Holds transfer setting.
Definition transfersettings.h:34
curlhelper_p.h
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp::target
Definition KeyRing.h:325
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
internal::CurlPollHelper::CurlPoll
Definition curlhelper_p.h:80
zypp::media::MediaCurl::RequestData
Definition MediaCurl.h:34
zypp::media::MediaCurl::RequestData::mirror
int mirror
Definition MediaCurl.h:35
zypp::media::MediaCurl::RequestData::curl
CURL * curl
Definition MediaCurl.h:36