dmitry          Thu Aug  3 13:54:05 2006 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src    NEWS 
    /php-src/win32      registry.c 
  Log:
  Added version specific registry keys to allow different configurations for 
different php version.
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.178&r2=1.2027.2.547.2.179&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.178 php-src/NEWS:1.2027.2.547.2.179
--- php-src/NEWS:1.2027.2.547.2.178     Thu Aug  3 11:04:52 2006
+++ php-src/NEWS        Thu Aug  3 13:54:05 2006
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? Aug 2006, PHP 5.2.0RC2
+- Added version specific registry keys to allow different configurations for
+  different php version. (Richard, Dmitry)
 - In addtion to path to php.ini, PHPRC now may specify full file name. (Dmitry)
 - Added "PHPINIDir" Apache directive to apache and apache_hooks SAPIs. (Dmitry)
 - Added an optional boolean parameter to memory_get_usage() and 
http://cvs.php.net/viewvc.cgi/php-src/win32/registry.c?r1=1.16&r2=1.16.4.1&diff_format=u
Index: php-src/win32/registry.c
diff -u php-src/win32/registry.c:1.16 php-src/win32/registry.c:1.16.4.1
--- php-src/win32/registry.c:1.16       Mon Mar 14 12:42:05 2005
+++ php-src/win32/registry.c    Thu Aug  3 13:54:05 2006
@@ -1,7 +1,60 @@
 #include "php.h"
 #include "php_ini.h"
 
-#define PHP_REGISTRY_KEY "SOFTWARE\\PHP"
+#define PHP_REGISTRY_KEY              "SOFTWARE\\PHP"
+
+#define PHP_VER1(V1)                  #V1
+#define PHP_VER2(V1,V2)               #V1"."#V2
+#define PHP_VER3(V1,V2,V3)            #V1"."#V2"."#V3
+
+#define PHP_REGISTRY_KEYV(VER)        PHP_REGISTRY_KEY"\\"VER
+#define PHP_REGISTRY_KEY1(V1)         PHP_REGISTRY_KEY"\\"PHP_VER1(V1)
+#define PHP_REGISTRY_KEY2(V1,V2)      PHP_REGISTRY_KEY"\\"PHP_VER2(V1,V2)
+#define PHP_REGISTRY_KEY3(V1,V2,V3)   PHP_REGISTRY_KEY"\\"PHP_VER3(V1,V2,V3)
+
+static const char* registry_keys[] = {
+       PHP_REGISTRY_KEYV(PHP_VERSION),
+       PHP_REGISTRY_KEY3(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, 
PHP_RELEASE_VERSION),
+       PHP_REGISTRY_KEY2(PHP_MAJOR_VERSION, PHP_MINOR_VERSION),
+       PHP_REGISTRY_KEY1(PHP_MAJOR_VERSION),
+       PHP_REGISTRY_KEY,
+       NULL
+};
+
+static int OpenPhpRegistryKey(char* sub_key, HKEY *hKey)
+{
+       const char **key_name = registry_keys;
+
+       if (sub_key) {
+               int main_key_len;
+               int sub_key_len = strlen(sub_key);
+               char *reg_key;
+
+               while (*key_name) {
+                       LONG ret;
+
+                       main_key_len = strlen(*key_name);
+                       reg_key = emalloc(main_key_len + sub_key_len + 1);
+                       memcpy(reg_key, *key_name, main_key_len);
+                       memcpy(reg_key + main_key_len, sub_key, sub_key_len + 
1);                       
+                       ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_key, 0, 
KEY_READ, hKey);
+                       efree(reg_key);
+                       
+                       if (ret == ERROR_SUCCESS) {
+                               return 1;
+                       }
+                       ++key_name;
+               }
+       } else {
+               while (*key_name) {
+                       if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, *key_name, 0, 
KEY_READ, hKey) == ERROR_SUCCESS) {
+                               return 1;
+                       }
+                       ++key_name;
+               }
+       }
+       return 0;
+}
 
 void UpdateIniFromRegistry(char *path TSRMLS_DC)
 {
@@ -9,7 +62,7 @@
        HKEY MainKey;
        char *strtok_buf = NULL;
 
-       if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, PHP_REGISTRY_KEY "\\Per Directory 
Values", 0, KEY_READ, &MainKey)!=ERROR_SUCCESS) {
+       if (!OpenPhpRegistryKey("\\Per Directory Values", &MainKey)) {
                return;
        }
 
@@ -100,7 +153,7 @@
        char *reg_location = NULL;
        HKEY hKey;
        
-       if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, PHP_REGISTRY_KEY, 0, KEY_READ, 
&hKey) == ERROR_SUCCESS) {
+       if (OpenPhpRegistryKey(NULL, &hKey)) {
                DWORD buflen = MAXPATHLEN;
                reg_location = emalloc(MAXPATHLEN+1);
                if(RegQueryValueEx(hKey, PHPRC_REGISTRY_NAME, 0, NULL, 
reg_location, &buflen) != ERROR_SUCCESS) {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to