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,
00043 };
00044 ZYPP_DECLARE_FLAGS(RequestOptions,RequestOption);
00045
00046 protected:
00047
00048 virtual void attachTo (bool next = false);
00049 virtual void releaseFrom( const std::string & ejectDev );
00050 virtual void getFile( const Pathname & filename ) const;
00051 virtual void getDir( const Pathname & dirname, bool recurse_r ) const;
00052 virtual void getDirInfo( std::list<std::string> & retlist,
00053 const Pathname & dirname, bool dots = true ) const;
00054 virtual void getDirInfo( filesystem::DirContent & retlist,
00055 const Pathname & dirname, bool dots = true ) const;
00061 virtual bool getDoesFileExist( const Pathname & filename ) const;
00062
00066 virtual bool doGetDoesFileExist( const Pathname & filename ) const;
00067
00073 virtual void disconnectFrom();
00079 virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename) const;
00080
00086 virtual void doGetFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
00087
00088
00089 virtual bool checkAttachPoint(const Pathname &apoint) const;
00090
00091 public:
00092
00093 MediaCurl( const Url & url_r,
00094 const Pathname & attach_point_hint_r );
00095
00096 virtual ~MediaCurl() { try { release(); } catch(...) {} }
00097
00098 static void setCookieFile( const Pathname & );
00099
00100 class Callbacks
00101 {
00102 public:
00103 virtual ~Callbacks() {}
00104 virtual bool progress( int percent ) = 0;
00105 };
00106
00107 protected:
00108
00109 static int progressCallback( void *clientp, double dltotal, double dlnow,
00110 double ultotal, double ulnow );
00111 private:
00116 std::string getAuthHint() const;
00117
00118 bool authenticate(const std::string & availAuthTypes, bool firstTry) const;
00119
00120 private:
00121
00134 void evaluateCurlCode( const zypp::Pathname &filename, CURLcode code, bool timeout ) const;
00135
00136 CURL *_curl;
00137 char _curlError[ CURL_ERROR_SIZE ];
00138 long _curlDebug;
00139 curl_slist *_customHeaders;
00140
00141 std::string _currentCookieFile;
00142 static Pathname _cookieFile;
00143 protected:
00144 TransferSettings _settings;
00145 };
00146 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions);
00147
00149
00150 }
00151 }
00152
00153 #endif // ZYPP_MEDIA_MEDIACURL_H