php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #67121
Patch geoip-netspeedcell revision 2014-04-23 20:47 UTC by bzentner at maxmind dot com

Patch geoip-netspeedcell for geoip Bug #67121

Patch version 2014-04-23 20:47 UTC

Return to Bug #67121 | Download this patch
Patch Revisions:

Developer: bzentner@maxmind.com

diff -Nur a/geoip-1.0.8/config.m4 b/geoip-1.0.8/config.m4
--- a/geoip-1.0.8/config.m4	1970-01-01 10:13:08.000000000 +0100
+++ b/geoip-1.0.8/config.m4	2013-02-19 04:53:23.000000000 +0100
@@ -80,6 +80,16 @@
   ],[
     -L$GEOIP_DIR/$PHP_LIBDIR -lm
   ])
+  
+  # Checking for GeoIP_record_by_addr_v6 in newer lib
+  PHP_CHECK_LIBRARY($LIBNAME,GeoIP_record_by_addr_v6,
+  [
+    AC_DEFINE(HAVE_RECORD_BY_ADDR_V6,1,[ ])
+    MIN_GEOIP_VERSION=1004008
+  ],[
+  ],[
+    -L$GEOIP_DIR/$PHP_LIBDIR -lm
+  ])
 
   # Check to see if we are using the LGPL library (version 1.4.0 and newer)
   AC_MSG_CHECKING([for LGPL compatible GeoIP libs])
diff -Nur a/geoip-1.0.8/geoip.c b/geoip-1.0.8/geoip.c
--- a/geoip-1.0.8/geoip.c	1970-01-01 10:13:08.000000000 +0100
+++ b/geoip-1.0.8/geoip.c	2013-02-19 03:05:33.000000000 +0100
@@ -53,6 +53,11 @@
 	PHP_FE(geoip_db_avail,	NULL)
 	PHP_FE(geoip_db_get_all_info,	NULL)
 	PHP_FE(geoip_db_filename,	NULL)
+	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
 #if LIBGEOIP_VERSION >= 1004001
 	PHP_FE(geoip_region_name_by_code,	NULL)
 	PHP_FE(geoip_time_zone_by_country_and_region,	NULL)
@@ -129,7 +134,9 @@
 	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);
@@ -347,6 +354,101 @@
 }
 /* }}} */
 
+/* {{{ 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;
+	int arglen;
+
+	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) {
+		php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Host %s not found", hostname);
+		RETURN_FALSE;
+	}
+	RETVAL_STRING(org, 1);
+	free(org);
+}
+/* }}} */
+
+#if LIBGEOIP_VERSION >= 1004008
+/* {{{ proto string geoip_netspeedcell_by_name( string hostname )
+   Returns the Domain Name found in the GeoIP Database */
+PHP_FUNCTION(geoip_netspeedcell_by_name)
+{
+	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_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) {
+		php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Host %s not found", hostname);
+		RETURN_FALSE;
+	}
+	RETVAL_STRING(org, 1);
+	free(org);
+}
+/* }}} */
+#endif
+
+/* {{{ 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;
+	int arglen;
+
+	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) {
+		php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Host %s not found", hostname);
+		RETURN_FALSE;
+	}
+	RETVAL_STRING(org, 1);
+	free(org);
+}
+/* }}} */
+
 /* {{{ proto string geoip_org_by_name( string hostname )
    Returns the Organization Name found in the GeoIP Database */
 PHP_FUNCTION(geoip_org_by_name)
@@ -367,7 +469,7 @@
 		return;
 	}
 
-	org = GeoIP_org_by_name(gi, hostname);
+	org = GeoIP_name_by_name(gi, hostname);
 	GeoIP_delete(gi);
 	if (org == NULL) {
 		php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Host %s not found", hostname);
diff -Nur a/geoip-1.0.8/php_geoip.h b/geoip-1.0.8/php_geoip.h
--- a/geoip-1.0.8/php_geoip.h	1970-01-01 10:13:08.000000000 +0100
+++ b/geoip-1.0.8/php_geoip.h	2013-02-19 03:05:33.000000000 +0100
@@ -60,6 +60,11 @@
 PHP_FUNCTION(geoip_db_avail);
 PHP_FUNCTION(geoip_db_get_all_info);
 PHP_FUNCTION(geoip_db_filename);
+PHP_FUNCTION(geoip_asnum_by_name);
+PHP_FUNCTION(geoip_domain_by_name);
+#if LIBGEOIP_VERSION >= 1004008
+PHP_FUNCTION(geoip_netspeedcell_by_name);
+#endif
 #if LIBGEOIP_VERSION >= 1004001
 PHP_FUNCTION(geoip_region_name_by_code);
 PHP_FUNCTION(geoip_time_zone_by_country_and_region);
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Sep 29 08:01:24 2020 UTC