#include <GeoIpCacheItem.h>
Public Member Functions | |
GeoIpCacheItem () | |
GeoIpCacheItem (const QHostAddress &from, const QHostAddress &to, const GeoIp &geoIp, const QDateTime &expires) | |
QHostAddress | ipRangeStart () const |
QHostAddress | ipRangeEnd () const |
bool | contains (const QHostAddress &ip) const |
bool | isValid () const |
bool | isExpired () const |
GeoIp | toGeoIp (const QHostAddress &ip) const |
QString | toCacheString () const |
Static Public Member Functions | |
static GeoIpCacheItem | fromCacheString (const QString &cacheLine) |
Private Attributes | |
quint32 | _fromIp |
quint32 | _toIp |
QDateTime | _expires |
QHash< QString, QVariant > | _fields |
Definition at line 29 of file GeoIpCacheItem.h.
GeoIpCacheItem::GeoIpCacheItem | ( | ) |
Default constructor
Definition at line 37 of file GeoIpCacheItem.cpp.
References _fromIp, and _toIp.
Referenced by fromCacheString().
GeoIpCacheItem::GeoIpCacheItem | ( | const QHostAddress & | from, | |
const QHostAddress & | to, | |||
const GeoIp & | geoIp, | |||
const QDateTime & | expires | |||
) |
Constructor.
Definition at line 43 of file GeoIpCacheItem.cpp.
References _expires, _fields, _fromIp, _toIp, CACHE_KEY_CITY, CACHE_KEY_COUNTRY, CACHE_KEY_COUNTRY_CODE, CACHE_KEY_LATITUDE, CACHE_KEY_LONGITUDE, CACHE_KEY_REGION, GeoIp::city(), GeoIp::country(), GeoIp::countryCode(), GeoIp::latitude(), GeoIp::longitude(), and GeoIp::region().
bool GeoIpCacheItem::contains | ( | const QHostAddress & | ip | ) | const |
Returns true if ip is within the range of IP addresses associated with this GeoIpCacheItem.
Definition at line 75 of file GeoIpCacheItem.cpp.
References _fromIp, and _toIp.
Referenced by toGeoIp().
GeoIpCacheItem GeoIpCacheItem::fromCacheString | ( | const QString & | cacheLine | ) | [static] |
Parses cacheLine and constructs a new GeoIpCacheItem object with the parsed values. The format of cacheLine must follow the format as produced by toCacheString().
Definition at line 135 of file GeoIpCacheItem.cpp.
References _expires, _fields, _fromIp, _toIp, CACHE_KEY_CITY, CACHE_KEY_COUNTRY, CACHE_KEY_COUNTRY_CODE, CACHE_KEY_EXPIRES, CACHE_KEY_FROM_IP, CACHE_KEY_LATITUDE, CACHE_KEY_LONGITUDE, CACHE_KEY_REGION, CACHE_KEY_TO_IP, GeoIpCacheItem(), and string_parse_keyvals().
Referenced by GeoIpCache::loadFromDisk().
QHostAddress GeoIpCacheItem::ipRangeEnd | ( | ) | const |
Returns the last IP address in the range of IP addresses associated with this GeoIpCacheItem.
Definition at line 69 of file GeoIpCacheItem.cpp.
References _toIp.
Referenced by GeoIpCache::addToCache().
QHostAddress GeoIpCacheItem::ipRangeStart | ( | ) | const |
Returns the first IP address in the range of IP addresses associated with this GeoIpCacheItem.
Definition at line 63 of file GeoIpCacheItem.cpp.
References _fromIp.
bool GeoIpCacheItem::isExpired | ( | ) | const |
Returns true if the cache item is too old to be considered accurate. Cached GeoIp responses are considered valid for thirty days after they are first added to the cache.
Definition at line 94 of file GeoIpCacheItem.cpp.
References _expires.
Referenced by GeoIpCache::addToCache(), GeoIpCache::loadFromDisk(), and GeoIpCache::saveToDisk().
bool GeoIpCacheItem::isValid | ( | ) | const |
Returns true if this GeoIpCacheItem object contains valid values for all required fields.
Definition at line 83 of file GeoIpCacheItem.cpp.
References _expires, _fields, _fromIp, _toIp, CACHE_KEY_LATITUDE, and CACHE_KEY_LONGITUDE.
Referenced by GeoIpCache::addToCache(), and GeoIpCache::loadFromDisk().
QString GeoIpCacheItem::toCacheString | ( | ) | const |
Formats the fields contained in this GeoIpCacheItem as a string suitable for writing to a cache file.
Definition at line 114 of file GeoIpCacheItem.cpp.
References _expires, _fields, _fromIp, _toIp, CACHE_KEY_EXPIRES, CACHE_KEY_FROM_IP, and CACHE_KEY_TO_IP.
Referenced by GeoIpCache::saveToDisk().
GeoIp GeoIpCacheItem::toGeoIp | ( | const QHostAddress & | ip | ) | const |
Returns a GeoIp object for ip, populated with the cached geographic information stored by this GeoIpCacheObject. If ip is not within the range of IP addresses associated with this object, an empty GeoIp object is returned.
Definition at line 100 of file GeoIpCacheItem.cpp.
References _fields, CACHE_KEY_CITY, CACHE_KEY_COUNTRY, CACHE_KEY_COUNTRY_CODE, CACHE_KEY_LATITUDE, CACHE_KEY_LONGITUDE, CACHE_KEY_REGION, and contains().
QDateTime GeoIpCacheItem::_expires [private] |
Time this item was cached.
Definition at line 92 of file GeoIpCacheItem.h.
Referenced by fromCacheString(), GeoIpCacheItem(), isExpired(), isValid(), and toCacheString().
QHash<QString,QVariant> GeoIpCacheItem::_fields [private] |
Definition at line 93 of file GeoIpCacheItem.h.
Referenced by fromCacheString(), GeoIpCacheItem(), isValid(), toCacheString(), and toGeoIp().
quint32 GeoIpCacheItem::_fromIp [private] |
Definition at line 90 of file GeoIpCacheItem.h.
Referenced by contains(), fromCacheString(), GeoIpCacheItem(), ipRangeStart(), isValid(), and toCacheString().
quint32 GeoIpCacheItem::_toIp [private] |
Definition at line 91 of file GeoIpCacheItem.h.
Referenced by contains(), fromCacheString(), GeoIpCacheItem(), ipRangeEnd(), isValid(), and toCacheString().