rasmus          Fri Oct  4 00:47:35 2002 EDT

  Modified files:              
    /php4       NEWS configure.in 
    /php4/ext/standard  info.c 
    /php4/main  build-defs.h.in main.c php_ini.c 
  Log:
  As discussed, add --with-config-file-scan-dir compile-time switch defining
  a directory which will be scanned for *.ini files after the main php.ini 
  file has been parsed.  This makes it much easier to automatically deploy 
  a modular PHP since adding extensions which have their own ini switches can
  now be done by simply dropping a foo.ini file in the right directory and 
  restarting.  A list of parsed ini files is maintained and shown on the
  phpinfo page.
  
  
Index: php4/NEWS
diff -u php4/NEWS:1.1178 php4/NEWS:1.1179
--- php4/NEWS:1.1178    Thu Oct  3 20:35:27 2002
+++ php4/NEWS   Fri Oct  4 00:47:33 2002
@@ -1,6 +1,8 @@
 PHP 4                                                                      NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ? ? ??? 2002, Version 4.3.0
+- Added --with-config-file-scan-dir compile-time switch which specifies a
+  directory which will be scanned for *.ini files.
 - Added wddx_serialize_type(). Allows users to cast values to WDDX types (jan)
 - Added ob_flush_all() that flushes all buffers. (Yasuo)
 - Added ob_get_clean() and og_get_flush(). (Yasuo)
Index: php4/configure.in
diff -u php4/configure.in:1.377 php4/configure.in:1.378
--- php4/configure.in:1.377     Wed Oct  2 08:52:53 2002
+++ php4/configure.in   Fri Oct  4 00:47:33 2002
@@ -1,4 +1,4 @@
-dnl ## $Id: configure.in,v 1.377 2002/10/02 12:52:53 helly Exp $ -*- sh -*-
+dnl ## $Id: configure.in,v 1.378 2002/10/04 04:47:33 rasmus Exp $ -*- sh -*-
 dnl ## Process this file with autoconf to produce a configure script.
 
 divert(1)
@@ -570,6 +570,12 @@
   esac
 fi
 
+PHP_ARG_WITH(config-file-scan-dir,[directory to be scanned for configuration files],
+[  --with-config-file-scan-dir=PATH ], DEFAULT, no) 
+if test "$PHP_CONFIG_FILE_SCAN_DIR" = "DEFAULT"; then
+       PHP_CONFIG_FILE_SCAN_DIR=""
+fi
+
 # compatibility
 if test -z "$with_pear" && test "$enable_pear" = "no"; then
   with_pear=no
@@ -890,6 +896,7 @@
 EXPANDED_SYSCONFDIR=`eval echo $sysconfdir`
 EXPANDED_DATADIR=$datadir
 EXPANDED_PHP_CONFIG_FILE_PATH=`eval echo "$PHP_CONFIG_FILE_PATH"`
+EXPANDED_PHP_CONFIG_FILE_SCAN_DIR=`eval echo "$PHP_CONFIG_FILE_SCAN_DIR"`
 INCLUDE_PATH=.:$EXPANDED_PEAR_INSTALLDIR
 
 exec_prefix=$old_exec_prefix
@@ -905,6 +912,7 @@
 AC_SUBST(EXPANDED_SYSCONFDIR)
 AC_SUBST(EXPANDED_LOCALSTATEDIR)
 AC_SUBST(EXPANDED_PHP_CONFIG_FILE_PATH)
+AC_SUBST(EXPANDED_PHP_CONFIG_FILE_SCAN_DIR)
 
 PHP_UTILIZE_RPATHS
 
Index: php4/ext/standard/info.c
diff -u php4/ext/standard/info.c:1.210 php4/ext/standard/info.c:1.211
--- php4/ext/standard/info.c:1.210      Wed Oct  2 10:27:32 2002
+++ php4/ext/standard/info.c    Fri Oct  4 00:47:34 2002
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: info.c,v 1.210 2002/10/02 14:27:32 cmv Exp $ */
+/* $Id: info.c,v 1.211 2002/10/04 04:47:34 rasmus Exp $ */
 
 #include "php.h"
 #include "php_ini.h"
@@ -59,6 +59,7 @@
                                                } \
 
 PHPAPI extern char *php_ini_opened_path;
+PHPAPI extern char *php_ini_scanned_files;
 
 /* {{{ _display_module_info
  */
