diff options
author | Zeev Suraski <zeev@php.net> | 1999-04-09 19:09:29 +0000 |
---|---|---|
committer | Zeev Suraski <zeev@php.net> | 1999-04-09 19:09:29 +0000 |
commit | 3e584505132e6cb161bfdd1d86d75609ebee7564 (patch) | |
tree | fcee61763fa7c575bf84ba31525c9f2868b02de2 /main/php_ini.c | |
parent | 5cb576d81a53da011b76b0b0e376dc7dafa1a529 (diff) | |
download | php-git-3e584505132e6cb161bfdd1d86d75609ebee7564.tar.gz |
* A lot of work on php_ini stuff
* A lot of work on getting rid from php3_ini
Diffstat (limited to 'main/php_ini.c')
-rw-r--r-- | main/php_ini.c | 130 |
1 files changed, 118 insertions, 12 deletions
diff --git a/main/php_ini.c b/main/php_ini.c index 163021bd86..757dd8217d 100644 --- a/main/php_ini.c +++ b/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; +} |