php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #59124
Patch geoip-1.1.0-ipv6-php7.patch revision 2015-09-23 17:31 UTC by as@php.net
Patch geoip-1.1.0-ipv6.patch revision 2014-05-27 02:27 UTC by yiftachswr at gmail dot com
Patch geoip-1.0.8-further-ipv6-fix.patch revision 2012-11-13 11:27 UTC by php at gnodde dot org
Patch geoip-include-ipv6.patch revision 2012-06-15 11:37 UTC by dominic dot benson at thirdlight dot com

Patch geoip-include-ipv6.patch for geoip Bug #59124

Patch version 2012-06-15 11:37 UTC

Return to Bug #59124 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions:

Developer: dominic.benson@thirdlight.com

diff -rupN geoip-1.0.8.orig/geoip.c geoip-1.0.8/geoip.c
--- geoip-1.0.8.orig/geoip.c	1970-01-01 10:13:08.000000000 +0100
+++ geoip-1.0.8/geoip.c	2012-06-15 11:49:23.913007687 +0100
@@ -42,8 +42,11 @@ zend_function_entry geoip_functions[] =
 	PHP_FE(geoip_database_info,   NULL)   
 #define GEOIPDEF(php_func, c_func, db_type) \
 	PHP_FE(php_func,	NULL)
+#define GEOIPMULTIDEF(php_func, c_func, db_type, c_func_v6, db_type_v6) \
+        PHP_FE(php_func,        NULL)
 #include "geoip.def"
 #undef GEOIPDEF
+#undef GEOIPMULTIDEF
 	PHP_FE(geoip_continent_code_by_name,   NULL)
 	PHP_FE(geoip_org_by_name,   NULL)
 	PHP_FE(geoip_record_by_name,   NULL)
@@ -119,6 +122,10 @@ PHP_MINIT_FUNCTION(geoip)
 	
 	/* For database type constants */
 	REGISTER_LONG_CONSTANT("GEOIP_COUNTRY_EDITION",     GEOIP_COUNTRY_EDITION,     CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("GEOIP_COUNTRY_EDITION_V4",  GEOIP_COUNTRY_EDITION,     CONST_CS | CONST_PERSISTENT);
+#if LIBGEOIP_VERSION >= 1004005
+	REGISTER_LONG_CONSTANT("GEOIP_COUNTRY_EDITION_V6",  GEOIP_COUNTRY_EDITION_V6,  CONST_CS | CONST_PERSISTENT);
+#endif
 	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);
@@ -313,10 +320,50 @@ PHP_FUNCTION(geoip_database_info)
 		RETURN_STRING((char*)return_code, 1); \
 		\
 	}
+
+#define GEOIPMULTIDEF(php_func, c_func, db_type, c_func_v6, db_type_v6) \
+        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_STRING((char*)return_code, 1); \
+                } \
+                if (GeoIP_db_avail(db_type_v6)) { \
+                        gi = GeoIP_open_type(db_type_v6, GEOIP_STANDARD); \
+                        return_code = c_func_v6(gi, hostname); \
+                        GeoIP_delete(gi); \
+                        if (return_code != NULL) { \
+                                RETURN_STRING((char*)return_code, 1); \
+                        } \
+                } \
+                php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Host %s not found", hostname); \
+                RETURN_FALSE; \
+                \
+        }
+
 #include "geoip.def"
 #undef GEOIPDEF
+#undef GEOIPMULTIDEF
 /* }}} */
 
+
 /* {{{ 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)
@@ -339,6 +386,13 @@ PHP_FUNCTION(geoip_continent_code_by_nam
 
 	id = GeoIP_id_by_name(gi, hostname);
 	GeoIP_delete(gi);
+#if LIBGEOIP_VERSION >= 1004005
+	if (id == 0 && GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
+		gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD);
+		id = GeoIP_id_by_name_v6(gi, hostname);
+		GeoIP_delete(gi);
+	}
+#endif
 	if (id == 0) {
 		php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Host %s not found", hostname);
 		RETURN_FALSE;
diff -rupN geoip-1.0.8.orig/geoip.def geoip-1.0.8/geoip.def
--- geoip-1.0.8.orig/geoip.def	1970-01-01 10:13:08.000000000 +0100
+++ geoip-1.0.8/geoip.def	2012-06-14 18:12:41.028882473 +0100
@@ -17,12 +17,20 @@
 */
 
 /* 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)
+GEOIPDEF(geoip_country_code_by_name_v4,	GeoIP_country_code_by_name,	GEOIP_COUNTRY_EDITION)
+GEOIPDEF(geoip_country_code3_by_name_v4,	GeoIP_country_code3_by_name,	GEOIP_COUNTRY_EDITION)
+GEOIPDEF(geoip_country_name_by_name_v4,	GeoIP_country_name_by_name,	GEOIP_COUNTRY_EDITION)
 
-#if LIBGEOIP_VERSION >= 1004005 && FALSE
+#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
\ No newline at end of file
+
+GEOIPMULTIDEF(geoip_country_code_by_name, GeoIP_country_code_by_name,     GEOIP_COUNTRY_EDITION, GeoIP_country_code_by_name_v6, GEOIP_COUNTRY_EDITION_V6)
+GEOIPMULTIDEF(geoip_country_code3_by_name,        GeoIP_country_code3_by_name,    GEOIP_COUNTRY_EDITION, GeoIP_country_code3_by_name_v6, GEOIP_COUNTRY_EDITION_V6)
+GEOIPMULTIDEF(geoip_country_name_by_name, GeoIP_country_name_by_name,     GEOIP_COUNTRY_EDITION, GeoIP_country_name_by_name_v6,  GEOIP_COUNTRY_EDITION_V6)
+#else
+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)
+#endif
diff -rupN geoip-1.0.8.orig/php_geoip.h geoip-1.0.8/php_geoip.h
--- geoip-1.0.8.orig/php_geoip.h	1970-01-01 10:13:08.000000000 +0100
+++ geoip-1.0.8/php_geoip.h	2012-06-14 19:23:12.629468140 +0100
@@ -49,8 +49,11 @@ PHP_MINFO_FUNCTION(geoip);
 PHP_FUNCTION(geoip_database_info);
 #define GEOIPDEF(php_func, c_func, db_type) \
 PHP_FUNCTION(php_func);
+#define GEOIPMULTIDEF(php_func, c_func, db_type, c_func_v6, db_type_v6) \
+PHP_FUNCTION(php_func);
 #include "geoip.def"
 #undef GEOIPDEF
+#undef GEOIPMULTIDEF
 PHP_FUNCTION(geoip_continent_code_by_name);
 PHP_FUNCTION(geoip_org_by_name);
 PHP_FUNCTION(geoip_record_by_name);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 20:01:32 2024 UTC