libzypp  11.13.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"
18 #include "zypp/ZYppCallbacks.h"
19 
20 #include <curl/curl.h>
21 
22 namespace zypp {
23  namespace media {
24 
26 //
27 // CLASS NAME : MediaCurl
32 class MediaCurl : public MediaHandler
33 {
34  public:
36  {
38  OPTION_NONE = 0x0,
40  OPTION_RANGE = 0x1,
42  OPTION_HEAD = 0x02,
47  };
48  ZYPP_DECLARE_FLAGS(RequestOptions,RequestOption);
49 
50  protected:
51 
52  Url clearQueryString(const Url &url) const;
53 
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;
67  virtual bool getDoesFileExist( const Pathname & filename ) const;
68 
72  virtual bool doGetDoesFileExist( const Pathname & filename ) const;
73 
79  virtual void disconnectFrom();
85  virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename) const;
86 
92  virtual void doGetFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
93 
94 
95  virtual bool checkAttachPoint(const Pathname &apoint) const;
96 
97  public:
98 
99  MediaCurl( const Url & url_r,
100  const Pathname & attach_point_hint_r );
101 
102  virtual ~MediaCurl() { try { release(); } catch(...) {} }
103 
105 
106  static void setCookieFile( const Pathname & );
107 
108  class Callbacks
109  {
110  public:
111  virtual ~Callbacks() {}
112  virtual bool progress( int percent ) = 0;
113  };
114 
115  protected:
116 
117  static int progressCallback( void *clientp, double dltotal, double dlnow,
118  double ultotal, double ulnow );
123  void checkProtocol(const Url &url) const;
124 
129  virtual void setupEasy();
134  Url getFileUrl(const Pathname & filename) const;
135 
148  void evaluateCurlCode( const zypp::Pathname &filename, CURLcode code, bool timeout ) const;
149 
150  void doGetFileCopyFile( const Pathname & srcFilename, const Pathname & dest, FILE *file, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
151 
152  private:
157  std::string getAuthHint() const;
158 
159  bool authenticate(const std::string & availAuthTypes, bool firstTry) const;
160 
161  bool detectDirIndex() const;
162 
163  private:
165 
166  std::string _currentCookieFile;
167  static Pathname _cookieFile;
168 
169  protected:
170  CURL *_curl;
171  char _curlError[ CURL_ERROR_SIZE ];
172  curl_slist *_customHeaders;
174 };
175 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions);
176 
178 
179  } // namespace media
180 } // namespace zypp
181 
182 #endif // ZYPP_MEDIA_MEDIACURL_H