14 #include <zypp-curl/TransferSettings> 16 #include <zypp-media/MediaException> 23 , _requestDispatcher (
std::move(requestDispatcher) )
24 , _mirrorControl(
std::move(mirrors) )
25 , _spec(
std::move(spec) )
39 MIL <<
"Authentication failed for " << req->url() <<
" trying to recover." << std::endl;
42 const auto &applyCredToSettings = [&ts](
const AuthData_Ptr& auth,
const std::string &authHint ) {
48 if ( nwCred->authType() == CURLAUTH_NONE )
52 if ( nwCred->authType() != CURLAUTH_NONE ) {
69 if ( cachedCred && cachedCred->lastDatabaseUpdate() > req->_authTimestamp ) {
70 MIL <<
"Found a credential match in the cache!" << std::endl;
71 applyCredToSettings( cachedCred,
"" );
77 credFromUser->setUrl( req->url() );
78 credFromUser->setLastDatabaseUpdate ( req->_authTimestamp );
81 std::string authHint = err.
extraInfoValue(
"authHint", std::string());
84 if ( credFromUser->valid() ) {
87 applyCredToSettings( credFromUser, authHint );
96 #if ENABLE_ZCHUNK_COMPRESSION 97 bool DownloadPrivateBase::hasZckInfo()
const 150 state<InitialState>()->initiate();
156 auto buildExtraInfo = [
this, &url](){
157 std::map<std::string, boost::any> extraInfo;
158 extraInfo.insert( {
"requestUrl", url } );
177 if (
set.authType() ==
"basic" 178 &&
set.username().size()
179 && !
set.password().size() ) {
181 const auto cred = cm.
getCred( url );
182 if ( cred && cred->valid() ) {
183 if ( !
set.username().size() )
184 set.setUsername(cred->username());
185 set.setPassword(cred->password());
214 const auto &s = d_func()->currentState();
236 if (! lReq.isError() ) {
240 return (
zypp::str::Format(
"%1%(%2%)") % lReq.toString() % lReq.nativeErrorString() );
252 if ( !d->_requestDispatcher )
258 d->visitState( [](
auto &s ){
259 using T = std::decay_t<decltype (s)>;
260 if constexpr ( std::is_same_v<T, DlMetalinkState>
261 #
if ENABLE_ZCHUNK_COMPRESSION
262 || std::is_same_v<T, DLZckState>
278 d_func()->_stopOnMetalink =
set;
283 return d_func()->_stoppedOnMetalink;
288 return d_func()->_spec;
293 return d_func()->_spec;
298 return d_func()->_lastTriedAuthTime;
303 return *d_func()->_requestDispatcher;
308 return d_func()->_sigStarted;
313 return d_func()->DownloadPrivateBase::_sigStateChanged;
318 return d_func()->_sigAlive;
323 return d_func()->_sigProgress;
328 return d_func()->DownloadPrivateBase::_sigFinished;
333 return d_func()->_sigAuthRequired;
338 , _mirrors(
std::move(mc) )
383 while ( d->_runningDownloads.size() ) {
384 d->_runningDownloads.back()->cancel();
385 d->_runningDownloads.pop_back();
392 std::shared_ptr<Download> dl (
new Download ( *
this, d->_requestDispatcher, d->_mirrors,
DownloadSpec(spec) ) );
394 d->_runningDownloads.push_back( dl );
396 d->_requestDispatcher->run();
403 return d_func()->_requestDispatcher;
408 return d_func()->_sigStarted;
413 return d_func()->_sigFinished;
418 return d_func()->_queueEmpty;
bool isError() const
isError Will return true if this is a actual error
zypp::media::AuthData_Ptr AuthData_Ptr
static const ViewOption WITH_USERNAME
Option to include username in the URL string.
SignalProxy< void(Download &req, off_t dlnow)> sigAlive()
DownloaderPrivate(std::shared_ptr< MirrorControl > mc, Downloader &p)
bool handleRequestAuthError(const std::shared_ptr< Request > &req, const zyppng::NetworkRequestError &err)
void setStopOnMetalink(const bool set=true)
SignalProxy< void(Download &req, NetworkAuthData &auth, const std::string &availAuth)> sigAuthRequired()
std::shared_ptr< NetworkRequestDispatcher > _requestDispatcher
DownloadPrivateBase(Downloader &parent, std::shared_ptr< NetworkRequestDispatcher > requestDispatcher, std::shared_ptr< MirrorControl > mirrors, DownloadSpec &&spec, Download &p)
zypp::TriBool _specHasZckInfo
connection _sigProgressConn
connection _sigStartedConn
Signal< void(Download &req, Download::State state)> _sigStateChanged
std::vector< std::shared_ptr< Download > > _runningDownloads
uint64_t lastAuthTimestamp() const
SignalProxy< void(Downloader &parent, Download &download)> sigStarted()
SignalProxy< void(Download &req)> sigFinished()
Url::asString() view options.
zypp::filesystem::Pathname deltaFile() const
Signal< void(Downloader &parent, Download &download)> _sigFinished
void onDownloadFinished(Download &download)
SignalProxy< void(Downloader &parent, Download &download)> sigFinished()
Signal< void(Downloader &parent)> _queueEmpty
AsyncOpRef< expected< repo::AsyncDownloadContextRef > > download(repo::AsyncDownloadContextRef dl, ProvideMediaHandle mediaHandle, ProgressObserverRef progressObserver)
zypp::repo::RepoException _error
std::shared_ptr< T > state()
time_t _lastTriedAuthTime
std::shared_ptr< MirrorControl > _mirrors
T extraInfoValue(const std::string &key, T &&defaultVal=T()) const
std::string asString() const
Error message provided by dumpOn as string.
Download(Downloader &parent, std::shared_ptr< NetworkRequestDispatcher > requestDispatcher, std::shared_ptr< MirrorControl > mirrors, DownloadSpec &&spec)
bool stoppedOnMetalink() const
The NetworkRequestError class Represents a error that occured in.
std::shared_ptr< NetworkRequestDispatcher > requestDispatcher() const
zypp::media::CurlAuthData_Ptr NetworkAuthData_Ptr
void fillSettingsFromUrl(const Url &url, media::TransferSettings &s)
Fills the settings structure using options passed on the url for example ?timeout=x&proxy=foo.
std::shared_ptr< Download > downloadFile(const DownloadSpec &spec)
NetworkRequestDispatcher & dispatcher() const
const zypp::Pathname & targetPath() const
NetworkRequestError lastRequestError() const
static const ViewOption WITH_QUERY_STR
Option to include query string in the URL string.
zypp::media::CurlAuthData NetworkAuthData
SignalProxy< void(Downloader &parent)> queueEmpty()
NetworkRequestError safeFillSettingsFromURL(const Url &url, TransferSettings &set)
DownloadPrivate(Downloader &parent, std::shared_ptr< NetworkRequestDispatcher > requestDispatcher, std::shared_ptr< MirrorControl > mirrors, DownloadSpec &&spec, Download &p)
SignalProxy< void(Download &req)> sigStarted()
const TransferSettings & settings() const
Base class for Exception.
static const ViewOption WITH_PASSWORD
Option to include password in the URL string.
static auto connectFunc(typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)
void onDownloadStarted(Download &download)
ZYPP_IMPL_PRIVATE(UnixSignalSource)
Signal< void(zyppng::Download &req, zyppng::NetworkAuthData &auth, const std::string &availAuth)> _sigAuthRequired
SignalProxy< void(Download &req, off_t dltotal, off_t dlnow)> sigProgress()
std::optional< StateId > currentState() const
void fillSettingsSystemProxy(const Url &url, media::TransferSettings &s)
Reads the system proxy configuration and fills the settings structure proxy information.
This defines the actual StateMachine.
Type type() const
type Returns the type of the error
std::string errorString() const
zypp::ByteCount headerSize() const
SignalProxy< void(Download &req, State state)> sigStateChanged()
connection _sigFinishedConn
static zyppng::NetworkRequestError customError(NetworkRequestError::Type t, std::string &&errorMsg="", std::map< std::string, boost::any > &&extraInfo={})
Signal< void(Download &req)> _sigFinished
~DownloadPrivateBase() override
Signal< void(Downloader &parent, Download &download)> _sigStarted
zypp::media::CredentialManager::CredentialSet _credCache