16 #include <zypp/ZConfig.h> 21 #include <zypp/Target.h> 23 #include <zypp-media/auth/CredentialManager> 24 #include <zypp-curl/auth/CurlAuthData> 27 #include <zypp/ZYppCallbacks.h> 30 #include <curl/curl.h> 37 :
MediaHandler( origin_r, attach_point_r, urlpath_below_attachpoint_r, does_download_r )
75 const auto &conf = ZConfig::instance();
76 if ( !conf.geoipEnabled() ) {
77 MIL <<
"GeoIp rewrites disabled via ZConfig." << std::endl;
82 MIL <<
"GeoIp rewrites disabled since the baseurl " <<
url <<
" uses an explicit country setting." << std::endl;
87 auto geoipFile = conf.geoipCachePath() / hostname ;
88 if (
PathInfo( geoipFile ).isFile() ) {
90 MIL <<
"Found GeoIP file for host: " << hostname << std::endl;
92 std::ifstream in( geoipFile.asString() );
94 MIL <<
"Failed to open GeoIP for host: " << hostname << std::endl;
105 MIL <<
"Found GeoIP rewrite: " << hostname <<
" -> " << newHost << std::endl;
111 MIL <<
"No valid GeoIP rewrite target found for " <<
url << std::endl;
116 MIL <<
"Failed to query GeoIP data, url rewriting disabled." << std::endl;
137 for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
138 Pathname filename = dirname + it->name;
141 switch ( it->type ) {
148 getDir( filename, recurse_r );
152 WAR <<
"Ignore error (" << res <<
") on creating local directory '" <<
localPath( filename ) <<
"'" << endl;
164 const Pathname & dirname,
bool dots )
const 170 const Pathname & dirname,
bool dots )
const 183 "X-ZYpp-AnonymousId: %s",
184 Target::anonymousUniqueId(
Pathname() ).c_str()
186 return _value.c_str();
197 "X-ZYpp-DistributionFlavor: %s",
198 Target::distributionFlavor(
Pathname() ).c_str()
200 return _value.c_str();
205 static const zypp::str::regex invalidRewrites(
"^.*\\/repomd.xml(.asc|.key)?$|^\\/geoip$");
214 MIL <<
"Redirecting " << filename_r <<
" request to geoip location." << std::endl;
217 Url newurl { baseUrl };
229 "ZYpp " LIBZYPP_VERSION_STRING
" (curl %s) %s",
230 curl_version_info(CURLVERSION_NOW)->version,
231 Target::targetDistribution(
Pathname() ).c_str())));
232 return _value.c_str();
257 if ( u.hasConfig (
"http-headers") ) {
260 std::string header { el.first };
263 MIL <<
"Added custom header -> " << header << std::endl;
264 set.addHeader( std::move(header) );
269 if ( u.url().getHost() ==
"download.opensuse.org" )
274 set.addHeader(
"Pragma:");
280 if (
set.proxy().empty() )
293 if (
set.authType() ==
"basic" 294 &&
set.username().size()
295 && !
set.password().size() ) {
296 const auto cred = cm.
getCred( u.url() );
297 if ( cred && cred->valid() ) {
298 if ( !
set.username().size() )
299 set.setUsername(cred->username());
300 set.setPassword(cred->password());
329 std::vector<unsigned> mirrOrder;
331 MIL <<
"Fetching file " << loc <<
" from authority only: " <<
_origin << std::endl;
332 mirrOrder.push_back (0);
336 mirrOrder.push_back(0);
348 if (cmcred && firstTry)
351 DBG <<
"got stored credentials:" << endl << *credentials << endl;
359 callback::SendReport<AuthenticationReport> auth_report;
366 curlcred->setUsername(cmcred->username());
375 curlcred->setAuthType(availAuthTypes);
378 if (auth_report->prompt(
url, prompt_msg, *curlcred))
380 DBG <<
"callback answer: retry" << endl
381 <<
"CurlAuthData: " << *curlcred << endl;
383 if (curlcred->valid())
385 credentials = curlcred;
399 DBG <<
"callback answer: cancel" << endl;
410 if (credentials->authType() == CURLAUTH_NONE)
411 credentials->setAuthType(availAuthTypes);
414 if (credentials->authType() != CURLAUTH_NONE) {
415 settings.
setAuthType(credentials->authTypeAsString());
420 credentials->setUrl(
url);
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
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)
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
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.
uint endpointCount() const
void fillSettingsSystemProxy(const Url &url, media::TransferSettings &s)
Reads the system proxy configuration and fills the settings structure proxy information.
Represents a single, configurable network endpoint, combining a URL with specific access settings...
endpoint_iterator begin()
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.