mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Makes @geoLookup optional depending on the availability of libGeoIP
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user