view release on metacpan or search on metacpan
"Test::Kwalitee" : "1.21",
"Test::Pod" : "1.41",
"Test::Pod::Coverage" : "1.08"
}
},
"runtime" : {
"requires" : {
"File::Spec" : "0",
"JSON::PP" : "0",
"perl" : "5.014",
"utf8" : "0",
"warnings" : "0"
}
},
"test" : {
"requires" : {
"ExtUtils::CBuilder" : "0",
"File::Temp" : "0",
"Test::More" : "0"
}
}
version: '1.4'
name: Alien-libmaxminddb
provides:
Alien::libmaxminddb:
file: lib/Alien/libmaxminddb.pm
version: '2.001'
requires:
File::Spec: '0'
JSON::PP: '0'
perl: '5.014'
utf8: '0'
warnings: '0'
resources:
bugtracker: https://github.com/voegelas/Alien-libmaxminddb/issues
homepage: https://github.com/voegelas/Alien-libmaxminddb/wiki
repository: https://github.com/voegelas/Alien-libmaxminddb.git
version: '2.001'
x_generated_by_perl: v5.40.1
x_serialization_backend: 'YAML::Tiny version 1.74'
x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later'
Makefile.PL view on Meta::CPAN
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "Alien-libmaxminddb",
"LICENSE" => "perl",
"MIN_PERL_VERSION" => "5.014",
"NAME" => "Alien::libmaxminddb",
"PREREQ_PM" => {
"File::Spec" => 0,
"JSON::PP" => 0,
"utf8" => 0,
"warnings" => 0
},
"TEST_REQUIRES" => {
"ExtUtils::CBuilder" => 0,
"File::Temp" => 0,
"Test::More" => 0
},
"VERSION" => "2.001",
"test" => {
"TESTS" => "t/*.t"
Makefile.PL view on Meta::CPAN
);
my %FallbackPrereqs = (
"ExtUtils::CBuilder" => 0,
"File::Copy" => 0,
"File::Path" => "2.07",
"File::Spec" => 0,
"File::Temp" => 0,
"JSON::PP" => 0,
"Test::More" => 0,
"utf8" => 0,
"warnings" => 0
);
unless ( eval { ExtUtils::MakeMaker->VERSION('6.63_03') } ) {
delete $WriteMakefileArgs{TEST_REQUIRES};
delete $WriteMakefileArgs{BUILD_REQUIRES};
$WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs;
}
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
# This file is generated by Dist::Zilla::Plugin::CPANFile v6.032
# Do not edit this file directly. To change prereqs, edit the `dist.ini` file.
requires "File::Spec" => "0";
requires "JSON::PP" => "0";
requires "perl" => "5.014";
requires "utf8" => "0";
requires "warnings" => "0";
on 'build' => sub {
requires "ExtUtils::CBuilder" => "0";
requires "File::Copy" => "0";
requires "File::Path" => "2.07";
requires "File::Temp" => "0";
};
on 'test' => sub {
lib/Alien/libmaxminddb.pm view on Meta::CPAN
package Alien::libmaxminddb;
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
use 5.014;
use warnings;
use utf8;
our $VERSION = 2.001;
use File::Spec qw();
use JSON::PP qw();
sub dist_dir {
my $class = shift;
my $dist = $class;
libmaxminddb.PL view on Meta::CPAN
use 5.014;
use warnings;
use utf8;
my $DIST_NAME = 'Alien-libmaxminddb';
my $BUNDLED_VERSION = '1.12.2';
package PgkConf;
use File::Spec qw();
sub new {
my ($class, %attrs) = @_;
maxminddb/include/maxminddb.h view on Meta::CPAN
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;
maxminddb/include/maxminddb.h view on Meta::CPAN
};
/* 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;
maxminddb/src/maxminddb.c view on Meta::CPAN
return bits;
}
char *type_num_to_name(uint8_t num) {
switch (num) {
case 0:
return "extended";
case 1:
return "pointer";
case 2:
return "utf8_string";
case 3:
return "double";
case 4:
return "bytes";
case 5:
return "uint16";
case 6:
return "uint32";
case 7:
return "map";
maxminddb/src/maxminddb.c view on Meta::CPAN
if (MMDB_SUCCESS != status) {
int saved_errno = errno;
free_mmdb_struct(mmdb);
errno = saved_errno;
}
return status;
}
#ifdef _WIN32
static LPWSTR utf8_to_utf16(const char *utf8_str) {
int wide_chars = MultiByteToWideChar(CP_UTF8, 0, utf8_str, -1, NULL, 0);
wchar_t *utf16_str = (wchar_t *)calloc(wide_chars, sizeof(wchar_t));
if (!utf16_str) {
return NULL;
}
if (MultiByteToWideChar(CP_UTF8, 0, utf8_str, -1, utf16_str, wide_chars) <
1) {
free(utf16_str);
return NULL;
}
return utf16_str;
}
static int map_file(MMDB_s *const mmdb) {
DWORD size;
int status = MMDB_SUCCESS;
HANDLE mmh = NULL;
HANDLE fd = INVALID_HANDLE_VALUE;
LPWSTR utf16_filename = utf8_to_utf16(mmdb->filename);
if (!utf16_filename) {
status = MMDB_FILE_OPEN_ERROR;
goto cleanup;
}
fd = CreateFileW(utf16_filename,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
maxminddb/src/maxminddb.c view on Meta::CPAN
int status = MMDB_aget_value(start, &entry_data, path);
if (MMDB_SUCCESS != status) {
return status;
}
if (MMDB_DATA_TYPE_UTF8_STRING != entry_data.type) {
DEBUG_MSGF("expect string for %s but received %s",
key,
type_num_to_name(entry_data.type));
return MMDB_INVALID_METADATA_ERROR;
}
*value = mmdb_strndup(entry_data.utf8_string, entry_data.data_size);
if (NULL == *value) {
return MMDB_OUT_OF_MEMORY_ERROR;
}
return MMDB_SUCCESS;
}
static int populate_languages_metadata(MMDB_s *mmdb,
MMDB_s *metadata_db,
MMDB_entry_s *metadata_start) {
MMDB_entry_data_s entry_data;
maxminddb/src/maxminddb.c view on Meta::CPAN
}
for (uint32_t i = 0; i < array_size; i++) {
member = member->next;
if (MMDB_DATA_TYPE_UTF8_STRING != member->entry_data.type) {
MMDB_free_entry_data_list(first_member);
return MMDB_INVALID_METADATA_ERROR;
}
mmdb->metadata.languages.names[i] = mmdb_strndup(
member->entry_data.utf8_string, member->entry_data.data_size);
if (NULL == mmdb->metadata.languages.names[i]) {
MMDB_free_entry_data_list(first_member);
return MMDB_OUT_OF_MEMORY_ERROR;
}
// We assign this as we go so that if we fail a calloc and need to
// free it, the count is right.
mmdb->metadata.languages.count = i + 1;
}
maxminddb/src/maxminddb.c view on Meta::CPAN
mmdb->metadata.description.descriptions[i]->description = NULL;
member = member->next;
if (MMDB_DATA_TYPE_UTF8_STRING != member->entry_data.type) {
status = MMDB_INVALID_METADATA_ERROR;
goto cleanup;
}
mmdb->metadata.description.descriptions[i]->language = mmdb_strndup(
member->entry_data.utf8_string, member->entry_data.data_size);
if (NULL == mmdb->metadata.description.descriptions[i]->language) {
status = MMDB_OUT_OF_MEMORY_ERROR;
goto cleanup;
}
member = member->next;
if (MMDB_DATA_TYPE_UTF8_STRING != member->entry_data.type) {
status = MMDB_INVALID_METADATA_ERROR;
goto cleanup;
}
mmdb->metadata.description.descriptions[i]->description = mmdb_strndup(
member->entry_data.utf8_string, member->entry_data.data_size);
if (NULL == mmdb->metadata.description.descriptions[i]->description) {
status = MMDB_OUT_OF_MEMORY_ERROR;
goto cleanup;
}
}
cleanup:
MMDB_free_entry_data_list(first_member);
maxminddb/src/maxminddb.c view on Meta::CPAN
MMDB_entry_data_s key, value;
CHECKED_DECODE_ONE_FOLLOW(mmdb, offset, &key);
uint32_t offset_to_value = key.offset_to_next;
if (MMDB_DATA_TYPE_UTF8_STRING != key.type) {
return MMDB_INVALID_DATA_ERROR;
}
if (key.data_size == path_elem_len &&
!memcmp(path_elem, key.utf8_string, path_elem_len)) {
DEBUG_MSG("found key matching path elem");
CHECKED_DECODE_ONE_FOLLOW(mmdb, offset_to_value, &value);
memcpy(entry_data, &value, sizeof(MMDB_entry_data_s));
return MMDB_SUCCESS;
} else {
/* We don't want to follow a pointer here. If the next element is
* a pointer we simply skip it and keep going */
CHECKED_DECODE_ONE(mmdb, offset_to_value, &value);
maxminddb/src/maxminddb.c view on Meta::CPAN
DEBUG_MSGF("float value: %f", entry_data->float_value);
} else if (type == MMDB_DATA_TYPE_DOUBLE) {
if (size != 8) {
DEBUG_MSGF("double of size %d", size);
return MMDB_INVALID_DATA_ERROR;
}
size = 8;
entry_data->double_value = get_ieee754_double(&mem[offset]);
DEBUG_MSGF("double value: %f", entry_data->double_value);
} else if (type == MMDB_DATA_TYPE_UTF8_STRING) {
entry_data->utf8_string = size == 0 ? "" : (char const *)&mem[offset];
entry_data->data_size = size;
#ifdef MMDB_DEBUG
char *string =
mmdb_strndup(entry_data->utf8_string, size > 50 ? 50 : size);
if (NULL == string) {
abort();
}
DEBUG_MSGF("string value: %s", string);
free(string);
#endif
} else if (type == MMDB_DATA_TYPE_BYTES) {
entry_data->bytes = &mem[offset];
entry_data->data_size = size;
}
maxminddb/src/maxminddb.c view on Meta::CPAN
for (entry_data_list = entry_data_list->next;
size && entry_data_list;
size--) {
if (MMDB_DATA_TYPE_UTF8_STRING !=
entry_data_list->entry_data.type) {
*status = MMDB_INVALID_DATA_ERROR;
return NULL;
}
char *key =
mmdb_strndup(entry_data_list->entry_data.utf8_string,
entry_data_list->entry_data.data_size);
if (NULL == key) {
*status = MMDB_OUT_OF_MEMORY_ERROR;
return NULL;
}
print_indentation(stream, indent);
fprintf(stream, "\"%s\": \n", key);
free(key);
maxminddb/src/maxminddb.c view on Meta::CPAN
if (MMDB_SUCCESS != *status) {
return NULL;
}
}
indent -= 2;
print_indentation(stream, indent);
fprintf(stream, "]\n");
} break;
case MMDB_DATA_TYPE_UTF8_STRING: {
char *string = mmdb_strndup(entry_data_list->entry_data.utf8_string,
entry_data_list->entry_data.data_size);
if (NULL == string) {
*status = MMDB_OUT_OF_MEMORY_ERROR;
return NULL;
}
print_indentation(stream, indent);
fprintf(stream, "\"%s\" <utf8_string>\n", string);
free(string);
entry_data_list = entry_data_list->next;
} break;
case MMDB_DATA_TYPE_BYTES: {
char *hex_string =
bytes_to_hex(entry_data_list->entry_data.bytes,
entry_data_list->entry_data.data_size);
if (NULL == hex_string) {
*status = MMDB_OUT_OF_MEMORY_ERROR;
#!perl
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
use 5.014;
use warnings;
use utf8;
use Alien::libmaxminddb;
use ExtUtils::CBuilder;
use File::Temp qw(tempfile);
use Test::More;
my $builder = ExtUtils::CBuilder->new;
plan skip_all => 'no C compiler found' if !$builder->have_compiler;