s_rc++;
}
+string getGeoForLua(const std::string& ip, GeoIPBackend::GeoIPQueryAttribute qa)
+{
+ try {
+ GeoIPBackend gib;
+ GeoIPLookup gl;
+ string res=gib.queryGeoIP(ip, false, qa, &gl);
+ // cout<<"Result for "<<ip<<" lookup: "<<res<<endl;
+ if(qa==GeoIPBackend::ASn && boost::starts_with(res, "as"))
+ return res.substr(2);
+ return res;
+ }
+ catch(std::exception& e) {
+ cout<<"Error: "<<e.what()<<endl;
+ }
+ catch(PDNSException& e) {
+ cout<<"Error: "<<e.reason<<endl;
+ }
+ return "";
+}
+
+
void GeoIPBackend::initialize() {
YAML::Node config;
vector<GeoIPDomain> tmp_domains;
s_domains.clear();
std::swap(s_domains, tmp_domains);
+
+ extern std::function<std::string(const std::string& ip, GeoIPBackend::GeoIPQueryAttribute)> g_getGeo;
+ g_getGeo = getGeoForLua;
}
GeoIPBackend::~GeoIPBackend() {
return false;
}
-string getGeo(const std::string& ip, GeoIPBackend::GeoIPQueryAttribute qa)
-{
- try {
- GeoIPBackend gib;
- GeoIPLookup gl;
- string res=gib.queryGeoIP(ip, false, qa, &gl);
- // cout<<"Result for "<<ip<<" lookup: "<<res<<endl;
- if(qa==GeoIPBackend::ASn && boost::starts_with(res, "as"))
- return res.substr(2);
- return res;
- }
- catch(std::exception& e) {
- cout<<"Error: "<<e.what()<<endl;
- }
- catch(PDNSException& e) {
- cout<<"Error: "<<e.reason<<endl;
- }
- return "";
-}
class GeoIPFactory : public BackendFactory{
#include "minicurl.hh"
#include "ueberbackend.hh"
#include <boost/format.hpp>
+// this is only for the ENUM
#include "../../modules/geoipbackend/geoipbackend.hh"
/* to do:
}
-std::string getGeo(const std::string& ip, GeoIPBackend::GeoIPQueryAttribute qa) __attribute__((weak));
+std::function<std::string(const std::string&, GeoIPBackend::GeoIPQueryAttribute)> g_getGeo;
std::string getGeo(const std::string& ip, GeoIPBackend::GeoIPQueryAttribute qa)
{
- cerr<<"Weak variant called"<<endl;
- return "unknown";
+ static bool intialized;
+ if(!g_getGeo) {
+ if(!initialized) {
+ L<<Logger::Error<<"LUA Record attempted to use GeoIPBackend functionality, but backend not launched"<<endl;
+ initialized=true;
+ }
+ return "unknown";
+ }
+ else
+ return g_getGeo(ip, qa);
}
static ComboAddress pickrandom(vector<ComboAddress>& ips)