Created my ip_to_geo .cpp and .hpp files and code.
Additionally, I added a .env file and started using cmake build styles rather than g++ for more efficient compiling and testing. Changes to be committed: new file: .env new file: CMakeLists.txt new file: build/CMakeCache.txt new file: build/CMakeFiles/4.3.2/CMakeCXXCompiler.cmake new file: build/CMakeFiles/4.3.2/CMakeDetermineCompilerABI_CXX.bin new file: build/CMakeFiles/4.3.2/CMakeSystem.cmake new file: build/CMakeFiles/4.3.2/CompilerIdCXX/CMakeCXXCompilerId.cpp new file: build/CMakeFiles/4.3.2/CompilerIdCXX/a.out new file: build/CMakeFiles/CMakeConfigureLog.yaml new file: build/CMakeFiles/CMakeDirectoryInformation.cmake new file: build/CMakeFiles/InstallScripts.json new file: build/CMakeFiles/Makefile.cmake new file: build/CMakeFiles/Makefile2 new file: build/CMakeFiles/TargetDirectories.txt new file: build/CMakeFiles/cmake.check_cache new file: build/CMakeFiles/parselog_cli.dir/DependInfo.cmake new file: build/CMakeFiles/parselog_cli.dir/build.make new file: build/CMakeFiles/parselog_cli.dir/cmake_clean.cmake new file: build/CMakeFiles/parselog_cli.dir/compiler_depend.internal new file: build/CMakeFiles/parselog_cli.dir/compiler_depend.make new file: build/CMakeFiles/parselog_cli.dir/compiler_depend.ts new file: build/CMakeFiles/parselog_cli.dir/depend.make new file: build/CMakeFiles/parselog_cli.dir/flags.make new file: build/CMakeFiles/parselog_cli.dir/ip_to_geo/ip_to_geo.cpp.o new file: build/CMakeFiles/parselog_cli.dir/ip_to_geo/ip_to_geo.cpp.o.d new file: build/CMakeFiles/parselog_cli.dir/link.d new file: build/CMakeFiles/parselog_cli.dir/link.txt new file: build/CMakeFiles/parselog_cli.dir/log_parsing/log_parsing.cpp.o new file: build/CMakeFiles/parselog_cli.dir/log_parsing/log_parsing.cpp.o.d new file: build/CMakeFiles/parselog_cli.dir/main.cpp.o new file: build/CMakeFiles/parselog_cli.dir/main.cpp.o.d new file: build/CMakeFiles/parselog_cli.dir/progress.make new file: build/CMakeFiles/parselog_cli.dir/third_party/src/GeoLite2PP.cpp.o new file: build/CMakeFiles/parselog_cli.dir/third_party/src/GeoLite2PP.cpp.o.d new file: build/CMakeFiles/parselog_cli.dir/third_party/src/GeoLite2PP_error_category.cpp.o new file: build/CMakeFiles/parselog_cli.dir/third_party/src/GeoLite2PP_error_category.cpp.o.d new file: build/CMakeFiles/progress.marks new file: build/Makefile new file: build/cmake_install.cmake new file: build/compile_commands.json new file: build/parselog_cli new file: compile_commands.json new file: data/GeoLite2-City.mmdb modified: ip_to_geo/ip_to_geo.cpp modified: ip_to_geo/ip_to_geo.hpp modified: main.cpp deleted: parselog_cli.exe deleted: test renamed: ip_to_geo/GeoLite2PP.hpp -> third_party/include/GeoLite2PP.hpp new file: third_party/include/GeoLite2PP_error_category.hpp new file: third_party/include/GeoLite2PP_version.hpp new file: third_party/include/maxminddb.h new file: third_party/include/maxminddb_config.h new file: third_party/lib/libmaxminddb.a new file: third_party/src/GeoLite2PP.cpp new file: third_party/src/GeoLite2PP_error_category.cpp
This commit is contained in:
239
third_party/include/GeoLite2PP.hpp
vendored
Normal file
239
third_party/include/GeoLite2PP.hpp
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
/* GeoLite2++ (C) 2016 Stephane Charette <stephanecharette@gmail.com>
|
||||
* $Id: GeoLite2PP.hpp 2036 2016-11-17 00:46:40Z stephane $
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <system_error>
|
||||
#include <maxminddb.h>
|
||||
|
||||
|
||||
/** The entire GeoLite2++ library is encapsulated in the GeoLite2PP namespace to prevent namespace pollution.
|
||||
*
|
||||
* Note that GeoLite2++ builds on top of the existing C library "libmaxminddb". GeoLite2++ provides alternate C++
|
||||
* bindings, it is not a replacement! GeoLite2++ was written to provide an easier method from C++ to access MaxMind's
|
||||
* GeoLite2 GeoIP database.
|
||||
*
|
||||
* The original C libmaxminddb library is here: https://github.com/maxmind/libmaxminddb/
|
||||
*/
|
||||
namespace GeoLite2PP
|
||||
{
|
||||
/// Map of std::string to std::string.
|
||||
typedef std::map<std::string, std::string> MStr;
|
||||
|
||||
/// Vector of C-style string pointers.
|
||||
typedef std::vector<const char *> VCStr;
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
class DB final
|
||||
{
|
||||
public:
|
||||
|
||||
/// Destructor.
|
||||
~DB( void );
|
||||
|
||||
/** Constructor.
|
||||
* @param [in] database_filename The database filename is the @p .mmdb file typically downloaded from
|
||||
* MaxMind. Normally, this file is called @p 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.
|
||||
*
|
||||
* ~~~~
|
||||
* std::string filename = "/opt/my_project_files/GeoLite2-City.mmdb";
|
||||
*
|
||||
* GeoLite2PP::DB db( filename );
|
||||
*
|
||||
* std::cout << db.get_mmdb_lib_version() << std::endl;
|
||||
* std::cout << db.lookup_metadata() << std::endl;
|
||||
* ~~~~
|
||||
*
|
||||
* @warning <b>An object of type @p GeoLite2PP::DB cannot be constructed without a valid database file!</b>
|
||||
*
|
||||
* @note The database can be manually downloaded, or the script @p 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.
|
||||
*/
|
||||
DB( const std::string &database_filename = "GeoLite2-City.mmdb" );
|
||||
|
||||
/** Get the MaxMind library version number.
|
||||
*
|
||||
* ~~~~
|
||||
* GeoLite2PP::DB db;
|
||||
* std::cout << db.get_lib_version_mmdb() << std::endl;
|
||||
* ~~~~
|
||||
*
|
||||
* Example output:
|
||||
* ~~~~{.txt}
|
||||
* 1.2.0
|
||||
* ~~~~
|
||||
*/
|
||||
std::string get_lib_version_mmdb( void ) const;
|
||||
|
||||
/** Get the GeoLite2++ library version number.
|
||||
*
|
||||
* ~~~~
|
||||
* GeoLite2PP::DB db;
|
||||
* std::cout << db.get_liv_version_geolite2pp() << std::endl;
|
||||
* ~~~~
|
||||
*
|
||||
* Example output:
|
||||
* ~~~~{.txt}
|
||||
* 0.0.1-1992
|
||||
* ~~~~
|
||||
*/
|
||||
std::string get_lib_version_geolite2pp( void ) const;
|
||||
|
||||
/** Get the database metadata. This returns a raw @p MMDB_metadata_s structure. This call is intended
|
||||
* mostly for internal purposes, or to call directly into the original C MMDB API.
|
||||
* @see @ref get_metadata()
|
||||
*/
|
||||
MMDB_metadata_s get_metadata_raw( void );
|
||||
|
||||
/** Get the database metadata as a JSON string.
|
||||
*
|
||||
* ~~~~
|
||||
* GeoLite2PP::DB db;
|
||||
* std::cout << db.get_metadata() << std::endl;
|
||||
* ~~~~
|
||||
*
|
||||
* Example output:
|
||||
* ~~~~{.json}
|
||||
* {
|
||||
* "binary_format_major_version" : 2,
|
||||
* "binary_format_minor_version" : 0,
|
||||
* "build_epoch" : 1475588619,
|
||||
* "database_type" : "GeoLite2-City",
|
||||
* "description" : { "en" : "GeoLite2 City database" },
|
||||
* "ip_version" : 6,
|
||||
* "languages" : [ "de", "en", "es", "fr", "ja", "pt-BR", "ru", "zh-CN" ],
|
||||
* "node_count" : 4065439,
|
||||
* "record_size" : 28
|
||||
* }
|
||||
* ~~~~
|
||||
* @see @ref get_metadata_raw()
|
||||
*/
|
||||
std::string get_metadata( void );
|
||||
|
||||
/** Look up an IP address. This returns a raw @p MMDB_lookup_result_s structure. This call is intended
|
||||
* mostly for internal purposes, or to call directly into the original C MMDB API.
|
||||
* @see @ref lookup()
|
||||
*/
|
||||
MMDB_lookup_result_s lookup_raw( const std::string &ip_address );
|
||||
|
||||
/** Look up an IP address and return a JSON string of everything found.
|
||||
*
|
||||
* ~~~~
|
||||
* GeoLite2PP::DB db;
|
||||
* std::string json = db.lookup( "65.44.217.6" );
|
||||
* std::cout << json << std::endl;
|
||||
* ~~~~
|
||||
*
|
||||
* Example output:
|
||||
* ~~~~{.json}
|
||||
* { "city" : { "names" : { "en" : "Fresno" } },
|
||||
* "continent" : { "code" : "NA", "names" : { "en" : "North America" } },
|
||||
* "country" : { "iso_code" : "US", "names" : { "en" : "United States" } },
|
||||
* "location" : { "accuracy_radius" : 200,
|
||||
* "latitude" : 36.6055,
|
||||
* "longitude" : -119.752,
|
||||
* "time_zone" : "America/Los_Angeles" },
|
||||
* "postal" : { "code" : "93725" },
|
||||
* "subdivisions" : [ { "iso_code" : "CA", "names" : { "en" : "California" } } ]
|
||||
* }
|
||||
* ~~~~
|
||||
* @note <i>For clarity, some of the JSON entries have been removed in this example output.</i>
|
||||
*/
|
||||
std::string lookup( const std::string &ip_address );
|
||||
|
||||
/** Return a @p 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.
|
||||
*
|
||||
* @note The method is mis-named. It returns @b many fields, but definitely does not return @b all fields.
|
||||
* To see all fields, see @ref lookup().
|
||||
*
|
||||
* ~~~~
|
||||
* GeoLite2PP::DB db;
|
||||
* GeoLite2PP::MStr m = db.get_all_fields( "65.44.217.6" );
|
||||
* for ( const auto iter : m )
|
||||
* {
|
||||
* std::cout << "key=" << iter.first << " -> " << iter.second << std::endl;
|
||||
* }
|
||||
* ~~~~
|
||||
*
|
||||
* Example output:
|
||||
* ~~~~{.txt}
|
||||
* accuracy_radius -> 200
|
||||
* city -> Fresno
|
||||
* continent -> North America
|
||||
* country -> United States
|
||||
* country_iso_code -> US
|
||||
* latitude -> 36.605500
|
||||
* longitude -> -119.752200
|
||||
* postal_code -> 93725
|
||||
* query_ip_address -> 65.44.217.6
|
||||
* query_language -> en
|
||||
* registered_country -> United States
|
||||
* subdivision -> California
|
||||
* subdivision_iso_code -> CA
|
||||
* time_zone -> America/Los_Angeles
|
||||
* ~~~~
|
||||
*/
|
||||
MStr get_all_fields( const std::string &ip_address, const std::string &language = "en" );
|
||||
|
||||
/** 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 @p get_field() method which takes a @p MMDB_lookup_result_s parameter.
|
||||
*
|
||||
* ~~~~
|
||||
* GeoLite2PP::DB db;
|
||||
* std::string city = db.get_field( "65.44.217.6", "en", GeoLite2PP::VCStr { "city" , "names" } );
|
||||
* std::string country = db.get_field( "65.44.217.6", "en", GeoLite2PP::VCStr { "country" , "names" } );
|
||||
* std::string latitude = db.get_field( "65.44.217.6", "en", GeoLite2PP::VCStr { "location", "latitude" } );
|
||||
* ~~~~
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* This is a more efficient call than the other @p get_field() method since the address doesn't need to
|
||||
* be looked up in the database at every call.
|
||||
*
|
||||
* ~~~~
|
||||
* GeoLite2PP::DB db;
|
||||
* MMDB_lookup_result_s result = db.lookup_raw( "65.44.217.6" );
|
||||
* std::string city = db.get_field( &result, "en", GeoLite2PP::VCStr { "city" , "names" } );
|
||||
* std::string country = db.get_field( &result, "en", GeoLite2PP::VCStr { "country" , "names" } );
|
||||
* std::string latitude = db.get_field( &result, "en", GeoLite2PP::VCStr { "location", "latitude" } );
|
||||
* ~~~~
|
||||
*/
|
||||
std::string get_field( MMDB_lookup_result_s *lookup, const std::string &language, const VCStr &v );
|
||||
|
||||
/** Process the specified node list and return a JSON-format string.
|
||||
*
|
||||
* @warning This @b will de-allocate the node list prior to returning; do not call
|
||||
* @p MMDB_free_entry_data_list() on the node.
|
||||
*
|
||||
* This call is intended mostly for internal purposes. @see @ref lookup() @see @ref get_metadata()
|
||||
*/
|
||||
std::string to_json( MMDB_entry_data_list_s *node );
|
||||
|
||||
private:
|
||||
|
||||
/// Internal handle to the database. @see @p MMDB_open()
|
||||
MMDB_s mmdb;
|
||||
|
||||
/// Traverse a list of nodes and build up a JSON string. This method is not exposed. It is for internal use only.
|
||||
void create_json_from_entry( std::stringstream &ss, size_t depth, uint32_t data_size, MMDB_entry_data_list_s * &next, const bool in_array = false );
|
||||
|
||||
/// Look up a specific name (e.g., "city") and store it in the specified map. This method is not exposed. It is for internal use only.
|
||||
void add_to_map( GeoLite2PP::MStr &m, MMDB_lookup_result_s *node, const std::string &name, const std::string &language, const VCStr &v );
|
||||
};
|
||||
}
|
||||
62
third_party/include/GeoLite2PP_error_category.hpp
vendored
Normal file
62
third_party/include/GeoLite2PP_error_category.hpp
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/* GeoLite2++ (C) 2016-2018 Stephane Charette <stephanecharette@gmail.com>
|
||||
* $Id: GeoLite2PP_error_category.hpp 2549 2018-06-08 18:48:31Z stephane $
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <maxminddb.h>
|
||||
|
||||
|
||||
namespace GeoLite2PP
|
||||
{
|
||||
/// Errors defined in maxminddb.h, converted to C++ enums.
|
||||
enum class MMDBStatus
|
||||
{
|
||||
success = MMDB_SUCCESS , ///<= 0
|
||||
file_open = MMDB_FILE_OPEN_ERROR , ///<= 1
|
||||
corrupt_search_tree = MMDB_CORRUPT_SEARCH_TREE_ERROR , ///<= 2
|
||||
invalid_metadata = MMDB_INVALID_METADATA_ERROR , ///<= 3
|
||||
io = MMDB_IO_ERROR , ///<= 4
|
||||
out_of_memory = MMDB_OUT_OF_MEMORY_ERROR , ///<= 5
|
||||
unknown_db_format = MMDB_UNKNOWN_DATABASE_FORMAT_ERROR , ///<= 6
|
||||
invalid_data = MMDB_INVALID_DATA_ERROR , ///<= 7
|
||||
invalid_lookup_path = MMDB_INVALID_LOOKUP_PATH_ERROR , ///<= 8
|
||||
lookup_path_does_not_match = MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR, ///<= 9
|
||||
invalid_node_number = MMDB_INVALID_NODE_NUMBER_ERROR , ///<= 10
|
||||
ipv6_lookup_in_ipv4_db = MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR ///<= 11
|
||||
};
|
||||
|
||||
|
||||
/** Error class used to return libmaxminddb error codes and messages when C++ exceptions are thrown.
|
||||
* @see @p MMDB_strerror()
|
||||
*/
|
||||
class ErrorCategory : public std::error_category
|
||||
{
|
||||
public:
|
||||
|
||||
/// Returns a unique name.
|
||||
virtual const char *name( void ) const noexcept;
|
||||
|
||||
/// Convert a MaxMindDB error/status code into a readable text string message.
|
||||
virtual std::string message( int code ) const;
|
||||
};
|
||||
|
||||
/// All error category objects should actually be references to the exact same object, which is provided by this function.
|
||||
const ErrorCategory &get_error_category( void ) noexcept;
|
||||
|
||||
/// Associate an error value with the category.
|
||||
std::error_code make_error_code( MMDBStatus s );
|
||||
|
||||
/// Associate an error_condition with the category.
|
||||
std::error_condition make_error_condition( MMDBStatus s );
|
||||
}
|
||||
|
||||
|
||||
namespace std
|
||||
{
|
||||
/// Make sure that MMDBStatus enums can be converted to error codes.
|
||||
template <>
|
||||
struct is_error_code_enum<GeoLite2PP::MMDBStatus> : public true_type {};
|
||||
}
|
||||
12
third_party/include/GeoLite2PP_version.hpp
vendored
Normal file
12
third_party/include/GeoLite2PP_version.hpp
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef GEOLITE2PP_VERSION_HPP
|
||||
#define GEOLITE2PP_VERSION_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace GeoLite2PP {
|
||||
// Basic hardcoded version metadata to replace the template file
|
||||
const std::string version = "0.0.1";
|
||||
const std::string build_date = "2026";
|
||||
}
|
||||
|
||||
#endif // GEOLITE2PP_VERSION_HPP
|
||||
260
third_party/include/maxminddb.h
vendored
Normal file
260
third_party/include/maxminddb.h
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef MAXMINDDB_H
|
||||
#define MAXMINDDB_H
|
||||
|
||||
#include "maxminddb_config.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __has_include
|
||||
#if __has_include(<endian.h>)
|
||||
#include <endian.h>
|
||||
#elif __has_include(<sys/endian.h>)
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
/* libmaxminddb package version from configure */
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
/* MSVC doesn't define signed size_t, copy it from configure */
|
||||
#define ssize_t SSIZE_T
|
||||
|
||||
#endif
|
||||
#else
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#if !defined(MMDB_LITTLE_ENDIAN)
|
||||
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define MMDB_LITTLE_ENDIAN 1
|
||||
#endif
|
||||
#elif defined(_WIN32) || defined(_WIN64)
|
||||
// We assume modern Windows targets are little endian
|
||||
#define MMDB_LITTLE_ENDIAN 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MMDB_DATA_TYPE_EXTENDED (0)
|
||||
#define MMDB_DATA_TYPE_POINTER (1)
|
||||
#define MMDB_DATA_TYPE_UTF8_STRING (2)
|
||||
#define MMDB_DATA_TYPE_DOUBLE (3)
|
||||
#define MMDB_DATA_TYPE_BYTES (4)
|
||||
#define MMDB_DATA_TYPE_UINT16 (5)
|
||||
#define MMDB_DATA_TYPE_UINT32 (6)
|
||||
#define MMDB_DATA_TYPE_MAP (7)
|
||||
#define MMDB_DATA_TYPE_INT32 (8)
|
||||
#define MMDB_DATA_TYPE_UINT64 (9)
|
||||
#define MMDB_DATA_TYPE_UINT128 (10)
|
||||
#define MMDB_DATA_TYPE_ARRAY (11)
|
||||
#define MMDB_DATA_TYPE_CONTAINER (12)
|
||||
#define MMDB_DATA_TYPE_END_MARKER (13)
|
||||
#define MMDB_DATA_TYPE_BOOLEAN (14)
|
||||
#define MMDB_DATA_TYPE_FLOAT (15)
|
||||
|
||||
#define MMDB_RECORD_TYPE_SEARCH_NODE (0)
|
||||
#define MMDB_RECORD_TYPE_EMPTY (1)
|
||||
#define MMDB_RECORD_TYPE_DATA (2)
|
||||
#define MMDB_RECORD_TYPE_INVALID (3)
|
||||
|
||||
/* flags for open */
|
||||
#define MMDB_MODE_MMAP (1)
|
||||
#define MMDB_MODE_MASK (7)
|
||||
|
||||
/* error codes */
|
||||
#define MMDB_SUCCESS (0)
|
||||
#define MMDB_FILE_OPEN_ERROR (1)
|
||||
#define MMDB_CORRUPT_SEARCH_TREE_ERROR (2)
|
||||
#define MMDB_INVALID_METADATA_ERROR (3)
|
||||
#define MMDB_IO_ERROR (4)
|
||||
#define MMDB_OUT_OF_MEMORY_ERROR (5)
|
||||
#define MMDB_UNKNOWN_DATABASE_FORMAT_ERROR (6)
|
||||
#define MMDB_INVALID_DATA_ERROR (7)
|
||||
#define MMDB_INVALID_LOOKUP_PATH_ERROR (8)
|
||||
#define MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR (9)
|
||||
#define MMDB_INVALID_NODE_NUMBER_ERROR (10)
|
||||
#define MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR (11)
|
||||
|
||||
#if !(MMDB_UINT128_IS_BYTE_ARRAY)
|
||||
#if MMDB_UINT128_USING_MODE
|
||||
typedef unsigned int mmdb_uint128_t __attribute__((__mode__(TI)));
|
||||
#else
|
||||
typedef unsigned __int128 mmdb_uint128_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This is a pointer into the data section for a given IP address lookup */
|
||||
typedef struct MMDB_entry_s {
|
||||
const struct MMDB_s *mmdb;
|
||||
uint32_t offset;
|
||||
} MMDB_entry_s;
|
||||
|
||||
typedef struct MMDB_lookup_result_s {
|
||||
bool found_entry;
|
||||
MMDB_entry_s entry;
|
||||
uint16_t netmask;
|
||||
} MMDB_lookup_result_s;
|
||||
|
||||
typedef struct MMDB_entry_data_s {
|
||||
bool has_data;
|
||||
union {
|
||||
uint32_t pointer;
|
||||
const char *utf8_string;
|
||||
double double_value;
|
||||
const uint8_t *bytes;
|
||||
uint16_t uint16;
|
||||
uint32_t uint32;
|
||||
int32_t int32;
|
||||
uint64_t uint64;
|
||||
#if MMDB_UINT128_IS_BYTE_ARRAY
|
||||
uint8_t uint128[16];
|
||||
#else
|
||||
mmdb_uint128_t uint128;
|
||||
#endif
|
||||
bool boolean;
|
||||
float float_value;
|
||||
};
|
||||
/* This is a 0 if a given entry cannot be found. This can only happen
|
||||
* when a call to MMDB_(v)get_value() asks for hash keys or array
|
||||
* indices that don't exist. */
|
||||
uint32_t offset;
|
||||
/* This is the next entry in the data section, but it's really only
|
||||
* relevant for entries that part of a larger map or array
|
||||
* struct. There's no good reason for an end user to look at this
|
||||
* directly. */
|
||||
uint32_t offset_to_next;
|
||||
/* This is only valid for strings, utf8_strings or binary data */
|
||||
uint32_t data_size;
|
||||
/* This is an MMDB_DATA_TYPE_* constant */
|
||||
uint32_t type;
|
||||
} MMDB_entry_data_s;
|
||||
|
||||
/* This is the return type when someone asks for all the entry data in a map or
|
||||
* array */
|
||||
typedef struct MMDB_entry_data_list_s {
|
||||
MMDB_entry_data_s entry_data;
|
||||
struct MMDB_entry_data_list_s *next;
|
||||
void *pool;
|
||||
} MMDB_entry_data_list_s;
|
||||
|
||||
typedef struct MMDB_description_s {
|
||||
const char *language;
|
||||
const char *description;
|
||||
} MMDB_description_s;
|
||||
|
||||
/* WARNING: do not add new fields to this struct without bumping the SONAME.
|
||||
* The struct is allocated by the users of this library and increasing the
|
||||
* size will cause existing users to allocate too little space when the shared
|
||||
* library is upgraded */
|
||||
typedef struct MMDB_metadata_s {
|
||||
uint32_t node_count;
|
||||
uint16_t record_size;
|
||||
uint16_t ip_version;
|
||||
const char *database_type;
|
||||
struct {
|
||||
size_t count;
|
||||
const char **names;
|
||||
} languages;
|
||||
uint16_t binary_format_major_version;
|
||||
uint16_t binary_format_minor_version;
|
||||
uint64_t build_epoch;
|
||||
struct {
|
||||
size_t count;
|
||||
MMDB_description_s **descriptions;
|
||||
} description;
|
||||
/* See above warning before adding fields */
|
||||
} MMDB_metadata_s;
|
||||
|
||||
/* WARNING: do not add new fields to this struct without bumping the SONAME.
|
||||
* The struct is allocated by the users of this library and increasing the
|
||||
* size will cause existing users to allocate too little space when the shared
|
||||
* library is upgraded */
|
||||
typedef struct MMDB_ipv4_start_node_s {
|
||||
uint16_t netmask;
|
||||
uint32_t node_value;
|
||||
/* See above warning before adding fields */
|
||||
} MMDB_ipv4_start_node_s;
|
||||
|
||||
/* WARNING: do not add new fields to this struct without bumping the SONAME.
|
||||
* The struct is allocated by the users of this library and increasing the
|
||||
* size will cause existing users to allocate too little space when the shared
|
||||
* library is upgraded */
|
||||
typedef struct MMDB_s {
|
||||
uint32_t flags;
|
||||
const char *filename;
|
||||
ssize_t file_size;
|
||||
const uint8_t *file_content;
|
||||
const uint8_t *data_section;
|
||||
uint32_t data_section_size;
|
||||
const uint8_t *metadata_section;
|
||||
uint32_t metadata_section_size;
|
||||
uint16_t full_record_byte_size;
|
||||
uint16_t depth;
|
||||
MMDB_ipv4_start_node_s ipv4_start_node;
|
||||
MMDB_metadata_s metadata;
|
||||
/* See above warning before adding fields */
|
||||
} MMDB_s;
|
||||
|
||||
typedef struct MMDB_search_node_s {
|
||||
uint64_t left_record;
|
||||
uint64_t right_record;
|
||||
uint8_t left_record_type;
|
||||
uint8_t right_record_type;
|
||||
MMDB_entry_s left_record_entry;
|
||||
MMDB_entry_s right_record_entry;
|
||||
} MMDB_search_node_s;
|
||||
|
||||
extern int
|
||||
MMDB_open(const char *const filename, uint32_t flags, MMDB_s *const mmdb);
|
||||
extern MMDB_lookup_result_s MMDB_lookup_string(const MMDB_s *const mmdb,
|
||||
const char *const ipstr,
|
||||
int *const gai_error,
|
||||
int *const mmdb_error);
|
||||
extern MMDB_lookup_result_s
|
||||
MMDB_lookup_sockaddr(const MMDB_s *const mmdb,
|
||||
const struct sockaddr *const sockaddr,
|
||||
int *const mmdb_error);
|
||||
extern int MMDB_read_node(const MMDB_s *const mmdb,
|
||||
uint32_t node_number,
|
||||
MMDB_search_node_s *const node);
|
||||
extern int MMDB_get_value(MMDB_entry_s *const start,
|
||||
MMDB_entry_data_s *const entry_data,
|
||||
...);
|
||||
extern int MMDB_vget_value(MMDB_entry_s *const start,
|
||||
MMDB_entry_data_s *const entry_data,
|
||||
va_list va_path);
|
||||
extern int MMDB_aget_value(MMDB_entry_s *const start,
|
||||
MMDB_entry_data_s *const entry_data,
|
||||
const char *const *const path);
|
||||
extern int MMDB_get_metadata_as_entry_data_list(
|
||||
const MMDB_s *const mmdb, MMDB_entry_data_list_s **const entry_data_list);
|
||||
extern int
|
||||
MMDB_get_entry_data_list(MMDB_entry_s *start,
|
||||
MMDB_entry_data_list_s **const entry_data_list);
|
||||
extern void
|
||||
MMDB_free_entry_data_list(MMDB_entry_data_list_s *const entry_data_list);
|
||||
extern void MMDB_close(MMDB_s *const mmdb);
|
||||
extern const char *MMDB_lib_version(void);
|
||||
extern int
|
||||
MMDB_dump_entry_data_list(FILE *const stream,
|
||||
MMDB_entry_data_list_s *const entry_data_list,
|
||||
int indent);
|
||||
extern const char *MMDB_strerror(int error_code);
|
||||
|
||||
#endif /* MAXMINDDB_H */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
15
third_party/include/maxminddb_config.h
vendored
Normal file
15
third_party/include/maxminddb_config.h
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
/* include/maxminddb_config.h. Generated from maxminddb_config.h.in by configure. */
|
||||
#ifndef MAXMINDDB_CONFIG_H
|
||||
#define MAXMINDDB_CONFIG_H
|
||||
|
||||
#ifndef MMDB_UINT128_USING_MODE
|
||||
/* Define as 1 if we use unsigned int __attribute__ ((__mode__(TI))) for uint128 values */
|
||||
#define MMDB_UINT128_USING_MODE 0
|
||||
#endif
|
||||
|
||||
#ifndef MMDB_UINT128_IS_BYTE_ARRAY
|
||||
/* Define as 1 if we don't have an unsigned __int128 type */
|
||||
#define MMDB_UINT128_IS_BYTE_ARRAY 0
|
||||
#endif
|
||||
|
||||
#endif /* MAXMINDDB_CONFIG_H */
|
||||
Reference in New Issue
Block a user