The DB class is the primary class used by GeoLite2++. More...
#include <GeoLite2PP.hpp>
Public Member Functions | |
~DB (void) | |
Destructor. More... | |
DB (const std::string &database_filename="GeoLite2-City.mmdb") | |
Constructor. More... | |
std::string | get_lib_version_mmdb (void) const |
Get the MaxMind library version number. More... | |
std::string | get_lib_version_geolite2pp (void) const |
Get the GeoLite2++ library version number. More... | |
MMDB_metadata_s | get_metadata_raw (void) |
Get the database metadata. More... | |
std::string | get_metadata (void) |
Get the database metadata as a JSON string. More... | |
MMDB_lookup_result_s | lookup_raw (const std::string &ip_address) |
Look up an IP address. More... | |
std::string | lookup (const std::string &ip_address) |
Look up an IP address and return a JSON string of everything found. More... | |
MStr | get_all_fields (const std::string &ip_address, const std::string &language="en") |
Return a std::map of many of the key fields available when looking up an address. More... | |
std::string | get_field (const std::string &ip_address, const std::string &language, const VCStr &v) |
Get a specific field, or an empty string if the field does not exist. More... | |
std::string | get_field (MMDB_lookup_result_s *lookup, const std::string &language, const VCStr &v) |
Get a specific field, or an empty string if the field does not exist. More... | |
std::string | to_json (MMDB_entry_data_list_s *node) |
Process the specified node list and return a JSON-format string. More... | |
The DB class is the primary class used by GeoLite2++.
It is used to point to the MaxMind's GeoLite2's database and to retrieve information based on IP addresses.
GeoLite2PP::DB::~DB | ( | void | ) |
Destructor.
GeoLite2PP::DB::DB | ( | const std::string & | database_filename = "GeoLite2-City.mmdb" | ) |
Constructor.
[in] | database_filename | The database filename is the .mmdb file typically downloaded from MaxMind. Normally, this file is called GeoLite2-City.mmdb and may be downloaded for free from http://dev.maxmind.com/geoip/geoip2/geolite2/#Downloads. The name used can be relative to the current working directory, or an absolute path and filename. |
GeoLite2PP::DB
cannot be constructed without a valid database file!geolite2pp_get_database.sh
can be used to easily download and extract the database into the current working directory. But either way, the MaxMind database must be available for GeoLite2++ to work. std::system_error | if the database file cannot be opened. |
References GeoLite2PP::get_error_category().
GeoLite2PP::MStr GeoLite2PP::DB::get_all_fields | ( | const std::string & | ip_address, |
const std::string & | language = "en" |
||
) |
Return a std::map
of many of the key fields available when looking up an address.
This includes fields such as subdivision name, city name, country name, continent name, longitude, latitude, accuracy radius, and relevant iso codes. Not all fields are available for all addresses and languages.
Example output:
References lookup_raw().
std::string GeoLite2PP::DB::get_field | ( | const std::string & | ip_address, |
const std::string & | language, | ||
const VCStr & | v | ||
) |
Get a specific field, or an empty string if the field does not exist.
A lookup of the given IP address needs to be performed every time this is called, which makes this less efficient than the other get_field()
method which takes a MMDB_lookup_result_s
parameter.
References lookup(), and lookup_raw().
Referenced by get_field().
std::string GeoLite2PP::DB::get_field | ( | MMDB_lookup_result_s * | lookup, |
const std::string & | language, | ||
const VCStr & | v | ||
) |
Get a specific field, or an empty string if the field does not exist.
This is a more efficient call than the other get_field()
method since the address doesn't need to be looked up in the database at every call.
References get_field().
std::string GeoLite2PP::DB::get_lib_version_geolite2pp | ( | void | ) | const |
Get the GeoLite2++ library version number.
Example output:
std::string GeoLite2PP::DB::get_lib_version_mmdb | ( | void | ) | const |
Get the MaxMind library version number.
Example output:
std::string GeoLite2PP::DB::get_metadata | ( | void | ) |
Get the database metadata as a JSON string.
Example output:
std::system_error | if the lookup resulted in a MMDB error |
References GeoLite2PP::get_error_category(), and to_json().
MMDB_metadata_s GeoLite2PP::DB::get_metadata_raw | ( | void | ) |
Get the database metadata.
This returns a raw MMDB_metadata_s
structure. This call is intended mostly for internal purposes, or to call directly into the original C MMDB API.
std::string GeoLite2PP::DB::lookup | ( | const std::string & | ip_address | ) |
Look up an IP address and return a JSON string of everything found.
Example output:
std::system_error | if the lookup resulted in a MMDB error |
References GeoLite2PP::get_error_category(), lookup_raw(), and to_json().
Referenced by get_field().
MMDB_lookup_result_s GeoLite2PP::DB::lookup_raw | ( | const std::string & | ip_address | ) |
Look up an IP address.
This returns a raw MMDB_lookup_result_s
structure. This call is intended mostly for internal purposes, or to call directly into the original C MMDB API.
std::invalid_argument | if the address is invalid |
std::system_error | if the lookup resulted in a MMDB error |
std::length_error | if an entry was not found in the database |
References GeoLite2PP::get_error_category().
Referenced by get_all_fields(), get_field(), and lookup().
std::string GeoLite2PP::DB::to_json | ( | MMDB_entry_data_list_s * | node | ) |
Process the specified node list and return a JSON-format string.
MMDB_free_entry_data_list()
on the node.This call is intended mostly for internal purposes.
Referenced by get_metadata(), and lookup().