| 288 | } |
| 289 | |
| 290 | String IP2GeoManager::IPIPLocator::getString(String ip, int location_type, ipdb_reader * reader) |
| 291 | { |
| 292 | char body[512]; |
| 293 | if (reader == nullptr) |
| 294 | throw Exception("IPDB file is not open or memory has been freed ", ErrorCodes::FILE_NOT_FOUND); |
| 295 | int err = ipdb_reader_find(reader, ip.c_str(), "CN", body); |
| 296 | if (!err) |
| 297 | { |
| 298 | char tmp[64]; |
| 299 | int f = 0, p1 = 0, p2 = -1; |
| 300 | do |
| 301 | { |
| 302 | if (*(body + p1) == '\t' || !*(body + p1)) |
| 303 | { |
| 304 | if (f == location_type) |
| 305 | { |
| 306 | strncpy(tmp, body + p2 + 1, static_cast<size_t>(p1 - p2)); |
| 307 | tmp[p1 - p2] = 0; |
| 308 | return tmp; |
| 309 | } |
| 310 | else |
| 311 | { |
| 312 | p2 = p1; |
| 313 | ++f; |
| 314 | } |
| 315 | } |
| 316 | } while (*(body + p1++)); |
| 317 | } |
| 318 | return "NULL"; |
| 319 | } |
| 320 | |
| 321 | void IP2GeoManager::IPIPLocator::freeIpipReader() |
| 322 | { |
no test coverage detected