libzypp 17.37.17
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>
19
20#include <curl/curl.h>
21
22namespace zypp {
23 namespace media {
24
26//
27// CLASS NAME : MediaCurl
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:
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
Store and operate with byte count.
Definition ByteCount.h:32
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Describes a resource file located on a medium.
Url manipulation class.
Definition Url.h:93
bool doGetDoesFileExist(const int mirror, const Pathname &filename)
static size_t writeCallback(char *ptr, size_t size, size_t nmemb, void *userdata)
Callback writing the data into our file.
void checkProtocol(const Url &url) const override
check the url is supported by the curl library
Definition MediaCurl.cc:288
static void setCookieFile(const Pathname &)
Definition MediaCurl.cc:274
bool getDoesFileExist(const Pathname &filename) const override
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly,...
Definition MediaCurl.cc:846
static void resetExpectedFileSize(void *clientp, const ByteCount &expectedFileSize)
MediaMultiCurl needs to reset the expected filesize in case a metalink file is downloaded otherwise t...
std::string _currentCookieFile
Definition MediaCurl.h:126
static Pathname _cookieFile
Definition MediaCurl.h:127
std::string getAuthHint(CURL *curl) const
Return a comma separated list of available authentication methods supported by server.
void getFileCopyFromMirror(const int mirror, const OnMediaLocation &srcFile, const Pathname &target)
Definition MediaCurl.cc:580
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.
std::string _lastRedirect
to log/report redirections
Definition MediaCurl.h:130
char _curlError[CURL_ERROR_SIZE]
Definition MediaCurl.h:128
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:876
bool detectDirIndex() const
CURLcode executeCurl(RequestData &rData)
const char * curlError() const
Definition MediaCurl.h:133
MediaCurl(const MirroredOrigin &origin_r, const Pathname &attach_point_hint_r)
Definition MediaCurl.cc:231
void setCurlError(const char *error)
Definition MediaCurl.cc:279
void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition MediaCurl.cc:548
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.
void disconnectFrom() override
Definition MediaCurl.cc:535
void setupEasy(RequestData &rData, TransferSettings &settings)
initializes the curl easy handle with the data from the url
Definition MediaCurl.cc:313
curl_slist * _customHeaders
Definition MediaCurl.h:131
void getFileCopy(const OnMediaLocation &srcFile, const Pathname &target) const override
Definition MediaCurl.cc:555
Url url() const
Primary Url used.
MediaNetworkCommonHandler(const MirroredOrigin &origin_r, const Pathname &attach_point_r, const Pathname &urlpath_below_attachpoint_r, const bool does_download_r)
Holds transfer setting.
Easy-to use interface to the ZYPP dependency resolver.