28 #include "ip2c/ip2ccountry.h"
29 #include "ip2c/ip2crange.h"
32 #include <QHostAddress>
48 class IP2C :
public QObject
66 static IP2C *instance();
67 static void deinstantiate();
75 const QPixmap flagLan;
76 const QPixmap flagLocalhost;
77 const QPixmap flagUnknown;
79 const QPixmap &flag(
const QString &countryCode);
82 bool isDataAccessLocked()
const
84 return bDataAccessLocked;
87 int numKnownEntries()
const
89 return database.size();
101 IP2CCountry countryInfoForAddress(
const QHostAddress &ipaddress)
107 void setDataAccessLockEnabled(
bool b)
109 bDataAccessLocked = b;
112 const QMap<QString, QString> &licenceNotice()
const {
return licences;}
113 const QString &urlDatabase()
const {
return databaseUrl;}
123 this->database = sortedRanges;
126 void setLicence(
const QMap<QString, QString> &licences)
128 this->licences = licences;
131 void setUrl(
const QString &url)
133 this->databaseUrl = url;
137 static QMutex instanceMutex;
138 static IP2C *staticInstance;
147 bool bDataAccessLocked;
148 QList<IP2CRange> database;
149 QHash<QString, IP2CCountry> countries;
154 const QHash<QString, QPixmap> flags;
158 QSet<QString> unknownCountries;
159 QSet<QString> unknownFlags;
161 QMap<QString, QString> licences;
166 Q_DISABLE_COPY(
IP2C);
171 const IP2CRange &lookupIP(
unsigned int ipaddress);
174 void logUnknownCountry(
const QString &countryCode);
175 void logUnknownFlag(
const QString &countryCode);
177 inline bool isLANAddress(
unsigned ipv4Address)
179 const static unsigned LAN_1_BEGIN = QHostAddress(
"10.0.0.0").toIPv4Address();
180 const static unsigned LAN_1_END = QHostAddress(
"10.255.255.255").toIPv4Address();
181 const static unsigned LAN_2_BEGIN = QHostAddress(
"172.16.0.0").toIPv4Address();
182 const static unsigned LAN_2_END = QHostAddress(
"172.31.255.255").toIPv4Address();
183 const static unsigned LAN_3_BEGIN = QHostAddress(
"192.168.0.0").toIPv4Address();
184 const static unsigned LAN_3_END = QHostAddress(
"192.168.255.255").toIPv4Address();
187 (ipv4Address >= LAN_1_BEGIN && ipv4Address <= LAN_1_END)
188 || (ipv4Address >= LAN_2_BEGIN && ipv4Address <= LAN_2_END)
189 || (ipv4Address >= LAN_3_BEGIN && ipv4Address <= LAN_3_END)
193 inline bool isLocalhostAddress(
unsigned ipv4Address)
195 const static unsigned LOCALHOST_BEGIN = QHostAddress(
"127.0.0.0").toIPv4Address();
196 const static unsigned LOCALHOST_END = QHostAddress(
"127.255.255.255").toIPv4Address();
198 return ipv4Address >= LOCALHOST_BEGIN && ipv4Address <= LOCALHOST_END;