1 /* 2 * This file is part of PowerDNS or dnsdist. 3 * Copyright -- PowerDNS.COM B.V. and its contributors 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of version 2 of the GNU General Public License as 7 * published by the Free Software Foundation. 8 * 9 * In addition, for the avoidance of any doubt, permission is granted to 10 * link this program with OpenSSL and to (re)distribute the binaries 11 * produced as the result of such linking. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 */ 22 #pragma once 23 #include "boost/optional.hpp" 24 25 #include "geoipbackend.hh" 26 27 class GeoIPInterface 28 { 29 public: 30 enum GeoIPQueryAttribute 31 { 32 ASn, 33 City, 34 Continent, 35 Country, 36 Country2, 37 Name, 38 Region, 39 Location 40 }; 41 42 virtual bool queryCountry(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 43 virtual bool queryCountryV6(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 44 virtual bool queryCountry2(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 45 virtual bool queryCountry2V6(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 46 virtual bool queryContinent(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 47 virtual bool queryContinentV6(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 48 virtual bool queryName(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 49 virtual bool queryNameV6(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 50 virtual bool queryASnum(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 51 virtual bool queryASnumV6(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 52 virtual bool queryRegion(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 53 virtual bool queryRegionV6(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 54 virtual bool queryCity(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 55 virtual bool queryCityV6(string& ret, GeoIPNetmask& gl, const string& ip) = 0; 56 virtual bool queryLocation(GeoIPNetmask& gl, const string& ip, 57 double& latitude, double& longitude, 58 boost::optional<int>& alt, boost::optional<int>& prec) 59 = 0; 60 virtual bool queryLocationV6(GeoIPNetmask& gl, const string& ip, 61 double& latitude, double& longitude, 62 boost::optional<int>& alt, boost::optional<int>& prec) 63 = 0; 64 ~GeoIPInterface()65 virtual ~GeoIPInterface() {} 66 67 static unique_ptr<GeoIPInterface> makeInterface(const string& dbStr); 68 69 private: 70 static unique_ptr<GeoIPInterface> makeMMDBInterface(const string& fname, const map<string, string>& opts); 71 static unique_ptr<GeoIPInterface> makeDATInterface(const string& fname, const map<string, string>& opts); 72 }; 73