13#include <zypp-curl/TransferSettings>
15#include <zypp-media/MediaException>
16#include <zypp-core/base/String.h>
22 , _requestDispatcher (
std::move(requestDispatcher) )
23 , _mirrorControl(
std::move(mirrors) )
24 , _spec(
std::move(spec) )
38 MIL <<
"Authentication failed for " << req->url() <<
" trying to recover." << std::endl;
41 const auto &applyCredToSettings = [&ts](
AuthData_Ptr auth,
const std::string &authHint ) {
47 if ( nwCred->authType() == CURLAUTH_NONE )
51 if ( nwCred->authType() != CURLAUTH_NONE ) {
68 if ( cachedCred && cachedCred->lastDatabaseUpdate() > req->_authTimestamp ) {
69 MIL <<
"Found a credential match in the cache!" << std::endl;
70 applyCredToSettings( cachedCred,
"" );
76 credFromUser->setUrl( req->url() );
77 credFromUser->setLastDatabaseUpdate ( req->_authTimestamp );
80 std::string authHint = err.
extraInfoValue(
"authHint", std::string());
83 if ( credFromUser->valid() ) {
86 applyCredToSettings( credFromUser, authHint );
95#if ENABLE_ZCHUNK_COMPRESSION
96 bool DownloadPrivateBase::hasZckInfo()
const
128 auto cState = currentState();
132 cState = currentState();
149 state<InitialState>()->initiate();
155 auto buildExtraInfo = [
this, &url](){
156 std::map<std::string, boost::any> extraInfo;
157 extraInfo.insert( {
"requestUrl", url } );
180 const auto cred = cm.
getCred( url );
181 if ( cred && cred->valid() ) {
213 const auto &s = d_func()->currentState();
235 if (! lReq.isError() ) {
239 return (
zypp::str::Format(
"%1%(%2%)") % lReq.toString() % lReq.nativeErrorString() );
251 if ( !d->_requestDispatcher )
257 d->visitState( [](
auto &s ){
258 using T = std::decay_t<
decltype (s)>;
259 if constexpr ( std::is_same_v<T, DlMetalinkState>
260#if ENABLE_ZCHUNK_COMPRESSION
261 || std::is_same_v<T, DLZckState>
277 d_func()->_stopOnMetalink = set;
282 return d_func()->_stoppedOnMetalink;
287 return d_func()->_spec;
292 return d_func()->_spec;
297 return d_func()->_lastTriedAuthTime;
302 return *d_func()->_requestDispatcher;
307 return d_func()->_sigStarted;
312 return d_func()->DownloadPrivateBase::_sigStateChanged;
317 return d_func()->_sigAlive;
322 return d_func()->_sigProgress;
327 return d_func()->DownloadPrivateBase::_sigFinished;
332 return d_func()->_sigAuthRequired;
337 , _mirrors(
std::move(mc) )
355 return dl.get() == &download;
382 while ( d->_runningDownloads.size() ) {
383 d->_runningDownloads.back()->cancel();
384 d->_runningDownloads.pop_back();
391 std::shared_ptr<Download> dl (
new Download ( *
this, d->_requestDispatcher, d->_mirrors,
DownloadSpec(spec) ) );
393 d->_runningDownloads.push_back( dl );
395 d->_requestDispatcher->run();
402 return d_func()->_requestDispatcher;
407 return d_func()->_sigStarted;
412 return d_func()->_sigFinished;
417 return d_func()->_queueEmpty;
Base class for Exception.
std::string asString() const
Error message provided by dumpOn as string.
time_t _lastTriedAuthTime
NetworkRequestError safeFillSettingsFromURL(const Url &url, TransferSettings &set)
Signal< void(Download &req, Download::State state)> _sigStateChanged
bool handleRequestAuthError(std::shared_ptr< Request > req, const zyppng::NetworkRequestError &err)
zypp::media::CredentialManager::CredentialSet _credCache
Signal< void(zyppng::Download &req, zyppng::NetworkAuthData &auth, const std::string &availAuth)> _sigAuthRequired
zypp::TriBool _specHasZckInfo
DownloadPrivateBase(Downloader &parent, std::shared_ptr< NetworkRequestDispatcher > requestDispatcher, std::shared_ptr< MirrorControl > mirrors, DownloadSpec &&spec, Download &p)
Signal< void(Download &req)> _sigFinished
DownloadPrivate(Downloader &parent, std::shared_ptr< NetworkRequestDispatcher > requestDispatcher, std::shared_ptr< MirrorControl > mirrors, DownloadSpec &&spec, Download &p)
const TransferSettings & settings() const
zypp::ByteCount headerSize() const
zypp::filesystem::Pathname deltaFile() const
const zypp::Pathname & targetPath() const
std::string errorString() const
void setStopOnMetalink(const bool set=true)
NetworkRequestDispatcher & dispatcher() const
SignalProxy< void(Download &req)> sigFinished()
SignalProxy< void(Download &req)> sigStarted()
SignalProxy< void(Download &req, State state)> sigStateChanged()
NetworkRequestError lastRequestError() const
SignalProxy< void(Download &req, off_t dlnow)> sigAlive()
uint64_t lastAuthTimestamp() const
SignalProxy< void(Download &req, NetworkAuthData &auth, const std::string &availAuth)> sigAuthRequired()
Download(Downloader &parent, std::shared_ptr< NetworkRequestDispatcher > requestDispatcher, std::shared_ptr< MirrorControl > mirrors, DownloadSpec &&spec)
SignalProxy< void(Download &req, off_t dltotal, off_t dlnow)> sigProgress()
bool stoppedOnMetalink() const
std::shared_ptr< MirrorControl > _mirrors
Signal< void(Downloader &parent, Download &download)> _sigStarted
std::vector< std::shared_ptr< Download > > _runningDownloads
void onDownloadFinished(Download &download)
Signal< void(Downloader &parent)> _queueEmpty
std::shared_ptr< NetworkRequestDispatcher > _requestDispatcher
Signal< void(Downloader &parent, Download &download)> _sigFinished
void onDownloadStarted(Download &download)
DownloaderPrivate(std::shared_ptr< MirrorControl > mc, Downloader &p)
SignalProxy< void(Downloader &parent)> queueEmpty()
std::shared_ptr< Download > downloadFile(const DownloadSpec &spec)
SignalProxy< void(Downloader &parent, Download &download)> sigStarted()
std::shared_ptr< NetworkRequestDispatcher > requestDispatcher() const
SignalProxy< void(Downloader &parent, Download &download)> sigFinished()
static zyppng::NetworkRequestError customError(NetworkRequestError::Type t, std::string &&errorMsg="", std::map< std::string, boost::any > &&extraInfo={})
The NetworkRequestError class Represents a error that occured in.
T extraInfoValue(const std::string &key, T &&defaultVal=T()) const
Type type() const
type Returns the type of the error
bool isError() const
isError Will return true if this is a actual error
void fillSettingsFromUrl(const Url &url, media::TransferSettings &s)
Fills the settings structure using options passed on the url for example ?timeout=x&proxy=foo.
void fillSettingsSystemProxy(const Url &url, media::TransferSettings &s)
Reads the system proxy configuration and fills the settings structure proxy information.
zypp::media::CurlAuthData_Ptr NetworkAuthData_Ptr
zypp::media::CurlAuthData NetworkAuthData
zypp::media::AuthData_Ptr AuthData_Ptr
ZYPP_IMPL_PRIVATE(Provide)
Url::asString() view options.
static const ViewOption WITH_PASSWORD
Option to include password in the URL string.
static const ViewOption WITH_USERNAME
Option to include username in the URL string.
static const ViewOption WITH_QUERY_STR
Option to include query string in the URL string.
connection _sigStartedConn
connection _sigFinishedConn
connection _sigProgressConn