From ac2a9c569e3057fc0a022defee892017c53543b1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 3 Jun 2020 15:03:19 +0200 Subject: [PATCH] [libcalamares] Allow "fixed" as a GeoIP lookup type --- src/libcalamares/CMakeLists.txt | 1 + src/libcalamares/geoip/Handler.cpp | 11 ++++++++++- src/libcalamares/geoip/Handler.h | 7 ++++--- src/libcalamares/geoip/Interface.h | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index fa4265d6e..f7e249a54 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -23,6 +23,7 @@ set( libSources # GeoIP services geoip/Interface.cpp + geoip/GeoIPFixed.cpp geoip/GeoIPJSON.cpp geoip/Handler.cpp diff --git a/src/libcalamares/geoip/Handler.cpp b/src/libcalamares/geoip/Handler.cpp index 99e55e926..ab7eea999 100644 --- a/src/libcalamares/geoip/Handler.cpp +++ b/src/libcalamares/geoip/Handler.cpp @@ -18,11 +18,13 @@ #include "Handler.h" +#include "GeoIPFixed.h" #include "GeoIPJSON.h" #if defined( QT_XML_LIB ) #include "GeoIPXML.h" #endif +#include "Settings.h" #include "network/Manager.h" #include "utils/Logger.h" #include "utils/NamedEnum.h" @@ -40,7 +42,8 @@ handlerTypes() static const NamedEnumTable names{ { QStringLiteral( "none" ), Type::None }, { QStringLiteral( "json" ), Type::JSON }, - { QStringLiteral( "xml" ), Type::XML } + { QStringLiteral( "xml" ), Type::XML }, + { QStringLiteral( "fixed" ), Type::Fixed } }; // *INDENT-ON* // clang-format on @@ -73,6 +76,10 @@ Handler::Handler( const QString& implementation, const QString& url, const QStri { cWarning() << "GeoIP style *none* does not do anything."; } + else if ( m_type == Type::Fixed && Calamares::Settings::instance() && !Calamares::Settings::instance()->debugMode() ) + { + cWarning() << "GeoIP style *fixed* is not recommended for production."; + } #if !defined( QT_XML_LIB ) else if ( m_type == Type::XML ) { @@ -99,6 +106,8 @@ create_interface( Handler::Type t, const QString& selector ) #else return nullptr; #endif + case Handler::Type::Fixed: + return std::make_unique< GeoIPFixed >( selector ); } NOTREACHED return nullptr; } diff --git a/src/libcalamares/geoip/Handler.h b/src/libcalamares/geoip/Handler.h index 518964caf..d15f7c710 100644 --- a/src/libcalamares/geoip/Handler.h +++ b/src/libcalamares/geoip/Handler.h @@ -43,9 +43,10 @@ class DLLEXPORT Handler public: enum class Type { - None, - JSON, - XML + None, // No lookup, returns empty string + JSON, // JSON-formatted data, returns extracted field + XML, // XML-formatted data, returns extracted field + Fixed // Returns selector string verbatim }; /** @brief An unconfigured handler; this always returns errors. */ diff --git a/src/libcalamares/geoip/Interface.h b/src/libcalamares/geoip/Interface.h index 1a9beaa41..78cc2392c 100644 --- a/src/libcalamares/geoip/Interface.h +++ b/src/libcalamares/geoip/Interface.h @@ -98,7 +98,7 @@ public: virtual QString rawReply( const QByteArray& ) = 0; protected: - Interface( const QString& e = QString() ); + Interface( const QString& element = QString() ); QString m_element; // string for selecting from data };