I have created a patch for two new .ini directives: include_ini = <filename> ; relative or full path include_ini_dir = <full directory path>
The patch is only in php_ini.c and does the following: Added 2 new static zend_llist: include_ini_list & include_ini_dir_list Add a case for include_ini and include_ini_dir in function php_config_ini_parser_cb. This new cases just add items to the static lists. Added three new functions: php_include_ini_load - Loads a .ini file from a passed in name (may be full path) php_include_ini_function_cb - callback loop over include_ini_list, which calls php_include_ini_load php_include_ini_dir_function_cb - callback loop over include_ini_dir_list, which calls php_include_ini_load on each file in a directory. In function php_init_config the new llist are init'ed and after zend_parse_ini_file is called, a loop is started until both include_ini_list and include_ini_dir_list are empty: loop over each item in include_ini_list calling php_include_ini_function_cb empting include_ini_list loop over each item in include_ini_dir_list calling php_include_ini_dir_function_cb empting include_ini_dir_list I am assumming that in the middle of a zend_llist_apply call if something is added to the llist, that item get the function applied to it? Right? Problems: I don't know how well this will work on Windows machines. The new php_include_ini_load is a hacked version of php_init_config and doesn't rely on paths from the commend line for searching. I would like some help to fix up this functions. include_ini_dir has to be the full path. I didn't know the best way to find the directory from the search path like how the php_fopen_with_path does it (so I just make it work with full paths). Please tell me how to do this so I can use the search paths and relative directories names. Yes, it is based off of the 4.2.3 release, but I am looking for more input on fixing current problems then getting into the next release. Cheers, Brian --- php-4.2.3.org/main/php_ini.c Mon Mar 4 16:21:28 2002 +++ php-4.2.3/main/php_ini.c Wed Sep 11 17:10:42 2002 @@ -41,6 +41,8 @@ static HashTable configuration_hash; PHPAPI char *php_ini_opened_path=NULL; static php_extension_lists extension_lists; +static zend_llist include_ini_list; +static zend_llist include_ini_dir_list; /* {{{ php_ini_displayer_cb */ @@ -166,6 +168,14 @@ char *extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)); zend_llist_add_element(&extension_lists.engine, &extension_name); + } else if (!strcasecmp(Z_STRVAL_P(arg1), "include_ini")) { + char *ini_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)); + zend_llist_add_element( &include_ini_list, &ini_name ); + fprintf(stderr, "got include_ini = %s\n", Z_STRVAL_P(arg2) ); + } else if (!strcasecmp(Z_STRVAL_P(arg1), "include_ini_dir")) { + char *ini_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)); + zend_llist_add_element( &include_ini_dir_list, &ini_name ); + fprintf(stderr, "got include_ini_dir = %s\n", Z_STRVAL_P(arg2) ); } else { zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, arg2, sizeof(zval), (void **) &entry); Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry)); @@ -178,6 +188,147 @@ } /* }}} */ + +static void php_include_ini_load( char *ini_file ) +{ + char *env_location, *php_ini_search_path; + int safe_mode_state; + char *open_basedir; + char *php_include_ini_opened_path = NULL; + int free_ini_search_path=0; + zend_file_handle fh; + TSRMLS_FETCH(); + + fprintf( stderr, "php_include_ini_function_cb: %s\n", ini_file ); + + safe_mode_state = PG(safe_mode); + open_basedir = PG(open_basedir); + + env_location = getenv("PHPRC"); + if (!env_location) { + env_location=""; + } + if (0) { + //php_ini_search_path = php_ini_path_override; + // free_ini_search_path = 0; + } else { + char *default_location; + int free_default_location; + +#ifdef PHP_WIN32 + default_location = (char *) emalloc(512); + + if (!GetWindowsDirectory(default_location, 255)) { + default_location[0]=0; + } + free_default_location=1; +#else + default_location = PHP_CONFIG_FILE_PATH; + free_default_location=0; +#endif + php_ini_search_path = (char *) emalloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1); + free_ini_search_path = 1; + if (strcmp(sapi_module.name, "cli")==0) { + if(env_location && env_location[0]) { + sprintf(php_ini_search_path, "%s%c%s", env_location, ZEND_PATHS_SEPARATOR, default_location); + } else { + sprintf(php_ini_search_path, "%s", default_location); + } + } else { + if(env_location && env_location[0]) { + sprintf(php_ini_search_path, ".%c%s%c%s", ZEND_PATHS_SEPARATOR, env_location, ZEND_PATHS_SEPARATOR, default_location); + } else { + sprintf(php_ini_search_path, ".%c%s", ZEND_PATHS_SEPARATOR, default_location); + } + } + if (free_default_location) { + efree(default_location); + } + } + + PG(safe_mode) = 0; + PG(open_basedir) = NULL; + + fh.handle.fp = php_fopen_with_path(ini_file, "r", php_ini_search_path, &php_include_ini_opened_path TSRMLS_CC); + if (free_ini_search_path) { + efree(php_ini_search_path); + } + PG(safe_mode) = safe_mode_state; + PG(open_basedir) = open_basedir; + + if (!fh.handle.fp) { + return; + } + fh.type = ZEND_HANDLE_FP; + fh.filename = php_include_ini_opened_path; + + zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists); + + if (php_ini_opened_path) { + efree(php_include_ini_opened_path); + } +} + +/* {{{ + */ +static void php_include_ini_function_cb(void *arg TSRMLS_DC) +{ + char *ini_file = Z_STRVAL_P( (zval *)arg ); + php_include_ini_load( ini_file ); +} +/* }}} */ + +/* {{{ + */ +static void php_include_ini_dir_function_cb(void *arg TSRMLS_DC) +{ + char *ini_dir = Z_STRVAL_P( (zval *)arg ); + + DIR *dirp; + struct dirent *dir_entry; + zval *entry; + zend_llist file_list; + fprintf( stderr, "php_include_ini_dir_function_cb : %s\n", ini_dir ); + + /* + * first course of business is to grok all the directory + * entries here and store 'em away. Recall we need full pathnames + * for this. + */ + dirp = opendir( ini_dir ); + + if (dirp == NULL) { + fprintf(stderr, "%s: could not open config directory %s\n", ini_dir ); + return; + } + + zend_llist_init(&file_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1); + + while ( (dir_entry = readdir(dirp)) != NULL) { + + if (strcmp(dir_entry->d_name, ".") && strcmp(dir_entry->d_name, "..")) { + + char *file_name = (char *)emalloc( strlen(ini_dir) + dir_entry->d_name + 3); + + /*** ZEND_PATHS_SEPARATOR is defined, but not no ZEND_DIR_SEPARATOR ***/ + sprintf(file_name, "%s%c%s", ini_dir, '/', dir_entry->d_name); + + zend_llist_add_element(&file_list, &file_name); + } + } + closedir(dirp); + + entry = zend_llist_get_first(&file_list); + while (entry != NULL ) { + php_include_ini_load( Z_STRVAL_P( entry ) ); + entry = zend_llist_get_next(&file_list); + } + + /** do I need to do a clean? **/ + zend_llist_clean( &file_list ); +} +/* }}} */ + /* {{{ php_load_function_extension_cb */ static void php_load_function_extension_cb(void *arg TSRMLS_DC) @@ -214,6 +365,9 @@ 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(&include_ini_list, sizeof(char *), (llist_dtor_func_t)free_estring, 1); + zend_llist_init(&include_ini_dir_list, sizeof(char *), (llist_dtor_func_t)free_estring, 1); safe_mode_state = PG(safe_mode); open_basedir = PG(open_basedir); @@ -277,6 +431,14 @@ fh.filename = php_ini_opened_path; zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists); + + while ( zend_llist_count( &include_ini_list ) || zend_llist_count( &include_ini_dir_list ) ) { + zend_llist_apply(&include_ini_list, php_include_ini_function_cb TSRMLS_CC); + zend_llist_clean(&include_ini_list ); + + zend_llist_apply(&include_ini_dir_list, php_include_ini_dir_function_cb TSRMLS_CC); + zend_llist_clean(&include_ini_dir_list ); + } if (php_ini_opened_path) { zval tmp; -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php