php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #72269
Patch htscanner_php7.0.patch revision 2016-07-03 10:11 UTC by roel at abittechnical dot com
revision 2016-07-02 21:32 UTC by roel at abittechnical dot com
revision 2016-07-02 14:02 UTC by roel at abittechnical dot com
revision 2016-06-05 20:51 UTC by roel at abittechnical dot com
revision 2016-06-05 20:37 UTC by roel at abittechnical dot com
revision 2016-05-31 20:14 UTC by roel at abittechnical dot com

Patch htscanner_php7.0.patch for htscanner Bug #72269

Patch version 2016-07-03 10:11 UTC

Return to Bug #72269 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions: 2016-07-03 10:11 UTC | 2016-07-02 21:32 UTC | 2016-07-02 14:02 UTC | 2016-06-05 20:51 UTC | 2016-06-05 20:37 UTC | 2016-05-31 20:14 UTC

Developer: roel@abittechnical.com

Line 1 (now 1), was 19 lines, now 17 lines
 diff --git a/htscanner.c b/htscanner.c
 index 55bc68b..9490afb 100644
 --- a/htscanner.c
 +++ b/htscanner.c
 @@ -147,18 +147,39 @@ static int value_hnd(char *name, char *value, int flag, int mode, HashTable *ini
 --- htscanner.c	2012-03-01 16:14:32.000000000 +0100
 +++ htscanner.c	2016-07-03 12:08:30.700863832 +0200
 @@ -147,18 +147,40 @@
   #endif
   #if PHP_VERSION_ID < 50204
   	if (zend_alter_ini_entry(name, name_len + 1, value, value_len, mode, PHP_INI_STAGE_RUNTIME) == FAILURE) {
  -#else
  +#elif PHP_VERSION_ID < 70000
   	if (zend_alter_ini_entry(name, name_len + 1, value, value_len, mode, PHP_INI_STAGE_HTACCESS) == FAILURE) {
  +#else
  +	zend_string *zname, *zvalue;
 +	zname = zend_string_init(name, name_len, 0);
 +	zvalue = zend_string_init(value, value_len, 0);
 +	zname = zend_string_init(name, name_len, 1);
 +	zvalue = zend_string_init(value, value_len, 1);
  +	int res = zend_alter_ini_entry(zname, zvalue, mode, PHP_INI_STAGE_HTACCESS);
  +	if (res == FAILURE) {
   #endif
   		htscanner_debug("zend_alter_ini_entry failed!");


  +	ZVAL_STR(&zval_value, zvalue);
  +
  +	if (ini_entries)
  +		zend_hash_update(ini_entries, zname, &zval_value);
 +	else
 +		zend_string_release(zvalue);
  +
  +	zend_string_release(zname);
 +	zend_string_release(zvalue);
  +#endif
   
   	return SUCCESS;
   }
 @@ -186,7 +207,11 @@ static void parse_config_file(char *file, HashTable *ini_entries TSRMLS_DC)
 @@ -186,7 +208,11 @@
   	}
   #endif
   
  +#if PHP_VERSION_ID < 70000
Line 54 (now 53), was 50 lines, now 42 lines

  +#endif
   	if (stream != NULL) {
   		char buf[FILE_BUFFER], *bufp, *tok, *value;
   		int flag, parse = 1;
 @@ -259,7 +284,7 @@ ZEND_GET_MODULE(htscanner)
 @@ -259,7 +285,7 @@
   PHP_INI_BEGIN()
   	STD_PHP_INI_ENTRY("htscanner.config_file", ".htaccess", PHP_INI_SYSTEM, OnUpdateString, config_file, zend_htscanner_globals, htscanner_globals)
   	STD_PHP_INI_ENTRY("htscanner.default_docroot", "/", PHP_INI_SYSTEM, OnUpdateString, default_docroot, zend_htscanner_globals, htscanner_globals)
  -#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0)
  +#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) || PHP_MAJOR_VERSION >= 7
   	STD_PHP_INI_ENTRY("htscanner.default_ttl", "300", PHP_INI_SYSTEM, OnUpdateLong, default_ttl, zend_htscanner_globals, htscanner_globals)
   	STD_PHP_INI_ENTRY("htscanner.stop_on_error", "0", PHP_INI_SYSTEM, OnUpdateLong, stop_on_error, zend_htscanner_globals, htscanner_globals)
   	STD_PHP_INI_ENTRY("htscanner.verbose", "0", PHP_INI_SYSTEM, OnUpdateLong, verbose, zend_htscanner_globals, htscanner_globals)
 @@ -274,18 +299,29 @@ PHP_INI_END()
 @@ -274,12 +300,23 @@
   htscannerMutexDeclare(ini_entries_cache_mutex);
   static HashTable *ini_entries_cache = NULL;
   
  +#if PHP_VERSION_ID < 70000
   static void ini_cache_entry_dtor(htscanner_cache_entry *entry) /* {{{ */
   {
   	zend_hash_destroy(entry->ini_entries);
 -	free(entry->ini_entries);
 +	efree(entry->ini_entries);
 +}
 +/* }}} */
  	free(entry->ini_entries);
  }
  /* }}} */
  +#else
  +static void ini_cache_entry_dtor(zval *zentry) /* {{{ */
  +{
  +	htscanner_cache_entry *entry = Z_PTR_P(zentry);
  +	zend_hash_destroy(entry->ini_entries);
 +	efree(entry->ini_entries);
 +	efree(entry);
  }
  /* }}} */
 +	free(entry->ini_entries);
 +	free(entry);
 +}
 +/* }}} */
  +#endif
  
  
   static int php_htscanner_create_cache() /* {{{ */
   {
  	htscannerMutexSetup(ini_entries_cache_mutex);
  
 -	ini_entries_cache = malloc(sizeof(HashTable));
 +	ini_entries_cache = emalloc(sizeof(HashTable));
  	if (!ini_entries_cache) {
  		return FAILURE;
  	}
 @@ -347,26 +383,48 @@ static int htscanner_main(TSRMLS_D) /* {{{ */
 @@ -347,31 +384,57 @@
   #endif
   
   	htscannerMutexLock(ini_entries_cache_mutex);
  +#if PHP_VERSION_ID < 70000


  +#if PHP_VERSION_ID < 70000
   			char *value, *name;
  -			HashPosition pos;
   			uint len;
 +			HashPosition pos;
  +#else
  +			zend_string *name;
  +			zval *value;
  +#endif
 +			HashPosition pos;
   			ulong num;
  
  
 +#if PHP_VERSION_ID < 70000
   			zend_hash_internal_pointer_reset_ex(entry_fetched->ini_entries, &pos);
   
 +#if PHP_VERSION_ID < 70000
   			while (SUCCESS == zend_hash_get_current_data_ex(entry_fetched->ini_entries, (void**)&value, &pos)) {
   				zend_hash_get_current_key_ex(entry_fetched->ini_entries, &name, &len, &num, 0, &pos);
   				htscanner_debug("setting: %s = %s (cache hit)", name, value);
  +#else
 +			while ((value = zend_hash_get_current_data_ex(entry_fetched->ini_entries, &pos))) {
 +				zend_hash_get_current_key_ex(entry_fetched->ini_entries, &name, &num, &pos);
 +				htscanner_debug("setting: %s = %s (cache hit)", name, Z_STRVAL_P(value));
 +			ZEND_HASH_FOREACH_KEY_VAL(entry_fetched->ini_entries, num, name, value) {
 +				htscanner_debug("setting: %s = %s (cache hit)", (char*)ZSTR_VAL(name), Z_STRVAL_P(value));
  +#endif
   #if PHP_VERSION_ID < 50204
   				if (zend_alter_ini_entry(name, len, value, strlen(value), PHP_INI_PERDIR, PHP_INI_STAGE_PHP_INI_STAGE_RUNTIME) == FAILURE) {
  -#else
  +#elif PHP_VERSION_ID < 70000
   				if (zend_alter_ini_entry(name, len, value, strlen(value), PHP_INI_PERDIR, PHP_INI_STAGE_HTACCESS) == FAILURE) {
  +#else
 +				if (zend_alter_ini_entry(name, Z_STR_P(value), PHP_INI_PERDIR, PHP_INI_STAGE_HTACCESS) == FAILURE) {
 +				int res = zend_alter_ini_entry(name, Z_STR_P(value), PHP_INI_PERDIR, PHP_INI_STAGE_HTACCESS);
 +				if (res == FAILURE) {
   #endif
   					char msg[1024];
  +#if PHP_VERSION_ID < 70000
   					snprintf(msg, sizeof (msg), "Adding option from cache (Name: '%s' Value: '%s') failed!\n", name, value);
  +#else
 +					snprintf(msg, sizeof (msg), "Adding option from cache (Name: '%s' Value: '%s') failed!\n", name->val, Z_STR_P(value));
 +					snprintf(msg, sizeof (msg), "Adding option from cache (Name: '%s' Value: '%s') failed!\n", (char*)ZSTR_VAL(name), Z_STR_P(value));
  +#endif
   					htscannerMutexUnlock(ini_entries_cache_mutex);
   					RETURN_FAILURE(msg);
   				}
 @@ -380,7 +438,7 @@ static int htscanner_main(TSRMLS_D) /* {{{ */
  	/* parse, insert, assign */
  	if (HTG(default_ttl)) {
  		entry.created_on = t;
 -		entry.ini_entries = ini_entries = malloc(sizeof(HashTable));
 +		entry.ini_entries = ini_entries = emalloc(sizeof(HashTable));
  		if (ini_entries)
  			zend_hash_init(ini_entries, 0, NULL, NULL, 1);
  	}
 @@ -405,8 +463,13 @@ static int htscanner_main(TSRMLS_D) /* {{{ */
 +#if PHP_VERSION_ID < 70000
  				zend_hash_move_forward_ex(entry_fetched->ini_entries, &pos);
  			}
 +#else
 +			} ZEND_HASH_FOREACH_END();
 +#endif
  			htscannerMutexUnlock(ini_entries_cache_mutex);
  			return SUCCESS;
   		}
  	}
 @@ -405,8 +468,13 @@
  		}
  	}
   
  +#if PHP_VERSION_ID < 70000
   	if (ini_entries)
   		zend_hash_update(ini_entries_cache, cwd, cwd_len, &entry, sizeof(htscanner_cache_entry), NULL);
Line 167 (now 158), was 15 lines, now 6 lines

  +	if (ini_entries)
  +		zend_hash_str_update_mem(ini_entries_cache, cwd, cwd_len, &entry, sizeof(htscanner_cache_entry));
  +#endif
   	htscannerMutexUnlock(ini_entries_cache_mutex);
  
  
   	return SUCCESS;
 @@ -451,7 +514,7 @@ static PHP_MSHUTDOWN_FUNCTION(htscanner) /* {{{ */
  	if (ini_entries_cache) {
  		htscannerMutexLock(ini_entries_cache_mutex);
  		zend_hash_destroy(ini_entries_cache);
 -		free(ini_entries_cache);
 +		efree(ini_entries_cache);
  		htscannerMutexShutdown(ini_entries_cache_mutex);
  	}
  
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Dec 04 08:03:38 2021 UTC