| 33 | MMDB_s *gMaxMindDB = nullptr; |
| 34 | |
| 35 | void |
| 36 | MMConditionGeo::initLibrary(const std::string &path) |
| 37 | { |
| 38 | if (path.empty()) { |
| 39 | Dbg(pi_dbg_ctl, "Empty MaxMind db path specified. Not initializing!"); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | if (gMaxMindDB != nullptr) { |
| 44 | Dbg(pi_dbg_ctl, "Maxmind library already initialized"); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | gMaxMindDB = new MMDB_s; |
| 49 | |
| 50 | int status = MMDB_open(path.c_str(), MMDB_MODE_MMAP, gMaxMindDB); |
| 51 | if (MMDB_SUCCESS != status) { |
| 52 | Dbg(pi_dbg_ctl, "Cannot open %s - %s", path.c_str(), MMDB_strerror(status)); |
| 53 | delete gMaxMindDB; |
| 54 | return; |
| 55 | } |
| 56 | Dbg(pi_dbg_ctl, "Loaded %s", path.c_str()); |
| 57 | } |
| 58 | |
| 59 | std::string |
| 60 | MMConditionGeo::get_geo_string(const sockaddr *addr) const |