- put AuthType in settings
[platform/upstream/libzypp.git] / zypp / media / TransferSettings.cc
1 #include <iostream>
2 #include <sstream>
3
4 #include "zypp/base/String.h"
5 #include "zypp/base/Logger.h"
6 #include "zypp/base/WatchFile.h"
7 #include "zypp/base/ReferenceCounted.h"
8 #include "zypp/base/NonCopyable.h"
9 #include "zypp/ExternalProgram.h"
10 #include "zypp/media/TransferSettings.h"
11 #include "zypp/ZConfig.h"
12
13 using namespace std;
14
15 #define ARIA2C_BINARY "/usr/bin/aria2c"
16 #define CURL_BINARY "/usr/bin/curl"
17
18 namespace zypp
19 {
20 namespace media
21 {
22     
23 class TransferSettings::Impl
24 {
25 public:
26     Impl()
27         : _useproxy(false)
28         , _timeout(0)
29         , _connect_timeout(0)
30         , _maxConcurrentConnections(ZConfig::instance().download_max_concurrent_connections())
31         , _minDownloadSpeed(ZConfig::instance().download_min_download_speed())
32         , _maxDownloadSpeed(ZConfig::instance().download_max_download_speed())
33         , _maxSilentTries(ZConfig::instance().download_max_silent_tries())
34         , _verify_host(false)
35         , _verify_peer(false)
36         , _ca_path("/etc/ssl/certs")
37     {}
38
39     virtual ~Impl()
40     {}    
41
42     /** Offer default Impl. */
43     static shared_ptr<Impl> nullimpl()
44     {
45       static shared_ptr<Impl> _nullimpl( new Impl );
46       return _nullimpl;
47     }
48
49 private:
50     friend Impl * rwcowClone<Impl>( const Impl * rhs );
51     /** clone for RWCOW_pointer */
52     Impl * clone() const
53     { return new Impl( *this ); }
54
55 public:
56     vector<string> _headers;
57     string _useragent;
58     string _username;
59     string _password;
60     bool _useproxy;
61     string _proxy;
62     string _proxy_username;
63     string _proxy_password;
64     string _authtype;
65     long _timeout;
66     long _connect_timeout;
67     Url _url;
68     Pathname _targetdir;
69
70     long _maxConcurrentConnections;
71     long _minDownloadSpeed;
72     long _maxDownloadSpeed;
73     long _maxSilentTries;
74
75     bool _verify_host;
76     bool _verify_peer;
77     Pathname _ca_path;
78 };
79     
80 TransferSettings::TransferSettings()
81     : _impl(new TransferSettings::Impl())
82 {
83
84 }
85
86 void TransferSettings::reset()
87 {
88     _impl.reset(new TransferSettings::Impl());
89 }
90
91 void TransferSettings::addHeader( const std::string &header )
92 {
93     _impl->_headers.push_back(header);
94 }
95
96 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
97 {
98     return _impl->_headers.begin();
99 }
100
101 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
102 {
103     return _impl->_headers.end();
104 }
105
106 void TransferSettings::setUserAgentString( const std::string &agent )
107 {
108     _impl->_useragent = agent;
109 }
110
111 std::string TransferSettings::userAgentString() const
112 {
113     return _impl->_useragent;
114 }
115
116 void TransferSettings::setUsername( const std::string &username )
117 {
118     _impl->_username = username;
119 }
120
121 std::string TransferSettings::username() const
122 {
123     return _impl->_username;
124 }
125
126 void TransferSettings::setPassword( const std::string &password )
127 {
128     _impl->_password = password;
129 }
130
131 void TransferSettings::setAnonymousAuth()
132 {
133     setUsername("anonymous");
134     string id = "yast@";
135     setPassword(id + VERSION);
136 }
137
138 std::string TransferSettings::password() const
139 {
140     return _impl->_password;
141 }
142
143 std::string TransferSettings::userPassword() const
144 {
145     string userpwd = username();
146     if ( password().size() ) {
147         userpwd += ":" + password();
148     }
149     return userpwd;
150 }
151
152 void TransferSettings::setProxyEnabled( bool enabled )
153 {
154     _impl->_useproxy = enabled;
155 }
156
157 bool TransferSettings::proxyEnabled() const
158 {
159     return _impl->_useproxy;
160 }
161
162 void TransferSettings::setProxy( const std::string &proxy )
163 {
164     _impl->_proxy = proxy;
165 }
166
167 std::string TransferSettings::proxy() const
168 {
169     return _impl->_proxy;
170 }
171
172 void TransferSettings::setProxyUsername( const std::string &proxyuser )
173 {
174     _impl->_proxy_username = proxyuser;
175 }
176
177 std::string TransferSettings::proxyUsername() const
178 {
179     return _impl->_proxy_username;
180 }
181
182 void TransferSettings::setProxyPassword( const std::string &proxypass )
183 {
184     _impl->_proxy_password = proxypass;
185 }
186
187 std::string TransferSettings::proxyPassword() const
188 {
189     return _impl->_proxy_password;
190 }
191
192 std::string TransferSettings::proxyUserPassword() const
193 {
194     string userpwd = proxyUsername();
195     if ( proxyPassword().size() ) {
196         userpwd += ":" + proxyPassword();
197     }
198     return userpwd;
199 }
200
201 void TransferSettings::setTimeout( long t )
202 {
203     _impl->_timeout = t;
204 }
205
206 long TransferSettings::timeout() const
207 {
208     return _impl->_timeout;
209 }
210
211 void TransferSettings::setConnectTimeout( long t )
212 {
213     _impl->_connect_timeout = t;
214 }
215
216 long TransferSettings::connectTimeout() const
217 {
218     return _impl->_connect_timeout;
219 }
220
221 long TransferSettings::maxConcurrentConnections() const
222 {
223     return _impl->_maxConcurrentConnections;
224 }
225
226 void TransferSettings::setMaxConcurrentConnections(long v)
227 {
228     _impl->_maxConcurrentConnections = v;
229 }
230
231 long TransferSettings::minDownloadSpeed() const
232 {
233     return _impl->_minDownloadSpeed;
234 }
235
236 void TransferSettings::setMinDownloadSpeed(long v)
237 {
238     _impl->_minDownloadSpeed = v;
239 }
240
241 long TransferSettings::maxDownloadSpeed() const
242 {
243     return _impl->_maxDownloadSpeed;
244 }
245
246 void TransferSettings::setMaxDownloadSpeed(long v)
247 {
248     _impl->_maxDownloadSpeed = v;
249 }
250
251 long TransferSettings::maxSilentTries() const
252 {
253     return _impl->_maxSilentTries;
254 }
255
256 void TransferSettings::setMaxSilentTries(long v)
257 {
258     _impl->_maxSilentTries = v;
259 }
260
261 bool TransferSettings::verifyHostEnabled() const
262 {
263     return _impl->_verify_host;
264 }
265
266 void TransferSettings::setVerifyHostEnabled( bool enabled )
267 {
268     _impl->_verify_host = enabled;
269 }
270
271 bool TransferSettings::verifyPeerEnabled() const
272 {
273     return _impl->_verify_peer;
274 }
275
276
277 void TransferSettings::setVerifyPeerEnabled( bool enabled )
278 {
279     _impl->_verify_peer = enabled;
280 }
281
282 Pathname TransferSettings::certificateAuthoritiesPath() const
283 {
284     return _impl->_ca_path;
285 }
286
287 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
288 {
289     _impl->_ca_path = path;
290 }
291
292 void TransferSettings::setAuthType( const std::string &authtype)
293 {
294     _impl->_authtype = authtype;
295 }
296
297 std::string TransferSettings::authType() const
298 {
299     return _impl->_authtype;
300 }
301
302
303
304 } // ns media
305 } // ns zypp
306