summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>2000-10-29 22:42:01 +0000
committerZeev Suraski <zeev@php.net>2000-10-29 22:42:01 +0000
commit4af433d627f069a5b783168940739cbbafa835a7 (patch)
tree744d62e179054ed117e6b0f8d7bd83c1689a54f4
parentab3beffad78160010a58d377e0d507c76e87e6c4 (diff)
downloadphp-git-4af433d627f069a5b783168940739cbbafa835a7.tar.gz
Use the new INI parser for parse_ini_str()
- parse_ini_str() is now thread-safe, and supported under Windows (Zeev)
-rw-r--r--ext/standard/basic_functions.c43
-rw-r--r--main/configuration-parser.y30
-rw-r--r--main/php_ini.c12
-rw-r--r--main/php_ini.h2
4 files changed, 50 insertions, 37 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 722c5cbcb2..4b9e2bdd25 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -2318,6 +2318,49 @@ PHP_FUNCTION(move_uploaded_file)
/* }}} */
+
+static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, zval *arr)
+{
+ zval *element;
+
+ switch (callback_type) {
+ case ZEND_INI_PARSER_ENTRY:
+ ALLOC_ZVAL(element);
+ *element = *arg2;
+ zval_copy_ctor(element);
+ INIT_PZVAL(element);
+ zend_hash_update(arr->value.ht, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &element, sizeof(zval *), NULL);
+ break;
+ case ZEND_INI_PARSER_SECTION:
+ break;
+ }
+}
+
+
+/* {{{ proto void parse_ini_file(string filename)
+ Parse configuration file */
+PHP_FUNCTION(parse_ini_file)
+{
+ zval **filename;
+ zend_file_handle fh;
+
+ if (ARG_COUNT(ht)!=1 || zend_get_parameters_ex(1, &filename)==FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string_ex(filename);
+ fh.handle.fp = V_FOPEN((*filename)->value.str.val, "r");
+ if (!fh.handle.fp) {
+ php_error(E_WARNING,"Cannot open '%s' for reading", (*filename)->value.str.val);
+ return;
+ }
+ 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);
+
+}
+/* }}} */
+
+
/*
* Local variables:
* tab-width: 4
diff --git a/main/configuration-parser.y b/main/configuration-parser.y
index 6c1cc3d8b4..7cea8de979 100644
--- a/main/configuration-parser.y
+++ b/main/configuration-parser.y
@@ -273,36 +273,6 @@ PHP_MINIT_FUNCTION(browscap)
}
-/* {{{ proto void parse_ini_file(string filename)
- Parse configuration file */
-PHP_FUNCTION(parse_ini_file)
-{
-#ifdef ZTS
- php_error(E_WARNING, "parse_ini_file() is not supported in multithreaded PHP");
- RETURN_FALSE;
-#else
- zval **filename;
-
- if (ARG_COUNT(ht)!=1 || zend_get_parameters_ex(1, &filename)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
- cfgin = V_FOPEN((*filename)->value.str.val, "r");
- if (!cfgin) {
- php_error(E_WARNING,"Cannot open '%s' for reading", (*filename)->value.str.val);
- return;
- }
- array_init(return_value);
- init_cfg_scanner();
- active_hash_table = return_value->value.ht;
- parsing_mode = PARSING_MODE_STANDALONE;
- currently_parsed_filename = (*filename)->value.str.val;
- yyparse();
- fclose(cfgin);
-#endif
-}
-/* }}} */
-
int php_shutdown_config(void)
{
zend_hash_destroy(&configuration_hash);
diff --git a/main/php_ini.c b/main/php_ini.c
index c681eb2270..1c52a384e5 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -2,17 +2,17 @@
+----------------------------------------------------------------------+
| PHP version 4.0 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
+ | license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
- | Author: Zeev Suraski <zeev@zend.com> |
+ | Author: Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
diff --git a/main/php_ini.h b/main/php_ini.h
index 80014e68b5..0321c1fa68 100644
--- a/main/php_ini.h
+++ b/main/php_ini.h
@@ -12,7 +12,7 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
- | Authors: Zeev Suraski <zeev@zend.com> |
+ | Author: Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/