-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxmind_db_reader.h
More file actions
43 lines (31 loc) · 923 Bytes
/
maxmind_db_reader.h
File metadata and controls
43 lines (31 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef MAXMIND_C_LIB_PRACTICE_MAXMIND_DB_READER_H
#define MAXMIND_C_LIB_PRACTICE_MAXMIND_DB_READER_H
#include <maxminddb.h>
#include <string>
#include <stdexcept>
#include "constants.h"
namespace geo_ip_loader {
/**
* libmaxminddb wrapper
*/
class MaxmindDBReader final {
private:
MMDB_s mmdb;
public:
explicit MaxmindDBReader(const std::string &db_filename);
~MaxmindDBReader();
MMDB_lookup_result_s lookup_raw(const std::string &ip_address);
std::string get_field(const std::string &ip_address, const VCStr &lookup_path);
/**
* @param[in] lookup
* @param lookup_path
* @return value if exists, or empty string
*/
std::string get_field(MMDB_lookup_result_s *lookup, const VCStr &lookup_path);
};
/// Exceptions
class NotFoundException final: public std::logic_error {
using std::logic_error::logic_error;
};
} // namespace geo_ip_loader
#endif //MAXMIND_C_LIB_PRACTICE_MAXMIND_DB_READER_H