Zakay/geoip — Issue #4: ipv6 support
Author: BaeRing7
Created: 2012-02-16 13:09:48+00:00
State: open

Below is a somewhat cumbersome patch that adds ipv6 support. It's a quick and dirty cut-and-paste job that includes a lot of code duplication, but it's working for me.

```patch
diff -ur ../_Zakay-clean/Zakay-geoip-16e9135//geoip.c ./geoip.c
--- ../_Zakay-clean/Zakay-geoip-16e9135//geoip.c	2011-10-15 11:00:10.000000000 +0200
+++ ./geoip.c	2012-02-14 17:45:40.000000000 +0100
@@ -41,13 +41,20 @@
function_entry geoip_functions[] = {
PHP_FE(geoip_database_info, NULL)
PHP_FE(geoip_country_code_by_name, NULL)
+	PHP_FE(geoip_country_code_by_name_v6, NULL)
PHP_FE(geoip_country_code3_by_name, NULL)
+	PHP_FE(geoip_country_code3_by_name_v6, NULL)
PHP_FE(geoip_country_name_by_name, NULL)
+	PHP_FE(geoip_country_name_by_name_v6, NULL)
PHP_FE(geoip_continent_code_by_name, NULL)
PHP_FE(geoip_org_by_name, NULL)
+	PHP_FE(geoip_org_by_name_v6, NULL)
PHP_FE(geoip_record_by_name, NULL)
+	PHP_FE(geoip_record_by_name_v6, NULL)
PHP_FE(geoip_id_by_name, NULL)
+	PHP_FE(geoip_id_by_name_v6, NULL)
PHP_FE(geoip_region_by_name, NULL)
+	PHP_FE(geoip_region_by_name_v6, NULL)
PHP_FE(geoip_isp_by_name, NULL)
PHP_FE(geoip_db_avail,	NULL)
PHP_FE(geoip_db_get_all_info,	NULL)
@@ -57,7 +64,17 @@
PHP_FE(geoip_time_zone_by_country_and_region,	NULL)
#endif
PHP_FE(geoip_country_code_by_addr, NULL)
+	PHP_FE(geoip_country_code_by_addr_v6, NULL)
PHP_FE(geoip_country_code3_by_addr, NULL)
+	PHP_FE(geoip_country_code3_by_addr_v6, NULL)
+	PHP_FE(geoip_country_name_by_addr, NULL)
+	PHP_FE(geoip_country_name_by_addr_v6, NULL)
+	PHP_FE(geoip_org_by_addr, NULL)
+	PHP_FE(geoip_org_by_addr_v6, NULL)
+	PHP_FE(geoip_record_by_addr, NULL)
+	PHP_FE(geoip_record_by_addr_v6, NULL)
+	PHP_FE(geoip_region_by_addr, NULL)
+	PHP_FE(geoip_region_by_addr_v6, NULL)
PHP_FE(geoip_setup_custom_directory, NULL)
{NULL, NULL, NULL}
};
@@ -138,6 +155,18 @@
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);
+
+ REGISTER_LONG_CONSTANT("GEOIP_LARGE_COUNTRY_EDITION_V6", GEOIP_LARGE_COUNTRY_EDITION_V6, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GEOIP_ASNUM_EDITION_V6", GEOIP_ASNUM_EDITION_V6, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GEOIP_ISP_EDITION_V6", GEOIP_ISP_EDITION_V6, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GEOIP_ORG_EDITION_V6", GEOIP_ORG_EDITION_V6, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GEOIP_DOMAIN_EDITION_V6", GEOIP_DOMAIN_EDITION_V6, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GEOIP_LOCATIONA_EDITION_V6", GEOIP_LOCATIONA_EDITION_V6, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GEOIP_REGISTRAR_EDITION_V6", GEOIP_REGISTRAR_EDITION_V6, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GEOIP_USERTYPE_EDITION_V6", GEOIP_USERTYPE_EDITION_V6, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV1_V6", GEOIP_CITY_EDITION_REV1_V6, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV0_V6", GEOIP_CITY_EDITION_REV0_V6, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GEOIP_NETSPEED_EDITION_REV1_V6", GEOIP_NETSPEED_EDITION_REV1_V6, CONST_CS | CONST_PERSISTENT);

return SUCCESS;
}
@@ -329,7 +358,36 @@
}
/* }}} */

-/* {{{ proto string geoip_country_code_by_name( string hostname )
+/* {{{ proto string geoip_country_code_by_name_v6( string hostname )
+ Return the Country Code found in the GeoIP Database */
+PHP_FUNCTION(geoip_country_code_by_name_v6)
+{
+	GeoIP * gi;
+	char * hostname = NULL;
+	const char * country_code;
+	int arglen;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
+	return;
+	}
+
+	if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
+	gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD);
+	} else {
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_COUNTRY_EDITION_V6]);
+	return;
+	}
+
+	country_code = GeoIP_country_code_by_name_v6(gi, hostname);
+	GeoIP_delete(gi);
+	if (country_code == NULL) {
+	RETURN_FALSE;
+	}
+	RETURN_STRING((char*)country_code, 1);
+}
+/* }}} */
+
+/* {{{ proto string geoip_country_code3_by_name( string hostname )
Return the Country Code found in the GeoIP Database */
PHP_FUNCTION(geoip_country_code3_by_name)
{
@@ -358,6 +416,35 @@
}
/* }}} */

+/* {{{ proto string geoip_country_code3_by_name_v6( string hostname )
+ Return the Country Code found in the GeoIP Database */
+PHP_FUNCTION(geoip_country_code3_by_name_v6)
+{
+	GeoIP * gi;
+	char * hostname = NULL;
+	const char * country_code;
+	int arglen;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
+	return;
+	}
+
+	if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
+	gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD);
+	} else {
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_COUNTRY_EDITION_V6]);
+	return;
+	}
+
+	country_code = GeoIP_country_code3_by_name_v6(gi, hostname);
+	GeoIP_delete(gi);
+	if (country_code == NULL) {
+	RETURN_FALSE;
+	}
+	RETURN_STRING((char*)country_code, 1);
+}
+/* }}} */
+
/* {{{ proto string geoip_country_name_by_name( string hostname )
Returns the Country name found in the GeoIP Database */
PHP_FUNCTION(geoip_country_name_by_name)
@@ -387,6 +474,35 @@
}
/* }}} */

+/* {{{ proto string geoip_country_name_by_name_v6( string hostname )
+ Returns the Country name found in the GeoIP Database */
+PHP_FUNCTION(geoip_country_name_by_name_v6)
+{
+	GeoIP * gi;
+	char * hostname = NULL;
+	const char * country_name;
+	int arglen;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
+	return;
+	}
+
+	if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
+	gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD);
+	} else {
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_COUNTRY_EDITION_V6]);
+	return;
+	}
+
+	country_name = GeoIP_country_name_by_name_v6(gi, hostname);
+	GeoIP_delete(gi);
+	if (country_name == NULL) {
+	RETURN_FALSE;
+	}
+	RETURN_STRING((char*)country_name, 1);
+}
+/* }}} */
+
/* {{{ 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)
@@ -446,6 +562,36 @@
}
/* }}} */

+/* {{{ proto string geoip_org_by_name_v6( string hostname )
+ Returns the Organization Name found in the GeoIP Database */
+PHP_FUNCTION(geoip_org_by_name_v6)
+{
+	GeoIP * gi;
+	char * hostname = NULL;
+	char * org;
+	int arglen;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
+	return;
+	}
+
+	if (GeoIP_db_avail(GEOIP_ORG_EDITION_V6)) {
+	gi = GeoIP_open_type(GEOIP_ORG_EDITION_V6, GEOIP_STANDARD);
+	} else {
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_ORG_EDITION_V6]);
+	return;
+	}
+
+	org = GeoIP_org_by_name_v6(gi, hostname);
+	GeoIP_delete(gi);
+	if (org == NULL) {
+	RETURN_FALSE;
+	}
+	RETVAL_STRING(org, 1);
+	free(org);
+}
+/* }}} */
+
/* {{{ proto array geoip_record_by_name( string hostname )
Returns the detailed City information found in the GeoIP Database */
PHP_FUNCTION(geoip_record_by_name)
@@ -500,6 +646,60 @@
}
/* }}} */

+/* {{{ proto array geoip_record_by_name_v6( string hostname )
+ Returns the detailed City information found in the GeoIP Database */
+PHP_FUNCTION(geoip_record_by_name_v6)
+{
+	GeoIP * gi;
+	char * hostname = NULL;
+	int arglen;
+	GeoIPRecord * gir;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
+	return;
+	}
+
+	if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1_V6) || GeoIP_db_avail(GEOIP_CITY_EDITION_REV0_V6)) {
+	if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1)) {
+	gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV1_V6, GEOIP_STANDARD);
+	} else {
+	gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV0_V6, GEOIP_STANDARD);
+	}
+	} else {
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_CITY_EDITION_REV0_V6]);
+	return;
+	}
+	gir = GeoIP_record_by_name_v6(gi, hostname);
+
+	GeoIP_delete(gi);
+
+	if (NULL == gir) {
+	RETURN_FALSE;
+	}
+
+	array_init(return_value);
+#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);
+	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)
@@ -526,6 +726,32 @@
}
/* }}} */

+/* {{{ proto integer geoip_id_by_name_v6( string hostname )
+ Returns the Net Speed found in the GeoIP Database */
+PHP_FUNCTION(geoip_id_by_name_v6)
+{
+	GeoIP * gi;
+	char * hostname = NULL;
+	int arglen;
+	int netspeed;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
+	return;
+	}
+
+	if (GeoIP_db_avail(GEOIP_NETSPEED_EDITION_REV1_V6)) {
+	gi = GeoIP_open_type(GEOIP_NETSPEED_EDITION_REV1_V6, GEOIP_STANDARD);
+	} else {
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_NETSPEED_EDITION_REV1_V6]);
+	return;
+	}
+
+	netspeed = GeoIP_id_by_name_v6(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)
@@ -565,6 +791,45 @@
}
/* }}} */

+/* {{{ proto array geoip_region_by_name_v6( string hostname )
+ Returns the Country Code and region found in the GeoIP Database */
+PHP_FUNCTION(geoip_region_by_name_v6)
+{
+	GeoIP * gi;
+	char * hostname = NULL;
+	int arglen;
+	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_v6(gi, hostname);
+	GeoIP_delete(gi);
+
+	if (NULL == region) {
+	RETURN_FALSE;
+	}
+
+	array_init(return_value);
+	add_assoc_string(return_value, "country_code", region->country_code, 1);
+	add_assoc_string(return_value, "region", region->region, 1);
+
+	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)
@@ -653,6 +918,35 @@
#endif

+/* {{{ proto string geoip_country_code_by_addr_v6( string addr )
+ Return the Country Code found in the GeoIP Database */
+PHP_FUNCTION(geoip_country_code_by_addr_v6)
+{
+	GeoIP * gi;
+	char * addr = NULL;
+	const char * country_code;
+	int arglen;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &arglen) == FAILURE) {
+	return;
+	}
+
+	if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
+	gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD);
+	} else {
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_COUNTRY_EDITION_V6]);
+	return;
+	}
+
+	country_code = GeoIP_country_code_by_addr_v6(gi, addr);
+	GeoIP_delete(gi);
+	if (country_code == NULL) {
+	RETURN_FALSE;
+	}
+	RETURN_STRING((char*)country_code, 1);
+}
+/* }}} */
+
/* {{{ proto string geoip_country_code_by_addr( string addr )
Return the Country Code found in the GeoIP Database */
PHP_FUNCTION(geoip_country_code_by_addr)
@@ -682,6 +976,35 @@
}
/* }}} */

+/* {{{ proto string geoip_country_code3_by_addr_v6( string addr )
+ Return the Country Code found in the GeoIP Database */
+PHP_FUNCTION(geoip_country_code3_by_addr_v6)
+{
+	GeoIP * gi;
+	char * addr = NULL;
+	const char * country_code;
+	int arglen;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &arglen) == FAILURE) {
+	return;
+	}
+
+	if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
+	gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD);
+	} else {
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_COUNTRY_EDITION_V6]);
+	return;
+	}
+
+	country_code = GeoIP_country_code3_by_addr_v6(gi, addr);
+	GeoIP_delete(gi);
+	if (country_code == NULL) {
+	RETURN_FALSE;
+	}
+	RETURN_STRING((char*)country_code, 1);
+}
+/* }}} */
+
/* {{{ proto string geoip_country_code3_by_addr( string addr )
Return the Country Code found in the GeoIP Database */
PHP_FUNCTION(geoip_country_code3_by_addr)
@@ -711,6 +1034,317 @@
}
/* }}} */

+/* {{{ proto string geoip_country_name_by_addr( string addr )
+ Return the Country Name found in the GeoIP Database */
+PHP_FUNCTION(geoip_country_name_by_addr)
+{
+	GeoIP * gi;
+	char * addr = NULL;
+	const char * country_name;
+	int arglen;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &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;
+	}
+
+	country_name = GeoIP_country_name_by_addr(gi, addr);
+	GeoIP_delete(gi);
+	if (country_name == NULL) {
+	RETURN_FALSE;
+	}
+	RETURN_STRING((char*)country_name, 1);
+}
+/* }}} */
+
+/* {{{ proto string geoip_country_name_by_addr_v6( string addr )
+ Return the Country Name found in the GeoIP Database */
+PHP_FUNCTION(geoip_country_name_by_addr_v6)
+{
+	GeoIP * gi;
+	char * addr = NULL;
+	const char * country_name;
+	int arglen;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &arglen) == FAILURE) {
+	return;
+	}
+
+	if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
+	gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD);
+	} else {
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_COUNTRY_EDITION_V6]);
+	return;
+	}
+
+	country_name = GeoIP_country_name_by_addr_v6(gi, addr);
+	GeoIP_delete(gi);
+	if (country_name == NULL) {
+	RETURN_FALSE;
+	}
+	RETURN_STRING((char*)country_name, 1);
+}
+/* }}} */
+
+
+/* {{{ proto string geoip_org_by_addr( string addr )
+ Returns the Organization Name found in the GeoIP Database */
+PHP_FUNCTION(geoip_org_by_addr)
+{
+	GeoIP * gi;
+	char * addr = NULL;
+	char * org;
+	int arglen;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &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_addr(gi, addr);
+	GeoIP_delete(gi);
+	if (org == NULL) {
+	RETURN_FALSE;
+	}
+	RETVAL_STRING(org, 1);
+	free(org);
+}
+/* }}} */
+
+/* {{{ proto string geoip_org_by_addr_v6( string addr )
+ Returns the Organization Name found in the GeoIP Database */
+PHP_FUNCTION(geoip_org_by_addr_v6)
+{
+	GeoIP * gi;
+	char * addr = NULL;
+	char * org;
+	int arglen;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &arglen) == FAILURE) {
+	return;
+	}
+
+	if (GeoIP_db_avail(GEOIP_ORG_EDITION_V6)) {
+	gi = GeoIP_open_type(GEOIP_ORG_EDITION_V6, GEOIP_STANDARD);
+	} else {
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_ORG_EDITION_V6]);
+	return;
+	}
+
+	org = GeoIP_org_by_addr_v6(gi, addr);
+	GeoIP_delete(gi);
+	if (org == NULL) {
+	RETURN_FALSE;
+	}
+	RETVAL_STRING(org, 1);
+	free(org);
+}
+/* }}} */
+
+
+
+/* {{{ proto array geoip_record_by_addr( string addr )
+ Returns the detailed City information found in the GeoIP Database */
+PHP_FUNCTION(geoip_record_by_addr)
+{
+	GeoIP * gi;
+	char * addr = NULL;
+	int arglen;
+	GeoIPRecord * gir;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &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_addr(gi, addr);
+
+	GeoIP_delete(gi);
+
+	if (NULL == gir) {
+	RETURN_FALSE;
+	}
+
+	array_init(return_value);
+#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);
+	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 array geoip_record_by_addr_v6( string addr )
+ Returns the detailed City information found in the GeoIP Database */
+PHP_FUNCTION(geoip_record_by_addr_v6)
+{
+	GeoIP * gi;
+	char * addr = NULL;
+	int arglen;
+	GeoIPRecord * gir;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &arglen) == FAILURE) {
+	return;
+	}
+
+	if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1_V6) || GeoIP_db_avail(GEOIP_CITY_EDITION_REV0_V6)) {
+	if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1)) {
+	gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV1_V6, GEOIP_STANDARD);
+	} else {
+	gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV0_V6, GEOIP_STANDARD);
+	}
+	} else {
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_CITY_EDITION_REV0_V6]);
+	return;
+	}
+	gir = GeoIP_record_by_name_v6(gi, addr);
+
+	GeoIP_delete(gi);
+
+	if (NULL == gir) {
+	RETURN_FALSE;
+	}
+
+	array_init(return_value);
+#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);
+	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 array geoip_region_by_addr( string addr )
+ Returns the Country Code and region found in the GeoIP Database */
+PHP_FUNCTION(geoip_region_by_addr)
+{
+	GeoIP * gi;
+	char * addr = NULL;
+	int arglen;
+	GeoIPRegion * region;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &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_addr(gi, addr);
+	GeoIP_delete(gi);
+
+	if (NULL == region) {
+	RETURN_FALSE;
+	}
+
+	array_init(return_value);
+	add_assoc_string(return_value, "country_code", region->country_code, 1);
+	add_assoc_string(return_value, "region", region->region, 1);
+
+	GeoIPRegion_delete(region);
+}
+/* }}} */
+
+/* {{{ proto array geoip_region_by_addr_v6( string addr )
+ Returns the Country Code and region found in the GeoIP Database */
+PHP_FUNCTION(geoip_region_by_addr_v6)
+{
+	GeoIP * gi;
+	char * addr = NULL;
+	int arglen;
+	GeoIPRegion * region;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &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_addr_v6(gi, addr);
+	GeoIP_delete(gi);
+
+	if (NULL == region) {
+	RETURN_FALSE;
+	}
+
+	array_init(return_value);
+	add_assoc_string(return_value, "country_code", region->country_code, 1);
+	add_assoc_string(return_value, "region", region->region, 1);
+
+	GeoIPRegion_delete(region);
+}
+/* }}} */
+
+
+
+
/* {{{ proto void geoip_setup_custom_directory( string directory )
Sets the custom directory for GeoIP databases */
PHP_FUNCTION(geoip_setup_custom_directory)
diff -ur ../_Zakay-clean/Zakay-geoip-16e9135//php_geoip.h ./php_geoip.h
--- ../_Zakay-clean/Zakay-geoip-16e9135//php_geoip.h	2011-10-15 11:00:10.000000000 +0200
+++ ./php_geoip.h	2012-02-14 17:45:35.000000000 +0100
@@ -48,13 +48,20 @@

PHP_FUNCTION(geoip_database_info);
PHP_FUNCTION(geoip_country_code_by_name);
+PHP_FUNCTION(geoip_country_code_by_name_v6);
PHP_FUNCTION(geoip_country_code3_by_name);
+PHP_FUNCTION(geoip_country_code3_by_name_v6);
PHP_FUNCTION(geoip_country_name_by_name);
+PHP_FUNCTION(geoip_country_name_by_name_v6);
PHP_FUNCTION(geoip_continent_code_by_name);
PHP_FUNCTION(geoip_org_by_name);
+PHP_FUNCTION(geoip_org_by_name_v6);
PHP_FUNCTION(geoip_record_by_name);
+PHP_FUNCTION(geoip_record_by_name_v6);
PHP_FUNCTION(geoip_id_by_name);
+PHP_FUNCTION(geoip_id_by_name_v6);
PHP_FUNCTION(geoip_region_by_name);
+PHP_FUNCTION(geoip_region_by_name_v6);
PHP_FUNCTION(geoip_isp_by_name);
PHP_FUNCTION(geoip_db_avail);
PHP_FUNCTION(geoip_db_get_all_info);
@@ -64,7 +71,17 @@
PHP_FUNCTION(geoip_time_zone_by_country_and_region);
#endif
PHP_FUNCTION(geoip_country_code_by_addr);
+PHP_FUNCTION(geoip_country_code_by_addr_v6);
PHP_FUNCTION(geoip_country_code3_by_addr);
+PHP_FUNCTION(geoip_country_code3_by_addr_v6);
+PHP_FUNCTION(geoip_country_name_by_addr);
+PHP_FUNCTION(geoip_country_name_by_addr_v6);
+PHP_FUNCTION(geoip_org_by_addr);
+PHP_FUNCTION(geoip_org_by_addr_v6);
+PHP_FUNCTION(geoip_record_by_addr);
+PHP_FUNCTION(geoip_record_by_addr_v6);
+PHP_FUNCTION(geoip_region_by_addr);
+PHP_FUNCTION(geoip_region_by_addr_v6);
PHP_FUNCTION(geoip_setup_custom_directory);

ZEND_BEGIN_MODULE_GLOBALS(geoip)
```