]> granicus.if.org Git - php/commitdiff
ini patch to allow 'entry[] = value' entries
authorHarald Radi <phanto@php.net>
Sun, 19 Jan 2003 12:18:46 +0000 (12:18 +0000)
committerHarald Radi <phanto@php.net>
Sun, 19 Jan 2003 12:18:46 +0000 (12:18 +0000)
ext/standard/basic_functions.c
main/php_ini.c

index ed882249f8c6b1cf3676c54bf8b244d73fb28f43..bac068e51d36d754d14b3fc7631b69c85fcff2e7 100644 (file)
@@ -2824,54 +2824,63 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
                        zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &element, sizeof(zval *), NULL);
                        break;
 
-               case ZEND_INI_PARSER_SECTION:
-                       break;
-       }
-}
-
-static void php_ini_parser_cb_with_sections(zval *arg1, zval *arg2, int callback_type, zval *arr)
-{
-       zval *element;
-       TSRMLS_FETCH();
-
-       switch (callback_type) {
-
-               case ZEND_INI_PARSER_ENTRY:
+               case ZEND_INI_PARSER_POP_ENTRY:
                {
-                       zval *active_arr;
+                       zval *hash, **find_hash;
 
                        if (!arg2) {
                                /* bare string - nothing to do */
                                break;
                        }
 
-                       if (BG(active_ini_file_section)) {
-                               active_arr = BG(active_ini_file_section);
+                       if (zend_hash_find(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void **) &find_hash) == FAILURE) {
+                               ALLOC_ZVAL(hash);
+                               INIT_PZVAL(hash);
+                               array_init(hash);
+
+                               zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &hash, sizeof(zval *), NULL);
                        } else {
-                               active_arr = arr;
+                               hash = *find_hash;
                        }
+
                        ALLOC_ZVAL(element);
                        *element = *arg2;
                        zval_copy_ctor(element);
                        INIT_PZVAL(element);
-                       zend_hash_update(Z_ARRVAL_P(active_arr), Z_STRVAL_P(arg1),
-                                                        Z_STRLEN_P(arg1)+1, &element,
-                                                        sizeof(zval *), NULL);
+                       add_next_index_zval(hash, element);                     
                }
                break;
 
                case ZEND_INI_PARSER_SECTION:
-                       MAKE_STD_ZVAL(BG(active_ini_file_section));
-                       array_init(BG(active_ini_file_section));
-                       zend_hash_update(       Z_ARRVAL_P(arr),
-                                                               Z_STRVAL_P(arg1),
-                                                               Z_STRLEN_P(arg1)+1,
-                                                               &BG(active_ini_file_section),
-                                                               sizeof(zval *), NULL);
                        break;
        }
 }
 
+static void php_ini_parser_cb_with_sections(zval *arg1, zval *arg2, int callback_type, zval *arr)
+{
+       TSRMLS_FETCH();
+
+       if (callback_type == ZEND_INI_PARSER_SECTION) {
+               MAKE_STD_ZVAL(BG(active_ini_file_section));
+               array_init(BG(active_ini_file_section));
+               zend_hash_update(       Z_ARRVAL_P(arr),
+                                                       Z_STRVAL_P(arg1),
+                                                       Z_STRLEN_P(arg1)+1,
+                                                       &BG(active_ini_file_section),
+                                                       sizeof(zval *), NULL);
+       } else if (arg2) {
+               zval *active_arr;
+
+               if (BG(active_ini_file_section)) {
+                       active_arr = BG(active_ini_file_section);
+               } else {
+                       active_arr = arr;
+               }
+
+               php_simple_ini_parser_cb(arg1, arg2, callback_type, active_arr);
+       }
+}
+
 
 /* {{{ proto array parse_ini_file(string filename [, bool process_sections])
    Parse configuration file */
index 8c2a57e0496a1760e162a794762c7d9e9276f207..e0f6f6c098e81359234efe62b71bba8ed629e03f 100644 (file)
@@ -195,6 +195,34 @@ static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
                                }
                        }
                        break;
+
+               case ZEND_INI_PARSER_POP_ENTRY: {
+                               zval *hash;
+                               zval **find_hash;
+                               zval *element;
+
+                               if (!arg2) {
+                                       /* bare string - nothing to do */
+                                       break;
+                               }
+
+                               if (zend_hash_find(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void **) &find_hash) == FAILURE) {
+                                       ALLOC_ZVAL(hash);
+                                       array_init(hash);
+
+                                       zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &hash, sizeof(zval *), NULL);
+                               } else {
+                                       hash = *find_hash;
+                               }
+
+                               ALLOC_ZVAL(element);
+                               *element = *arg2;
+                               zval_copy_ctor(element);
+                               INIT_PZVAL(element);
+                               add_next_index_zval(hash, element);                     
+                       }
+                       break;
+
                case ZEND_INI_PARSER_SECTION:
                        break;
        }