-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Second initial commit. Added code, spec and readme
- Loading branch information
MegaMaddin
committed
Jun 7, 2013
1 parent
55c563d
commit 37f9da6
Showing
15 changed files
with
693 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Copyright (c) 2011 Varnish Software AS | ||
Copyright (c) 2013 Martin Probst | ||
... | ||
See LICENSE for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Copyright (c) 2011 Varnish Software AS | ||
Copyright (c) 2013 Martin Probst | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions | ||
are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ACLOCAL_AMFLAGS = -I m4 | ||
|
||
SUBDIRS = src man |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
varnish-libvmod-geoip | ||
===================== | ||
Varnish VMOD for using GeoIP functionality inside VCL code. | ||
For further details, please have a look into the manpage. | ||
|
||
Varnish VMOD for using GeoIP | ||
This module is tested and used in production on CentOS 5/6 systems. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/sh | ||
|
||
warn() { | ||
echo "WARNING: $@" 1>&2 | ||
} | ||
|
||
case `uname -s` in | ||
Darwin) | ||
LIBTOOLIZE=glibtoolize | ||
;; | ||
FreeBSD) | ||
LIBTOOLIZE=libtoolize | ||
;; | ||
Linux) | ||
LIBTOOLIZE=libtoolize | ||
;; | ||
SunOS) | ||
LIBTOOLIZE=libtoolize | ||
;; | ||
*) | ||
warn "unrecognized platform:" `uname -s` | ||
LIBTOOLIZE=libtoolize | ||
esac | ||
|
||
automake_version=`automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+'` | ||
if [ -z "$automake_version" ] ; then | ||
warn "unable to determine automake version" | ||
else | ||
case $automake_version in | ||
0.*|1.[0-8]|1.[0-8][.-]*) | ||
warn "automake ($automake_version) detected; 1.9 or newer recommended" | ||
;; | ||
*) | ||
;; | ||
esac | ||
fi | ||
|
||
set -ex | ||
|
||
aclocal -I m4 | ||
$LIBTOOLIZE --copy --force | ||
autoheader | ||
automake --add-missing --copy --foreign | ||
autoconf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
AC_PREREQ(2.59) | ||
AC_COPYRIGHT([Copyright (c) 2013 Martin Probst]) | ||
AC_INIT([libvmod-geoip], [trunk], [github@megamaddin.org]) | ||
AC_CONFIG_MACRO_DIR([m4]) | ||
AC_CONFIG_SRCDIR(src/vmod_geoip.vcc) | ||
AM_CONFIG_HEADER(config.h) | ||
|
||
AC_CANONICAL_SYSTEM | ||
AC_LANG(C) | ||
|
||
AM_INIT_AUTOMAKE([foreign]) | ||
|
||
AC_GNU_SOURCE | ||
AC_PROG_CC | ||
AC_PROG_CC_STDC | ||
if test "x$ac_cv_prog_cc_c99" = xno; then | ||
AC_MSG_ERROR([Could not find a C99 compatible compiler]) | ||
fi | ||
AC_PROG_CPP | ||
|
||
AC_PROG_INSTALL | ||
AC_PROG_LIBTOOL | ||
AC_PROG_MAKE_SET | ||
|
||
# Check for rst utilities | ||
AC_CHECK_PROGS(RST2MAN, [rst2man rst2man.py], "no") | ||
if test "x$RST2MAN" = "xno"; then | ||
AC_MSG_WARN([rst2man not found - not building man pages]) | ||
fi | ||
AM_CONDITIONAL(HAVE_RST2MAN, [test "x$RST2MAN" != "xno"]) | ||
|
||
# Check for pkg-config | ||
PKG_PROG_PKG_CONFIG | ||
|
||
# Checks for header files. | ||
AC_HEADER_STDC | ||
AC_CHECK_HEADERS([sys/stdlib.h]) | ||
AC_CHECK_HEADERS([GeoIP.h]) | ||
|
||
# Check for python | ||
AC_CHECK_PROGS(PYTHON, [python3 python3.1 python3.2 python2.7 python2.6 python2.5 python2 python], [AC_MSG_ERROR([Python is needed to build this vmod, please install python.])]) | ||
|
||
# Varnish source tree | ||
AC_ARG_VAR([VARNISHSRC], [path to Varnish source tree (mandatory)]) | ||
if test "x$VARNISHSRC" = x; then | ||
AC_MSG_ERROR([No Varnish source tree specified]) | ||
fi | ||
VARNISHSRC=`cd $VARNISHSRC && pwd` | ||
AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h], | ||
[], | ||
[AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])] | ||
) | ||
|
||
# Check that varnishtest is built in the varnish source directory | ||
AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest], | ||
[], | ||
[AC_MSG_FAILURE([Can't find "$VARNISHSRC/bin/varnishtest/varnishtest". Please build your varnish source directory])] | ||
) | ||
|
||
# vmod installation dir | ||
AC_ARG_VAR([VMODDIR], [vmod installation directory @<:@LIBDIR/varnish/vmods@:>@]) | ||
if test "x$VMODDIR" = x; then | ||
VMODDIR=`pkg-config --variable=vmoddir varnishapi` | ||
if test "x$VMODDIR" = x; then | ||
AC_MSG_FAILURE([Can't determine vmod installation directory]) | ||
fi | ||
fi | ||
|
||
AC_CONFIG_FILES([ | ||
Makefile | ||
src/Makefile | ||
man/Makefile | ||
]) | ||
AC_OUTPUT |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ACLOCAL_AMFLAGS = -I $(top_srcdir)/m4 | ||
|
||
dist_man_MANS = vmod_geoip.3 | ||
MAINTAINERCLEANFILES = $(dist_man_MANS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
.\" Man page generated from reStructeredText. | ||
. | ||
.TH VMOD_GEOIP 3 "2013-05-13" "0.4" "" | ||
.SH NAME | ||
vmod_geoip \- Varnish Geoip Module | ||
. | ||
.nr rst2man-indent-level 0 | ||
. | ||
.de1 rstReportMargin | ||
\\$1 \\n[an-margin] | ||
level \\n[rst2man-indent-level] | ||
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] | ||
- | ||
\\n[rst2man-indent0] | ||
\\n[rst2man-indent1] | ||
\\n[rst2man-indent2] | ||
.. | ||
.de1 INDENT | ||
.\" .rstReportMargin pre: | ||
. RS \\$1 | ||
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] | ||
. nr rst2man-indent-level +1 | ||
.\" .rstReportMargin post: | ||
.. | ||
.de UNINDENT | ||
. RE | ||
.\" indent \\n[an-margin] | ||
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] | ||
.nr rst2man-indent-level -1 | ||
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] | ||
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u | ||
.. | ||
.SH SYNOPSIS | ||
.sp | ||
import geoip; | ||
.SH DESCRipTION | ||
.sp | ||
libvmod\-geoip extends Varnish, to use Geoip functionality from inside VCL. | ||
.SH FUNCTIONS | ||
.SS load_geoip_db | ||
.INDENT 0.0 | ||
.TP | ||
.B Prototype | ||
.sp | ||
.nf | ||
.ft C | ||
load_geoip_db(STRING S) | ||
.ft P | ||
.fi | ||
.TP | ||
.B Return value | ||
. | ||
VOID | ||
.TP | ||
.B Description | ||
. | ||
Loads the Geoip database file. | ||
.TP | ||
.B Example | ||
.sp | ||
.nf | ||
.ft C | ||
vcl_init { | ||
geoip.load_geoip_db("/var/lib/Geoip/Geoip.dat"); | ||
return (ok); | ||
} | ||
.ft P | ||
.fi | ||
.UNINDENT | ||
.SS get_country_code | ||
.INDENT 0.0 | ||
.TP | ||
.B Prototype | ||
.sp | ||
.nf | ||
.ft C | ||
get_country_code(STRING S) | ||
.ft P | ||
.fi | ||
.TP | ||
.B Return value | ||
. | ||
STRING country code, NULL as STRING if ip address was not found in the Geoip database. | ||
.TP | ||
.B Description | ||
. | ||
Returns the country code which belongs to the passed ip address. | ||
.TP | ||
.B Example | ||
.sp | ||
.nf | ||
.ft C | ||
vcl_recv { | ||
set req.http.X\-Forwarded\-For = client.ip; | ||
set req.http.X\-Country\-Code = geoip.get_country_code(req.http.X\-Forwarded\-For); | ||
} | ||
.ft P | ||
.fi | ||
.UNINDENT | ||
.SS get_country_name | ||
.INDENT 0.0 | ||
.TP | ||
.B Prototype | ||
.sp | ||
.nf | ||
.ft C | ||
get_country_name(STRING S) | ||
.ft P | ||
.fi | ||
.TP | ||
.B Return value | ||
. | ||
STRING country name, NULL as STRING if ip address was not found in the Geoip database. | ||
.TP | ||
.B Description | ||
. | ||
Returns the country name which belongs to the passed ip address. | ||
.TP | ||
.B Example | ||
.sp | ||
.nf | ||
.ft C | ||
vcl_recv { | ||
set req.http.X\-Forwarded\-For = client.ip; | ||
set req.http.X\-Country\-Name = geoip.get_country_name(req.http.X\-Forwarded\-For); | ||
} | ||
.ft P | ||
.fi | ||
.UNINDENT | ||
.SH INSTALLATION | ||
.sp | ||
The source tree is based on autotools to configure the building, and | ||
does also have the necessary bits in place to do functional unit tests | ||
using the varnishtest tool. | ||
.sp | ||
Usage: | ||
.sp | ||
.nf | ||
.ft C | ||
\&./configure VARNISHSRC=DIR [VMODDIR=DIR] | ||
.ft P | ||
.fi | ||
.sp | ||
\fIVARNISHSRC\fP is the directory of the Varnish source tree for which to | ||
compile your vmod. Both the \fIVARNISHSRC\fP and \fIVARNISHSRC/include\fP | ||
will be added to the include search paths for your module. | ||
.sp | ||
Optionally you can also set the vmod install directory by adding | ||
\fIVMODDIR=DIR\fP (defaults to the pkg\-config discovered directory from your | ||
Varnish installation). | ||
.sp | ||
Make targets: | ||
.INDENT 0.0 | ||
.IP \(bu 2 | ||
. | ||
make \- builds the vmod | ||
.IP \(bu 2 | ||
. | ||
make install \- installs your vmod in \fIVMODDIR\fP | ||
.IP \(bu 2 | ||
. | ||
make check \- runs the unit tests in \fCsrc/tests/*.vtc\fP | ||
.UNINDENT | ||
.SH HISTORY | ||
.sp | ||
This manual page was released as part of the libvmod\-geoip package. | ||
.SH COPYRIGHT | ||
.sp | ||
This document is licensed under the same license as the | ||
libvmod\-geoip project. See LICENSE for details. | ||
.INDENT 0.0 | ||
.IP \(bu 2 | ||
. | ||
Copyright (c) 2011 Varnish Software | ||
.IP \(bu 2 | ||
. | ||
Copyright (c) 2013 Martin Probst | ||
.UNINDENT | ||
.SH AUTHOR | ||
Martin Probst <github@megamaddin.org> | ||
.\" Generated by docutils manpage writer. | ||
.\" | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
INCLUDES = -I$(VARNISHSRC)/include -I$(VARNISHSRC) | ||
|
||
vmoddir = $(VMODDIR) | ||
vmod_LTLIBRARIES = libvmod_geoip.la | ||
|
||
libvmod_geoip_la_LIBADD = -lGeoIP | ||
libvmod_geoip_la_LDFLAGS = -module -export-dynamic -avoid-version -shared | ||
|
||
libvmod_geoip_la_SOURCES = \ | ||
vcc_if.c \ | ||
vcc_if.h \ | ||
vmod_geoip.c | ||
|
||
vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_geoip.vcc | ||
@PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_geoip.vcc | ||
|
||
VMOD_TESTS = tests/*.vtc | ||
.PHONY: $(VMOD_TESTS) | ||
|
||
tests/*.vtc: | ||
$(VARNISHSRC)/bin/varnishtest/varnishtest -Dvarnishd=$(VARNISHSRC)/bin/varnishd/varnishd -Dvmod_topbuild=$(abs_top_builddir) $@ | ||
|
||
check: $(VMOD_TESTS) | ||
|
||
EXTRA_DIST = \ | ||
vmod_geoip.vcc \ | ||
$(VMOD_TESTS) | ||
|
||
CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h |
Oops, something went wrong.