28 #include "ip2c/entities/ip2ccountryinfo.h" 31 #include <QHostAddress> 35 #include <QProgressBar> 48 class IP2C :
public QObject
59 QString countryFullName;
66 bool isCountryKnown()
const;
74 return ipStart != ipEnd;
78 static IP2C *instance();
79 static void deinstantiate();
81 const QPixmap flagLan;
82 const QPixmap flagLocalhost;
83 const QPixmap flagUnknown;
92 const QPixmap &flag(
const QString &countryShortName);
95 bool isDataAccessLocked()
const 97 return bDataAccessLocked;
106 return lookupIP(ipaddress.toIPv4Address());
109 int numKnownEntries()
const 111 return database.size();
123 void setDataAccessLockEnabled(
bool b)
125 bDataAccessLocked = b;
136 QMutexLocker dataAccessMutexLocker(&dataAccessMutex);
137 database = sortedCountryData;
141 inline bool isLANAddress(
unsigned ipv4Address)
143 const static unsigned LAN_1_BEGIN = QHostAddress(
"10.0.0.0").toIPv4Address();
144 const static unsigned LAN_1_END = QHostAddress(
"10.255.255.255").toIPv4Address();
145 const static unsigned LAN_2_BEGIN = QHostAddress(
"172.16.0.0").toIPv4Address();
146 const static unsigned LAN_2_END = QHostAddress(
"172.31.255.255").toIPv4Address();
147 const static unsigned LAN_3_BEGIN = QHostAddress(
"192.168.0.0").toIPv4Address();
148 const static unsigned LAN_3_END = QHostAddress(
"192.168.255.255").toIPv4Address();
151 (ipv4Address >= LAN_1_BEGIN && ipv4Address <= LAN_1_END)
152 || (ipv4Address >= LAN_2_BEGIN && ipv4Address <= LAN_2_END)
153 || (ipv4Address >= LAN_3_BEGIN && ipv4Address <= LAN_3_END)
157 inline bool isLocalhostAddress(
unsigned ipv4Address)
159 const static unsigned LOCALHOST_BEGIN = QHostAddress(
"127.0.0.0").toIPv4Address();
160 const static unsigned LOCALHOST_END = QHostAddress(
"127.255.255.255").toIPv4Address();
162 return ipv4Address >= LOCALHOST_BEGIN && ipv4Address <= LOCALHOST_END;
166 static QMutex instanceMutex;
167 static IP2C *staticInstance;
176 bool bDataAccessLocked;
177 QMutex dataAccessMutex;
178 QList<IP2CData> database;
179 QHash<QString, QPixmap> flags;
void setDatabase(const QList< IP2CData > &sortedCountryData)
Sets database contents to the list specified.
IP2CCountryInfo obtainCountryInfo(unsigned int ipaddress)
void appendEntryToDatabase(const IP2CData &entry)
Adds new country entry to the database.
const IP2CData & lookupIP(unsigned int ipaddress)
IP to Country database handler.
Flag and name of the country.