mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
* A lot of work on php_ini stuff
* A lot of work on getting rid from php3_ini
This commit is contained in:
73
main/main.c
73
main/main.c
@@ -63,6 +63,7 @@
|
||||
#endif
|
||||
#include "zend.h"
|
||||
#include "php_ini.h"
|
||||
#include "php_globals.h"
|
||||
#include "main.h"
|
||||
#include "control_structures.h"
|
||||
#include "fopen-wrappers.h"
|
||||
@@ -104,6 +105,10 @@ int compiler_globals_id;
|
||||
int executor_globals_id;
|
||||
#endif
|
||||
|
||||
#ifndef ZTS
|
||||
php_core_globals core_globals;
|
||||
#endif
|
||||
|
||||
void *gLock; /*mutex variable */
|
||||
|
||||
|
||||
@@ -115,6 +120,34 @@ void *gLock; /*mutex variable */
|
||||
HashTable configuration_hash;
|
||||
char *php3_ini_path = NULL;
|
||||
|
||||
PHP_INI_MH(OnSetPrecision)
|
||||
{
|
||||
ELS_FETCH();
|
||||
|
||||
EG(precision) = atoi(new_value);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
PHP_INI_BEGIN()
|
||||
PHP_INI_ENTRY("short_open_tag", "1", PHP_INI_ALL, NULL, NULL)
|
||||
PHP_INI_ENTRY("asp_tags", "0", PHP_INI_ALL, NULL, NULL)
|
||||
PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision, NULL)
|
||||
|
||||
PHP_INI_ENTRY("highlight.comment", HL_COMMENT_COLOR, PHP_INI_ALL, NULL, NULL)
|
||||
PHP_INI_ENTRY("highlight.default", HL_DEFAULT_COLOR, PHP_INI_ALL, NULL, NULL)
|
||||
PHP_INI_ENTRY("highlight.html", HL_HTML_COLOR, PHP_INI_ALL, NULL, NULL)
|
||||
PHP_INI_ENTRY("highlight.string", HL_STRING_COLOR, PHP_INI_ALL, NULL, NULL)
|
||||
PHP_INI_ENTRY("highlight.bg", HL_BG_COLOR, PHP_INI_ALL, NULL, NULL)
|
||||
PHP_INI_ENTRY("highlight.keyword", HL_KEYWORD_COLOR, PHP_INI_ALL, NULL, NULL)
|
||||
|
||||
PHP_INI_ENTRY("magic_quotes_gpc", "1", PHP_INI_ALL, OnUpdateInt, (void *) XtOffsetOf(php_core_globals, magic_quotes_gpc))
|
||||
PHP_INI_ENTRY("magic_quotes_runtime", "0", PHP_INI_ALL, OnUpdateInt, (void *) XtOffsetOf(php_core_globals, magic_quotes_runtime))
|
||||
PHP_INI_ENTRY("magic_quotes_sybase", "0", PHP_INI_ALL, OnUpdateInt, (void *) XtOffsetOf(php_core_globals, magic_quotes_sybase))
|
||||
PHP_INI_END()
|
||||
|
||||
|
||||
|
||||
#ifndef THREAD_SAFE
|
||||
/*
|
||||
* Globals yet to be protected
|
||||
@@ -534,7 +567,6 @@ int php3_request_startup(CLS_D ELS_DC)
|
||||
EG(error_reporting) = php3_ini.errors;
|
||||
GLOBAL(header_is_being_sent) = 0;
|
||||
GLOBAL(php3_track_vars) = php3_ini.track_vars;
|
||||
EG(precision) = php3_ini.precision;
|
||||
}
|
||||
|
||||
if (php3_init_request_info((void *) &php3_ini)) {
|
||||
@@ -696,9 +728,6 @@ static int php3_config_ini_startup(ELS_D)
|
||||
if (cfg_get_long("memory_limit", &php3_ini.memory_limit) == FAILURE) {
|
||||
php3_ini.memory_limit = 1<<23; /* 8MB */
|
||||
}
|
||||
if (cfg_get_long("precision", &php3_ini.precision) == FAILURE) {
|
||||
php3_ini.precision = 14;
|
||||
}
|
||||
if (cfg_get_string("SMTP", &php3_ini.smtp) == FAILURE) {
|
||||
php3_ini.smtp = "localhost";
|
||||
}
|
||||
@@ -733,15 +762,6 @@ static int php3_config_ini_startup(ELS_D)
|
||||
if (cfg_get_long("warn_plus_overloading", &php3_ini.warn_plus_overloading) == FAILURE) {
|
||||
php3_ini.warn_plus_overloading = 0;
|
||||
}
|
||||
if (cfg_get_long("magic_quotes_gpc", &php3_ini.magic_quotes_gpc) == FAILURE) {
|
||||
php3_ini.magic_quotes_gpc = MAGIC_QUOTES;
|
||||
}
|
||||
if (cfg_get_long("magic_quotes_runtime", &php3_ini.magic_quotes_runtime) == FAILURE) {
|
||||
php3_ini.magic_quotes_runtime = MAGIC_QUOTES;
|
||||
}
|
||||
if (cfg_get_long("magic_quotes_sybase", &php3_ini.magic_quotes_sybase) == FAILURE) {
|
||||
php3_ini.magic_quotes_sybase = 0;
|
||||
}
|
||||
if (cfg_get_long("y2k_compliance", &php3_ini.y2k_compliance) == FAILURE) {
|
||||
php3_ini.y2k_compliance = 0;
|
||||
}
|
||||
@@ -815,25 +835,6 @@ static int php3_config_ini_startup(ELS_D)
|
||||
if (cfg_get_long("sql.safe_mode", &php3_ini.sql_safe_mode) == FAILURE) {
|
||||
php3_ini.sql_safe_mode = 0;
|
||||
}
|
||||
/* Syntax highlighting */
|
||||
if (cfg_get_string("highlight.comment", &php3_ini.highlight_comment) == FAILURE) {
|
||||
php3_ini.highlight_comment = HL_COMMENT_COLOR;
|
||||
}
|
||||
if (cfg_get_string("highlight.default", &php3_ini.highlight_default) == FAILURE) {
|
||||
php3_ini.highlight_default = HL_DEFAULT_COLOR;
|
||||
}
|
||||
if (cfg_get_string("highlight.html", &php3_ini.highlight_html) == FAILURE) {
|
||||
php3_ini.highlight_html = HL_HTML_COLOR;
|
||||
}
|
||||
if (cfg_get_string("highlight.string", &php3_ini.highlight_string) == FAILURE) {
|
||||
php3_ini.highlight_string = HL_STRING_COLOR;
|
||||
}
|
||||
if (cfg_get_string("highlight.bg", &php3_ini.highlight_bg) == FAILURE) {
|
||||
php3_ini.highlight_bg = HL_BG_COLOR;
|
||||
}
|
||||
if (cfg_get_string("highlight.keyword", &php3_ini.highlight_keyword) == FAILURE) {
|
||||
php3_ini.highlight_keyword = HL_KEYWORD_COLOR;
|
||||
}
|
||||
if (cfg_get_long("engine", &php3_ini.engine) == FAILURE) {
|
||||
php3_ini.engine = 1;
|
||||
}
|
||||
@@ -890,6 +891,7 @@ int php3_module_startup(CLS_D ELS_DC)
|
||||
{
|
||||
zend_utility_functions zuf;
|
||||
zend_utility_values zuv;
|
||||
int module_number=0; /* for REGISTER_INI_ENTRIES() */
|
||||
|
||||
#if (WIN32|WINNT) && !(USE_SAPI)
|
||||
WORD wVersionRequested;
|
||||
@@ -917,8 +919,6 @@ int php3_module_startup(CLS_D ELS_DC)
|
||||
|
||||
zend_startup(&zuf, &zuv, NULL);
|
||||
|
||||
php_ini_mstartup();
|
||||
|
||||
#if HAVE_SETLOCALE
|
||||
setlocale(LC_CTYPE, "");
|
||||
#endif
|
||||
@@ -948,6 +948,9 @@ int php3_module_startup(CLS_D ELS_DC)
|
||||
}
|
||||
#endif
|
||||
|
||||
php_ini_mstartup();
|
||||
REGISTER_INI_ENTRIES();
|
||||
|
||||
if (module_startup_modules() == FAILURE) {
|
||||
php3_printf("Unable to start modules\n");
|
||||
return FAILURE;
|
||||
@@ -964,6 +967,7 @@ void php3_module_shutdown_for_exec(void)
|
||||
|
||||
void php3_module_shutdown()
|
||||
{
|
||||
int module_number=0; /* for UNREGISTER_INI_ENTRIES() */
|
||||
CLS_FETCH();
|
||||
ELS_FETCH();
|
||||
|
||||
@@ -991,6 +995,7 @@ void php3_module_shutdown()
|
||||
#endif
|
||||
|
||||
zend_shutdown();
|
||||
UNREGISTER_INI_ENTRIES();
|
||||
php_ini_mshutdown();
|
||||
shutdown_memory_manager(0, 1);
|
||||
}
|
||||
|
||||
33
main/php.h
33
main/php.h
@@ -475,6 +475,39 @@ extern int yylineno;
|
||||
#endif
|
||||
extern void phprestart(FILE *input_file);
|
||||
|
||||
|
||||
/* Finding offsets of elements within structures.
|
||||
* Taken from the Apache code, which in turn, was taken from X code...
|
||||
*/
|
||||
|
||||
#if defined(CRAY) || (defined(__arm) && !defined(LINUX))
|
||||
#ifdef __STDC__
|
||||
#define XtOffset(p_type,field) _Offsetof(p_type,field)
|
||||
#else
|
||||
#ifdef CRAY2
|
||||
#define XtOffset(p_type,field) \
|
||||
(sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
|
||||
|
||||
#else /* !CRAY2 */
|
||||
|
||||
#define XtOffset(p_type,field) ((unsigned int)&(((p_type)NULL)->field))
|
||||
|
||||
#endif /* !CRAY2 */
|
||||
#endif /* __STDC__ */
|
||||
#else /* ! (CRAY || __arm) */
|
||||
|
||||
#define XtOffset(p_type,field) \
|
||||
((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
|
||||
|
||||
#endif /* !CRAY */
|
||||
|
||||
#ifdef offsetof
|
||||
#define XtOffsetOf(s_type,field) offsetof(s_type,field)
|
||||
#else
|
||||
#define XtOffsetOf(s_type,field) XtOffset(s_type*,field)
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
130
main/php_ini.c
130
main/php_ini.c
@@ -3,6 +3,7 @@
|
||||
#include "php.h"
|
||||
#include "php_ini.h"
|
||||
#include "zend_alloc.h"
|
||||
#include "php_globals.h"
|
||||
|
||||
static HashTable known_directives;
|
||||
|
||||
@@ -20,7 +21,7 @@ static int php_remove_ini_entries(php_ini_entry *ini_entry, int *module_number)
|
||||
}
|
||||
|
||||
|
||||
static int php_restore_ini_entry(php_ini_entry *ini_entry)
|
||||
static int php_restore_ini_entry_cb(php_ini_entry *ini_entry)
|
||||
{
|
||||
if (ini_entry->modified) {
|
||||
efree(ini_entry->value);
|
||||
@@ -52,7 +53,7 @@ int php_ini_mshutdown()
|
||||
|
||||
int php_ini_rshutdown()
|
||||
{
|
||||
_php3_hash_apply(&known_directives, (int (*)(void *)) php_restore_ini_entry);
|
||||
_php3_hash_apply(&known_directives, (int (*)(void *)) php_restore_ini_entry_cb);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -74,7 +75,7 @@ int php_register_ini_entries(php_ini_entry *ini_entry, int module_number)
|
||||
}
|
||||
if ((default_value=cfg_get_entry(p->name, p->name_length))) {
|
||||
if (!hashed_ini_entry->on_modify
|
||||
|| hashed_ini_entry->on_modify(hashed_ini_entry, default_value->value.str.val, default_value->value.str.len)==SUCCESS) {
|
||||
|| hashed_ini_entry->on_modify(hashed_ini_entry, default_value->value.str.val, default_value->value.str.len, hashed_ini_entry->mh_arg)==SUCCESS) {
|
||||
hashed_ini_entry->value = default_value->value.str.val;
|
||||
hashed_ini_entry->value_length = default_value->value.str.len;
|
||||
}
|
||||
@@ -91,6 +92,7 @@ void php_unregister_ini_entries(int module_number)
|
||||
_php3_hash_apply_with_argument(&known_directives, (int (*)(void *, void *)) php_remove_ini_entries, (void *) &module_number);
|
||||
}
|
||||
|
||||
|
||||
int php_alter_ini_entry(char *name, uint name_length, char *new_value, uint new_value_length, int modify_type)
|
||||
{
|
||||
php_ini_entry *ini_entry;
|
||||
@@ -103,49 +105,153 @@ int php_alter_ini_entry(char *name, uint name_length, char *new_value, uint new_
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
ini_entry->value = estrndup(new_value, new_value_length);
|
||||
ini_entry->value_length = new_value_length;
|
||||
ini_entry->modified = 1;
|
||||
if (!ini_entry->on_modify
|
||||
|| ini_entry->on_modify(ini_entry, new_value, new_value_length, ini_entry->mh_arg)==SUCCESS) {
|
||||
if (!ini_entry->orig_value) {
|
||||
ini_entry->orig_value = ini_entry->value;
|
||||
ini_entry->orig_value_length = ini_entry->value_length;
|
||||
} else { /* we already changed the value, free the changed value */
|
||||
efree(ini_entry->value);
|
||||
}
|
||||
ini_entry->value = estrndup(new_value, new_value_length);
|
||||
ini_entry->value_length = new_value_length;
|
||||
ini_entry->modified = 1;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int php_restore_ini_entry(char *name, uint name_length)
|
||||
{
|
||||
php_ini_entry *ini_entry;
|
||||
|
||||
if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==FAILURE) {
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if (ini_entry->orig_value) {
|
||||
ini_entry->value = ini_entry->orig_value;
|
||||
ini_entry->value_length = ini_entry->orig_value_length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Data retrieval
|
||||
*/
|
||||
|
||||
long php_ini_long(char *name, uint name_length)
|
||||
long php_ini_long(char *name, uint name_length, int orig)
|
||||
{
|
||||
php_ini_entry *ini_entry;
|
||||
|
||||
if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) {
|
||||
return (long) atoi(ini_entry->value);
|
||||
if (orig) {
|
||||
if (ini_entry->orig_value) {
|
||||
return (long) atoi(ini_entry->orig_value);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return (long) atoi(ini_entry->value);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
double php_ini_double(char *name, uint name_length)
|
||||
double php_ini_double(char *name, uint name_length, int orig)
|
||||
{
|
||||
php_ini_entry *ini_entry;
|
||||
|
||||
if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) {
|
||||
return (double) strtod(ini_entry->value, NULL);
|
||||
if (orig) {
|
||||
if (ini_entry->orig_value) {
|
||||
return (double) strtod(ini_entry->orig_value, NULL);
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
} else {
|
||||
return (double) strtod(ini_entry->value, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
char *php_ini_string(char *name, uint name_length)
|
||||
char *php_ini_string(char *name, uint name_length, int orig)
|
||||
{
|
||||
php_ini_entry *ini_entry;
|
||||
|
||||
if (_php3_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==SUCCESS) {
|
||||
return ini_entry->value;
|
||||
if (orig) {
|
||||
return ini_entry->orig_value;
|
||||
} else {
|
||||
return ini_entry->value;
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Standard message handlers for core_globals */
|
||||
|
||||
PHP_INI_MH(OnUpdateInt)
|
||||
{
|
||||
long *p;
|
||||
#ifndef ZTS
|
||||
char *base = (char *) &core_globals;
|
||||
#else
|
||||
char *base;
|
||||
PLS_FETCH();
|
||||
|
||||
base = (char *) core_globals;
|
||||
#endif
|
||||
|
||||
p = (long *) (base+(size_t) mh_arg);
|
||||
|
||||
*p = atoi(new_value);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
PHP_INI_MH(OnUpdateReal)
|
||||
{
|
||||
double *p;
|
||||
#ifndef ZTS
|
||||
char *base = (char *) &core_globals;
|
||||
#else
|
||||
char *base;
|
||||
PLS_FETCH();
|
||||
|
||||
base = (char *) core_globals;
|
||||
#endif
|
||||
|
||||
p = (double *) (base+(size_t) mh_arg);
|
||||
|
||||
*p = strtod(new_value, NULL);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
PHP_INI_MH(OnUpdateString)
|
||||
{
|
||||
char **p;
|
||||
#ifndef ZTS
|
||||
char *base = (char *) &core_globals;
|
||||
#else
|
||||
char *base;
|
||||
PLS_FETCH();
|
||||
|
||||
base = (char *) core_globals;
|
||||
#endif
|
||||
|
||||
p = (char **) (base+(size_t) mh_arg);
|
||||
|
||||
*p = new_value;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@@ -10,12 +10,15 @@
|
||||
|
||||
typedef struct _php_ini_entry php_ini_entry;
|
||||
|
||||
#define PHP_INI_MH(name) int name(php_ini_entry *entry, char *new_value, uint new_value_length, void *mh_arg)
|
||||
|
||||
struct _php_ini_entry {
|
||||
int module_number;
|
||||
int modifyable;
|
||||
char *name;
|
||||
uint name_length;
|
||||
int (*on_modify)(php_ini_entry *entry, char *new_value, uint new_value_length);
|
||||
PHP_INI_MH((*on_modify));
|
||||
void *mh_arg;
|
||||
|
||||
char *value;
|
||||
uint value_length;
|
||||
@@ -33,22 +36,28 @@ int php_ini_rshutdown();
|
||||
int php_register_ini_entries(php_ini_entry *ini_entry, int module_number);
|
||||
void php_unregister_ini_entries(int module_number);
|
||||
int php_alter_ini_entry(char *name, uint name_length, char *new_value, uint new_value_length, int modify_type);
|
||||
int php_restore_ini_entry(char *name, uint name_length);
|
||||
|
||||
long php_ini_long(char *name, uint name_length);
|
||||
double php_ini_double(char *name, uint name_length);
|
||||
char *php_ini_string(char *name, uint name_length);
|
||||
long php_ini_long(char *name, uint name_length, int orig);
|
||||
double php_ini_double(char *name, uint name_length, int orig);
|
||||
char *php_ini_string(char *name, uint name_length, int orig);
|
||||
|
||||
#define PHP_INI_BEGIN() static php_ini_entry ini_entries[] = {
|
||||
|
||||
#define PHP_INI_ENTRY(name, default_value, modifyable, on_modify) \
|
||||
{ 0, modifyable, name, sizeof(name), on_modify, default_value, sizeof(default_value)-1, NULL, 0, 0 },
|
||||
#define PHP_INI_ENTRY(name, default_value, modifyable, on_modify, ptr) \
|
||||
{ 0, modifyable, name, sizeof(name), on_modify, ptr, default_value, sizeof(default_value)-1, NULL, 0, 0 },
|
||||
|
||||
#define PHP_INI_END() \
|
||||
{ 0, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0 } };
|
||||
{ 0, 0, NULL, 0, NULL, NULL, NULL, 0, NULL, 0, 0 } };
|
||||
|
||||
#define INI_INT(name) php_ini_long((name), sizeof(name))
|
||||
#define INI_FLT(name) php_ini_double((name), sizeof(name))
|
||||
#define INI_STR(name) php_ini_string((name), sizeof(name))
|
||||
#define INI_INT(name) php_ini_long((name), sizeof(name), 0)
|
||||
#define INI_FLT(name) php_ini_double((name), sizeof(name), 0)
|
||||
#define INI_STR(name) php_ini_string((name), sizeof(name), 0)
|
||||
|
||||
|
||||
#define INI_ORIG_INT(name) php_ini_long((name), sizeof(name), 1)
|
||||
#define INI_ORIG_FLT(name) php_ini_double((name), sizeof(name), 1)
|
||||
#define INI_ORIG_STR(name) php_ini_string((name), sizeof(name), 1)
|
||||
|
||||
|
||||
#define REGISTER_INI_ENTRIES() php_register_ini_entries(ini_entries, module_number)
|
||||
@@ -56,4 +65,10 @@ char *php_ini_string(char *name, uint name_length);
|
||||
|
||||
pval *cfg_get_entry(char *name, uint name_length);
|
||||
|
||||
|
||||
/* Standard message handlers */
|
||||
PHP_INI_MH(OnUpdateInt);
|
||||
PHP_INI_MH(OnUpdateReal);
|
||||
PHP_INI_MH(OnUpdateString);
|
||||
|
||||
#endif /* _PHP_INI_H */
|
||||
|
||||
12
mod_php3.h
12
mod_php3.h
@@ -41,11 +41,7 @@ typedef struct {
|
||||
char *smtp; /*win 32 only*/
|
||||
char *sendmail_path;
|
||||
char *sendmail_from; /*win 32 only*/
|
||||
long precision;
|
||||
long errors;
|
||||
long magic_quotes_gpc;
|
||||
long magic_quotes_runtime;
|
||||
long magic_quotes_sybase;
|
||||
long track_errors;
|
||||
long display_errors;
|
||||
long log_errors;
|
||||
@@ -66,15 +62,7 @@ typedef struct {
|
||||
char *extension_dir;
|
||||
long short_open_tag;
|
||||
long asp_tags;
|
||||
char *debugger_host;
|
||||
long debugger_port;
|
||||
char *error_log;
|
||||
char *highlight_comment;
|
||||
char *highlight_default;
|
||||
char *highlight_html;
|
||||
char *highlight_string;
|
||||
char *highlight_bg;
|
||||
char *highlight_keyword;
|
||||
long sql_safe_mode;
|
||||
long xbithack;
|
||||
long engine;
|
||||
|
||||
Reference in New Issue
Block a user