Makes @geoLookup optional depending on the availability of libGeoIP

This commit is contained in:
Felipe Zimmerle
2015-11-20 09:52:36 -03:00
parent 21cae53d47
commit 09a958544d
6 changed files with 51 additions and 9 deletions

View File

@@ -31,9 +31,13 @@ namespace Utils {
GeoLookup::~GeoLookup() {
#ifdef WITH_GEOIP
cleanUp();
#endif // WITH_GEOIP
}
#ifdef WITH_GEOIP
void GeoLookup::cleanUp() {
if (m_gi != NULL) {
GeoIP_delete(m_gi);
@@ -41,10 +45,8 @@ void GeoLookup::cleanUp() {
}
}
bool GeoLookup::setDataBase(const std::string& filePath) {
m_gi = GeoIP_open(filePath.c_str(), GEOIP_INDEX_CACHE);
if (m_gi == NULL) {
return false;
}
@@ -71,6 +73,8 @@ bool GeoLookup::lookup(const std::string& target, GeoIPRecord **gir,
return true;
}
#endif // WITH_GEOIP
} // namespace Utils
} // namespace ModSecurity

View File

@@ -18,7 +18,9 @@
#include <string>
#include <functional>
#ifdef WITH_GEOIP // WITH_GEOIP
#include <GeoIPCity.h>
#endif
#ifndef SRC_UTILS_GEO_LOOKUP_H_
#define SRC_UTILS_GEO_LOOKUP_H_
@@ -35,11 +37,12 @@ class GeoLookup {
static GeoLookup instance;
return instance;
}
#ifdef WITH_GEOIP
bool setDataBase(const std::string& filePath);
bool lookup(const std::string& target, GeoIPRecord **georec,
std::function<bool(int, std::string)> callback);
void cleanUp();
#endif // WITH_GEOIP
private:
GeoLookup()
@@ -47,8 +50,11 @@ class GeoLookup {
~GeoLookup();
GeoLookup(GeoLookup const&);
void operator=(GeoLookup const&);
#ifdef WITH_GEOIP
GeoIP *m_gi;
#else // WITH_GEOIP
void *m_gi;
#endif // WITH_GEOIP
};