summaryrefslogtreecommitdiff
path: root/main/php_ini.c
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>2001-01-02 22:49:31 +0000
committerZeev Suraski <zeev@php.net>2001-01-02 22:49:31 +0000
commitbd0ac7fe14b6f2eb82a2e13a38c3eca5d4fe2e4f (patch)
treeff521b5242f3800f3495220bfdf51f9cf35bbe20 /main/php_ini.c
parent348f6c609c148c2c1f17669dad521fe04cd50a2a (diff)
downloadphp-git-bd0ac7fe14b6f2eb82a2e13a38c3eca5d4fe2e4f.tar.gz
Many patches. I hope I remember them all:
- Make sapi_module available to external modules (PHPAPI) - Make the php.ini path reported in phpinfo() always point to real full path of the php.ini file - Optimized the ISAPI module not to read unnecessary server variables and read necessary variables at most once.
Diffstat (limited to 'main/php_ini.c')
-rw-r--r--main/php_ini.c137
1 files changed, 62 insertions, 75 deletions
diff --git a/main/php_ini.c b/main/php_ini.c
index 8c1b08c40b..0a0fc04bd2 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -24,8 +24,9 @@
#include "ext/standard/dl.h"
#include "zend_extensions.h"
+/* True globals */
static HashTable configuration_hash;
-PHPAPI extern char *php_ini_path;
+PHPAPI char *php_ini_opened_path=NULL;
static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type)
@@ -145,96 +146,79 @@ static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
}
-int php_init_config(void)
+int php_init_config(char *php_ini_path_override)
{
+ char *env_location, *php_ini_search_path;
+ int safe_mode_state;
+ char *open_basedir;
+ int free_ini_search_path=0;
+ zend_file_handle fh;
PLS_FETCH();
if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) {
return FAILURE;
}
-#if USE_CONFIG_FILE
- {
- char *env_location,*default_location,*php_ini_search_path;
- int safe_mode_state = PG(safe_mode);
- char *open_basedir = PG(open_basedir);
- char *opened_path;
- int free_default_location=0;
- zend_file_handle fh;
-
- env_location = getenv("PHPRC");
- if (!env_location) {
- env_location="";
- }
-#ifdef PHP_WIN32
- {
- if (php_ini_path) {
- default_location = php_ini_path;
- } else {
- default_location = (char *) malloc(512);
-
- if (!GetWindowsDirectory(default_location,255)) {
- default_location[0]=0;
- }
- free_default_location=1;
- }
- }
-#else
- if (!php_ini_path) {
- default_location = CONFIGURATION_FILE_PATH;
- } else {
- default_location = php_ini_path;
- }
-#endif
+ safe_mode_state = PG(safe_mode);
+ open_basedir = PG(open_basedir);
-/* build a path */
- php_ini_search_path = (char *) malloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1);
+ env_location = getenv("PHPRC");
+ if (!env_location) {
+ env_location="";
+ }
+ if (php_ini_path_override) {
+ php_ini_search_path = php_ini_path_override;
+ free_ini_search_path = 0;
+ } else {
+ char *default_location;
+ int free_default_location;
- if (!php_ini_path) {
#ifdef PHP_WIN32
- sprintf(php_ini_search_path,".;%s;%s",env_location,default_location);
+ default_location = (char *) emalloc(512);
+
+ if (!GetWindowsDirectory(default_location,255)) {
+ default_location[0]=0;
+ }
+ free_default_location=1;
#else
- sprintf(php_ini_search_path,".:%s:%s",env_location,default_location);
+ default_location = CONFIGURATION_FILE_PATH;
+ free_default_location=0;
#endif
- } else {
- /* if path was set via -c flag, only look there */
- strcpy(php_ini_search_path,default_location);
- }
- PG(safe_mode) = 0;
- PG(open_basedir) = NULL;
-
-
- fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path);
- free(php_ini_search_path);
+ php_ini_search_path = (char *) emalloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1);
+ free_ini_search_path = 1;
+ sprintf(php_ini_search_path, ".%c%s%c%s", ZEND_PATHS_SEPARATOR, env_location, ZEND_PATHS_SEPARATOR, default_location);
if (free_default_location) {
- free(default_location);
- }
- 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;
- fh.filename = opened_path;
-
- zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, NULL);
-
- if (opened_path) {
- zval tmp;
-
- tmp.value.str.val = strdup(opened_path);
- tmp.value.str.len = strlen(opened_path);
- tmp.type = IS_STRING;
- zend_hash_update(&configuration_hash,"cfg_file_path",sizeof("cfg_file_path"),(void *) &tmp,sizeof(zval),NULL);
-#if DEBUG_CFG_PARSER
- php_printf("INI file opened at '%s'\n",opened_path);
-#endif
- efree(opened_path);
+ efree(default_location);
}
}
+
+ PG(safe_mode) = 0;
+ PG(open_basedir) = NULL;
-#endif
+ fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path);
+ 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 SUCCESS; /* having no configuration file is ok */
+ }
+ fh.type = ZEND_HANDLE_FP;
+ fh.filename = php_ini_opened_path;
+
+ zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, NULL);
+
+ if (php_ini_opened_path) {
+ zval tmp;
+
+ tmp.value.str.len = strlen(php_ini_opened_path);
+ tmp.value.str.val = zend_strndup(php_ini_opened_path, tmp.value.str.len);
+ tmp.type = IS_STRING;
+ zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"),(void *) &tmp,sizeof(zval), NULL);
+ persist_alloc(php_ini_opened_path);
+ }
return SUCCESS;
}
@@ -243,6 +227,9 @@ int php_init_config(void)
int php_shutdown_config(void)
{
zend_hash_destroy(&configuration_hash);
+ if (php_ini_opened_path) {
+ efree(php_ini_opened_path);
+ }
return SUCCESS;
}