package.xml 0000644 0000765 0000024 00000021544 12755450165 012547 0 ustar olivier staff
geoippecl.php.netMap IP address to geographic placesThis PHP extension allows you to find the location of an IP address - City, State, Country, Longitude, Latitude, and other information as all, such as ISP and connection type. For more info, please visit Maxmind's website.Olivier Hillohillohill@php.netyes2016-08-191.1.11.0.3betastablePHP License
* Add IPv6 support (geoip_country_code_by_*_v6)
* PHP7 support (thanks to Adam and Dan Ackroyd)
4.3.01.4.0b1geoip1.1.01.0.3betastable2014-05-01PHP License
* Add geoip_setup_custom_directory() to setup custom directories per request.
* Remove E_NOTICES for IPs not found in database.
* Fix a segfault with geoip_db_get_all_info() on newer libs (bug #64692).
* Add support for geoip_netspeedcell_by_name(), geoip_asnum_by_name() and geoip_domain_by_name() (bug #67121).
* Fix memory leak with custom directories (bug #67138).
* Support changing custom directory via ini_set() (bug #61607).
1.0.81.0.3stablestable2011-10-23PHP License
* Windows support
* Fix segfault with newer geoip libraries and geoip_db_get_all_info() (bug #60066)
* Use X-Macros for repeated code
* Updated tests
1.0.71.0.3stablestable2009-03-11PHP License
* Do not issue a NOTICE when values don't exist for timezone and region name (as added in 1.0.4)
* Fix a compile issue on FreeBSD
* Try to be bulletproof on library features detection.
1.0.61.0.3stablestable2009-01-20PHP License
* Fixing compile bug when multiple GeoIP libs are installed, bug #15372.
1.0.51.0.3stablestable2008-12-19PHP License
* Small bug in phpinfo() when printing version number could crash PHP.
1.0.41.0.3stablestable2008-12-19PHP License
* Fix memleaks, bug #14851
* Small patch for MacPorts by jhohle
* Add geoip_time_zone_by_country_and_region() and geoip_region_name_by_code() (thanks to Sid Dunayer)
* Add continent_code field for City Database, only if using GeoIP lib 1.4.3 or newer
1.0.31.0.3stablestable2008-06-12PHP License
* Change license from PHP 3.0 to PHP 3.01 for Debian?
* Added geoip_continent_code_by_name() to get continent instead of country
* Fixing a small casting issue (compiler warning)
* Fixing missing entries in geoip_record_by_name(), bug #14131
1.0.21.0.2stablestable2007-11-20PHP
* Added geoip_isp_by_name (patch by Yannick Gard)
1.0.11.0.1stablestable2007-08-22PHP
* Added geoip_db_avail() to check for DB availability (file found)
* Added geoip_db_filename() to get the internal file name of the library
* Added geoip_db_get_all_info() to fetch all info about all database types
* Added some tests so that make test can crunch something.
* Added database file path and name in warning when DB is not found.
* Added geoip.custom_directory php.ini option to change default path for DBs
1.0.01.0.0stablestable2007-08-14PHP
* Marked as stable
* Fixing wrong version number inside extension
0.2.00.2.0betabeta2006-08-22PHP
Initial PECL release
geoip-1.1.1/tests/001.phpt 0000644 0000765 0000024 00000000337 12755450165 014525 0 ustar olivier staff --TEST--
Checking Country (Free) DB availability
--SKIPIF--
--POST--
--GET--
--FILE--
--EXPECT--
bool(true)
geoip-1.1.1/tests/002.phpt 0000644 0000765 0000024 00000002231 12755450165 014521 0 ustar olivier staff --TEST--
Checking if all db info and name match
--SKIPIF--
--FILE--
--EXPECT--
string(21) "GeoIP Country Edition"
string(27) "GeoIP Region Edition, Rev 0"
string(25) "GeoIP City Edition, Rev 0"
string(26) "GeoIP Organization Edition"
string(17) "GeoIP ISP Edition"
string(25) "GeoIP City Edition, Rev 1"
string(27) "GeoIP Region Edition, Rev 1"
string(19) "GeoIP Proxy Edition"
string(19) "GeoIP ASNum Edition"
string(22) "GeoIP Netspeed Edition"
string(25) "GeoIP Domain Name Edition"
geoip-1.1.1/tests/003.phpt 0000644 0000765 0000024 00000000331 12755450165 014521 0 ustar olivier staff --TEST--
Checking for database filename
--SKIPIF--
--FILE--
--EXPECTF--
string(%d) "%sGeoIP.dat"
geoip-1.1.1/tests/004.phpt 0000644 0000765 0000024 00000000600 12755450165 014521 0 ustar olivier staff --TEST--
Checking for out of bound type with geoip_db_filename()
--SKIPIF--
--FILE--
--EXPECTF--
Warning: geoip_db_filename(): Database type given is out of bound. in %s on line %d
Warning: geoip_db_filename(): Database type given is out of bound. in %s on line %d
geoip-1.1.1/tests/005.phpt 0000644 0000765 0000024 00000000561 12755450165 014530 0 ustar olivier staff --TEST--
Checking for out of bound type with geoip_db_avail()
--SKIPIF--
--FILE--
--EXPECTF--
Warning: geoip_db_avail(): Database type given is out of bound. in %s on line %d
Warning: geoip_db_avail(): Database type given is out of bound. in %s on line %d
geoip-1.1.1/tests/006.phpt 0000644 0000765 0000024 00000000414 12755450165 014526 0 ustar olivier staff --TEST--
Checking for custom directory INI entry
--SKIPIF--
--INI--
geoip.custom_directory="/test"
--FILE--
--EXPECT--
string(15) "/test/GeoIP.dat"
geoip-1.1.1/tests/007.phpt 0000644 0000765 0000024 00000000443 12755450165 014531 0 ustar olivier staff --TEST--
Checking for custom directory INI entry (with trailing slash)
--SKIPIF--
--INI--
geoip.custom_directory="/test/"
--FILE--
--EXPECT--
string(15) "/test/GeoIP.dat"
geoip-1.1.1/tests/008.phpt 0000644 0000765 0000024 00000000335 12755450165 014532 0 ustar olivier staff --TEST--
Calling geoip_db_filename() with a non-existant database type within bound.
--SKIPIF--
--FILE--
--EXPECT--
NULL
geoip-1.1.1/tests/009.phpt 0000644 0000765 0000024 00000000336 12755450165 014534 0 ustar olivier staff --TEST--
Calling geoip_db_avail() with a non-existant database type within bound.
--SKIPIF--
--FILE--
--EXPECT--
bool(false)
geoip-1.1.1/tests/010.phpt 0000644 0000765 0000024 00000000612 12755450165 014521 0 ustar olivier staff --TEST--
Checking for out of bound type with geoip_database_info()
--SKIPIF--
--FILE--
--EXPECTF--
Warning: geoip_database_info(): Database type given is out of bound. in %s on line %d
Warning: geoip_database_info(): Database type given is out of bound. in %s on line %d
geoip-1.1.1/tests/011.phpt 0000644 0000765 0000024 00000000443 12755450165 014524 0 ustar olivier staff --TEST--
Calling geoip_database_info() with a non-existant database type within bound.
--SKIPIF--
--FILE--
--EXPECTF--
Warning: geoip_database_info(): Required database not available. in %s on line %d
geoip-1.1.1/tests/013.phpt 0000644 0000765 0000024 00000000500 12755450165 014520 0 ustar olivier staff --TEST--
Checking timezone info
--SKIPIF--
--POST--
--GET--
--FILE--
--EXPECT--
string(17) "America/Vancouver"
string(10) "Asia/Tokyo"
geoip-1.1.1/tests/014.phpt 0000644 0000765 0000024 00000001412 12755450165 014524 0 ustar olivier staff --TEST--
Checking timezone info with (some) empty fields
--SKIPIF--
--POST--
--GET--
--FILE--
--EXPECTF--
string(%d) "America/%s"
bool(false)
string(%d) "Europe/%s"
Warning: geoip_time_zone_by_country_and_region(): You need to specify at least the country code. in %s on line %d
bool(false)
Warning: geoip_time_zone_by_country_and_region(): You need to specify at least the country code. in %s on line %d
bool(false)
geoip-1.1.1/tests/015.phpt 0000644 0000765 0000024 00000000363 12755450165 014531 0 ustar olivier staff --TEST--
Checking geoip_region_name_by_code for Canada/Quebec
--SKIPIF--
--POST--
--GET--
--FILE--
--EXPECT--
string(6) "Quebec"
geoip-1.1.1/tests/016.phpt 0000644 0000765 0000024 00000001676 12755450165 014542 0 ustar olivier staff --TEST--
Checking geoip_region_name_by_code with (some) empty fields
--SKIPIF--
--POST--
--GET--
--FILE--
--EXPECTF--
Warning: geoip_region_name_by_code(): You need to specify the country and region codes. in %s on line %d
bool(false)
Warning: geoip_region_name_by_code(): You need to specify the country and region codes. in %s on line %d
bool(false)
bool(false)
Warning: geoip_region_name_by_code(): You need to specify the country and region codes. in %s on line %d
bool(false)
Warning: geoip_region_name_by_code(): You need to specify the country and region codes. in %s on line %d
bool(false)
bool(false)
geoip-1.1.1/tests/017.phpt 0000644 0000765 0000024 00000000613 12755450165 014531 0 ustar olivier staff --TEST--
Checking geoip_setup_custom_directory()
--SKIPIF--
--INI--
geoip.custom_directory="/test"
--FILE--
--EXPECT--
string(27) "/some/other/place/GeoIP.dat"
string(5) "/test" geoip-1.1.1/tests/018.phpt 0000644 0000765 0000024 00000000643 12755450165 014535 0 ustar olivier staff --TEST--
Checking geoip_setup_custom_directory() (with trailing slash)
--SKIPIF--
--INI--
geoip.custom_directory="/test/"
--FILE--
--EXPECT--
string(27) "/some/other/place/GeoIP.dat"
string(6) "/test/" geoip-1.1.1/tests/019.phpt 0000644 0000765 0000024 00000000515 12755450165 014534 0 ustar olivier staff --TEST--
Checking geoip_setup_custom_directory() (with trailing slash)
--SKIPIF--
--INI--
geoip.custom_directory="/test/"
--FILE--
--EXPECT--
string(27) "/some/other/place/GeoIP.dat"
string(6) "/test/" geoip-1.1.1/ChangeLog 0000644 0000765 0000024 00000006764 12755450165 013752 0 ustar olivier staff 1.1.0-dev 2012-xx-xx
* Add geoip_setup_custom_directory() to setup custom directories per request.
* Remove E_NOTICES for IPs not found in database.
* Fix a segfault with geoip_db_get_all_info() on newer libs (bug #64692).
* Add support for geoip_netspeedcell_by_name(), geoip_asnum_by_name() and geoip_domain_by_name() (bug #67121).
* Fix memory leak with custom directories (bug #67138).
* Support changing custom directory via ini_set() (bug #61607).
1.0.8 2011-10-23
* Windows support
* Fix segfault with newer geoip libraries and geoip_db_get_all_info() (bug #60066)
* Use X-Macros for repeated code
* Updated tests
1.0.7 2009-03-11
* Do not issue a NOTICE when values don't exist for timezone and region name (as added in 1.0.4)
* Fix a compile issue on FreeBSD
* Try to be bulletproof on library features detection.
1.0.6 2009-01-20
* Fixing compile bug when multiple GeoIP libs are installed, bug #15372
1.0.5 2008-12-19
* Small bug in phpinfo() when printing version number could crash PHP.
1.0.4 2008-12-19
* Fix memleaks, bug #14851
* Small patch for MacPorts by jhohle
* Add geoip_time_zone_by_country_and_region() and geoip_region_name_by_code() (thanks to Sid Dunayer)
* Add continent_code field for City Database, only if using GeoIP lib 1.4.3 or newer
1.0.3 2008-06-12
* Change license from PHP 3.0 to PHP 3.01 for Debian?
* Added geoip_continent_code_by_name() to get continent instead of country
* Fixing a small casting issue (compiler warning)
* Fixing missing entries in geoip_record_by_name, bug #14131
1.0.2 2007-11-20
* Added geoip_isp_by_name (patch by Yannick Gard)
1.0.1 2007-08-22
* Added geoip_db_avail() to check for DB availability (file found)
* Added geoip_db_filename() to get the internal file name of the library
* Added geoip_db_get_all_info() to fetch all info about all database types
* Added some tests so that make test can crunch something.
* Added database file path and name in warning when DB is not found.
* Added geoip.custom_directory php.ini option to change default path for DBs
1.0.0 2007-08-14
* Marked as stable
* Fixing wrong version number inside extension
0.2.0 2006-08-22
* Initial PECL Release
* Fixing various memory leaks
* Registering the C API constants in PHP
0.1.3 2006-7-10
Following changes made by Olivier Hill
* Missing PHP function prototypes
* Fixing code foldings in Emacs
* Outputting E_NOTICES instead of E_WARNING when non fatal errors
* Return type of longitude/latitude should be DOUBLE and not LONG
0.1.2 2006-5-19
* Following changes all contributed by Guenter Knauf
- moved argument parsing up at various places before we create a GeoIP.
- moved GeoIP_delete() call at various places up to get it called before we error out.
- fixed one place where a missing return caused a segfault on all platforms because
RETURN_STRING() was called with NULL when GeoIP lookup failed.
- added php.ini entry parsing; prepared for usage of geoip.database_standard var.
This works fine so far as you can test with the geoip_database_info() call which uses
the database configured with the geoip.database_standard var; if not set it defaults
to the usual place specified during compile time with GEOIPDATADIR. All other functions
currently still ignore the geoip.database_standard setting, but default usually also
to GEOIPDATADIR from what I see. Search for the dirty '//' comments ....
* Added config.m4, contributed by Jonathan Whiteman of cyberflowsolutions.com
0.1.1 2005-9-21
* Initial release, contributed by Matthew Fonda
geoip-1.1.1/config.m4 0000644 0000765 0000024 00000010212 12755450165 013666 0 ustar olivier staff dnl $Id: config.m4 333464 2014-05-03 10:21:31Z remi $
dnl config.m4 for extension geoip
dnl Base file contributed by Jonathan Whiteman of cyberflowsolutions.com
PHP_ARG_WITH(geoip, for geoip support,
dnl Make sure that the comment is aligned:
[ --with-geoip Include GeoIP support])
if test "$PHP_GEOIP" != "no"; then
# --with-geoip -> check with-path
SEARCH_PATH="/usr/local /usr /sw /opt/local"
SEARCH_FOR="/include/GeoIP.h"
if test -r $PHP_GEOIP/$SEARCH_FOR; then
GEOIP_DIR=$PHP_GEOIP
else # search default path list
AC_MSG_CHECKING([for geoip files in default path])
for i in $SEARCH_PATH ; do
if test -r $i/$SEARCH_FOR; then
GEOIP_DIR=$i
AC_MSG_RESULT([found in $i])
fi
done
fi
if test -z "$GEOIP_DIR"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please reinstall the geoip distribution])
fi
# --with-geoip -> add include path
PHP_ADD_INCLUDE($GEOIP_DIR/include)
# odd PHP4 fix
if test "x$PHP_LIBDIR" = "x"; then
PHP_LIBDIR=lib
fi
# --with-geoip -> check for lib and symbol presence
LIBNAME=GeoIP # you may want to change this
LIBSYMBOL=GeoIP_open # you most likely want to change this
PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
[
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $GEOIP_DIR/$PHP_LIBDIR, GEOIP_SHARED_LIBADD)
AC_DEFINE(HAVE_GEOIPLIB,1,[ ])
],[
AC_MSG_ERROR([wrong geoip lib version or lib not found])
],[
-L$GEOIP_DIR/$PHP_LIBDIR -lm
])
# Checking for GeoIP_setup_custom_directory in newer lib
PHP_CHECK_LIBRARY($LIBNAME,GeoIP_setup_custom_directory,
[
AC_DEFINE(HAVE_CUSTOM_DIRECTORY,1,[ ])
MIN_GEOIP_VERSION=1004001
],[
],[
-L$GEOIP_DIR/$PHP_LIBDIR -lm
])
# Checking for GeoIP_set_charset in newer lib
PHP_CHECK_LIBRARY($LIBNAME,GeoIP_set_charset,
[
AC_DEFINE(HAVE_SET_CHARSET,1,[ ])
MIN_GEOIP_VERSION=1004003
],[
],[
-L$GEOIP_DIR/$PHP_LIBDIR -lm
])
# Checking for GeoIP_continent_by_id in newer lib
PHP_CHECK_LIBRARY($LIBNAME,GeoIP_continent_by_id,
[
AC_DEFINE(HAVE_CONTINENT_BY_ID,1,[ ])
MIN_GEOIP_VERSION=1004005
],[
],[
-L$GEOIP_DIR/$PHP_LIBDIR -lm
])
# Checking for GeoIP_addr_to_num in newer lib
PHP_CHECK_LIBRARY($LIBNAME,GeoIP_addr_to_num,
[
AC_DEFINE(HAVE_ADDR_TO_NUM,1,[ ])
MIN_GEOIP_VERSION=1004007
],[
],[
-L$GEOIP_DIR/$PHP_LIBDIR -lm
])
# Checking for GEOIP_NETSPEED_EDITION_REV1
AC_CHECK_DECL(GEOIP_NETSPEED_EDITION_REV1,
[
MIN_GEOIP_VERSION=1004008
],[],[
#include
])
# Checking for GEOIP_ACCURACYRADIUS_EDITION
AC_CHECK_DECL(GEOIP_ACCURACYRADIUS_EDITION,
[
MIN_GEOIP_VERSION=1005000
],[],[
#include
])
# Check to see if we are using the LGPL library (version 1.4.0 and newer)
AC_MSG_CHECKING([for LGPL compatible GeoIP libs])
libgeoip_full_version=`find $GEOIP_DIR/$PHP_LIBDIR/ -name libGeoIP.\*.\*.\*.\* | cut -d . -f 2-5 | sort`
for lines in $libgeoip_full_version; do
ac_IFS=$IFS
IFS="."
set $lines
IFS=$ac_IFS
done
# Version after the suffix (eg: .so.1.4.0)
if test "[$]1" = "$SHLIB_SUFFIX_NAME"; then
LIBGEOIP_VERSION=`expr [$]2 \* 1000000 + [$]3 \* 1000 + [$]4`
# Version before the suffix (eg: 1.4.0.dylib on OS X)
else
LIBGEOIP_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
fi
# Just in case it didn't work, try alternate method, or fail
if test "x$LIBGEOIP_VERSION" = "x"; then
AC_MSG_RESULT([cannot detect])
# Alternate method based on library capabilities (not 100% acurate)
AC_MSG_CHECKING([library features to determine version (not acurate)])
if test "x$MIN_GEOIP_VERSION" = "x"; then
AC_MSG_ERROR([For some reason, libGeoIP is installed, but I cannot determine the version used])
else
LIBGEOIP_VERSION=$MIN_GEOIP_VERSION
fi
fi
if test "$LIBGEOIP_VERSION" -lt "1004000"; then
AC_MSG_RESULT([wrong version])
AC_MSG_ERROR([You need version 1.4.0 or higher of the C API])
else
AC_MSG_RESULT([found $LIBGEOIP_VERSION])
AC_DEFINE_UNQUOTED(LIBGEOIP_VERSION, $LIBGEOIP_VERSION, [ ])
fi
PHP_SUBST(GEOIP_SHARED_LIBADD)
PHP_NEW_EXTENSION(geoip, geoip.c, $ext_shared)
fi
geoip-1.1.1/config.w32 0000644 0000765 0000024 00000001162 12755450165 013765 0 ustar olivier staff // $Id: config.w32 327850 2012-10-01 12:50:22Z ab $
// vim:ft=javascript
ARG_WITH("geoip", "GeoIP Support", "no");
if (PHP_GEOIP == "yes") {
if (CHECK_HEADER_ADD_INCLUDE("geoip.h", "CFLAGS_GEOIP", PHP_GEOIP + ";" + PHP_PHP_BUILD + "\\include\\geoip") &&
CHECK_LIB("geoip_a.lib;GeoIP.lib", "geoip", PHP_GEOIP)) {
AC_DEFINE('HAVE_GEOIP', 1, 'Have GeoIP support', false);
AC_DEFINE('LIBGEOIP_VERSION', 1004008, 'GeoIP Version');
AC_DEFINE('HAVE_CUSTOM_DIRECTORY', 1, 'Support for custom database directory');
EXTENSION("geoip", "geoip.c");
} else {
WARNING('Could not find geoip.h or geoip lib; skipping');
}
}
geoip-1.1.1/geoip.def 0000644 0000765 0000024 00000003354 12755450165 013753 0 ustar olivier staff /*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 2002-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Olivier Hill |
+----------------------------------------------------------------------+
*/
/* GEOIPDEF(php_func, c_func, db_type) */
GEOIPDEF(geoip_country_code_by_name, GeoIP_country_code_by_name, GEOIP_COUNTRY_EDITION)
GEOIPDEF(geoip_country_code3_by_name, GeoIP_country_code3_by_name, GEOIP_COUNTRY_EDITION)
GEOIPDEF(geoip_country_name_by_name, GeoIP_country_name_by_name, GEOIP_COUNTRY_EDITION)
#if LIBGEOIP_VERSION >= 1004005
GEOIPDEF(geoip_country_code_by_name_v6, GeoIP_country_code_by_name_v6, GEOIP_COUNTRY_EDITION_V6)
GEOIPDEF(geoip_country_code3_by_name_v6, GeoIP_country_code3_by_name_v6, GEOIP_COUNTRY_EDITION_V6)
GEOIPDEF(geoip_country_name_by_name_v6, GeoIP_country_name_by_name_v6, GEOIP_COUNTRY_EDITION_V6)
#endif geoip-1.1.1/geoip.c 0000644 0000765 0000024 00000060524 12755450165 013441 0 ustar olivier staff /*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Olivier Hill |
| Matthew Fonda |
+----------------------------------------------------------------------+
Please contact support@maxmind.com with any comments
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include
#include
#ifdef PHP_WIN32
#include
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_geoip.h"
ZEND_DECLARE_MODULE_GLOBALS(geoip)
static int le_geoip;
/* {{{ */
zend_function_entry geoip_functions[] = {
PHP_FE(geoip_database_info, NULL)
#define GEOIPDEF(php_func, c_func, db_type) \
PHP_FE(php_func, NULL)
#include "geoip.def"
#undef GEOIPDEF
PHP_FE(geoip_continent_code_by_name, NULL)
PHP_FE(geoip_org_by_name, NULL)
PHP_FE(geoip_record_by_name, NULL)
PHP_FE(geoip_id_by_name, NULL)
PHP_FE(geoip_region_by_name, NULL)
PHP_FE(geoip_isp_by_name, NULL)
PHP_FE(geoip_db_avail, NULL)
PHP_FE(geoip_db_get_all_info, NULL)
PHP_FE(geoip_db_filename, NULL)
#if LIBGEOIP_VERSION >= 1004001
PHP_FE(geoip_region_name_by_code, NULL)
PHP_FE(geoip_time_zone_by_country_and_region, NULL)
#endif
#ifdef HAVE_CUSTOM_DIRECTORY
PHP_FE(geoip_setup_custom_directory, NULL)
#endif
PHP_FE(geoip_asnum_by_name, NULL)
PHP_FE(geoip_domain_by_name, NULL)
#if LIBGEOIP_VERSION >= 1004008
PHP_FE(geoip_netspeedcell_by_name, NULL)
#endif
{NULL, NULL, NULL}
};
/* }}} */
/* {{{ geoip_module_entry
*/
zend_module_entry geoip_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"geoip",
geoip_functions,
PHP_MINIT(geoip),
PHP_MSHUTDOWN(geoip),
PHP_RINIT(geoip),
PHP_RSHUTDOWN(geoip),
PHP_MINFO(geoip),
#if ZEND_MODULE_API_NO >= 20010901
PHP_GEOIP_VERSION, /* version number of the extension */
#endif
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_GEOIP
ZEND_GET_MODULE(geoip)
#endif
#ifdef HAVE_CUSTOM_DIRECTORY
/* {{{ geoip_change_custom_directory() helper function
*/
static void geoip_change_custom_directory(char *value)
{
#if LIBGEOIP_VERSION >= 1004007
GeoIP_cleanup();
#else
int i;
if (GeoIPDBFileName != NULL) {
for (i = 0; i < NUM_DB_TYPES; i++) {
if (GeoIPDBFileName[i]) {
free(GeoIPDBFileName[i]);
}
}
free(GeoIPDBFileName);
GeoIPDBFileName = NULL;
}
#endif
GeoIP_setup_custom_directory(value);
GeoIP_db_avail(GEOIP_COUNTRY_EDITION);
}
/* }}} */
#endif
#ifdef HAVE_CUSTOM_DIRECTORY
/* {{{ PHP_INI_MH
+ */
static PHP_INI_MH(OnUpdateDirectory)
{
if (stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) {
GEOIP_G(set_runtime_custom_directory) = 1;
#if PHP_MAJOR_VERSION >= 7
geoip_change_custom_directory(new_value->val);
#else
geoip_change_custom_directory(new_value);
#endif
return SUCCESS;
}
#if PHP_MAJOR_VERSION >= 7
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
#else
return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
#endif
}
/* }}} */
#endif
/* {{{ PHP_INI
*/
PHP_INI_BEGIN()
#ifdef HAVE_CUSTOM_DIRECTORY
STD_PHP_INI_ENTRY("geoip.custom_directory", NULL, PHP_INI_ALL, OnUpdateDirectory, custom_directory, zend_geoip_globals, geoip_globals)
#endif
PHP_INI_END()
/* }}} */
/* {{{ php_geoip_init_globals
*/
static void php_geoip_init_globals(zend_geoip_globals *geoip_globals)
{
geoip_globals->custom_directory = NULL;
geoip_globals->set_runtime_custom_directory = 0;
}
/* }}} */
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(geoip)
{
ZEND_INIT_MODULE_GLOBALS(geoip, php_geoip_init_globals, NULL);
REGISTER_INI_ENTRIES();
/* @TODO: Do something for custom_directory before initialization here */
#ifdef HAVE_CUSTOM_DIRECTORY
GeoIP_setup_custom_directory(GEOIP_G(custom_directory));
#endif
/* This will initialize file structure */
GeoIP_db_avail(GEOIP_COUNTRY_EDITION);
/* For database type constants */
REGISTER_LONG_CONSTANT("GEOIP_COUNTRY_EDITION", GEOIP_COUNTRY_EDITION, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_REGION_EDITION_REV0", GEOIP_REGION_EDITION_REV0, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV0", GEOIP_CITY_EDITION_REV0, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_ORG_EDITION", GEOIP_ORG_EDITION, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_ISP_EDITION", GEOIP_ISP_EDITION, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV1", GEOIP_CITY_EDITION_REV1, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_REGION_EDITION_REV1", GEOIP_REGION_EDITION_REV1, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_PROXY_EDITION", GEOIP_PROXY_EDITION, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_ASNUM_EDITION", GEOIP_ASNUM_EDITION, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_NETSPEED_EDITION", GEOIP_NETSPEED_EDITION, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_DOMAIN_EDITION", GEOIP_DOMAIN_EDITION, CONST_CS | CONST_PERSISTENT);
#if LIBGEOIP_VERSION >= 1004008
REGISTER_LONG_CONSTANT("GEOIP_NETSPEED_EDITION_REV1",GEOIP_NETSPEED_EDITION_REV1,CONST_CS | CONST_PERSISTENT);
#endif
/* For netspeed constants */
REGISTER_LONG_CONSTANT("GEOIP_UNKNOWN_SPEED", GEOIP_UNKNOWN_SPEED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_DIALUP_SPEED", GEOIP_DIALUP_SPEED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_CABLEDSL_SPEED", GEOIP_CABLEDSL_SPEED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GEOIP_CORPORATE_SPEED", GEOIP_CORPORATE_SPEED, CONST_CS | CONST_PERSISTENT);
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(geoip)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION(geoip)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
PHP_RSHUTDOWN_FUNCTION(geoip)
{
#ifdef HAVE_CUSTOM_DIRECTORY
/* If we have a custom directory (and have support from */
/* libgeoip, we reset the extension to default directory) */
if (GEOIP_G(set_runtime_custom_directory)) {
geoip_change_custom_directory(GEOIP_G(custom_directory));
GEOIP_G(set_runtime_custom_directory) = 0;
}
#endif
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(geoip)
{
char buf[32];
php_info_print_table_start();
php_info_print_table_header(2, "geoip support", "enabled");
php_info_print_table_row(2, "geoip extension version", PHP_GEOIP_VERSION);
snprintf(buf, sizeof(buf), "%d", LIBGEOIP_VERSION);
php_info_print_table_row(2, "geoip library version", buf);
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
/* }}} */
/* {{{ proto boolean geoip_db_avail( [ int database ] ) */
PHP_FUNCTION(geoip_db_avail)
{
zend_long edition;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &edition) == FAILURE) {
return;
}
if (edition < 0 || edition >= NUM_DB_TYPES)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Database type given is out of bound.");
return;
}
RETURN_BOOL(GeoIP_db_avail(edition));
}
/* }}} */
/* {{{ proto string geoip_db_filename( [ int database ] ) */
PHP_FUNCTION(geoip_db_filename)
{
zend_long edition;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &edition) == FAILURE) {
return;
}
if (edition < 0 || edition >= NUM_DB_TYPES)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Database type given is out of bound.");
return;
}
if (NULL != GeoIPDBFileName[edition])
#if PHP_MAJOR_VERSION >= 7
RETURN_STRING(GeoIPDBFileName[edition]);
#else
RETURN_STRING(GeoIPDBFileName[edition], 1);
#endif
}
/* }}} */
/* {{{ proto array geoip_db_get_all_info( ) */
PHP_FUNCTION(geoip_db_get_all_info)
{
int i;
array_init(return_value);
for (i=0; i < NUM_DB_TYPES; i++)
{
if (NULL != GeoIPDBDescription[i])
{
#if PHP_MAJOR_VERSION >= 7
zval real_row;
zval *row = &real_row;
array_init(row);
#else
zval *row;
ALLOC_INIT_ZVAL(row);
array_init(row);
#endif
add_assoc_bool(row, "available", GeoIP_db_avail(i));
if (GeoIPDBDescription[i]) {
#if PHP_MAJOR_VERSION >= 7
add_assoc_string(row, "description", (char *)GeoIPDBDescription[i]);
#else
add_assoc_string(row, "description", (char *)GeoIPDBDescription[i], 1);
#endif
}
if (GeoIPDBFileName[i]) {
#if PHP_MAJOR_VERSION >= 7
add_assoc_string(row, "filename", GeoIPDBFileName[i]);
#else
add_assoc_string(row, "filename", GeoIPDBFileName[i], 1);
#endif
}
add_index_zval(return_value, i, row);
}
}
}
/* }}} */
/* {{{ proto string geoip_database_info( [ int database ] )
Returns GeoIP Database information */
PHP_FUNCTION(geoip_database_info)
{
GeoIP * gi;
char * db_info;
zend_long edition = GEOIP_COUNTRY_EDITION;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &edition) == FAILURE) {
return;
}
if (edition < 0 || edition >= NUM_DB_TYPES)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Database type given is out of bound.");
return;
}
if (GeoIP_db_avail(edition)) {
gi = GeoIP_open_type(edition, GEOIP_STANDARD);
} else {
if (NULL != GeoIPDBFileName[edition])
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_COUNTRY_EDITION]);
else
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available.");
return;
}
db_info = GeoIP_database_info(gi);
GeoIP_delete(gi);
#if PHP_MAJOR_VERSION >= 7
RETVAL_STRING(db_info);
#else
RETVAL_STRING(db_info, 1);
#endif
free(db_info);
}
/* }}} */
/* {{{ */
#if PHP_MAJOR_VERSION >= 7
#define GEOIPDEF(php_func, c_func, db_type) \
PHP_FUNCTION(php_func) \
{ \
GeoIP * gi; \
char * hostname = NULL; \
const char * return_code; \
size_t arglen; \
\
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) { \
return; \
} \
\
if (GeoIP_db_avail(db_type)) { \
gi = GeoIP_open_type(db_type, GEOIP_STANDARD); \
} else { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[db_type]); \
return; \
} \
\
return_code = c_func(gi, hostname); \
GeoIP_delete(gi); \
if (return_code == NULL) { \
RETURN_FALSE; \
} \
RETURN_STRING((char*)return_code); \
\
}
#else
#define GEOIPDEF(php_func, c_func, db_type) \
PHP_FUNCTION(php_func) \
{ \
GeoIP * gi; \
char * hostname = NULL; \
const char * return_code; \
int arglen; \
\
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) { \
return; \
} \
\
if (GeoIP_db_avail(db_type)) { \
gi = GeoIP_open_type(db_type, GEOIP_STANDARD); \
} else { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[db_type]); \
return; \
} \
\
return_code = c_func(gi, hostname); \
GeoIP_delete(gi); \
if (return_code == NULL) { \
RETURN_FALSE; \
} \
RETURN_STRING((char*)return_code, 1); \
\
}
#endif
#include "geoip.def"
#undef GEOIPDEF
/* }}} */
/* {{{ proto string geoip_continent_code_by_name( string hostname )
Returns the Continent name found in the GeoIP Database */
PHP_FUNCTION(geoip_continent_code_by_name)
{
GeoIP * gi;
char * hostname = NULL;
int id;
#if PHP_MAJOR_VERSION >= 7
size_t arglen;
#else
int arglen;
#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
}
if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) {
gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_COUNTRY_EDITION]);
return;
}
id = GeoIP_id_by_name(gi, hostname);
GeoIP_delete(gi);
if (id == 0) {
RETURN_FALSE;
}
#if PHP_MAJOR_VERSION >= 7
RETURN_STRING((char *)GeoIP_country_continent[id]);
#else
RETURN_STRING((char *)GeoIP_country_continent[id], 1);
#endif
}
/* }}} */
/* {{{ proto string geoip_org_by_name( string hostname )
Returns the Organization Name found in the GeoIP Database */
PHP_FUNCTION(geoip_org_by_name)
{
GeoIP * gi;
char * hostname = NULL;
char * org;
#if PHP_MAJOR_VERSION >= 7
size_t arglen;
#else
int arglen;
#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
}
if (GeoIP_db_avail(GEOIP_ORG_EDITION)) {
gi = GeoIP_open_type(GEOIP_ORG_EDITION, GEOIP_STANDARD);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_ORG_EDITION]);
return;
}
org = GeoIP_org_by_name(gi, hostname);
GeoIP_delete(gi);
if (org == NULL) {
RETURN_FALSE;
}
#if PHP_MAJOR_VERSION >= 7
RETVAL_STRING(org);
#else
RETVAL_STRING(org, 1);
#endif
free(org);
}
/* }}} */
/* {{{ proto string geoip_asnum_by_name( string hostname )
Returns the Domain Name found in the GeoIP Database */
PHP_FUNCTION(geoip_asnum_by_name)
{
GeoIP * gi;
char * hostname = NULL;
char * org;
#if PHP_MAJOR_VERSION >= 7
size_t arglen;
#else
int arglen;
#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
}
if (GeoIP_db_avail(GEOIP_ASNUM_EDITION)) {
gi = GeoIP_open_type(GEOIP_ASNUM_EDITION, GEOIP_STANDARD);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_ASNUM_EDITION]);
return;
}
org = GeoIP_name_by_name(gi, hostname);
GeoIP_delete(gi);
if (org == NULL) {
RETURN_FALSE;
}
#if PHP_MAJOR_VERSION >= 7
RETVAL_STRING(org);
#else
RETVAL_STRING(org, 1);
#endif
free(org);
}
/* }}} */
/* {{{ proto string geoip_domain_by_name( string hostname )
Returns the Domain Name found in the GeoIP Database */
PHP_FUNCTION(geoip_domain_by_name)
{
GeoIP * gi;
char * hostname = NULL;
char * org;
#if PHP_MAJOR_VERSION >= 7
size_t arglen;
#else
int arglen;
#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
}
if (GeoIP_db_avail(GEOIP_DOMAIN_EDITION)) {
gi = GeoIP_open_type(GEOIP_DOMAIN_EDITION, GEOIP_STANDARD);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_DOMAIN_EDITION]);
return;
}
org = GeoIP_name_by_name(gi, hostname);
GeoIP_delete(gi);
if (org == NULL) {
RETURN_FALSE;
}
#if PHP_MAJOR_VERSION >= 7
RETVAL_STRING(org);
#else
RETVAL_STRING(org, 1);
#endif
free(org);
}
/* }}} */
#if LIBGEOIP_VERSION >= 1004008
/* {{{ proto string geoip_netspeedcell_by_name( string hostname )
Returns the Net Speed found in the GeoIP Database */
PHP_FUNCTION(geoip_netspeedcell_by_name)
{
GeoIP * gi;
char * hostname = NULL;
char * org;
#if PHP_MAJOR_VERSION >= 7
size_t arglen;
#else
int arglen;
#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
}
if (GeoIP_db_avail(GEOIP_NETSPEED_EDITION_REV1)) {
gi = GeoIP_open_type(GEOIP_NETSPEED_EDITION_REV1, GEOIP_STANDARD);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_NETSPEED_EDITION_REV1]);
return;
}
org = GeoIP_name_by_name(gi, hostname);
GeoIP_delete(gi);
if (org == NULL) {
RETURN_FALSE;
}
#if PHP_MAJOR_VERSION >= 7
RETVAL_STRING(org);
#else
RETVAL_STRING(org, 1);
#endif
free(org);
}
/* }}} */
#endif
/* {{{ proto array geoip_record_by_name( string hostname )
Returns the detailed City information found in the GeoIP Database */
PHP_FUNCTION(geoip_record_by_name)
{
GeoIP * gi;
char * hostname = NULL;
#if PHP_MAJOR_VERSION >= 7
size_t arglen;
#else
int arglen;
#endif
GeoIPRecord * gir;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
}
if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1) || GeoIP_db_avail(GEOIP_CITY_EDITION_REV0)) {
if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1)) {
gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV1, GEOIP_STANDARD);
} else {
gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV0, GEOIP_STANDARD);
}
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_CITY_EDITION_REV0]);
return;
}
gir = GeoIP_record_by_name(gi, hostname);
GeoIP_delete(gi);
if (NULL == gir) {
RETURN_FALSE;
}
array_init(return_value);
#if PHP_MAJOR_VERSION >= 7
# if LIBGEOIP_VERSION >= 1004003
add_assoc_string(return_value, "continent_code", (gir->continent_code == NULL) ? "" : gir->continent_code);
# endif
add_assoc_string(return_value, "country_code", (gir->country_code == NULL) ? "" : gir->country_code);
add_assoc_string(return_value, "country_code3", (gir->country_code3 == NULL) ? "" : gir->country_code3);
add_assoc_string(return_value, "country_name", (gir->country_name == NULL) ? "" : gir->country_name);
add_assoc_string(return_value, "region", (gir->region == NULL) ? "" : gir->region);
add_assoc_string(return_value, "city", (gir->city == NULL) ? "" : gir->city);
add_assoc_string(return_value, "postal_code", (gir->postal_code == NULL) ? "" : gir->postal_code);
#else
# if LIBGEOIP_VERSION >= 1004003
add_assoc_string(return_value, "continent_code", (gir->continent_code == NULL) ? "" : gir->continent_code, 1);
# endif
add_assoc_string(return_value, "country_code", (gir->country_code == NULL) ? "" : gir->country_code, 1);
add_assoc_string(return_value, "country_code3", (gir->country_code3 == NULL) ? "" : gir->country_code3, 1);
add_assoc_string(return_value, "country_name", (gir->country_name == NULL) ? "" : gir->country_name, 1);
add_assoc_string(return_value, "region", (gir->region == NULL) ? "" : gir->region, 1);
add_assoc_string(return_value, "city", (gir->city == NULL) ? "" : gir->city, 1);
add_assoc_string(return_value, "postal_code", (gir->postal_code == NULL) ? "" : gir->postal_code, 1);
#endif
add_assoc_double(return_value, "latitude", gir->latitude);
add_assoc_double(return_value, "longitude", gir->longitude);
#if LIBGEOIP_VERSION >= 1004005
add_assoc_long(return_value, "dma_code", gir->metro_code);
#else
add_assoc_long(return_value, "dma_code", gir->dma_code);
#endif
add_assoc_long(return_value, "area_code", gir->area_code);
GeoIPRecord_delete(gir);
}
/* }}} */
/* {{{ proto integer geoip_id_by_name( string hostname )
Returns the Net Speed found in the GeoIP Database */
PHP_FUNCTION(geoip_id_by_name)
{
GeoIP * gi;
char * hostname = NULL;
#if PHP_MAJOR_VERSION >= 7
size_t arglen;
#else
int arglen;
#endif
int netspeed;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
}
if (GeoIP_db_avail(GEOIP_NETSPEED_EDITION)) {
gi = GeoIP_open_type(GEOIP_NETSPEED_EDITION, GEOIP_STANDARD);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_NETSPEED_EDITION]);
return;
}
netspeed = GeoIP_id_by_name(gi, hostname);
GeoIP_delete(gi);
RETURN_LONG(netspeed);
}
/* }}} */
/* {{{ proto array geoip_region_by_name( string hostname )
Returns the Country Code and region found in the GeoIP Database */
PHP_FUNCTION(geoip_region_by_name)
{
GeoIP * gi;
char * hostname = NULL;
#if PHP_MAJOR_VERSION >= 7
size_t arglen;
#else
int arglen;
#endif
GeoIPRegion * region;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
}
if (GeoIP_db_avail(GEOIP_REGION_EDITION_REV0) || GeoIP_db_avail(GEOIP_REGION_EDITION_REV1)) {
if (GeoIP_db_avail(GEOIP_REGION_EDITION_REV1)) {
gi = GeoIP_open_type(GEOIP_REGION_EDITION_REV1, GEOIP_STANDARD);
} else {
gi = GeoIP_open_type(GEOIP_REGION_EDITION_REV0, GEOIP_STANDARD);
}
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_REGION_EDITION_REV0]);
return;
}
region = GeoIP_region_by_name(gi, hostname);
GeoIP_delete(gi);
if (NULL == region) {
RETURN_FALSE;
}
array_init(return_value);
#if PHP_MAJOR_VERSION >= 7
add_assoc_string(return_value, "country_code", region->country_code);
add_assoc_string(return_value, "region", region->region);
#else
add_assoc_string(return_value, "country_code", region->country_code, 1);
add_assoc_string(return_value, "region", region->region, 1);
#endif
GeoIPRegion_delete(region);
}
/* }}} */
/* {{{ proto string geoip_isp_by_name( string hostname )
Returns the ISP Name found in the GeoIP Database */
PHP_FUNCTION(geoip_isp_by_name)
{
GeoIP * gi;
char * hostname = NULL;
char * isp;
#if PHP_MAJOR_VERSION >= 7
size_t arglen;
#else
int arglen;
#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
}
if (GeoIP_db_avail(GEOIP_ISP_EDITION)) {
gi = GeoIP_open_type(GEOIP_ISP_EDITION, GEOIP_STANDARD);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_ISP_EDITION]);
return;
}
isp = GeoIP_name_by_name(gi, hostname);
GeoIP_delete(gi);
if (isp == NULL) {
RETURN_FALSE;
}
#if PHP_MAJOR_VERSION >= 7
RETVAL_STRING(isp);
#else
RETVAL_STRING(isp, 1);
#endif
free(isp);
}
#if LIBGEOIP_VERSION >= 1004001
/* {{{ proto string geoip_region_name_by_code( string country_code, string region_code )
Returns the region name for some country code and region code combo */
PHP_FUNCTION(geoip_region_name_by_code)
{
char * country_code = NULL;
char * region_code = NULL;
const char * region_name;
#if PHP_MAJOR_VERSION >= 7
size_t countrylen, regionlen;
#else
int countrylen, regionlen;
#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &country_code, &countrylen, ®ion_code, ®ionlen) == FAILURE) {
return;
}
if (!countrylen || !regionlen) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You need to specify the country and region codes.");
RETURN_FALSE;
}
region_name = GeoIP_region_name_by_code(country_code, region_code);
if (region_name == NULL) {
RETURN_FALSE;
}
#if PHP_MAJOR_VERSION >= 7
RETURN_STRING((char*)region_name);
#else
RETURN_STRING((char*)region_name, 1);
#endif
}
/* }}} */
#endif
#if LIBGEOIP_VERSION >= 1004001
/* {{{ proto string geoip_time_zone_by_country_and_region( string country, string region )
Returns the time zone for some country code and region code combo */
PHP_FUNCTION(geoip_time_zone_by_country_and_region)
{
char * country = NULL;
char * region = NULL;
const char * timezone;
#if PHP_MAJOR_VERSION >= 7
size_t countrylen, arg2len;
#else
int countrylen, arg2len;
#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &country, &countrylen, ®ion, &arg2len) == FAILURE) {
return;
}
if (!countrylen) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You need to specify at least the country code.");
RETURN_FALSE;
}
timezone = GeoIP_time_zone_by_country_and_region(country, region);
if (timezone == NULL) {
RETURN_FALSE;
}
#if PHP_MAJOR_VERSION >= 7
RETURN_STRING((char*)timezone);
#else
RETURN_STRING((char*)timezone, 1);
#endif
}
/* }}} */
#endif
#ifdef HAVE_CUSTOM_DIRECTORY
/* {{{ proto void geoip_setup_custom_directory( string directory )
Sets the custom directory for GeoIP databases */
PHP_FUNCTION(geoip_setup_custom_directory)
{
char * dir = NULL;
#if PHP_MAJOR_VERSION >= 7
size_t dirlen;
#else
int dirlen;
#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dir, &dirlen) == FAILURE) {
return;
}
GEOIP_G(set_runtime_custom_directory) = 1;
geoip_change_custom_directory(dir);
}
/* }}} */
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
geoip-1.1.1/php_geoip.h 0000644 0000765 0000024 00000005751 12755450165 014316 0 ustar olivier staff /*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Olivier Hill |
| Matthew Fonda |
+----------------------------------------------------------------------+
Please contact support@maxmind.com with any comments
*/
#ifndef PHP_GEOIP_H
#define PHP_GEOIP_H
extern zend_module_entry geoip_module_entry;
#define phpext_geoip_ptr &geoip_module_entry
#define PHP_GEOIP_VERSION "1.1.1"
#if PHP_MAJOR_VERSION < 7
typedef long zend_long;
#endif
#ifdef PHP_WIN32
#define PHP_GEOIP_API __declspec(dllexport)
#else
#define PHP_GEOIP_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
#include
#include
PHP_MINIT_FUNCTION(geoip);
PHP_MSHUTDOWN_FUNCTION(geoip);
PHP_RINIT_FUNCTION(geoip);
PHP_RSHUTDOWN_FUNCTION(geoip);
PHP_MINFO_FUNCTION(geoip);
PHP_FUNCTION(geoip_database_info);
#define GEOIPDEF(php_func, c_func, db_type) \
PHP_FUNCTION(php_func);
#include "geoip.def"
#undef GEOIPDEF
PHP_FUNCTION(geoip_continent_code_by_name);
PHP_FUNCTION(geoip_org_by_name);
PHP_FUNCTION(geoip_record_by_name);
PHP_FUNCTION(geoip_id_by_name);
PHP_FUNCTION(geoip_region_by_name);
PHP_FUNCTION(geoip_isp_by_name);
PHP_FUNCTION(geoip_db_avail);
PHP_FUNCTION(geoip_db_get_all_info);
PHP_FUNCTION(geoip_db_filename);
#if LIBGEOIP_VERSION >= 1004001
PHP_FUNCTION(geoip_region_name_by_code);
PHP_FUNCTION(geoip_time_zone_by_country_and_region);
#endif
#ifdef HAVE_CUSTOM_DIRECTORY
PHP_FUNCTION(geoip_setup_custom_directory);
#endif
PHP_FUNCTION(geoip_asnum_by_name);
PHP_FUNCTION(geoip_domain_by_name);
#if LIBGEOIP_VERSION >= 1004008
PHP_FUNCTION(geoip_netspeedcell_by_name);
#endif
ZEND_BEGIN_MODULE_GLOBALS(geoip)
char* custom_directory;
int set_runtime_custom_directory;
ZEND_END_MODULE_GLOBALS(geoip)
#ifdef ZTS
#define GEOIP_G(v) TSRMG(geoip_globals_id, zend_geoip_globals *, v)
#else
#define GEOIP_G(v) (geoip_globals.v)
#endif
#endif /* PHP_GEOIP_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
geoip-1.1.1/README 0000644 0000765 0000024 00000000534 12755450165 013045 0 ustar olivier staff This PHP extension allows you to find the location of an IP address - City, State,
Country, Longitude, Latitude, and other information as all, such as ISP and connection type.
To compile it, you will need to have the GeoIP c library installed.
For installation instructions for PHP extensions, see:
http://www.php.net/manual/en/install.pecl.php
geoip-1.1.1/LICENSE 0000644 0000765 0000024 00000006222 12755450165 013172 0 ustar olivier staff --------------------------------------------------------------------
The PHP License, version 3.01
Copyright (c) 1999 - 2014 The PHP Group. All rights reserved.
--------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, is 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.
3. The name "PHP" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact group@php.net.
4. Products derived from this software may not be called "PHP", nor
may "PHP" appear in their name, without prior written permission
from group@php.net. You may indicate that your software works in
conjunction with PHP by saying "Foo for PHP" instead of calling
it "PHP Foo" or "phpfoo"
5. The PHP Group may publish revised and/or new versions of the
license from time to time. Each version will be given a
distinguishing version number.
Once covered code has been published under a particular version
of the license, you may always continue to use it under the terms
of that version. You may also choose to use such covered code
under the terms of any subsequent version of the license
published by the PHP Group. No one other than the PHP Group has
the right to modify the terms applicable to covered code created
under this License.
6. Redistributions of any form whatsoever must retain the following
acknowledgment:
"This product includes PHP software, freely available from
".
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
ANY EXPRESSED 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 THE PHP
DEVELOPMENT TEAM OR ITS 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 software consists of voluntary contributions made by many
individuals on behalf of the PHP Group.
The PHP Group can be contacted via Email at group@php.net.
For more information on the PHP Group and the PHP project,
please see .
PHP includes the Zend Engine, freely available at
.