Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41687 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10433 invoked from network); 5 Nov 2008 16:30:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Nov 2008 16:30:29 -0000 Authentication-Results: pb1.pair.com header.from=grange@lemonde.fr; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=grange@lemonde.fr; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lemonde.fr from 194.3.81.6 cause and error) X-PHP-List-Original-Sender: grange@lemonde.fr X-Host-Fingerprint: 194.3.81.6 smtp1.lemonde.fr Linux 2.4 w/o timestamps Received: from [194.3.81.6] ([194.3.81.6:47447] helo=smtp1.lemonde.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 42/14-22938-22AC1194 for ; Wed, 05 Nov 2008 11:30:28 -0500 Received: from smtp1.lemonde.fr (smtp1.lemonde.fr [127.0.0.1]) by localhost (smtp1) with SMTP id 5E51F2D50 for ; Wed, 5 Nov 2008 17:30:23 +0100 (CET) Received: from [127.0.0.1] (unknown [172.30.1.54]) by smtp1.lemonde.fr (smtp1) with ESMTP id 437C230 for ; Wed, 5 Nov 2008 17:30:22 +0100 (CET) Message-ID: <4911CA1D.7030008@lemonde.fr> Date: Wed, 05 Nov 2008 17:30:21 +0100 Organization: Le Monde interactif User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: internals@lists.php.net Content-Type: multipart/mixed; boundary="------------080907020409030301090601" Subject: [PATCH] parse_ini_string() From: grange@lemonde.fr (Olivier Grange-Labat) --------------080907020409030301090601 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hello, Here's a patch again PHP_5_3 to add a parse_ini_string() function. It just works as parse_ini_file(), except it accepts a string instead of a filename, obviously. We've been using for months a simple PHP function to do that, and while I had to modify it to accept constants (as parse_ini_file() does), I thought it was time to use the core parsers instead of reinventing the wheel. I have the same patch available for 5.2, if anyone is interested. Thank you for all the time and effort you put into PHP ! Olivier --------------080907020409030301090601 Content-Type: text/plain; name="parse_ini_string-PHP_5_3.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="parse_ini_string-PHP_5_3.diff" Index: ext/standard/basic_functions.c =================================================================== RCS file: /repository/php-src/ext/standard/basic_functions.c,v retrieving revision 1.725.2.31.2.64.2.68 diff -u -r1.725.2.31.2.64.2.68 basic_functions.c --- ext/standard/basic_functions.c 2 Nov 2008 21:19:37 -0000 1.725.2.31.2.64.2.68 +++ ext/standard/basic_functions.c 5 Nov 2008 15:42:37 -0000 @@ -989,6 +989,13 @@ ZEND_ARG_INFO(0, scanner_mode) ZEND_END_ARG_INFO() +static +ZEND_BEGIN_ARG_INFO_EX(arginfo_parse_ini_string, 0, 0, 1) + ZEND_ARG_INFO(0, str) + ZEND_ARG_INFO(0, process_sections) + ZEND_ARG_INFO(0, scanner_mode) +ZEND_END_ARG_INFO() + #if ZEND_DEBUG static ZEND_BEGIN_ARG_INFO(arginfo_config_get_hash, 0) @@ -3450,6 +3457,7 @@ PHP_FE(connection_status, arginfo_connection_status) PHP_FE(ignore_user_abort, arginfo_ignore_user_abort) PHP_FE(parse_ini_file, arginfo_parse_ini_file) + PHP_FE(parse_ini_string, arginfo_parse_ini_string) #if ZEND_DEBUG PHP_FE(config_get_hash, arginfo_config_get_hash) #endif @@ -6372,6 +6380,42 @@ } /* }}} */ +/* {{{ proto array parse_ini_string(string str [, bool process_sections [, int scanner_mode]]) + Parse configuration string */ +PHP_FUNCTION(parse_ini_string) +{ + char *string = NULL, *str = NULL; + int str_len = 0; + zend_bool process_sections = 0; + long scanner_mode = ZEND_INI_SCANNER_NORMAL; + zend_ini_parser_cb_t ini_parser_cb; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|bl", &str, &str_len, &process_sections, &scanner_mode) == FAILURE) { + RETURN_FALSE; + } + + /* Set callback function */ + if (process_sections) { + 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; + } + + /* Setup string */ + string = (char *) emalloc(str_len + 1); + strcpy(string, str); + *(string + str_len + 1) = '\0'; + + array_init(return_value); + if (zend_parse_ini_string(string, 0, scanner_mode, ini_parser_cb, return_value TSRMLS_CC) == FAILURE) { + zend_hash_destroy(Z_ARRVAL_P(return_value)); + efree(Z_ARRVAL_P(return_value)); + RETURN_FALSE; + } +} +/* }}} */ + #if ZEND_DEBUG /* This function returns an array of ALL valid ini options with values and * is not the same as ini_get_all() which returns only registered ini options. Only useful for devs to debug php.ini scanner/parser! */ Index: ext/standard/basic_functions.h =================================================================== RCS file: /repository/php-src/ext/standard/basic_functions.h,v retrieving revision 1.139.2.4.2.6.2.9 diff -u -r1.139.2.4.2.6.2.9 basic_functions.h --- ext/standard/basic_functions.h 15 Apr 2008 08:44:21 -0000 1.139.2.4.2.6.2.9 +++ ext/standard/basic_functions.h 5 Nov 2008 15:42:37 -0000 @@ -127,6 +127,7 @@ /* From the INI parser */ PHP_FUNCTION(parse_ini_file); +PHP_FUNCTION(parse_ini_string); #if ZEND_DEBUG PHP_FUNCTION(config_get_hash); #endif --------------080907020409030301090601--