summaryrefslogtreecommitdiff
path: root/main
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
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')
-rw-r--r--main/SAPI.c2
-rw-r--r--main/SAPI.h6
-rw-r--r--main/main.c13
-rw-r--r--main/php_ini.c137
-rw-r--r--main/php_ini.h2
5 files changed, 69 insertions, 91 deletions
diff --git a/main/SAPI.c b/main/SAPI.c
index eba50440dd..fb7b073d93 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -54,7 +54,7 @@ static void sapi_globals_ctor(sapi_globals_struct *sapi_globals)
}
/* True globals (no need for thread safety) */
-sapi_module_struct sapi_module;
+SAPI_API sapi_module_struct sapi_module;
SAPI_API void (*sapi_error)(int error_type, const char *message, ...);
diff --git a/main/SAPI.h b/main/SAPI.h
index 9d7c70ac79..4e9ada0278 100644
--- a/main/SAPI.h
+++ b/main/SAPI.h
@@ -57,7 +57,7 @@ typedef struct _sapi_post_entry sapi_post_entry;
typedef struct _sapi_module_struct sapi_module_struct;
-extern sapi_module_struct sapi_module; /* true global */
+extern SAPI_API sapi_module_struct sapi_module; /* true global */
/* Some values in this structure needs to be filled in before
* calling sapi_activate(). We WILL change the `char *' entries,
@@ -188,6 +188,8 @@ struct _sapi_module_struct {
void (*register_server_variables)(zval *track_vars_array ELS_DC SLS_DC PLS_DC);
void (*log_message)(char *message);
+ char *php_ini_path_override;
+
void (*block_interruptions)(void);
void (*unblock_interruptions)(void);
@@ -222,7 +224,7 @@ struct _sapi_post_entry {
SAPI_POST_READER_FUNC(sapi_read_standard_form_data);
SAPI_POST_READER_FUNC(php_default_post_reader);
-#define STANDARD_SAPI_MODULE_PROPERTIES NULL
+#define STANDARD_SAPI_MODULE_PROPERTIES NULL, NULL
#endif /* SAPI_H */
diff --git a/main/main.c b/main/main.c
index 8eacdaa7fa..aa6423b122 100644
--- a/main/main.c
+++ b/main/main.c
@@ -106,8 +106,6 @@ void *gLock; /*mutex variable */
/* True globals (no need for thread safety) */
HashTable configuration_hash;
-PHPAPI char *php_ini_path = NULL;
-
#define SAFE_FILENAME(f) ((f)?(f):"-")
@@ -700,15 +698,6 @@ void php_request_shutdown(void *dummy)
}
}
-
-static int php_config_ini_startup(void)
-{
- if (php_init_config() == FAILURE) {
- php_printf("PHP: Unable to parse configuration file.\n");
- return FAILURE;
- }
- return SUCCESS;
-}
static void php_config_ini_shutdown(void)
{
@@ -860,7 +849,7 @@ int php_module_startup(sapi_module_struct *sf)
le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
FREE_MUTEX(gLock);
- if (php_config_ini_startup() == FAILURE) {
+ if (php_init_config(sf->php_ini_path_override) == FAILURE) {
return FAILURE;
}
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;
}
diff --git a/main/php_ini.h b/main/php_ini.h
index cd1b2b00a6..d7aa475d68 100644
--- a/main/php_ini.h
+++ b/main/php_ini.h
@@ -21,7 +21,7 @@
#include "zend_ini.h"
-int php_init_config(void);
+int php_init_config(char *php_ini_path_override);
int php_shutdown_config(void);
#define PHP_INI_USER ZEND_INI_USER