php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch geoip-1.1.0-ipv6.patch for geoip Bug #59124Patch version 2014-05-27 02:27 UTC Return to Bug #59124 | Download this patchThis patch is obsolete Obsoleted by patches: This patch renders other patches obsolete Obsolete patches:
Developer: yiftachswr@gmail.comdiff -uNr geoip-1.1.0.org/geoip.c geoip-1.1.0/geoip.c --- geoip-1.1.0.org/geoip.c 2014-05-02 01:44:31.000000000 +0800 +++ geoip-1.1.0/geoip.c 2014-05-31 09:29:14.000000000 +0800 @@ -45,8 +45,11 @@ 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) @@ -172,11 +175,23 @@ /* 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_CITY_EDITION_REV0_V4", GEOIP_CITY_EDITION_REV0, CONST_CS | CONST_PERSISTENT); +#if LIBGEOIP_VERSION >= 1004005 + REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV0_V6", GEOIP_CITY_EDITION_REV0_V6, CONST_CS | CONST_PERSISTENT); +#endif 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_CITY_EDITION_REV1_V4", GEOIP_CITY_EDITION_REV1, CONST_CS | CONST_PERSISTENT); +#if LIBGEOIP_VERSION >= 1004005 + REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV1_V6", GEOIP_CITY_EDITION_REV1_V6, CONST_CS | CONST_PERSISTENT); +#endif 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); @@ -379,8 +394,47 @@ 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 ) @@ -405,6 +459,13 @@ 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) { RETURN_FALSE; } @@ -464,6 +525,14 @@ org = GeoIP_name_by_name(gi, hostname); GeoIP_delete(gi); +#if LIBGEOIP_VERSION >= 1004005 + if (org == NULL && GeoIP_db_avail(GEOIP_ASNUM_EDITION_V6)) { + gi = GeoIP_open_type(GEOIP_ASNUM_EDITION_V6, GEOIP_STANDARD); + org = GeoIP_name_by_name_v6(gi, hostname); + GeoIP_delete(gi); + } +#endif + if (org == NULL) { RETURN_FALSE; } @@ -541,27 +610,64 @@ GeoIP * gi; char * hostname = NULL; int arglen; - GeoIPRecord * gir; + GeoIPRecord * gir = NULL; 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); + int ipv4_db_available = 1; +#if LIBGEOIP_VERSION >= 1004005 + int ipv6_db_available = 1; +#endif + + if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1)) { + gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV1, GEOIP_STANDARD); + } else if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV0)) { + gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV0, GEOIP_STANDARD); + } else { + ipv4_db_available = 9; + } + + if (ipv4_db_available) { + gir = GeoIP_record_by_name(gi, hostname); + } + + if (NULL != gi) { + GeoIP_delete(gi); + } + +#if LIBGEOIP_VERSION >= 1004005 + if (NULL == gir) { + if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1_V6)) { + gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV1_V6, GEOIP_STANDARD); + } else if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV0_V6)) { + gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV0_V6, GEOIP_STANDARD); + ipv6_db_available = 0; + } + + if (ipv6_db_available) { + gir = GeoIP_record_by_name_v6(gi, hostname); + } + + if (NULL != gi) { + GeoIP_delete(gi); } 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); - +#endif if (NULL == gir) { + if (!ipv4_db_available) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required IPv4 database not available at %s.", GeoIPDBFileName[GEOIP_CITY_EDITION_REV0]); + } + +#if LIBGEOIP_VERSION >= 1004005 + if (!ipv6_db_available) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Required IPv6 database not available at %s.", GeoIPDBFileName[GEOIP_CITY_EDITION_REV0_V6]); + } +#endif RETURN_FALSE; } diff -uNr geoip-1.1.0.org/geoip.def geoip-1.1.0/geoip.def --- geoip-1.1.0.org/geoip.def 2014-05-02 01:44:31.000000000 +0800 +++ geoip-1.1.0/geoip.def 2014-05-31 05:48:01.000000000 +0800 @@ -17,12 +17,19 @@ */ /* 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 -uNr geoip-1.1.0.org/php_geoip.h geoip-1.1.0/php_geoip.h --- geoip-1.1.0.org/php_geoip.h 2014-05-02 01:44:31.000000000 +0800 +++ geoip-1.1.0/php_geoip.h 2014-05-31 05:48:40.000000000 +0800 @@ -49,8 +49,11 @@ 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); |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Sun Nov 24 20:01:32 2024 UTC |