23 #include <zypp-media/auth/CredentialManager> 24 #include <zypp-curl/auth/CurlAuthData> 30 #include <curl/curl.h> 37 :
MediaHandler( url_r, mirrors_r, attach_point_r, urlpath_below_attachpoint_r, does_download_r )
75 if ( !conf.geoipEnabled() ) {
76 MIL <<
"GeoIp rewrites disabled via ZConfig." << std::endl;
81 MIL <<
"GeoIp rewrites disabled since the baseurl " <<
url <<
" uses an explicit country setting." << std::endl;
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 );
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",
196 "X-ZYpp-DistributionFlavor: %s",
204 static const zypp::str::regex invalidRewrites(
"^.*\\/repomd.xml(.asc|.key)?$|^\\/geoip$");
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,
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;
258 set.addHeader( std::move(header) );
263 if ( u.url().getHost() ==
"download.opensuse.org" )
268 set.addHeader(
"Pragma:");
274 if (
set.proxy().empty() )
287 if (
set.authType() ==
"basic" 288 &&
set.username().size()
289 && !
set.password().size() ) {
290 const auto cred = cm.
getCred( u.url() );
291 if ( cred && cred->valid() ) {
292 if ( !
set.username().size() )
293 set.setUsername(cred->username());
294 set.setPassword(cred->password());
323 if (cmcred && firstTry)
326 DBG <<
"got stored credentials:" << endl << *credentials << endl;
341 curlcred->setUsername(cmcred->username());
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);
std::string targetDistribution() const
This is register.target attribute of the installed base product.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
static ZConfig & instance()
Singleton ctor.
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
Url clearQueryString(const Url &url)
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
std::list< DirEntry > DirContent
Returned by readdir.
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
std::string asString() const
Returns a default string representation of the Url object.
std::string getQueryParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
std::string trim(const std::string &s, const Trim trim_r)
const std::string & asString() const
String representation.
void fillSettingsFromUrl(const Url &url, media::TransferSettings &s)
Fills the settings structure using options passed on the url for example ?timeout=x&proxy=foo.
bool matches(const char *s, str::smatch &matches, int flags=none) const
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Base class for Exception.
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Wrapper class for ::stat/::lstat.
void fillSettingsSystemProxy(const Url &url, media::TransferSettings &s)
Reads the system proxy configuration and fills the settings structure proxy information.
std::string anonymousUniqueId() const
anonymous unique id
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 getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.