1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaCurl.h
12 #ifndef ZYPP_MEDIA_MEDIACURL_H
13 #define ZYPP_MEDIA_MEDIACURL_H
15 #include "zypp/base/Flags.h"
16 #include "zypp/media/TransferSettings.h"
17 #include "zypp/media/MediaHandler.h"
18 #include "zypp/ZYppCallbacks.h"
20 #include <curl/curl.h>
25 ///////////////////////////////////////////////////////////////////
27 // CLASS NAME : MediaCurl
29 * @short Implementation class for FTP, HTTP and HTTPS MediaHandler
32 class MediaCurl : public MediaHandler
39 /** retrieve only a range of the file */
41 /** only issue a HEAD (or equivalent) request */
43 /** to not add a IFMODSINCE header if target exists */
44 OPTION_NO_IFMODSINCE = 0x04,
45 /** do not send a start ProgressReport */
46 OPTION_NO_REPORT_START = 0x08,
48 ZYPP_DECLARE_FLAGS(RequestOptions,RequestOption);
52 Url clearQueryString(const Url &url) const;
54 virtual void attachTo (bool next = false);
55 virtual void releaseFrom( const std::string & ejectDev );
56 virtual void getFile( const Pathname & filename ) const;
57 virtual void getDir( const Pathname & dirname, bool recurse_r ) const;
58 virtual void getDirInfo( std::list<std::string> & retlist,
59 const Pathname & dirname, bool dots = true ) const;
60 virtual void getDirInfo( filesystem::DirContent & retlist,
61 const Pathname & dirname, bool dots = true ) const;
63 * Repeatedly calls doGetDoesFileExist() until it successfully returns,
64 * fails unexpectedly, or user cancels the operation. This is used to
65 * handle authentication or similar retry scenarios on media level.
67 virtual bool getDoesFileExist( const Pathname & filename ) const;
70 * \see MediaHandler::getDoesFileExist
72 virtual bool doGetDoesFileExist( const Pathname & filename ) const;
76 * \throws MediaException
79 virtual void disconnectFrom();
82 * \throws MediaException
85 virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename) const;
89 * \throws MediaException
92 virtual void doGetFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
95 virtual bool checkAttachPoint(const Pathname &apoint) const;
99 MediaCurl( const Url & url_r,
100 const Pathname & attach_point_hint_r );
102 virtual ~MediaCurl() { try { release(); } catch(...) {} }
104 TransferSettings & settings();
106 static void setCookieFile( const Pathname & );
111 virtual ~Callbacks() {}
112 virtual bool progress( int percent ) = 0;
117 static int progressCallback( void *clientp, double dltotal, double dlnow,
118 double ultotal, double ulnow );
119 static CURL *progressCallback_getcurl( void *clientp );
121 * check the url is supported by the curl library
122 * \throws MediaBadUrlException if there is a problem
124 void checkProtocol(const Url &url) const;
127 * initializes the curl easy handle with the data from the url
128 * \throws MediaCurlSetOptException if there is a problem
130 virtual void setupEasy();
132 * concatenate the attach url and the filename to a complete
135 Url getFileUrl(const Pathname & filename) const;
138 * Evaluates a curl return code and throws the right MediaException
139 * \p filename Filename being downloaded
140 * \p code Code curl returnes
141 * \p timeout Whether we reached timeout, which we need to differentiate
142 * in case the codes aborted-by-callback or timeout are returned by curl
143 * Otherwise we can't differentiate abort from timeout. Here you may
144 * want to pass the progress data object timeout-reached value, or
145 * just true if you are not doing user interaction.
147 * \throws MediaException If there is a problem
149 void evaluateCurlCode( const zypp::Pathname &filename, CURLcode code, bool timeout ) const;
151 void doGetFileCopyFile( const Pathname & srcFilename, const Pathname & dest, FILE *file, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
155 * Return a comma separated list of available authentication methods
156 * supported by server.
158 std::string getAuthHint() const;
160 bool authenticate(const std::string & availAuthTypes, bool firstTry) const;
162 bool detectDirIndex() const;
167 std::string _currentCookieFile;
168 static Pathname _cookieFile;
172 char _curlError[ CURL_ERROR_SIZE ];
173 curl_slist *_customHeaders;
174 TransferSettings _settings;
176 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions);
178 ///////////////////////////////////////////////////////////////////
183 #endif // ZYPP_MEDIA_MEDIACURL_H