cvs: php4 / NEWS /ext/standard basic_functions.c basic_functions.h
| From: | Zeev Suraski | Date: | Sun, 29 Oct 2000 23:34:33 +0000 |
| Subject: | cvs: php4 / NEWS /ext/standard basic_functions.c basic_functions.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-2351@lists.php.net to get a copy of this message | ||
zeev Sun Oct 29 15:34:33 2000 EDT
Modified files:
/php4 NEWS
/php4/ext/standard basic_functions.c basic_functions.h
Log:
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
Index: php4/NEWS
diff -u php4/NEWS:1.497 php4/NEWS:1.498
--- php4/NEWS:1.497 Sun Oct 29 14:45:46 2000
+++ php4/NEWS Sun Oct 29 15:34:33 2000
@@ -3,7 +3,10 @@
?? ??? 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: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.272 php4/ext/standard/basic_functions.c:1.273
--- php4/ext/standard/basic_functions.c:1.272 Sun Oct 29 14:42:01 2000
+++ php4/ext/standard/basic_functions.c Sun Oct 29 15:34:33 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.272 2000/10/29 22:42:01 zeev Exp $ */
+/* $Id: basic_functions.c,v 1.273 2000/10/29 23:34:33 zeev Exp $ */
#include "php.h"
#include "php_main.h"
@@ -2337,16 +2337,70 @@
}
-/* {{{ 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 @@
}
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: php4/ext/standard/basic_functions.h
diff -u php4/ext/standard/basic_functions.h:1.66 php4/ext/standard/basic_functions.h:1.67
--- php4/ext/standard/basic_functions.h:1.66 Tue Sep 19 10:32:27 2000
+++ php4/ext/standard/basic_functions.h Sun Oct 29 15:34:33 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.h,v 1.66 2000/09/19 17:32:27 sas Exp $ */
+/* $Id: basic_functions.h,v 1.67 2000/10/29 23:34:33 zeev Exp $ */
#ifndef BASIC_FUNCTIONS_H
#define BASIC_FUNCTIONS_H
@@ -147,6 +147,8 @@
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;