/* Copyright (C) 2019 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #pragma once #include #if HAVE_MAXMINDDB #include #endif #if HAVE_MAXMINDDB #define geodb_t MMDB_s #define geodb_data_t MMDB_entry_data_s #else #define geodb_t void #define geodb_data_t char #endif // MaxMind DB related constants. #define GEODB_MAX_PATH_LEN 8 #define GEODB_MAX_DEPTH 8 typedef enum { GEODB_KEY_ID, GEODB_KEY_TXT } geodb_key_type_t; static const knot_lookup_t geodb_key_types[] = { { GEODB_KEY_ID, "id" }, { GEODB_KEY_TXT, "" }, { 0, NULL } }; typedef struct { geodb_key_type_t type; char *path[GEODB_MAX_PATH_LEN + 1]; // MMDB_aget_value() requires last member to be NULL. } geodb_path_t; int parse_geodb_path(geodb_path_t *path, const char *input); int parse_geodb_data(const char *input, void **geodata, uint32_t *geodata_len, uint8_t *geodepth, geodb_path_t *path, uint16_t path_cnt); bool geodb_available(void); geodb_t *geodb_open(const char *filename); void geodb_close(geodb_t *geodb); int geodb_query(geodb_t *geodb, geodb_data_t *entries, struct sockaddr *remote, geodb_path_t *paths, uint16_t path_cnt, uint16_t *netmask); void geodb_fill_geodata(geodb_data_t *entries, uint16_t path_cnt, void **geodata, uint32_t *geodata_len, uint8_t *geodepth);