16#include <zypp-core/fs/PathInfo.h>
17#include <zypp/base/Logger.h>
18#include <zypp-core/base/Regex.h>
28 if ( !conf.geoipEnabled() ) {
29 MIL <<
"GeoIp rewrites disabled via ZConfig." << std::endl;
34 MIL <<
"GeoIp rewrites disabled since the baseurl " <<
url <<
" uses an explicit country setting." << std::endl;
39 auto geoipFile = conf.geoipCachePath() / hostname ;
40 if (
PathInfo( geoipFile ).isFile() ) {
42 MIL <<
"Found GeoIP file for host: " << hostname << std::endl;
44 std::ifstream in( geoipFile.asString() );
46 MIL <<
"Failed to open GeoIP for host: " << hostname << std::endl;
57 MIL <<
"Found GeoIP rewrite: " << hostname <<
" -> " << newHost << std::endl;
63 MIL <<
"No valid GeoIP rewrite target found for " <<
url << std::endl;
68 MIL <<
"Failed to query GeoIP data, url rewriting disabled." << std::endl;
77 static const zypp::str::regex invalidRewrites(
"^.*\\/repomd.xml(.asc|.key)?$|^\\/geoip$");
83 MIL <<
"Redirecting " << filename_r <<
" request to geoip location." << std::endl;
92 Url newurl( baseUrl );
93 newurl.
setPathName( (
Pathname(
"./"+baseUrl.getPathName()) / filename_r ).asString().substr(1) );
Base class for Exception.
std::string getQueryParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
bool isValid() const
Verifies the Url.
static ZConfig & instance()
Singleton ctor.
Wrapper class for stat/lstat.
const std::string & asString() const
String representation.
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).