Skip to content

Instantly share code, notes, and snippets.

@rquadling rquadling/gist_1.diff
Last active Dec 23, 2015

Embed
What would you like to do?
Patch to PHP to allow [SAPI] sections in INI files.
diff --git a/main/main.c b/main/main.c
index 5942b23..e8171a5 100644
--- a/main/main.c
+++ b/main/main.c
@@ -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
diff --git a/main/php_ini.c b/main/php_ini.c
index e9529a2..e25b4bc 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;
@@ -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)
diff --git a/main/php_ini.h b/main/php_ini.h
index 65c80f7..6142ca9 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()
@mnapoli

This comment has been minimized.

Copy link

commented Sep 16, 2013

Maybe if you rename your file into ".c.diff" the added and removed lines will be colored? (I'm not sure though)

@rquadling

This comment has been minimized.

Copy link
Owner Author

commented Sep 21, 2013

How's that? Pretty colours now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.