1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-16 07:07:13 +02:00

Integrate MaxmindDB module.

This commit is contained in:
Sandu Liviu Catalin
2020-03-22 16:33:48 +02:00
parent e46c1b0aa9
commit 3b7568f13a
88 changed files with 15336 additions and 1 deletions

View File

@ -0,0 +1,76 @@
#!/usr/bin/env perl
use strict;
use warnings;
use autodie qw( :all );
use FindBin qw( $Bin );
use File::Path qw( mkpath );
use File::Slurp qw( edit_file read_file write_file );
use File::Temp qw( tempdir );
use File::Which qw( which );
sub main {
my $target = shift || "$Bin/..";
my $pandoc = which('pandoc')
or die
"\n You must install pandoc in order to generate the man pages.\n\n";
_make_man( $target, 'libmaxminddb', 3 );
_make_lib_man_links($target);
_make_man( $target, 'mmdblookup', 1 );
}
sub _make_man {
my $target = shift;
my $name = shift;
my $section = shift;
my $man_dir = "$target/man/man$section";
mkpath($man_dir);
my $tempdir = tempdir( CLEANUP => 1 );
my $markdown = <<"EOF";
% $name($section)
EOF
$markdown .= read_file("$Bin/../doc/$name.md");
my $tempfile = "$tempdir/$name.$section.md";
write_file( $tempfile, $markdown );
my $man_file = "$man_dir/$name.$section";
system( qw( pandoc -s -t man ), $tempfile, '-o', $man_file );
_fix_indentation($man_file);
}
sub _make_lib_man_links {
my $target = shift;
my $header = read_file("$Bin/../include/maxminddb.h");
for my $proto ( $header =~ /^ *extern.+?(\w+)\(/gsm ) {
open my $fh, '>', "$target/man/man3/$proto.3";
print {$fh} ".so man3/libmaxminddb.3\n";
close $fh;
}
}
# AFAICT there's no way to control the indentation depth for code blocks with
# Pandoc.
sub _fix_indentation {
my $file = shift;
edit_file(
sub {
s/^\.IP\n\.nf/.IP "" 4\n.nf/gm;
},
$file
);
}
main(shift);

View File

@ -0,0 +1,53 @@
#!/bin/bash
set -e
set -x
set -u
DISTS=( artful zesty xenial trusty precise )
VERSION=$(perl -MFile::Slurp::Tiny=read_file -MDateTime <<EOF
use v5.16;
my \$log = read_file(q{Changes.md});
\$log =~ /^## (\d+\.\d+\.\d+) - (\d{4}-\d{2}-\d{2})/;
die 'Release time is not today!' unless DateTime->now->ymd eq \$2;
say \$1;
EOF
)
RESULTS=/tmp/build-libmaxminddb-results/
SRCDIR="$RESULTS/libmaxminddb"
mkdir -p "$SRCDIR"
# gbp does weird things without a pristine checkout
git clone git@github.com:maxmind/libmaxminddb.git -b ubuntu-ppa $SRCDIR
pushd "$SRCDIR"
git merge "$VERSION"
for dist in "${DISTS[@]}"; do
dch -v "$VERSION-0+maxmind1~$dist" -D "$dist" -u low "New upstream release."
gbp buildpackage -S --git-ignore-new
git clean -xfd
git reset HEAD --hard
done
read -e -p "Release to PPA? (y/n)" SHOULD_RELEASE
if [ "$SHOULD_RELEASE" != "y" ]; then
echo "Aborting"
exit 1
fi
# Upload to launchpad
dput ppa:maxmind/ppa ../*source.changes
# Make the changelog up to date in git
dch -v "$VERSION-0+maxmind1" -D "${DISTS[0]}" -u low "New upstream release."
git add debian/changelog
git commit -m "Update debian/changelog for $VERSION"
git push

View File

@ -0,0 +1,54 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin qw( $Bin );
use Data::UUID;
use File::Slurp qw( read_file write_file );
use Path::Iterator::Rule;
sub main {
my $rule = Path::Iterator::Rule->new;
$rule->file->name(qr/_t.c$/);
my $ug = Data::UUID->new;
my $template = read_file("$Bin/../projects/test.vcxproj.template");
my @names;
for my $file ( $rule->all("$Bin/../t/") ) {
my ($name) = $file =~ /(\w*)_t.c$/;
next unless $name;
next if $name eq 'threads';
push @names, $name;
my $project = $template;
$project =~ s/%TESTNAME%/$name/g;
my $uuid = $ug->to_string( $ug->create );
$project =~ s/%UUID%/$uuid/g;
write_file( "$Bin/../projects/VS12-tests/$name.vcxproj", $project );
}
_modify_yml(@names);
}
sub _modify_yml {
my @names = @_;
my $exe_block = join "\n",
map { " - .\\projects\\VS12\\Debug\\test_${_}.exe" } @names;
my $file = "$Bin/../appveyor.yml";
my $config = read_file($file);
$config =~ s/(#EXES).*?(#ENDEXES)/$1\n$exe_block\n $2/s;
write_file( $file, $config );
}
main();

View File

@ -0,0 +1,113 @@
#!/bin/bash
set -eu -o pipefail
changelog=$(cat Changes.md)
regex='## ([0-9]+\.[0-9]+\.[0-9]+) - ([0-9]{4}-[0-9]{2}-[0-9]{2})
((.|
)*)
'
if [[ ! $changelog =~ $regex ]]; then
echo "Could not find date line in change log!"
exit 1
fi
version="${BASH_REMATCH[1]}"
date="${BASH_REMATCH[2]}"
notes="$(echo "${BASH_REMATCH[3]}" | sed -n -e '/^## [0-9]\+\.[0-9]\+\.[0-9]\+/,$!p')"
dist="libmaxminddb-$version.tar.gz"
if [[ "$date" != $(date +"%Y-%m-%d") ]]; then
echo "$date is not today!"
exit 1
fi
if [ -n "$(git status --porcelain)" ]; then
echo ". is not clean." >&2
exit 1
fi
old_version=$(perl -MFile::Slurp=read_file <<EOF
use v5.16;
my \$conf = read_file(q{configure.ac});
\$conf =~ /AC_INIT.+\[(\d+\.\d+\.\d+)\]/;
say \$1;
EOF
)
perl -MFile::Slurp=edit_file -e \
"edit_file { s/\Q$old_version/$version/g } \$_ for qw( configure.ac include/maxminddb.h )"
if [ -n "$(git status --porcelain)" ]; then
git add configure.ac include/maxminddb.h
git commit -m "Bumped version to $version"
fi
./bootstrap
./configure
make
make check
make clean
make safedist
if [ ! -d .gh-pages ]; then
echo "Checking out gh-pages in .gh-pages"
git clone -b gh-pages git@github.com:maxmind/libmaxminddb.git .gh-pages
pushd .gh-pages
else
echo "Updating .gh-pages"
pushd .gh-pages
git pull
fi
if [ -n "$(git status --porcelain)" ]; then
echo ".gh-pages is not clean" >&2
exit 1
fi
index=index.md
cat <<EOF > $index
---
layout: default
title: libmaxminddb - a library for working with MaxMind DB files
version: $version
---
EOF
cat ../doc/libmaxminddb.md >> $index
mmdblookup=mmdblookup.md
cat <<EOF > $mmdblookup
---
layout: default
title: mmdblookup - a utility to look up an IP address in a MaxMind DB file
version: $version
---
EOF
cat ../doc/mmdblookup.md >> $mmdblookup
git commit -m "Updated for $version" -a
read -p "Push to origin? (y/n) " should_push
if [ "$should_push" != "y" ]; then
echo "Aborting"
exit 1
fi
git push
popd
git push
message="$version
$notes"
hub release create -a "$dist" -m "$message" "$version"

View File

@ -0,0 +1,19 @@
#!/bin/sh
uncrustify="uncrustify -c .uncrustify.cfg --replace --no-backup"
# We indent each thing twice because uncrustify is not idempotent - in some
# cases it will flip-flop between two indentation styles.
for dir in bin include src t; do
c_files=`find $dir -maxdepth 1 -name '*.c'`
if [ "$c_files" != "" ]; then
$uncrustify $dir/*.c;
$uncrustify $dir/*.c;
fi
h_files=`find $dir -maxdepth 1 -name '*.h'`
if [ "$h_files" != "" ]; then
$uncrustify $dir/*.h;
$uncrustify $dir/*.h;
fi
done

View File

@ -0,0 +1,53 @@
#!/usr/bin/env perl
# Note to run this you will probably want to build with ./configure
# --disable-shared. You don't want to valgrind the libtool script.
#
# Also make sure you compile the tests first (`make check').
use strict;
use warnings;
use File::Basename qw( basename );
use FindBin qw( $Bin );
use IPC::Run3;
my $top_dir = "$Bin/..";
my $output;
my @tests;
push @tests, glob "$top_dir/t/*_t";
push @tests, glob "$top_dir/t/*-t";
my @mmdblookup = (
"$top_dir/bin/mmdblookup",
'--file', "$top_dir/t/maxmind-db/test-data/MaxMind-DB-test-decoder.mmdb",
'--ip',
);
# We want IPv4 and IPv6 addresses - one of each that exists in the db and one
# that doesn't
my @ips = ( '1.1.1.1', '10.0.0.0', 'abcd::', '0900::' );
my @cmds = (
( map { [ @mmdblookup, $_ ] } @ips ),
( map { [$_] } @tests ),
);
for my $cmd (@cmds) {
my $output;
run3(
[ qw( valgrind -v --leak-check=full --show-leak-kinds=all -- ), @{$cmd} ],
\undef,
\$output,
\$output,
);
$output =~ s/^(?!=).*\n//mg;
my $marker = '-' x 60;
print $marker, "\n", ( join q{ }, basename( shift @{$cmd} ), @{$cmd} ),
"\n", $marker, "\n", $output,
"\n\n";
}