libzypp 17.37.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>
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 );
84 static CURL *progressCallback_getcurl( void *clientp );
85
86 void checkProtocol(const Url &url) const override;
87
92 void setupEasy(RequestData &rData, TransferSettings &settings );
93
106 void evaluateCurlCode( RequestData &rData, const zypp::Pathname &fileName, CURLcode code, bool timeout ) const;
107
108 static void resetExpectedFileSize ( void *clientp, const ByteCount &expectedFileSize );
109
110 private:
111
112 CURLcode executeCurl( RequestData &rData );
113
118 std::string getAuthHint(CURL *curl) const;
119
120 //bool authenticate(const std::string & availAuthTypes, bool firstTry) const;
121
122 bool detectDirIndex() const;
123
124 private:
127 char _curlError[ CURL_ERROR_SIZE ];
128
129 mutable std::string _lastRedirect;
130 curl_slist *_customHeaders;
131
132 const char* curlError() const { return _curlError; };
133 void setCurlError(const char* error);
134};
135
137
138 } // namespace media
139} // namespace zypp
140
141#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)
Definition MediaCurl.cc:984
void checkProtocol(const Url &url) const override
check the url is supported by the curl library
Definition MediaCurl.cc:263
static void setCookieFile(const Pathname &)
Definition MediaCurl.cc:249
bool getDoesFileExist(const Pathname &filename) const override
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly,...
Definition MediaCurl.cc:811
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:125
static Pathname _cookieFile
Definition MediaCurl.h:126
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:555
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:129
char _curlError[CURL_ERROR_SIZE]
Definition MediaCurl.h:127
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:841
bool detectDirIndex() const
CURLcode executeCurl(RequestData &rData)
const char * curlError() const
Definition MediaCurl.h:132
MediaCurl(const MirroredOrigin &origin_r, const Pathname &attach_point_hint_r)
Definition MediaCurl.cc:206
void setCurlError(const char *error)
Definition MediaCurl.cc:254
static CURL * progressCallback_getcurl(void *clientp)
void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition MediaCurl.cc:523
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:510
void setupEasy(RequestData &rData, TransferSettings &settings)
initializes the curl easy handle with the data from the url
Definition MediaCurl.cc:288
curl_slist * _customHeaders
Definition MediaCurl.h:130
void getFileCopy(const OnMediaLocation &srcFile, const Pathname &target) const override
Definition MediaCurl.cc:530
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.