libzypp  17.37.5
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 
22 namespace 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 MediaUrl &url_r,
73  const std::vector<MediaUrl> &mirrors_r,
74  const Pathname &attach_point_hint_r );
75 
76  ~MediaCurl() override;
77 
78  static void setCookieFile( const Pathname & );
79 
80  protected:
82  static int aliveCallback( void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow );
84  static int progressCallback( void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow );
85  static CURL *progressCallback_getcurl( void *clientp );
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;
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
Describes a resource file located on a medium.
Implementation class for FTP, HTTP and HTTPS MediaHandler.
Definition: MediaCurl.h:32
CURLcode executeCurl(RequestData &rData)
Definition: MediaCurl.cc:1158
Store and operate with byte count.
Definition: ByteCount.h:31
Holds transfer setting.
bool doGetDoesFileExist(const int mirror, const Pathname &filename)
Definition: MediaCurl.cc:983
void setupEasy(RequestData &rData, TransferSettings &settings)
initializes the curl easy handle with the data from the url
Definition: MediaCurl.cc:288
std::string _currentCookieFile
Definition: MediaCurl.h:126
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:840
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
void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition: MediaCurl.cc:523
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:1145
bool detectDirIndex() const
MediaCurl(const MediaUrl &url_r, const std::vector< MediaUrl > &mirrors_r, const Pathname &attach_point_hint_r)
Definition: MediaCurl.cc:206
const char * curlError() const
Definition: MediaCurl.h:133
void getFileCopyFromMirror(const int mirror, const OnMediaLocation &srcFile, const Pathname &target)
Definition: MediaCurl.cc:554
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:1102
bool getDoesFileExist(const Pathname &filename) const override
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly, or user cancels the operation.
Definition: MediaCurl.cc:810
curl_slist * _customHeaders
Definition: MediaCurl.h:131
std::string _lastRedirect
to log/report redirections
Definition: MediaCurl.h:130
Url url() const
Primary Url used.
Definition: MediaHandler.h:509
void disconnectFrom() override
Definition: MediaCurl.cc:510
static CURL * progressCallback_getcurl(void *clientp)
Definition: MediaCurl.cc:1118
void setCurlError(const char *error)
Definition: MediaCurl.cc:254
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.
Definition: MediaCurl.cc:1126
void getFileCopy(const OnMediaLocation &srcFile, const Pathname &target) const override
Definition: MediaCurl.cc:530
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
char _curlError[CURL_ERROR_SIZE]
Definition: MediaCurl.h:128
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:1088
Url manipulation class.
Definition: Url.h:92