MediaCurl.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_MEDIA_MEDIACURL_H
00013 #define ZYPP_MEDIA_MEDIACURL_H
00014
00015 #include "zypp/base/Flags.h"
00016 #include "zypp/media/TransferSettings.h"
00017 #include "zypp/media/MediaHandler.h"
00018 #include "zypp/ZYppCallbacks.h"
00019
00020 #include <curl/curl.h>
00021
00022 namespace zypp {
00023 namespace media {
00024
00026
00027
00032 class MediaCurl : public MediaHandler
00033 {
00034 public:
00035 enum RequestOption
00036 {
00038 OPTION_NONE = 0x0,
00040 OPTION_RANGE = 0x1,
00042 OPTION_HEAD = 0x02,
00044 OPTION_NO_IFMODSINCE = 0x04,
00046 OPTION_NO_REPORT_START = 0x08,
00047 };
00048 ZYPP_DECLARE_FLAGS(RequestOptions,RequestOption);
00049
00050 protected:
00051
00052 Url clearQueryString(const Url &url) const;
00053
00054 virtual void attachTo (bool next = false);
00055 virtual void releaseFrom( const std::string & ejectDev );
00056 virtual void getFile( const Pathname & filename ) const;
00057 virtual void getDir( const Pathname & dirname, bool recurse_r ) const;
00058 virtual void getDirInfo( std::list<std::string> & retlist,
00059 const Pathname & dirname, bool dots = true ) const;
00060 virtual void getDirInfo( filesystem::DirContent & retlist,
00061 const Pathname & dirname, bool dots = true ) const;
00067 virtual bool getDoesFileExist( const Pathname & filename ) const;
00068
00072 virtual bool doGetDoesFileExist( const Pathname & filename ) const;
00073
00079 virtual void disconnectFrom();
00085 virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename) const;
00086
00092 virtual void doGetFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
00093
00094
00095 virtual bool checkAttachPoint(const Pathname &apoint) const;
00096
00097 public:
00098
00099 MediaCurl( const Url & url_r,
00100 const Pathname & attach_point_hint_r );
00101
00102 virtual ~MediaCurl() { try { release(); } catch(...) {} }
00103
00104 TransferSettings & settings();
00105
00106 static void setCookieFile( const Pathname & );
00107
00108 class Callbacks
00109 {
00110 public:
00111 virtual ~Callbacks() {}
00112 virtual bool progress( int percent ) = 0;
00113 };
00114
00115 protected:
00116
00117 static int progressCallback( void *clientp, double dltotal, double dlnow,
00118 double ultotal, double ulnow );
00123 void checkProtocol(const Url &url) const;
00124
00129 virtual void setupEasy();
00134 Url getFileUrl(const Pathname & filename) const;
00135
00148 void evaluateCurlCode( const zypp::Pathname &filename, CURLcode code, bool timeout ) const;
00149
00150 void doGetFileCopyFile( const Pathname & srcFilename, const Pathname & dest, FILE *file, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
00151
00152 private:
00157 std::string getAuthHint() const;
00158
00159 bool authenticate(const std::string & availAuthTypes, bool firstTry) const;
00160
00161 bool detectDirIndex() const;
00162
00163 private:
00164 long _curlDebug;
00165
00166 std::string _currentCookieFile;
00167 static Pathname _cookieFile;
00168
00169 protected:
00170 CURL *_curl;
00171 char _curlError[ CURL_ERROR_SIZE ];
00172 curl_slist *_customHeaders;
00173 TransferSettings _settings;
00174 };
00175 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions);
00176
00178
00179 }
00180 }
00181
00182 #endif // ZYPP_MEDIA_MEDIACURL_H