summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--ext/standard/basic_functions.c65
-rw-r--r--ext/standard/basic_functions.h2
3 files changed, 65 insertions, 7 deletions
diff --git a/NEWS b/NEWS
index 988785ea70..d37b255b28 100644
--- a/NEWS
+++ b/NEWS
@@ -3,7 +3,10 @@ PHP 4.0 NEWS
?? ??? 2000, Version 4.0.4
-- parse_ini_str() is now thread-safe, and supported under Windows (Zeev)
+- parse_ini_file() supports a new optional 2nd argument that instructs it
+ to divide the directives to arrays according to the sections in which they
+ reside (Zeev)
+- parse_ini_file() is now thread-safe, and supported under Windows (Zeev)
- Unified aborted-connection semantics of all SAPI modules (Sascha)
- URL-opened files now store the HTTP response header in $http_response_header
(Zeev)
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 4b9e2bdd25..1477cbbc20 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -2337,16 +2337,70 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
}
-/* {{{ proto void parse_ini_file(string filename)
+static void php_ini_parser_cb_with_sections(zval *arg1, zval *arg2, int callback_type, zval *arr)
+{
+ zval *element;
+ BLS_FETCH();
+
+ switch (callback_type) {
+ case ZEND_INI_PARSER_ENTRY: {
+ zval *active_arr;
+
+ if (BG(active_ini_file_section)) {
+ active_arr = BG(active_ini_file_section);
+ } else {
+ active_arr = arr;
+ }
+ ALLOC_ZVAL(element);
+ *element = *arg2;
+ zval_copy_ctor(element);
+ INIT_PZVAL(element);
+ zend_hash_update(active_arr->value.ht, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &element, sizeof(zval *), NULL);
+ }
+ break;
+ case ZEND_INI_PARSER_SECTION:
+ MAKE_STD_ZVAL(BG(active_ini_file_section));
+ array_init(BG(active_ini_file_section));
+ zend_hash_update(arr->value.ht, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &BG(active_ini_file_section), sizeof(zval *), NULL);
+ break;
+ }
+}
+
+
+/* {{{ proto void parse_ini_file(string filename [, boolean process_sections])
Parse configuration file */
PHP_FUNCTION(parse_ini_file)
{
- zval **filename;
+ zval **filename, **process_sections;
zend_file_handle fh;
+ zend_ini_parser_cb_t ini_parser_cb;
- if (ARG_COUNT(ht)!=1 || zend_get_parameters_ex(1, &filename)==FAILURE) {
- WRONG_PARAM_COUNT;
+ switch (ARG_COUNT(ht)) {
+ case 1:
+ if (zend_get_parameters_ex(1, &filename)==FAILURE) {
+ RETURN_FALSE;
+ }
+ ini_parser_cb = (zend_ini_parser_cb_t) php_simple_ini_parser_cb;
+ break;
+ case 2:
+ if (zend_get_parameters_ex(2, &filename, &process_sections)==FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_boolean_ex(process_sections);
+ if (Z_BVAL_PP(process_sections)) {
+ BLS_FETCH();
+
+ BG(active_ini_file_section) = NULL;
+ ini_parser_cb = (zend_ini_parser_cb_t) php_ini_parser_cb_with_sections;
+ } else {
+ ini_parser_cb = (zend_ini_parser_cb_t) php_simple_ini_parser_cb;
+ }
+ break;
+ default:
+ ZEND_WRONG_PARAM_COUNT();
+ break;
}
+
convert_to_string_ex(filename);
fh.handle.fp = V_FOPEN((*filename)->value.str.val, "r");
if (!fh.handle.fp) {
@@ -2355,8 +2409,7 @@ PHP_FUNCTION(parse_ini_file)
}
fh.type = ZEND_HANDLE_FP;
array_init(return_value);
- zend_parse_ini_file(&fh, (zend_ini_parser_cb_t) php_simple_ini_parser_cb, return_value);
-
+ zend_parse_ini_file(&fh, ini_parser_cb, return_value);
}
/* }}} */
diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h
index 59de99e24e..9c3ed32ae5 100644
--- a/ext/standard/basic_functions.h
+++ b/ext/standard/basic_functions.h
@@ -147,6 +147,8 @@ typedef struct {
zval **array_walk_func_name;
zval **user_compare_func_name;
zend_llist *user_tick_functions;
+
+ zval *active_ini_file_section;
HashTable sm_protected_env_vars;
char *sm_allowed_env_vars;