]> granicus.if.org Git - php/commitdiff
parse_ini_file() supports a new optional 2nd argument that instructs it
authorZeev Suraski <zeev@php.net>
Sun, 29 Oct 2000 23:34:33 +0000 (23:34 +0000)
committerZeev Suraski <zeev@php.net>
Sun, 29 Oct 2000 23:34:33 +0000 (23:34 +0000)
to divide the directives to arrays according to the sections in which they
reside

NEWS
ext/standard/basic_functions.c
ext/standard/basic_functions.h

diff --git a/NEWS b/NEWS
index 988785ea7012d56e394fd4aa86b54928b95c3ba2..d37b255b28d47e55eb105320c453c7ca2efd9453 100644 (file)
--- 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)
index 4b9e2bdd25f73fa5a9272320de986437cdee7311..1477cbbc2048d831fe7fdbbadbb986923b99560e 100644 (file)
@@ -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);
 }
 /* }}} */
 
index 59de99e24e8cafc3bd5ca746816a3adbb936e96c..9c3ed32ae5069cd5a07b3e3b69acda8c394e9ca1 100644 (file)
@@ -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;