@@ -378,6 +379,13 @@
 #endif
 
                php_info_print_table_row(2, "Configuration File (php.ini) Path", 
php_ini_opened_path?php_ini_opened_path:PHP_CONFIG_FILE_PATH);
+
+               if(strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
+                       php_info_print_table_row(2, "Scan this dir for additional .ini 
+files", PHP_CONFIG_FILE_SCAN_DIR);
+                       if(php_ini_scanned_files) {
+                               php_info_print_table_row(2, "additional .ini files 
+parsed", php_ini_scanned_files);
+                       }
+               }
                
                snprintf(temp_api, sizeof(temp_api), "%d", PHP_API_VERSION);
                php_info_print_table_row(2, "PHP API", temp_api);
Index: php4/main/build-defs.h.in
diff -u php4/main/build-defs.h.in:1.10 php4/main/build-defs.h.in:1.11
--- php4/main/build-defs.h.in:1.10      Fri Jun  7 08:19:26 2002
+++ php4/main/build-defs.h.in   Fri Oct  4 00:47:34 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: build-defs.h.in,v 1.10 2002/06/07 12:19:26 ssb Exp $ */
+/* $Id: build-defs.h.in,v 1.11 2002/10/04 04:47:34 rasmus Exp $ */
 
 #define CONFIGURE_COMMAND "@CONFIGURE_COMMAND@"
 #define PHP_ADA_INCLUDE                ""
@@ -87,4 +87,5 @@
 #define PHP_SYSCONFDIR          "@EXPANDED_SYSCONFDIR@"
 #define PHP_LOCALSTATEDIR       "@EXPANDED_LOCALSTATEDIR@"
 #define PHP_CONFIG_FILE_PATH    "@EXPANDED_PHP_CONFIG_FILE_PATH@"
+#define PHP_CONFIG_FILE_SCAN_DIR    "@EXPANDED_PHP_CONFIG_FILE_SCAN_DIR@"
 #define PHP_SHLIB_SUFFIX        "@SHLIB_SUFFIX_NAME@"
Index: php4/main/main.c
diff -u php4/main/main.c:1.495 php4/main/main.c:1.496
--- php4/main/main.c:1.495      Thu Oct  3 07:18:39 2002
+++ php4/main/main.c    Fri Oct  4 00:47:34 2002
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: main.c,v 1.495 2002/10/03 11:18:39 zeev Exp $ */
+/* $Id: main.c,v 1.496 2002/10/04 04:47:34 rasmus Exp $ */
 
 /* {{{ includes
  */
@@ -1108,6 +1108,7 @@
        REGISTER_MAIN_STRINGL_CONSTANT("PHP_SYSCONFDIR", PHP_SYSCONFDIR, 
sizeof(PHP_SYSCONFDIR)-1, CONST_PERSISTENT | CONST_CS);
        REGISTER_MAIN_STRINGL_CONSTANT("PHP_LOCALSTATEDIR", PHP_LOCALSTATEDIR, 
sizeof(PHP_LOCALSTATEDIR)-1, CONST_PERSISTENT | CONST_CS);
        REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, 
sizeof(PHP_CONFIG_FILE_PATH)-1, CONST_PERSISTENT | CONST_CS);
+       REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_SCAN_DIR", 
+PHP_CONFIG_FILE_SCAN_DIR, sizeof(PHP_CONFIG_FILE_SCAN_DIR)-1, CONST_PERSISTENT | 
+CONST_CS);
        REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, 
sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);
        php_output_register_constants(TSRMLS_C);
        php_rfc1867_register_constants(TSRMLS_C);
Index: php4/main/php_ini.c
diff -u php4/main/php_ini.c:1.103 php4/main/php_ini.c:1.104
--- php4/main/php_ini.c:1.103   Thu Sep 26 13:54:53 2002
+++ php4/main/php_ini.c Fri Oct  4 00:47:35 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_ini.c,v 1.103 2002/09/26 17:54:53 cmv Exp $ */
+/* $Id: php_ini.c,v 1.104 2002/10/04 04:47:35 rasmus Exp $ */
 
 /* Check CWD for php.ini */
 #define INI_CHECK_CWD
@@ -34,6 +34,10 @@
 #include "SAPI.h"
 #include "php_main.h"
 
