23#include <zypp-media/auth/CredentialManager>
24#include <zypp-curl/auth/CurlAuthData>
37 :
MediaHandler( url_r, mirrors_r, attach_point_r, urlpath_below_attachpoint_r, does_download_r )
68 return ::internal::clearQueryString(
url);
75 if ( !conf.geoipEnabled() ) {
76 MIL <<
"GeoIp rewrites disabled via ZConfig." << std::endl;
80 if ( !(
url.getQueryParam(
"COUNTRY").empty() &&
url.getQueryParam(
"AVOID_COUNTRY").empty() )) {
81 MIL <<
"GeoIp rewrites disabled since the baseurl " <<
url <<
" uses an explicit country setting." << std::endl;
85 const auto &hostname =
url.getHost();
86 auto geoipFile = conf.geoipCachePath() / hostname ;
87 if (
PathInfo( geoipFile ).isFile() ) {
89 MIL <<
"Found GeoIP file for host: " << hostname << std::endl;
91 std::ifstream in( geoipFile.asString() );
93 MIL <<
"Failed to open GeoIP for host: " << hostname << std::endl;
104 MIL <<
"Found GeoIP rewrite: " << hostname <<
" -> " << newHost << std::endl;
110 MIL <<
"No valid GeoIP rewrite target found for " <<
url << std::endl;
115 MIL <<
"Failed to query GeoIP data, url rewriting disabled." << std::endl;
136 for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
137 Pathname filename = dirname + it->name;
140 switch ( it->type ) {
147 getDir( filename, recurse_r );
149 res = assert_dir(
localPath( filename ) );
151 WAR <<
"Ignore error (" << res <<
") on creating local directory '" <<
localPath( filename ) <<
"'" << endl;
163 const Pathname & dirname,
bool dots )
const
169 const Pathname & dirname,
bool dots )
const
182 "X-ZYpp-AnonymousId: %s",
185 return _value.c_str();
196 "X-ZYpp-DistributionFlavor: %s",
199 return _value.c_str();
204 static const zypp::str::regex invalidRewrites(
"^.*\\/repomd.xml(.asc|.key)?$|^\\/geoip$");
210 const auto &baseUrl = ( canRedir ) ?
_redirTargets[mirrorIdx] :
_urls[mirrorIdx].url();
213 MIL <<
"Redirecting " << filename_r <<
" request to geoip location." << std::endl;
216 Url newurl { baseUrl };
228 "ZYpp " LIBZYPP_VERSION_STRING
" (curl %s) %s",
229 curl_version_info(CURLVERSION_NOW)->version,
231 return _value.c_str();
243 if ( !u.url().isValid() )
251 if ( u.hasConfig (
"http-headers") ) {
254 std::string header { el.first };
257 MIL <<
"Added custom header -> " << header << std::endl;
263 if ( u.url().getHost() ==
"download.opensuse.org" )
274 if ( set.
proxy().empty() )
290 const auto cred = cm.
getCred( u.url() );
291 if ( cred && cred->valid() ) {
323 if (cmcred && firstTry)
326 DBG <<
"got stored credentials:" << endl << *credentials << endl;
337 if (!
url.getUsername().empty() && firstTry)
338 curlcred->setUsername(
url.getUsername());
341 curlcred->setUsername(cmcred->username());
346 std::string prompt_msg =
str::Format(
_(
"Authentication required for '%s'")) %
url.asString();
350 curlcred->setAuthType(availAuthTypes);
353 if (auth_report->prompt(
url, prompt_msg, *curlcred))
355 DBG <<
"callback answer: retry" << endl
356 <<
"CurlAuthData: " << *curlcred << endl;
358 if (curlcred->valid())
360 credentials = curlcred;
374 DBG <<
"callback answer: cancel" << endl;
385 if (credentials->authType() == CURLAUTH_NONE)
386 credentials->setAuthType(availAuthTypes);
389 if (credentials->authType() != CURLAUTH_NONE) {
390 settings.
setAuthType(credentials->authTypeAsString());
395 credentials->setUrl(
url);
Base class for Exception.
std::string distributionFlavor() const
This is flavor attribute of the installed base product but does not require the target to be loaded a...
std::string anonymousUniqueId() const
anonymous unique id
std::string targetDistribution() const
This is register.target attribute of the installed base product.
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
static ZConfig & instance()
Singleton ctor.
Wrapper class for stat/lstat.
const std::string & asString() const
String representation.
Pathname absolutename() const
Return this path, adding a leading '/' if relative.
bool matches(const char *s, str::smatch &matches, int flags=none) const
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.
std::list< DirEntry > DirContent
Returned by readdir.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
std::string trim(const std::string &s, const Trim trim_r)
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.