Skip to content

Allow ini files to have a [SAPI=] section in exactly the same manner as ... #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2244,6 +2244,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
Expand Down
35 changes: 34 additions & 1 deletion main/php_ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -857,6 +867,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)
Expand Down
2 changes: 2 additions & 0 deletions main/php_ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down