1 | /* === This file is part of Calamares - <http://github.com/calamares> === |
---|
2 | * |
---|
3 | * Copyright 2018, Adriaan de Groot <groot@kde.org> |
---|
4 | * |
---|
5 | * Calamares is free software: you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU General Public License as published by |
---|
7 | * the Free Software Foundation, either version 3 of the License, or |
---|
8 | * (at your option) any later version. |
---|
9 | * |
---|
10 | * Calamares is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public License |
---|
16 | * along with Calamares. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | */ |
---|
18 | |
---|
19 | /** |
---|
20 | * This is a test-application that does one GeoIP parse. |
---|
21 | */ |
---|
22 | |
---|
23 | #include <iostream> |
---|
24 | |
---|
25 | #include "GeoIPJSON.h" |
---|
26 | #ifdef HAVE_XML |
---|
27 | #include "GeoIPXML.h" |
---|
28 | #endif |
---|
29 | |
---|
30 | using std::cerr; |
---|
31 | |
---|
32 | int main(int argc, char** argv) |
---|
33 | { |
---|
34 | if (argc != 2) |
---|
35 | { |
---|
36 | cerr << "Usage: curl url | test_geoip <format>\n"; |
---|
37 | return 1; |
---|
38 | } |
---|
39 | |
---|
40 | GeoIP* handler = nullptr; |
---|
41 | if ( QLatin1String( "json" ) == argv[1] ) |
---|
42 | handler = new GeoIPJSON; |
---|
43 | #ifdef HAVE_XML |
---|
44 | else if ( QLatin1String( "xml" ) == argv[1] ) |
---|
45 | handler = new GeoIPXML; |
---|
46 | #endif |
---|
47 | |
---|
48 | if ( !handler ) |
---|
49 | { |
---|
50 | cerr << "Unknown format '" << argv[1] << "'\n"; |
---|
51 | return 1; |
---|
52 | } |
---|
53 | |
---|
54 | QByteArray ba; |
---|
55 | while( !std::cin.eof() ) { |
---|
56 | char arr[1024]; |
---|
57 | std::cin.read(arr,sizeof(arr)); |
---|
58 | int s = std::cin.gcount(); |
---|
59 | ba.append(arr, s); |
---|
60 | } |
---|
61 | |
---|
62 | auto tz = handler->processReply( ba ); |
---|
63 | if ( tz.first.isEmpty() ) |
---|
64 | { |
---|
65 | std::cout << "No TimeZone determined from input.\n"; |
---|
66 | } |
---|
67 | else |
---|
68 | { |
---|
69 | std::cout << "TimeZone Region=" << tz.first.toLatin1().constData() << "\nTimeZone Zone=" << tz.second.toLatin1().constData() << '\n'; |
---|
70 | } |
---|
71 | |
---|
72 | return 0; |
---|
73 | } |
---|