ID: 38162
User updated by: RQuadling at GMail dot com
Reported By: RQuadling at GMail dot com
Status: Open
Bug Type: Feature/Change Request
Operating System: Windows XP SP2
PHP Version: 5CVS-2006-07-20 (snap)
New Comment:
Stupid bloody site! Lost the file.
http://rquadling.php1h.com/ini_patch.diff.txt
Previous Comments:
------------------------------------------------------------------------
[2006-07-22 22:28:20] RQuadling at GMail dot com
http://rquadling.phpnet.us/enhance_ini_and_registry__diff.txt
------------------------------------------------------------------------
[2006-07-20 14:55:20] tony2001@php.net
Please upload the patch somewhere and put the link here.
------------------------------------------------------------------------
[2006-07-20 14:24:32] RQuadling at GMail dot com
Description:
------------
PHP doesn't allow for version specific config files (or registry
settings).
The following patch will allow this.
Index: main/php_ini.c
===================================================================
RCS file: /repository/php-src/main/php_ini.c,v
retrieving revision 1.143
diff -u -r1.143 php_ini.c
--- main/php_ini.c 4 Jul 2006 06:38:32 -0000 1.143
+++ main/php_ini.c 18 Jul 2006 08:36:34 -0000
@@ -293,6 +293,7 @@
static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
#ifdef PHP_WIN32
char *reg_location;
+ int version_specific;
#endif
env_location = getenv("PHPRC");
@@ -318,14 +319,17 @@
#ifdef PHP_WIN32
/* Add registry location */
- reg_location = GetIniPathFromRegistry();
- if (reg_location != NULL) {
- if (*php_ini_search_path) {
- strcat(php_ini_search_path, paths_separator);
+ /* RAQ : Add version specific registry location */
+ for (version_specific = MAX_VERSION_SPECIFIC ; version_specific >=
NOT_VERSION_SPECIFIC ; --version_specific)
+ {
+ reg_location = GetIniPathFromRegistry(version_specific);
+ if (reg_location != NULL) {
+ if (*php_ini_search_path) {
+ strcat(php_ini_search_path, paths_separator);
+ }
+ strcat(php_ini_search_path, reg_location);
+ efree(reg_location);
}
- strcat(php_ini_search_path, reg_location);
- efree(reg_location);
- }
#endif
/* Add cwd (only with CLI) */
@@ -428,6 +432,50 @@
}
}
}
+ /* RAQ : Search php%php-version%-%sapi-module-name%.ini file in
search path */
+ if (!fh.handle.fp) {
+ const char *fmt = "php%s-%s.ini";
+ char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name) +
strlen(PHP_VERSION));
+ sprintf(ini_fname, fmt, PHP_VERSION, sapi_module.name);
+ fh.handle.fp = php_fopen_with_path(ini_fname, "r",
php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
+ efree(ini_fname);
+ if (fh.handle.fp) {
+ fh.filename = php_ini_opened_path;
+ }
+ }
+ /* RAQ : Search
php%php-major-version%.%php-minor-version%.%php-release-version%-%sapi-module-name%.ini
file in search path */
+ if (!fh.handle.fp) {
+ const char *fmt = "php%d.%d.%d-%s.ini";
+ char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name) +
6);
+ sprintf(ini_fname, fmt, PHP_MAJOR_VERSION, PHP_MINOR_VERSION,
PHP_RELEASE_VERSION, sapi_module.name);
+ fh.handle.fp = php_fopen_with_path(ini_fname, "r",
php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
+ efree(ini_fname);
+ if (fh.handle.fp) {
+ fh.filename = php_ini_opened_path;
+ }
+ }
+ /* RAQ : Search
php%php-major-version%.%php-minor-version%-%sapi-module-name%.ini file
in search path */
+ if (!fh.handle.fp) {
+ const char *fmt = "php%d.%d-%s.ini";
+ char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name) +
4);
+ sprintf(ini_fname, fmt, PHP_MAJOR_VERSION, PHP_MINOR_VERSION,
sapi_module.name);
+ fh.handle.fp = php_fopen_with_path(ini_fname, "r",
php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
+ efree(ini_fname);
+ if (fh.handle.fp) {
+ fh.filename = php_ini_opened_path;
+ }
+ }
+ /* RAQ : Search php%php-major-version%-%sapi-module-name%.ini file
in search path */
+ if (!fh.handle.fp) {
+ const char *fmt = "php%d-%s.ini";
+ char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name) +
2);
+ sprintf(ini_fname, fmt, PHP_MAJOR_VERSION, sapi_module.name);
+ fh.handle.fp = php_fopen_with_path(ini_fname, "r",
php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
+ efree(ini_fname);
+ if (fh.handle.fp) {
+ fh.filename = php_ini_opened_path;
+ }
+ }
/* Search php-%sapi-module-name%.ini file in search path */
if (!fh.handle.fp) {
const char *fmt = "php-%s.ini";
Index: win32/php_registry.h
===================================================================
RCS file: /repository/php-src/win32/php_registry.h,v
retrieving revision 1.4
diff -u -r1.4 php_registry.h
--- win32/php_registry.h 19 Oct 2003 10:22:21 -0000 1.4
+++ win32/php_registry.h 18 Jul 2006 08:36:34 -0000
@@ -1,8 +1,17 @@
#ifndef PHP_REGISTRY_H
#define PHP_REGISTRY_H
+/* RAQ : Constants to assist in version specificness. */
+#define NOT_VERSION_SPECIFIC 0
+#define MAJOR_VERSION_SPECIFIC 1
+#define MINOR_VERSION_SPECIFIC 2
+#define RELEASE_VERSION_SPECIFIC 3
+#define EXTRA_VERSION_SPECIFIC 4
+/* Maximum version specificness for for() loops. */
+#define MAX_VERSION_SPECIFIC 4
void UpdateIniFromRegistry(char *path TSRMLS_DC);
-char *GetIniPathFromRegistry();
+/* RAQ : Allow for version specificness */
+char *GetIniPathFromRegistry(int version_specific);
#endif /* PHP_REGISTRY_H */
Index: win32/registry.c
===================================================================
RCS file: /repository/php-src/win32/registry.c,v
retrieving revision 1.16
diff -u -r1.16 registry.c
--- win32/registry.c 14 Mar 2005 12:42:05 -0000 1.16
+++ win32/registry.c 18 Jul 2006 08:36:34 -0000
@@ -3,15 +3,66 @@
#define PHP_REGISTRY_KEY "SOFTWARE\\PHP"
+#include "php_registry.h"
+
void UpdateIniFromRegistry(char *path TSRMLS_DC)
{
char *p, *orig_path;
HKEY MainKey;
char *strtok_buf = NULL;
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, PHP_REGISTRY_KEY "\\Per
Directory Values", 0, KEY_READ, &MainKey)!=ERROR_SUCCESS) {
- return;
- }
+ /* RAQ : Version specificness */
+ int version_specific;
+ char * reg_key;
+
+ /* RAQ : Get default and then version specific entries. */
+ /**
+ version_specific has the following meanings
+ 0 = No additional subkeys - SOFTWARE\\PHP\\Per Directory Values
+ 1 = PHP_MAJOR_VERSION added - SOFTWARE\\PHP\\V99\\Per Directory
Values
+ 2 = PHP_MINOR_VERSION added - SOFTWARE\\PHP\\V99.99\\Per Directory
Values
+ 3 = PHP_RELEASE_VERSION added - SOFTWARE\\PHPV99.99.99\\Per
Directory Values
+ 4 = PHP_EXTRA_VERSION added - SOFTWARE\\PHP\\V99.99.99-dev\\Per
Directory Values - Actually uses the full PHP_VERSION.
+ **/
+ for (version_specific = NOT_VERSION_SPECIFIC ; version_specific <=
MAX_VERSION_SPECIFIC ; ++version_specific)
+ {
+ /* RAQ : Build key which may include version specificness */
+ switch(version_specific)
+ {
+ case MAJOR_VERSION_SPECIFIC :
+ reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) +
strlen("\\V99\\Per Directory Values"));
+ sprintf(reg_key, "%s\\V%d\\Per Directory Values",
+ PHP_REGISTRY_KEY,
+ PHP_MAJOR_VERSION);
+ break;
+ case MINOR_VERSION_SPECIFIC :
+ reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) +
strlen("\\V99.99\\Per Directory Values"));
+ sprintf(reg_key, "%s\\V%d.%d\\Per Directory Values",
+ PHP_REGISTRY_KEY,
+ PHP_MAJOR_VERSION, PHP_MINOR_VERSION);
+ break;
+ case RELEASE_VERSION_SPECIFIC :
+ reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) +
strlen("\\V99.99.99\\Per Directory Values"));
+ sprintf(reg_key, "%s\\V%d.%d.%d\\Per Directory Values",
+ PHP_REGISTRY_KEY,
+ PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION);
+ break;
+ case EXTRA_VERSION_SPECIFIC :
+ reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) +
strlen("\\V\\Per Directory Values") + strlen(PHP_VERSION));
+ sprintf(reg_key, "%s\\V%s\\Per Directory Values",
+ PHP_REGISTRY_KEY,
+ PHP_VERSION);
+ break;
+ default :
+ reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) +
strlen("\\Per Directory Values"));
+ sprintf(reg_key, "%s\\Per Directory Values", PHP_REGISTRY_KEY);
+ break;
+ }
+ /* RAQ END : Continue with appropriate key. */
+
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_key, 0, KEY_READ,
&MainKey)!=ERROR_SUCCESS) {
+ return;
+ }
orig_path = path = estrdup(path);
@@ -55,7 +106,7 @@
HKEY hKey;
DWORD lType;
DWORD values = 0, max_name = 0, max_value = 0, i = 0;
-
+
if (p>path) {
*(p-1) = '\\'; /* restore the slash */
}
@@ -91,16 +142,53 @@
}
RegCloseKey(MainKey);
efree(orig_path);
+ } /* RAQ : End of version specificness loop */
}
#define PHPRC_REGISTRY_NAME "IniFilePath"
-char *GetIniPathFromRegistry()
+char *GetIniPathFromRegistry(int version_specific)
{
char *reg_location = NULL;
HKEY hKey;
-
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, PHP_REGISTRY_KEY, 0, KEY_READ,
&hKey) == ERROR_SUCCESS) {
+ char *reg_key = NULL;
+
+ // RAQ : Determine which key to use - may include version
specificiness.
+ switch(version_specific)
+ {
+ case MAJOR_VERSION_SPECIFIC :
+ reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) +
strlen("\\V99"));
+ sprintf(reg_key, "%s\\V%d",
+ PHP_REGISTRY_KEY,
+ PHP_MAJOR_VERSION);
+ break;
+ case MINOR_VERSION_SPECIFIC :
+ reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) +
strlen("\\V99.99"));
+ sprintf(reg_key, "%s\\V%d.%d",
+ PHP_REGISTRY_KEY,
+ PHP_MAJOR_VERSION, PHP_MINOR_VERSION);
+ break;
+ case RELEASE_VERSION_SPECIFIC :
+ reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) +
strlen("\\V99.99.99"));
+ sprintf(reg_key, "%s\\V%d.%d.%d",
+ PHP_REGISTRY_KEY,
+ PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION);
+ break;
+ case EXTRA_VERSION_SPECIFIC :
+ reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY) + strlen("\\V")
+ strlen(PHP_VERSION));
+ sprintf(reg_key, "%s\\V%s",
+ PHP_REGISTRY_KEY,
+ PHP_VERSION);
+ break;
+ default :
+ reg_key = (char *) emalloc(strlen(PHP_REGISTRY_KEY));
+ sprintf(reg_key, "%s", PHP_REGISTRY_KEY);
+ break;
+ }
+ /* RAQ END : Continue with appropriate key. */
+
+ /* RAQ : Use potentially version specific registry key :
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, PHP_REGISTRY_KEY, 0, KEY_READ,
&hKey) == ERROR_SUCCESS) {*/
+ if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_key, 0, KEY_READ, &hKey) ==
ERROR_SUCCESS) {
DWORD buflen = MAXPATHLEN;
reg_location = emalloc(MAXPATHLEN+1);
if(RegQueryValueEx(hKey, PHPRC_REGISTRY_NAME, 0, NULL, reg_location,
&buflen) != ERROR_SUCCESS) {
Expected result:
----------------
PHP to support version specific configuration files and registry
settings.
Actual result:
--------------
"One size fits all". No ability to distinguish between 1 version and
the next.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=38162&edit=1