- catch exceptions in dtors
[platform/upstream/libzypp.git] / zypp / media / MediaCurl.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaCurl.h
10  *
11 */
12 #ifndef ZYPP_MEDIA_MEDIACURL_H
13 #define ZYPP_MEDIA_MEDIACURL_H
14
15 #include "zypp/media/MediaHandler.h"
16 #include "zypp/ZYppCallbacks.h"
17
18 #include <curl/curl.h>
19
20 namespace zypp {
21   namespace media {
22
23 ///////////////////////////////////////////////////////////////////
24 //
25 //      CLASS NAME : MediaCurl
26 /**
27  * @short Implementation class for FTP, HTTP and HTTPS MediaHandler
28  * @see MediaHandler
29  **/
30 class MediaCurl : public MediaHandler {
31
32   protected:
33
34     MEDIA_HANDLER_API;
35     /**
36      *
37      * \throws MediaException
38      *
39      */
40     virtual void disconnectFrom();
41     /**
42      *
43      * \throws MediaException
44      *
45      */
46     virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename) const;
47
48     /**
49      *
50      * \throws MediaException
51      *
52      */
53     virtual void doGetFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report) const;
54
55
56
57   public:
58
59     MediaCurl( const Url &      url_r,
60                const Pathname & attach_point_hint_r );
61
62     virtual ~MediaCurl() { try { release(); } catch(...) {} }
63
64     static void setCookieFile( const Pathname & );
65
66     class Callbacks
67     {
68       public:
69         virtual ~Callbacks() {}
70         virtual bool progress( int percent ) = 0;
71     };
72
73   protected:
74
75     static int progressCallback( void *clientp, double dltotal, double dlnow,
76                                  double ultotal, double ulnow );
77
78   private:
79     CURL *_curl;
80     char _curlError[ CURL_ERROR_SIZE ];
81
82     std::string _userpwd;
83     std::string _proxy;
84     std::string _proxyuserpwd;
85     std::string _currentCookieFile;
86
87     static Pathname _cookieFile;
88
89     bool _connected;
90
91     static bool _globalInit;
92 };
93
94 ///////////////////////////////////////////////////////////////////
95
96   } // namespace media
97 } // namespace zypp
98
99 #endif // ZYPP_MEDIA_MEDIACURL_H