+#ifndef S_ISREG
+#define S_ISREG(mode)   (((mode) & S_IFMT) == S_IFREG)
+#endif
+
 typedef struct _php_extension_lists {
        zend_llist engine;
        zend_llist functions;
@@ -44,6 +48,7 @@
 static HashTable configuration_hash;
 PHPAPI char *php_ini_opened_path=NULL;
 static php_extension_lists extension_lists;
+PHPAPI char *php_ini_scanned_files=NULL;
 
 /* {{{ php_ini_displayer_cb
  */
@@ -228,6 +233,14 @@
        char *open_basedir;
        int free_ini_search_path=0;
        zend_file_handle fh;
+       DIR *dirp = NULL;
+       struct dirent *dir_entry;
+       struct stat sb;
+       char ini_file[MAXPATHLEN];
+       char *p;
+       zend_llist scanned_ini_list;
+       int l, total_l=0;
+       zend_llist_element *element;
        TSRMLS_FETCH();
 
        if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) 
pvalue_config_destructor, 1)==FAILURE) {
@@ -236,6 +249,7 @@
 
        zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) 
free_estring, 1);
        zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t)  
ZVAL_DESTRUCTOR, 1);
+       zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) 
+free_estring, 1);
        
        safe_mode_state = PG(safe_mode);
        open_basedir = PG(open_basedir);
@@ -363,25 +377,62 @@
        PG(safe_mode) = safe_mode_state;
        PG(open_basedir) = open_basedir;
 
-       if (!fh.handle.fp) {
-               return SUCCESS;  /* having no configuration file is ok */
-       }
-       fh.type = ZEND_HANDLE_FP;
+       if (fh.handle.fp) {
+               fh.type = ZEND_HANDLE_FP;
 
-       zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
+               zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, 
+&extension_lists);
        
-       {
-               zval tmp;
+               {
+                       zval tmp;
                
-               Z_STRLEN(tmp) = strlen(fh.filename);
-               Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
-               Z_TYPE(tmp) = IS_STRING;
-               zend_hash_update(&configuration_hash, "cfg_file_path", 
sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL);
-               if(php_ini_opened_path) 
-                       efree(php_ini_opened_path);
-               php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
+                       Z_STRLEN(tmp) = strlen(fh.filename);
+                       Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
+                       Z_TYPE(tmp) = IS_STRING;
+                       zend_hash_update(&configuration_hash, "cfg_file_path", 
+sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL);
+                       if(php_ini_opened_path) 
+                               efree(php_ini_opened_path);
+                       php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), 
+Z_STRLEN(tmp));
+               }
+       }       
+
+       /* If the config_file_scan_dir is set at compile-time, go and scan this 
+directory and
+        * parse any .ini files found in this directory. */
+       if(strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
+               dirp = VCWD_OPENDIR(PHP_CONFIG_FILE_SCAN_DIR);
+               if (dirp) {
+                       fh.type = ZEND_HANDLE_FP;
+                       while ((dir_entry = readdir(dirp)) != NULL) {
+                               /* check for a .ini extension */
+                               if ((p = strrchr(dir_entry->d_name,'.')) && 
+strcmp(p,".ini")) continue;
+                               snprintf(ini_file, MAXPATHLEN, "%s%c%s", 
+PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, dir_entry->d_name);
+                               if (VCWD_STAT(ini_file, &sb) == 0) {
+                                       if (S_ISREG(sb.st_mode)) {
+                                               if ((fh.handle.fp = 
+VCWD_FOPEN(ini_file, "r"))) {
+                                                       fh.filename = ini_file;
+                                                       zend_parse_ini_file(&fh, 1, 
+php_config_ini_parser_cb, &extension_lists);
+                                                       /* Here, add it to the list of 
+ini files read */
+                                                       l = strlen(ini_file);
+                                                       total_l += l+2;
+                                                       p = estrndup(ini_file,l); 
+                                                       
+zend_llist_add_element(&scanned_ini_list, &p);
+                                               }
+                                       }
+                               }
+                       }
+                       closedir(dirp);
+                       /* 
+                        * Don't need an extra byte for the \0 in this malloc as the 
+last
+                        * element will not get a trailing , which gives us the byte 
+for the \0
+                        */
+                       php_ini_scanned_files = (char *)malloc(total_l);
+                       *php_ini_scanned_files = '\0';
+                       for (element=scanned_ini_list.head; element; 
+element=element->next) {
+                               strcat(php_ini_scanned_files,*(char **)element->data); 
+         
+                               strcat(php_ini_scanned_files,element->next ? 
+",\n":"\n");
+                       }       
+                       zend_llist_destroy(&scanned_ini_list);
+               }
        }
-       
        return SUCCESS;
 }
 /* }}} */
@@ -393,6 +444,9 @@
        zend_hash_destroy(&configuration_hash);
        if (php_ini_opened_path) {
                free(php_ini_opened_path);
+       }
+       if (php_ini_scanned_files) {
+               free(php_ini_scanned_files);
        }
        return SUCCESS;
 }

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

Reply via email to