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 virtual void attachTo (bool next = false);
00053 virtual void releaseFrom( const std::string & ejectDev );
00054 virtual void getFile( const Pathname & filename ) const;
00055 virtual void getDir( const Pathname & dirname, bool recurse_r ) const;
00056 virtual void getDirInfo( std::list<std::string> & retlist,
00057 const Pathname & dirname, bool dots = true ) const;
00058 virtual void getDirInfo( filesystem::DirContent & retlist,
00059 const Pathname & dirname, bool dots = true ) const;
00065 virtual bool getDoesFileExist( const Pathname & filename ) const;
00066
00070 virtual bool doGetDoesFileExist( const Pathname & filename ) const;
00071
00077 virtual void disconnectFrom();
00083 virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename) const;
00084
00090 virtual void doGetFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
00091
00092
00093 virtual bool checkAttachPoint(const Pathname &apoint) const;
00094
00095 public:
00096
00097 MediaCurl( const Url & url_r,
00098 const Pathname & attach_point_hint_r );
00099
00100 virtual ~MediaCurl() { try { release(); } catch(...) {} }
00101
00102 TransferSettings & settings();
00103
00104 static void setCookieFile( const Pathname & );
00105
00106 class Callbacks
00107 {
00108 public:
00109 virtual ~Callbacks() {}
00110 virtual bool progress( int percent ) = 0;
00111 };
00112
00113 protected:
00114
00115 static int progressCallback( void *clientp, double dltotal, double dlnow,
00116 double ultotal, double ulnow );
00121 void checkProtocol(const Url &url) const;
00122
00127 virtual void setupEasy();
00132 Url getFileUrl(const Pathname & filename) const;
00133
00146 void evaluateCurlCode( const zypp::Pathname &filename, CURLcode code, bool timeout ) const;
00147
00148 void doGetFileCopyFile( const Pathname & srcFilename, const Pathname & dest, FILE *file, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
00149
00150 private:
00155 std::string getAuthHint() const;
00156
00157 bool authenticate(const std::string & availAuthTypes, bool firstTry) const;
00158
00159 bool detectDirIndex() const;
00160
00161 private:
00162 long _curlDebug;
00163
00164 std::string _currentCookieFile;
00165 static Pathname _cookieFile;
00166
00167 protected:
00168 CURL *_curl;
00169 char _curlError[ CURL_ERROR_SIZE ];
00170 curl_slist *_customHeaders;
00171 TransferSettings _settings;
00172 };
00173 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions);
00174
00176
00177 }
00178 }
00179
00180 #endif // ZYPP_MEDIA_MEDIACURL_H