Fix memory corruption in curl media handler
[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     virtual void attachTo (bool next = false);
35     virtual void releaseFrom( const std::string & ejectDev );
36     virtual void getFile( const Pathname & filename ) const;
37     virtual void getDir( const Pathname & dirname, bool recurse_r ) const;
38     virtual void getDirInfo( std::list<std::string> & retlist,
39                              const Pathname & dirname, bool dots = true ) const;
40     virtual void getDirInfo( filesystem::DirContent & retlist,
41                              const Pathname & dirname, bool dots = true ) const;
42     /**
43      * Repeatedly calls doGetDoesFileExist() until it successfully returns,
44      * fails unexpectedly, or user cancels the operation. This is used to
45      * handle authentication or similar retry scenarios on media level.
46      */
47     virtual bool getDoesFileExist( const Pathname & filename ) const;
48
49     /**
50      * \see MediaHandler::getDoesFileExist
51      */
52     virtual bool doGetDoesFileExist( const Pathname & filename ) const;
53
54     /**
55      *
56      * \throws MediaException
57      *
58      */
59     virtual void disconnectFrom();
60     /**
61      *
62      * \throws MediaException
63      *
64      */
65     virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename) const;
66
67     /**
68      *
69      * \throws MediaException
70      *
71      */
72     virtual void doGetFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report) const;
73
74
75     virtual bool checkAttachPoint(const Pathname &apoint) const;
76
77   public:
78
79     MediaCurl( const Url &      url_r,
80                const Pathname & attach_point_hint_r );
81
82     virtual ~MediaCurl() { try { release(); } catch(...) {} }
83
84     static void setCookieFile( const Pathname & );
85
86     class Callbacks
87     {
88       public:
89         virtual ~Callbacks() {}
90         virtual bool progress( int percent ) = 0;
91     };
92
93   protected:
94
95     static int progressCallback( void *clientp, double dltotal, double dlnow,
96                                  double ultotal, double ulnow );
97
98     /** The user agent string */
99     static const char *const agentString();
100
101   private:
102     /**
103      * Return a comma separated list of available authentication methods
104      * supported by server.
105      */
106     std::string getAuthHint() const;
107
108   private:
109     CURL *_curl;
110     char _curlError[ CURL_ERROR_SIZE ];
111     long _curlDebug;
112
113     mutable std::string _userpwd;
114     std::string _proxy;
115     std::string _proxyuserpwd;
116     std::string _currentCookieFile;
117     std::string _ca_path;
118     long        _xfer_timeout;
119
120     static Pathname _cookieFile;
121 };
122
123 ///////////////////////////////////////////////////////////////////
124
125   } // namespace media
126 } // namespace zypp
127
128 #endif // ZYPP_MEDIA_MEDIACURL_H