|
|
|
@ -19,7 +19,7 @@
|
|
|
|
|
#include "Handler.h"
|
|
|
|
|
|
|
|
|
|
#include "GeoIPJSON.h"
|
|
|
|
|
#if defined(QT_XML_LIB)
|
|
|
|
|
#if defined( QT_XML_LIB )
|
|
|
|
|
#include "GeoIPXML.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -28,8 +28,8 @@
|
|
|
|
|
#include "utils/Variant.h"
|
|
|
|
|
|
|
|
|
|
#include <QEventLoop>
|
|
|
|
|
#include <QNetworkRequest>
|
|
|
|
|
#include <QNetworkReply>
|
|
|
|
|
#include <QNetworkRequest>
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
@ -76,7 +76,7 @@ Handler::Handler( const QString& implementation, const QString& url, const QStri
|
|
|
|
|
{
|
|
|
|
|
cWarning() << "GeoIP style *none* does not do anything.";
|
|
|
|
|
}
|
|
|
|
|
#if !defined(QT_XML_LIB)
|
|
|
|
|
#if !defined( QT_XML_LIB )
|
|
|
|
|
else if ( m_type == Type::XML )
|
|
|
|
|
{
|
|
|
|
|
m_type = Type::None;
|
|
|
|
@ -85,9 +85,7 @@ Handler::Handler( const QString& implementation, const QString& url, const QStri
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Handler::~Handler()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
Handler::~Handler() {}
|
|
|
|
|
|
|
|
|
|
static QByteArray
|
|
|
|
|
synchronous_get( const QString& urlstring )
|
|
|
|
@ -108,17 +106,17 @@ synchronous_get( const QString& urlstring )
|
|
|
|
|
static std::unique_ptr< Interface >
|
|
|
|
|
create_interface( Handler::Type t, const QString& selector )
|
|
|
|
|
{
|
|
|
|
|
switch( t )
|
|
|
|
|
switch ( t )
|
|
|
|
|
{
|
|
|
|
|
case Handler::Type::None:
|
|
|
|
|
return nullptr;
|
|
|
|
|
case Handler::Type::JSON:
|
|
|
|
|
return std::make_unique< GeoIPJSON >( selector );
|
|
|
|
|
case Handler::Type::XML:
|
|
|
|
|
#if defined(QT_XML_LIB)
|
|
|
|
|
return std::make_unique< GeoIPXML >( selector );
|
|
|
|
|
case Handler::Type::None:
|
|
|
|
|
return nullptr;
|
|
|
|
|
case Handler::Type::JSON:
|
|
|
|
|
return std::make_unique< GeoIPJSON >( selector );
|
|
|
|
|
case Handler::Type::XML:
|
|
|
|
|
#if defined( QT_XML_LIB )
|
|
|
|
|
return std::make_unique< GeoIPXML >( selector );
|
|
|
|
|
#else
|
|
|
|
|
return nullptr;
|
|
|
|
|
return nullptr;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
NOTREACHED return nullptr;
|
|
|
|
@ -129,7 +127,9 @@ do_query( Handler::Type type, const QString& url, const QString& selector )
|
|
|
|
|
{
|
|
|
|
|
const auto interface = create_interface( type, selector );
|
|
|
|
|
if ( !interface )
|
|
|
|
|
{
|
|
|
|
|
return RegionZonePair();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return interface->processReply( synchronous_get( url ) );
|
|
|
|
|
}
|
|
|
|
@ -139,7 +139,9 @@ do_raw_query( Handler::Type type, const QString& url, const QString& selector )
|
|
|
|
|
{
|
|
|
|
|
const auto interface = create_interface( type, selector );
|
|
|
|
|
if ( !interface )
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return interface->rawReply( synchronous_get( url ) );
|
|
|
|
|
}
|
|
|
|
@ -148,7 +150,9 @@ RegionZonePair
|
|
|
|
|
Handler::get() const
|
|
|
|
|
{
|
|
|
|
|
if ( !isValid() )
|
|
|
|
|
{
|
|
|
|
|
return RegionZonePair();
|
|
|
|
|
}
|
|
|
|
|
return do_query( m_type, m_url, m_selector );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -160,17 +164,16 @@ Handler::query() const
|
|
|
|
|
QString url = m_url;
|
|
|
|
|
QString selector = m_selector;
|
|
|
|
|
|
|
|
|
|
return QtConcurrent::run( [=]
|
|
|
|
|
{
|
|
|
|
|
return do_query( type, url, selector );
|
|
|
|
|
} );
|
|
|
|
|
return QtConcurrent::run( [=] { return do_query( type, url, selector ); } );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
|
Handler::getRaw() const
|
|
|
|
|
{
|
|
|
|
|
if ( !isValid() )
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
return do_raw_query( m_type, m_url, m_selector );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -182,11 +185,8 @@ Handler::queryRaw() const
|
|
|
|
|
QString url = m_url;
|
|
|
|
|
QString selector = m_selector;
|
|
|
|
|
|
|
|
|
|
return QtConcurrent::run( [=]
|
|
|
|
|
{
|
|
|
|
|
return do_raw_query( type, url, selector );
|
|
|
|
|
} );
|
|
|
|
|
return QtConcurrent::run( [=] { return do_raw_query( type, url, selector ); } );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} // namespace
|
|
|
|
|
} // namespace GeoIP
|
|
|
|
|
} // namespace CalamaresUtils
|
|
|
|
|