22 #include <curl/curl.h> 30 if ( !conf.geoipEnabled() ) {
31 MIL <<
"GeoIp rewrites disabled via ZConfig." << std::endl;
36 MIL <<
"GeoIp rewrites disabled since the baseurl " <<
url <<
" uses an explicit country setting." << std::endl;
41 auto geoipFile = conf.geoipCachePath() / hostname ;
42 if (
PathInfo( geoipFile ).isFile() ) {
44 MIL <<
"Found GeoIP file for host: " << hostname << std::endl;
46 std::ifstream in( geoipFile.asString() );
48 MIL <<
"Failed to open GeoIP for host: " << hostname << std::endl;
59 MIL <<
"Found GeoIP rewrite: " << hostname <<
" -> " << newHost << std::endl;
65 MIL <<
"No valid GeoIP rewrite target found for " <<
url << std::endl;
70 MIL <<
"Failed to query GeoIP data, url rewriting disabled." << std::endl;
85 "X-ZYpp-AnonymousId: %s",
99 "X-ZYpp-DistributionFlavor: %s",
107 static const zypp::str::regex invalidRewrites(
"^.*\\/repomd.xml(.asc|.key)?$|^\\/geoip$");
113 MIL <<
"Redirecting " << filename_r <<
" request to geoip location." << std::endl;
122 Url newurl( baseUrl );
123 newurl.
setPathName( (
Pathname(
"./"+baseUrl.getPathName()) / filename_r ).asString().substr(1) );
134 "ZYpp " LIBZYPP_VERSION_STRING
" (curl %s) %s",
135 curl_version_info(CURLVERSION_NOW)->version,
std::string targetDistribution() const
This is register.target attribute of the installed base product.
static ZConfig & instance()
Singleton ctor.
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.
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
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.
bool matches(const char *s, str::smatch &matches, int flags=none) const
bool isValid() const
Verifies the Url.
#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.
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...