2018-04-12 22:55:24 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2018, Adriaan de Groot <groot@kde.org>
|
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a test-application that does one GeoIP parse.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
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
|
|
|
|
|
|
|
|
using std::cerr;
|
2019-05-02 13:25:48 +02:00
|
|
|
using namespace CalamaresUtils::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
|
|
|
{
|
2019-08-08 12:32:21 +02:00
|
|
|
if ( argc != 2 )
|
2018-04-12 22:55:24 +02:00
|
|
|
{
|
|
|
|
cerr << "Usage: curl url | test_geoip <format>\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-05-02 13:25:48 +02:00
|
|
|
Interface* handler = nullptr;
|
2019-08-08 12:32:21 +02:00
|
|
|
if ( QStringLiteral( "json" ) == argv[ 1 ] )
|
|
|
|
{
|
2018-04-16 10:32:49 +02:00
|
|
|
handler = new GeoIPJSON;
|
2019-08-08 12:32:21 +02:00
|
|
|
}
|
2019-05-01 12:39:20 +02:00
|
|
|
#ifdef QT_XML_LIB
|
2019-08-08 12:32:21 +02:00
|
|
|
else if ( QStringLiteral( "xml" ) == argv[ 1 ] )
|
|
|
|
{
|
2018-04-16 10:35:32 +02:00
|
|
|
handler = new GeoIPXML;
|
2019-08-08 12:32:21 +02:00
|
|
|
}
|
2018-04-12 22:55:24 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( !handler )
|
|
|
|
{
|
2019-08-08 12:32:21 +02:00
|
|
|
cerr << "Unknown format '" << argv[ 1 ] << "'\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;
|
|
|
|
}
|