1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2026-05-01 00:07:19 +02:00

Update MaxmindDB to current git.

This commit is contained in:
Sandu Liviu Catalin
2021-08-22 20:15:19 +03:00
parent 0008869ddd
commit 69a4d305a5
40 changed files with 2291 additions and 1912 deletions
+57 -49
View File
@@ -17,8 +17,7 @@ typedef struct test_result {
char *data_value;
} test_result_s;
void test_one_ip(MMDB_s *mmdb, const char *ip, test_result_s *test_result)
{
void test_one_ip(MMDB_s *mmdb, const char *ip, test_result_s *test_result) {
test_result->ip_looked_up = ip;
@@ -60,66 +59,77 @@ void test_one_ip(MMDB_s *mmdb, const char *ip, test_result_s *test_result)
return;
}
void *run_one_thread(void *arg)
{
void *run_one_thread(void *arg) {
thread_arg_s *thread_arg = (thread_arg_s *)arg;
MMDB_s *mmdb = thread_arg->mmdb;
const char *ip = thread_arg->ip_to_lookup;
test_result_s *result = malloc(sizeof(test_result_s));
if (!result) {
BAIL_OUT("could not allocate memory");
}
test_one_ip(mmdb, ip, result);
pthread_exit((void *)result);
}
void process_result(test_result_s *result, const char *expect,
const char *mode_desc)
{
void process_result(test_result_s *result,
const char *expect,
const char *mode_desc) {
int is_ok;
is_ok =
ok(!result->lookup_string_gai_error, "no getaddrinfo error for %s - %s",
result->ip_looked_up, mode_desc);
is_ok = ok(!result->lookup_string_gai_error,
"no getaddrinfo error for %s - %s",
result->ip_looked_up,
mode_desc);
if (!is_ok) {
return;
}
is_ok = ok(!result->lookup_string_mmdb_error, "no mmdb error for %s - %s",
result->ip_looked_up, mode_desc);
is_ok = ok(!result->lookup_string_mmdb_error,
"no mmdb error for %s - %s",
result->ip_looked_up,
mode_desc);
if (!is_ok) {
return;
}
is_ok = ok(result->found_entry, "got a result for %s in the database - %s",
result->ip_looked_up, mode_desc);
is_ok = ok(result->found_entry,
"got a result for %s in the database - %s",
result->ip_looked_up,
mode_desc);
if (!is_ok) {
return;
}
is_ok =
ok(!result->get_value_status,
"no error from MMDB_get_value for %s - %s",
result->ip_looked_up,
mode_desc);
is_ok = ok(!result->get_value_status,
"no error from MMDB_get_value for %s - %s",
result->ip_looked_up,
mode_desc);
if (!is_ok) {
return;
}
is_ok = ok(result->data_type_ok,
"MMDB_get_value found a utf8_string at 'ip' key for %s - %s",
result->ip_looked_up, mode_desc);
result->ip_looked_up,
mode_desc);
if (!is_ok) {
return;
}
is(result->data_value, expect,
is(result->data_value,
expect,
"found expected result for 'ip' key for %s - %s",
result->ip_looked_up, mode_desc);
result->ip_looked_up,
mode_desc);
}
void run_ipX_tests(MMDB_s *mmdb, const char *pairs[][2], int pairs_rows,
int mode, const char *mode_desc)
{
void run_ipX_tests(MMDB_s *mmdb,
const char *pairs[][2],
int pairs_rows,
int mode,
const char *mode_desc) {
pthread_t threads[pairs_rows];
struct thread_arg thread_args[pairs_rows];
@@ -128,8 +138,8 @@ void run_ipX_tests(MMDB_s *mmdb, const char *pairs[][2], int pairs_rows,
thread_args[i].mmdb = mmdb;
thread_args[i].ip_to_lookup = pairs[i][0];
int error = pthread_create(&threads[i], NULL, run_one_thread,
&thread_args[i]);
int error =
pthread_create(&threads[i], NULL, run_one_thread, &thread_args[i]);
if (error) {
BAIL_OUT("pthread_create failed");
}
@@ -153,32 +163,31 @@ void run_ipX_tests(MMDB_s *mmdb, const char *pairs[][2], int pairs_rows,
}
}
void run_tests(int mode, const char *mode_desc)
{
void run_tests(int mode, const char *mode_desc) {
const char *filename = "MaxMind-DB-test-mixed-32.mmdb";
const char *path = test_database_path(filename);
MMDB_s *mmdb = open_ok(path, mode, mode_desc);
free((void *)path);
const char *pairs[18][2] = {
{ "1.1.1.1", "::1.1.1.1" },
{ "1.1.1.2", "::1.1.1.2" },
{ "1.1.1.3", "::1.1.1.2" },
{ "1.1.1.7", "::1.1.1.4" },
{ "1.1.1.9", "::1.1.1.8" },
{ "1.1.1.15", "::1.1.1.8" },
{ "1.1.1.17", "::1.1.1.16" },
{ "1.1.1.31", "::1.1.1.16" },
{ "1.1.1.32", "::1.1.1.32" },
{ "::1:ffff:ffff", "::1:ffff:ffff" },
{ "::2:0:0", "::2:0:0" },
{ "::2:0:1a", "::2:0:0" },
{ "::2:0:40", "::2:0:40" },
{ "::2:0:4f", "::2:0:40" },
{ "::2:0:50", "::2:0:50" },
{ "::2:0:52", "::2:0:50" },
{ "::2:0:58", "::2:0:58" },
{ "::2:0:59", "::2:0:58" },
{"1.1.1.1", "::1.1.1.1"},
{"1.1.1.2", "::1.1.1.2"},
{"1.1.1.3", "::1.1.1.2"},
{"1.1.1.7", "::1.1.1.4"},
{"1.1.1.9", "::1.1.1.8"},
{"1.1.1.15", "::1.1.1.8"},
{"1.1.1.17", "::1.1.1.16"},
{"1.1.1.31", "::1.1.1.16"},
{"1.1.1.32", "::1.1.1.32"},
{"::1:ffff:ffff", "::1:ffff:ffff"},
{"::2:0:0", "::2:0:0"},
{"::2:0:1a", "::2:0:0"},
{"::2:0:40", "::2:0:40"},
{"::2:0:4f", "::2:0:40"},
{"::2:0:50", "::2:0:50"},
{"::2:0:52", "::2:0:50"},
{"::2:0:58", "::2:0:58"},
{"::2:0:59", "::2:0:58"},
};
run_ipX_tests(mmdb, pairs, 18, mode, mode_desc);
@@ -187,8 +196,7 @@ void run_tests(int mode, const char *mode_desc)
free(mmdb);
}
int main(void)
{
int main(void) {
plan(NO_PLAN);
for_all_modes(&run_tests);
done_testing();