diff --git a/main/main.c b/main/main.c index 1fd82c8398203..563f417c1cdad 100644 --- a/main/main.c +++ b/main/main.c @@ -2252,6 +2252,12 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod } #endif + /* Activate SAPI specific section. */ + if (php_ini_has_per_sapi_config() && sapi_module.name) { + /* Activate per-sapi-system-configuration defined in php.ini and stored into configuration_hash during startup */ + php_ini_activate_per_sapi_config(sapi_module.name, strlen(sapi_module.name) + 1 TSRMLS_CC); + } + #ifdef ZTS zend_post_startup(TSRMLS_C); #endif diff --git a/main/php_ini.c b/main/php_ini.c index 444b4ce844305..a39a86f9aae1b 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -65,6 +65,7 @@ typedef struct _php_extension_lists { static int is_special_section = 0; static HashTable *active_ini_hash; static HashTable configuration_hash; +static int has_per_sapi_config = 0; static int has_per_dir_config = 0; static int has_per_host_config = 0; PHPAPI char *php_ini_opened_path=NULL; @@ -282,8 +283,17 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t char *key = NULL; uint key_len; + /* SAPI sections */ + if (!strncasecmp(Z_STRVAL_P(arg1), "SAPI", sizeof("SAPI") - 1)) { + key = Z_STRVAL_P(arg1); + key = key + sizeof("SAPI") - 1; + key_len = Z_STRLEN_P(arg1) - sizeof("SAPI") + 1; + is_special_section = 1; + has_per_sapi_config = 1; + zend_str_tolower(key, key_len); /* sapi names are lower-case. */ + /* PATH sections */ - if (!strncasecmp(Z_STRVAL_P(arg1), "PATH", sizeof("PATH") - 1)) { + } else if (!strncasecmp(Z_STRVAL_P(arg1), "PATH", sizeof("PATH") - 1)) { key = Z_STRVAL_P(arg1); key = key + sizeof("PATH") - 1; key_len = Z_STRLEN_P(arg1) - sizeof("PATH") + 1; @@ -840,6 +850,29 @@ PHPAPI void php_ini_activate_per_host_config(const char *host, uint host_len TSR } /* }}} */ +/* {{{ php_ini_has_per_sapi_config + */ +PHPAPI int php_ini_has_per_sapi_config(void) +{ + return has_per_sapi_config; +} +/* }}} */ + +/* {{{ php_ini_activate_per_sapi_config + */ +PHPAPI void php_ini_activate_per_sapi_config(const char *sapi, uint sapi_len TSRMLS_DC) +{ + zval *tmp; + + if (has_per_sapi_config && sapi && sapi_len) { + /* Search for source array matching the sapi from configuration_hash */ + if (zend_hash_find(&configuration_hash, sapi, sapi_len, (void **) &tmp) == SUCCESS) { + php_ini_activate_config(Z_ARRVAL_P(tmp), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE TSRMLS_CC); + } + } +} +/* }}} */ + /* {{{ cfg_get_entry */ PHPAPI zval *cfg_get_entry(const char *name, uint name_length) diff --git a/main/php_ini.h b/main/php_ini.h index 65c80f75933b4..6142ca9504f70 100644 --- a/main/php_ini.h +++ b/main/php_ini.h @@ -36,8 +36,10 @@ PHPAPI int php_parse_user_ini_file(const char *dirname, char *ini_filename, Hash PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage TSRMLS_DC); PHPAPI int php_ini_has_per_dir_config(void); PHPAPI int php_ini_has_per_host_config(void); +PHPAPI int php_ini_has_per_sapi_config(void); PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC); PHPAPI void php_ini_activate_per_host_config(const char *host, uint host_len TSRMLS_DC); +PHPAPI void php_ini_activate_per_sapi_config(const char *sapi, uint sapi_len TSRMLS_DC); PHPAPI HashTable* php_ini_get_configuration_hash(void); END_EXTERN_C()