2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* SPDX-FileCopyrightText: 2018 Adriaan de Groot <groot@kde.org>
|
2020-05-30 16:15:03 +02:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2020-08-25 16:05:56 +02:00
|
|
|
*
|
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
2018-04-12 22:55:24 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a test-application that does one GeoIP parse.
|
|
|
|
*/
|
|
|
|
|
2020-06-03 14:34:45 +02:00
|
|
|
#include "GeoIPFixed.h"
|
2018-04-16 10:32:49 +02:00
|
|
|
#include "GeoIPJSON.h"
|
2019-05-01 12:39:20 +02:00
|
|
|
#ifdef QT_XML_LIB
|
2018-04-12 22:55:24 +02:00
|
|
|
#include "GeoIPXML.h"
|
|
|
|
#endif
|
|
|
|
|
2020-10-16 12:36:03 +02:00
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2018-04-12 22:55:24 +02:00
|
|
|
using std::cerr;
|
2023-09-10 22:26:17 +02:00
|
|
|
using namespace Calamares::GeoIP;
|
2018-04-12 22:55:24 +02:00
|
|
|
|
2019-08-08 12:32:21 +02:00
|
|
|
int
|
|
|
|
main( int argc, char** argv )
|
2018-04-12 22:55:24 +02:00
|
|
|
{
|
2020-06-03 14:34:45 +02:00
|
|
|
if ( ( argc != 2 ) && ( argc != 3 ) )
|
2018-04-12 22:55:24 +02:00
|
|
|
{
|
2020-06-03 14:34:45 +02:00
|
|
|
cerr << "Usage: curl url | test_geoip <format> [selector]\n";
|
2018-04-12 22:55:24 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-06-03 14:34:45 +02:00
|
|
|
QString format( argv[ 1 ] );
|
|
|
|
QString selector = argc == 3 ? QString( argv[ 2 ] ) : QString();
|
|
|
|
|
2020-11-05 00:00:29 +01:00
|
|
|
Logger::setupLogLevel( Logger::LOGVERBOSE );
|
2020-10-16 12:36:03 +02:00
|
|
|
cDebug() << "Doing GeoIP interpretation with format=" << format << "selector=" << selector;
|
|
|
|
|
2019-05-02 13:25:48 +02:00
|
|
|
Interface* handler = nullptr;
|
2020-06-03 14:34:45 +02:00
|
|
|
if ( QStringLiteral( "json" ) == format )
|
2019-08-08 12:32:21 +02:00
|
|
|
{
|
2020-06-03 14:34:45 +02:00
|
|
|
handler = new GeoIPJSON( selector );
|
2019-08-08 12:32:21 +02:00
|
|
|
}
|
2019-05-01 12:39:20 +02:00
|
|
|
#ifdef QT_XML_LIB
|
2020-06-03 14:34:45 +02:00
|
|
|
else if ( QStringLiteral( "xml" ) == format )
|
2019-08-08 12:32:21 +02:00
|
|
|
{
|
2020-06-03 14:34:45 +02:00
|
|
|
handler = new GeoIPXML( selector );
|
2019-08-08 12:32:21 +02:00
|
|
|
}
|
2018-04-12 22:55:24 +02:00
|
|
|
#endif
|
2020-06-03 14:34:45 +02:00
|
|
|
else if ( QStringLiteral( "fixed" ) == format )
|
|
|
|
{
|
|
|
|
handler = new GeoIPFixed( selector );
|
|
|
|
}
|
2018-04-12 22:55:24 +02:00
|
|
|
|
|
|
|
if ( !handler )
|
|
|
|
{
|
2020-06-03 14:34:45 +02:00
|
|
|
cerr << "Unknown format '" << format.toLatin1().constData() << "'\n";
|
2018-04-12 22:55:24 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray ba;
|
2019-08-08 12:32:21 +02:00
|
|
|
while ( !std::cin.eof() )
|
|
|
|
{
|
|
|
|
char arr[ 1024 ];
|
|
|
|
std::cin.read( arr, sizeof( arr ) );
|
|
|
|
int s = static_cast< int >( std::cin.gcount() );
|
|
|
|
ba.append( arr, s );
|
2018-04-12 22:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto tz = handler->processReply( ba );
|
|
|
|
if ( tz.first.isEmpty() )
|
|
|
|
{
|
|
|
|
std::cout << "No TimeZone determined from input.\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-08 12:32:21 +02:00
|
|
|
std::cout << "TimeZone Region=" << tz.first.toLatin1().constData()
|
|
|
|
<< "\nTimeZone Zone=" << tz.second.toLatin1().constData() << '\n';
|
2018-04-12 22:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|