php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #61607
Patch geoip_custom_directory_patch_rev2 revision 2012-04-18 01:01 UTC by tiago dot peralta at sapo dot pt
Patch geoip_custom_directory_patch revision 2012-04-18 00:18 UTC by tiago dot peralta at sapo dot pt

Patch geoip_custom_directory_patch for geoip Bug #61607

Patch version 2012-04-18 00:18 UTC

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

Obsoleted by patches:

Patch Revisions:

Developer: tiago.peralta@sapo.pt

--- geoip.c	1970-01-01 10:13:08.000000000 +0100
+++ geoip.new	2012-04-18 01:10:54.000000000 +0100
@@ -85,11 +85,34 @@
 ZEND_GET_MODULE(geoip)
 #endif
 
+
+/* {{{ PHP_INI_MH 
+ */
+static PHP_INI_MH(OnUpdateDirectory)
+{
+    char* new_val = new_value;
+    
+    struct stat st;
+    if( stat( new_val, &st ) == 0)
+    {
+        GEOIP_G(custom_directory) = new_value;
+        return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+    }
+    
+}
+/* }}} */
+
+
+static void setup_dir()
+{
+    GeoIP_setup_custom_directory(GEOIP_G(custom_directory));
+    _GeoIP_setup_dbfilename();
+}
 /* {{{ PHP_INI
  */
 PHP_INI_BEGIN()
 #ifdef HAVE_CUSTOM_DIRECTORY
-	STD_PHP_INI_ENTRY("geoip.custom_directory", NULL, PHP_INI_ALL, OnUpdateString, custom_directory, zend_geoip_globals, geoip_globals)
+	STD_PHP_INI_ENTRY("geoip.custom_directory", NULL, PHP_INI_ALL, OnUpdateDirectory, custom_directory, zend_geoip_globals, geoip_globals)
 #endif
 PHP_INI_END()
 /* }}} */
@@ -110,12 +133,8 @@
 	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
-	
-	_GeoIP_setup_dbfilename();
+        
+	//_GeoIP_setup_dbfilename();
 	
 	/* For database type constants */
 	REGISTER_LONG_CONSTANT("GEOIP_COUNTRY_EDITION",     GEOIP_COUNTRY_EDITION,     CONST_CS | CONST_PERSISTENT);
@@ -185,6 +204,7 @@
 /* {{{ proto boolean geoip_db_avail( [ int database ] ) */
 PHP_FUNCTION(geoip_db_avail)
 {
+        setup_dir();
 	long edition;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &edition) == FAILURE) {
@@ -204,6 +224,7 @@
 /* {{{ proto string geoip_db_filename( [ int database ] ) */
 PHP_FUNCTION(geoip_db_filename)
 {
+        setup_dir();
 	long edition;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &edition) == FAILURE) {
@@ -224,6 +245,7 @@
 /* {{{ proto array geoip_db_get_all_info( ) */
 PHP_FUNCTION(geoip_db_get_all_info)
 {
+        setup_dir();
 	int i;
 	
 	array_init(return_value);
@@ -252,6 +274,7 @@
    Returns GeoIP Database information */
 PHP_FUNCTION(geoip_database_info)
 {
+        setup_dir();
 	GeoIP * gi;
 	char * db_info;
 	long edition = GEOIP_COUNTRY_EDITION;
@@ -288,6 +311,7 @@
 #define GEOIPDEF(php_func, c_func, db_type) \
 	PHP_FUNCTION(php_func) \
 	{ \
+                setup_dir(); \
 		GeoIP * gi; \
 		char * hostname = NULL; \
 		const char * return_code; \
@@ -321,6 +345,7 @@
    Returns the Continent name found in the GeoIP Database */
 PHP_FUNCTION(geoip_continent_code_by_name)
 {
+        setup_dir();
 	GeoIP * gi;
 	char * hostname = NULL;
 	int id;
@@ -351,6 +376,7 @@
    Returns the Organization Name found in the GeoIP Database */
 PHP_FUNCTION(geoip_org_by_name)
 {
+        setup_dir();
 	GeoIP * gi;
 	char * hostname = NULL;
 	char * org;
@@ -382,6 +408,7 @@
    Returns the detailed City information found in the GeoIP Database */
 PHP_FUNCTION(geoip_record_by_name)
 {
+        setup_dir();
 	GeoIP * gi;
 	char * hostname = NULL;
 	int arglen;
@@ -437,6 +464,7 @@
    Returns the Net Speed found in the GeoIP Database */
 PHP_FUNCTION(geoip_id_by_name)
 {
+        setup_dir();
 	GeoIP * gi;
 	char * hostname = NULL;
 	int arglen;
@@ -463,6 +491,7 @@
    Returns the Country Code and region found in the GeoIP Database */
 PHP_FUNCTION(geoip_region_by_name)
 {
+        setup_dir();
 	GeoIP * gi;
 	char * hostname = NULL;
 	int arglen;
@@ -503,6 +532,7 @@
    Returns the ISP Name found in the GeoIP Database */
 PHP_FUNCTION(geoip_isp_by_name)
 {
+        setup_dir();
 	GeoIP * gi;
 	char * hostname = NULL;
 	char * isp;
@@ -534,6 +564,7 @@
    Returns the region name for some country code and region code combo */
 PHP_FUNCTION(geoip_region_name_by_code)
 {
+        setup_dir();
 	char * country_code = NULL;
 	char * region_code = NULL;
 	const char * region_name;
@@ -562,6 +593,7 @@
    Returns the time zone for some country code and region code combo */
 PHP_FUNCTION(geoip_time_zone_by_country_and_region)
 {
+        setup_dir();
 	char * country = NULL;
 	char * region = NULL;
 	const char * timezone;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 05:01:28 2024 UTC