summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>2000-10-30 23:39:14 +0000
committerZeev Suraski <zeev@php.net>2000-10-30 23:39:14 +0000
commit78194a47b7ad76aaea3bb8e91fa0f5707ae88d00 (patch)
treefe0a66d9f67176d1cce99994d09770141827c428 /main
parent4171da016ce465832d32196e3b8eed014c073704 (diff)
downloadphp-git-78194a47b7ad76aaea3bb8e91fa0f5707ae88d00.tar.gz
- Complete the move to the new INI parser. (Side effect: at last, people
can finally have spaces and tabs in their extension statements...)
Diffstat (limited to 'main')
-rw-r--r--main/Makefile.in6
-rw-r--r--main/configuration-parser.y432
-rw-r--r--main/configuration-scanner.l182
-rw-r--r--main/php_ini.c218
-rw-r--r--main/php_ini.h3
-rw-r--r--main/php_main.h5
6 files changed, 221 insertions, 625 deletions
diff --git a/main/Makefile.in b/main/Makefile.in
index 89bf0c41d0..0c83137408 100644
--- a/main/Makefile.in
+++ b/main/Makefile.in
@@ -2,7 +2,6 @@ LTLIBRARY_NAME = libmain.la
LTLIBRARY_SOURCES = \
main.c internal_functions.c snprintf.c php_sprintf.c \
- configuration-parser.c configuration-scanner.c \
safe_mode.c fopen-wrappers.c alloca.c \
php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c \
@@ -10,11 +9,6 @@ LTLIBRARY_SOURCES = \
include $(top_srcdir)/build/ltlib.mk
-configuration-parser.h configuration-parser.c: $(srcdir)/configuration-parser.y
- $(YACC) -p cfg -v -d $< -o configuration-parser.c
-
-configuration-scanner.c: $(srcdir)/configuration-scanner.l
- $(LEX) -Pcfg -o$@ -i $<
internal_functions.c: $(srcdir)/internal_functions.c.in $(top_builddir)/config.status
cd $(top_builddir) && \
diff --git a/main/configuration-parser.y b/main/configuration-parser.y
deleted file mode 100644
index b9b281a7aa..0000000000
--- a/main/configuration-parser.y
+++ /dev/null
@@ -1,432 +0,0 @@
-%{
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | 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. |
- | 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. |
- +----------------------------------------------------------------------+
- | Authors: Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
- */
-
-
-
-/* $Id$ */
-
-#define DEBUG_CFG_PARSER 0
-#include "php.h"
-#include "php_globals.h"
-#include "php_ini.h"
-#include "ext/standard/dl.h"
-#include "ext/standard/file.h"
-#include "zend_extensions.h"
-
-
-#if WIN32
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <winbase.h>
-#include "win32/wfile.h"
-#endif
-
-#define YYSTYPE zval
-
-#define PARSING_MODE_CFG 0
-#define PARSING_MODE_STANDALONE 2
-
-static HashTable configuration_hash;
-PHPAPI extern char *php_ini_path;
-static HashTable *active_hash_table;
-static char *currently_parsed_filename;
-
-static int parsing_mode;
-
-zval yylval;
-
-extern int cfglex(zval *cfglval);
-extern FILE *cfgin;
-extern int cfglineno;
-extern void init_cfg_scanner(void);
-
-zval *cfg_get_entry(char *name, uint name_length)
-{
- zval *tmp;
-
- if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp)==SUCCESS) {
- return tmp;
- } else {
- return NULL;
- }
-}
-
-
-PHPAPI int cfg_get_long(char *varname,long *result)
-{
- zval *tmp,var;
-
- if (zend_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
- *result=(long)NULL;
- return FAILURE;
- }
- var = *tmp;
- zval_copy_ctor(&var);
- convert_to_long(&var);
- *result = var.value.lval;
- return SUCCESS;
-}
-
-
-PHPAPI int cfg_get_double(char *varname,double *result)
-{
- zval *tmp,var;
-
- if (zend_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
- *result=(double)0;
- return FAILURE;
- }
- var = *tmp;
- zval_copy_ctor(&var);
- convert_to_double(&var);
- *result = var.value.dval;
- return SUCCESS;
-}
-
-
-PHPAPI int cfg_get_string(char *varname, char **result)
-{
- zval *tmp;
-
- if (zend_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
- *result=NULL;
- return FAILURE;
- }
- *result = tmp->value.str.val;
- return SUCCESS;
-}
-
-
-static void yyerror(char *str)
-{
- char *error_buf;
- int error_buf_len;
-
- error_buf_len = 128+strlen(currently_parsed_filename); /* should be more than enough */
- error_buf = (char *) emalloc(error_buf_len);
-
- sprintf(error_buf, "Error parsing %s on line %d\n", currently_parsed_filename, cfglineno);
-#ifdef PHP_WIN32
- MessageBox(NULL, error_buf, "PHP Error", MB_OK|MB_TOPMOST|0x00200000L);
-#else
- fprintf(stderr, "PHP: %s", error_buf);
-#endif
- efree(error_buf);
-}
-
-
-static void pvalue_config_destructor(zval *pvalue)
-{
- if (pvalue->type == IS_STRING && pvalue->value.str.val != empty_string) {
- free(pvalue->value.str.val);
- }
-}
-
-
-int php_init_config(void)
-{
- PLS_FETCH();
-
- if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) {
- return FAILURE;
- }
-
-#if USE_CONFIG_FILE
- {
- char *env_location,*default_location,*php_ini_search_path;
- int safe_mode_state = PG(safe_mode);
- char *open_basedir = PG(open_basedir);
- char *opened_path;
- int free_default_location=0;
-
- env_location = getenv("PHPRC");
- if (!env_location) {
- env_location="";
- }
-#ifdef PHP_WIN32
- {
- if (php_ini_path) {
- default_location = php_ini_path;
- } else {
- default_location = (char *) malloc(512);
-
- if (!GetWindowsDirectory(default_location,255)) {
- default_location[0]=0;
- }
- free_default_location=1;
- }
- }
-#else
- if (!php_ini_path) {
- default_location = CONFIGURATION_FILE_PATH;
- } else {
- default_location = php_ini_path;
- }
-#endif
-
-/* build a path */
- php_ini_search_path = (char *) malloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1);
-
- if (!php_ini_path) {
-#ifdef PHP_WIN32
- sprintf(php_ini_search_path,".;%s;%s",env_location,default_location);
-#else
- sprintf(php_ini_search_path,".:%s:%s",env_location,default_location);
-#endif
- } else {
- /* if path was set via -c flag, only look there */
- strcpy(php_ini_search_path,default_location);
- }
- PG(safe_mode) = 0;
- PG(open_basedir) = NULL;
- cfgin = php_fopen_with_path("php.ini","r",php_ini_search_path,&opened_path);
- free(php_ini_search_path);
- if (free_default_location) {
- free(default_location);
- }
- PG(safe_mode) = safe_mode_state;
- PG(open_basedir) = open_basedir;
-
- if (!cfgin) {
- return SUCCESS; /* having no configuration file is ok */
- }
-
- if (opened_path) {
- zval tmp;
-
- tmp.value.str.val = strdup(opened_path);
- tmp.value.str.len = strlen(opened_path);
- tmp.type = IS_STRING;
- zend_hash_update(&configuration_hash,"cfg_file_path",sizeof("cfg_file_path"),(void *) &tmp,sizeof(zval),NULL);
-#if DEBUG_CFG_PARSER
- php_printf("INI file opened at '%s'\n",opened_path);
-#endif
- efree(opened_path);
- }
-
- init_cfg_scanner();
- active_hash_table = &configuration_hash;
- parsing_mode = PARSING_MODE_CFG;
- currently_parsed_filename = "php.ini";
- yyparse();
- fclose(cfgin);
- }
-
-#endif
-
- return SUCCESS;
-}
-
-
-int php_shutdown_config(void)
-{
- zend_hash_destroy(&configuration_hash);
- return SUCCESS;
-}
-
-
-void do_cfg_op(char type, zval *result, zval *op1, zval *op2)
-{
- int i_result;
- int i_op1, i_op2;
- char str_result[MAX_LENGTH_OF_LONG];
-
- i_op1 = atoi(op1->value.str.val);
- free(op1->value.str.val);
- if (op2) {
- i_op2 = atoi(op2->value.str.val);
- free(op2->value.str.val);
- } else {
- i_op2 = 0;
- }
-
- switch (type) {
- case '|':
- i_result = i_op1 | i_op2;
- break;
- case '&':
- i_result = i_op1 & i_op2;
- break;
- case '~':
- i_result = ~i_op1;
- break;
- case '!':
- i_result = !i_op1;
- break;
- default:
- i_result = 0;
- break;
- }
-
- result->value.str.len = zend_sprintf(str_result, "%d", i_result);
- result->value.str.val = (char *) malloc(result->value.str.len+1);
- memcpy(result->value.str.val, str_result, result->value.str.len);
- result->value.str.val[result->value.str.len] = 0;
- result->type = IS_STRING;
-}
-
-
-void do_cfg_get_constant(zval *result, zval *name)
-{
- zval z_constant;
-
- if (zend_get_constant(name->value.str.val, name->value.str.len, &z_constant)) {
- /* z_constant is emalloc()'d */
- convert_to_string(&z_constant);
- result->value.str.val = zend_strndup(z_constant.value.str.val, z_constant.value.str.len);
- result->value.str.len = z_constant.value.str.len;
- result->type = z_constant.type;
- zval_dtor(&z_constant);
- free(name->value.str.val);
- } else {
- *result = *name;
- }
-}
-
-
-%}
-
-%pure_parser
-%token TC_STRING
-%token TC_ENCAPSULATED_STRING
-%token SECTION
-%token CFG_TRUE
-%token CFG_FALSE
-%token EXTENSION
-%token T_ZEND_EXTENSION
-%token T_ZEND_EXTENSION_TS
-%token T_ZEND_EXTENSION_DEBUG
-%token T_ZEND_EXTENSION_DEBUG_TS
-%left '|' '&'
-%right '~' '!'
-
-%%
-
-statement_list:
- statement_list statement
- | /* empty */
-;
-
-statement:
- TC_STRING '=' string_or_value {
-#if DEBUG_CFG_PARSER
- printf("'%s' = '%s'\n",$1.value.str.val,$3.value.str.val);
-#endif
- $3.type = IS_STRING;
- switch (parsing_mode) {
- case PARSING_MODE_CFG:
- zend_hash_update(active_hash_table, $1.value.str.val, $1.value.str.len+1, &$3, sizeof(zval), NULL);
- if (active_hash_table == &configuration_hash) {
- zend_alter_ini_entry($1.value.str.val, $1.value.str.len+1, $3.value.str.val, $3.value.str.len+1, PHP_INI_SYSTEM, PHP_INI_STAGE_STARTUP);
- }
- break;
- case PARSING_MODE_STANDALONE: {
- zval *entry;
-
- MAKE_STD_ZVAL(entry);
- entry->value.str.val = estrndup($3.value.str.val, $3.value.str.len);
- entry->value.str.len = $3.value.str.len;
- entry->type = IS_STRING;
- zend_hash_update(active_hash_table, $1.value.str.val, $1.value.str.len+1, &entry, sizeof(zval *), NULL);
- pvalue_config_destructor(&$3);
- }
- break;
- }
- free($1.value.str.val);
- }
- | TC_STRING { free($1.value.str.val); }
- | EXTENSION '=' cfg_string {
- if (parsing_mode==PARSING_MODE_CFG) {
- zval dummy;
-
-#if DEBUG_CFG_PARSER
- printf("Loading '%s'\n",$3.value.str.val);
-#endif
- php_dl(&$3,MODULE_PERSISTENT,&dummy);
- }
- }
- | T_ZEND_EXTENSION '=' cfg_string {
- if (parsing_mode==PARSING_MODE_CFG) {
-#if !defined(ZTS) && !ZEND_DEBUG
- zend_load_extension($3.value.str.val);
-#endif
- free($3.value.str.val);
- }
- }
- | T_ZEND_EXTENSION_TS '=' cfg_string {
- if (parsing_mode==PARSING_MODE_CFG) {
-#if defined(ZTS) && !ZEND_DEBUG
- zend_load_extension($3.value.str.val);
-#endif
- free($3.value.str.val);
- }
- }
- | T_ZEND_EXTENSION_DEBUG '=' cfg_string {
- if (parsing_mode==PARSING_MODE_CFG) {
-#if !defined(ZTS) && ZEND_DEBUG
- zend_load_extension($3.value.str.val);
-#endif
- free($3.value.str.val);
- }
- }
- | T_ZEND_EXTENSION_DEBUG_TS '=' cfg_string {
- if (parsing_mode==PARSING_MODE_CFG) {
-#if defined(ZTS) && ZEND_DEBUG
- zend_load_extension($3.value.str.val);
-#endif
- free($3.value.str.val);
- }
- }
- | SECTION { free($1.value.str.val); }
- | '\n'
-;
-
-
-cfg_string:
- TC_STRING { $$ = $1; }
- | TC_ENCAPSULATED_STRING { $$ = $1; }
-;
-
-string_or_value:
- expr { $$ = $1; }
- | TC_ENCAPSULATED_STRING { $$ = $1; }
- | CFG_TRUE { $$ = $1; }
- | CFG_FALSE { $$ = $1; }
- | '\n' { $$.value.str.val = strdup(""); $$.value.str.len=0; $$.type = IS_STRING; }
- | '\0' { $$.value.str.val = strdup(""); $$.value.str.len=0; $$.type = IS_STRING; }
-;
-
-expr:
- constant_string { $$ = $1; }
- | expr '|' expr { do_cfg_op('|', &$$, &$1, &$3); }
- | expr '&' expr { do_cfg_op('&', &$$, &$1, &$3); }
- | '~' expr { do_cfg_op('~', &$$, &$2, NULL); }
- | '!' expr { do_cfg_op('!', &$$, &$2, NULL); }
- | '(' expr ')' { $$ = $2; }
-;
-
-constant_string:
- TC_STRING { do_cfg_get_constant(&$$, &$1); }
-;
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/main/configuration-scanner.l b/main/configuration-scanner.l
deleted file mode 100644
index 4e90739d21..0000000000
--- a/main/configuration-scanner.l
+++ /dev/null
@@ -1,182 +0,0 @@
-%{
-
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | 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. |
- | 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. |
- +----------------------------------------------------------------------+
- | Authors: Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-
-#include "php.h"
-#include "configuration-parser.h"
-
-#undef YYSTYPE
-#define YYSTYPE pval
-
-#define YY_DECL cfglex(pval *cfglval)
-
-
-void init_cfg_scanner()
-{
- cfglineno=1;
-}
-
-
-%}
-
-%option noyywrap
-%option yylineno
-
-%%
-
-<INITIAL>"extension" {
-#if 0
- printf("found extension\n");
-#endif
- return EXTENSION;
-}
-
-
-<INITIAL>"zend_extension" {
- return T_ZEND_EXTENSION;
-}
-
-
-<INITIAL>"zend_extension_ts" {
- return T_ZEND_EXTENSION_TS;
-}
-
-
-<INITIAL>"zend_extension_debug" {
- return T_ZEND_EXTENSION_DEBUG;
-}
-
-
-<INITIAL>"zend_extension_debug_ts" {
- return T_ZEND_EXTENSION_DEBUG_TS;
-}
-
-
-<INITIAL>[ ]*("true"|"on"|"yes")[ ]* {
- cfglval->value.str.val = zend_strndup("1",1);
- cfglval->value.str.len = 1;
- cfglval->type = IS_STRING;
- return CFG_TRUE;
-}
-
-
-<INITIAL>[ ]*("false"|"off"|"no"|"none")[ ]* {
- cfglval->value.str.val = zend_strndup("",0);
- cfglval->value.str.len = 0;
- cfglval->type = IS_STRING;
- return CFG_FALSE;
-}
-
-<INITIAL>[[][^[]+[\]]([\n]?|"\r\n"?) {
- /* SECTION */
-
- /* eat trailng ] */
- while (yyleng>0 && (yytext[yyleng-1]=='\n' || yytext[yyleng-1]=='\r' || yytext[yyleng-1]==']')) {
- yyleng--;
- yytext[yyleng]=0;
- }
-
- /* eat leading [ */
- yytext++;
- yyleng--;
-
- cfglval->value.str.val = zend_strndup(yytext,yyleng);
- cfglval->value.str.len = yyleng;
- cfglval->type = IS_STRING;
- return SECTION;
-}
-
-
-<INITIAL>["][^\n\r"]*["] {
- /* ENCAPSULATED TC_STRING */
-
- /* eat trailing " */
- yytext[yyleng-1]=0;
-
- /* eat leading " */
- yytext++;
-
- cfglval->value.str.val = zend_strndup(yytext, yyleng - 2);
- cfglval->value.str.len = yyleng - 2;
- cfglval->type = IS_STRING;
- return TC_ENCAPSULATED_STRING;
-}
-
-<INITIAL>[&|~()!] {
- return yytext[0];
-}
-
-
-<INITIAL>[^=\n\r\t;|&~()!"]+ {
- /* STRING */
- register int i;
-
- /* eat trailing whitespace */
- for (i=yyleng-1; i>=0; i--) {
- if (yytext[i]==' ' || yytext[i]=='\t') {
- yytext[i]=0;
- yyleng--;
- } else {
- break;
- }
- }
- /* eat leading whitespace */
- while (yytext[0]) {
- if (yytext[0]==' ' || yytext[0]=='\t') {
- yytext++;
- yyleng--;
- } else {
- break;
- }
- }
- if (yyleng!=0) {
- cfglval->value.str.val = zend_strndup(yytext,yyleng);
- cfglval->value.str.len = yyleng;
- cfglval->type = IS_STRING;
- return TC_STRING;
- } else {
- /* whitespace */
- }
-}
-
-
-
-<INITIAL>[=\n] {
- return yytext[0];
-}
-
-<INITIAL>"\r\n" {
- return '\n';
-}
-
-<INITIAL>[;][^\r\n]*[\r\n]? {
- /* comment */
- return '\n';
-}
-
-<INITIAL>[ \t] {
- /* eat whitespace */
-}
-
-<INITIAL>. {
-#if DEBUG
- php_error(E_NOTICE,"Unexpected character on line %d: '%s' (ASCII %d)\n",yylineno,yytext,yytext[0]);
-#endif
-}
diff --git a/main/php_ini.c b/main/php_ini.c
index 1c52a384e5..21afeb54e1 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -20,6 +20,12 @@
#include "php.h"
#include "ext/standard/info.h"
#include "zend_ini.h"
+#include "php_ini.h"
+#include "ext/standard/dl.h"
+#include "zend_extensions.h"
+
+static HashTable configuration_hash;
+PHPAPI extern char *php_ini_path;
static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type)
@@ -83,3 +89,215 @@ PHPAPI void display_ini_entries(zend_module_entry *module)
php_info_print_table_end();
}
+
+
+/* php.ini support */
+
+#ifdef ZTS
+# if (ZEND_DEBUG)
+# define ZEND_EXTENSION_TOKEN "zend_extension_debug_ts"
+# else
+# define ZEND_EXTENSION_TOKEN "zend_extension_ts"
+# endif
+#else
+# if (ZEND_DEBUG)
+# define ZEND_EXTENSION_TOKEN "zend_extension_debug"
+# else
+# define ZEND_EXTENSION_TOKEN "zend_extension"
+# endif
+#endif
+
+
+static void pvalue_config_destructor(zval *pvalue)
+{
+ if (pvalue->type == IS_STRING && pvalue->value.str.val != empty_string) {
+ free(pvalue->value.str.val);
+ }
+}
+
+
+static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, void *arg)
+{
+ switch (callback_type) {
+ case ZEND_INI_PARSER_ENTRY: {
+ zval *entry;
+
+ if (!arg2) {
+ break;
+ }
+ if (!strcasecmp(Z_STRVAL_P(arg1), "extension")) { /* load function module */
+ zval dummy;
+
+ php_dl(arg2, MODULE_PERSISTENT, &dummy);
+ } else if (!strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */
+ zend_load_extension(Z_STRVAL_P(arg2));
+ } else {
+ zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, arg2, sizeof(zval), (void **) &entry);
+ Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
+ php_alter_ini_entry(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)+1, PHP_INI_SYSTEM, PHP_INI_STAGE_STARTUP);
+ }
+ }
+ break;
+ case ZEND_INI_PARSER_SECTION:
+ break;
+ }
+}
+
+
+int php_init_config(void)
+{
+ PLS_FETCH();
+
+ if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) {
+ return FAILURE;
+ }
+
+#if USE_CONFIG_FILE
+ {
+ char *env_location,*default_location,*php_ini_search_path;
+ int safe_mode_state = PG(safe_mode);
+ char *open_basedir = PG(open_basedir);
+ char *opened_path;
+ int free_default_location=0;
+ zend_file_handle fh;
+
+ env_location = getenv("PHPRC");
+ if (!env_location) {
+ env_location="";
+ }
+#ifdef PHP_WIN32
+ {
+ if (php_ini_path) {
+ default_location = php_ini_path;
+ } else {
+ default_location = (char *) malloc(512);
+
+ if (!GetWindowsDirectory(default_location,255)) {
+ default_location[0]=0;
+ }
+ free_default_location=1;
+ }
+ }
+#else
+ if (!php_ini_path) {
+ default_location = CONFIGURATION_FILE_PATH;
+ } else {
+ default_location = php_ini_path;
+ }
+#endif
+
+/* build a path */
+ php_ini_search_path = (char *) malloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1);
+
+ if (!php_ini_path) {
+#ifdef PHP_WIN32
+ sprintf(php_ini_search_path,".;%s;%s",env_location,default_location);
+#else
+ sprintf(php_ini_search_path,".:%s:%s",env_location,default_location);
+#endif
+ } else {
+ /* if path was set via -c flag, only look there */
+ strcpy(php_ini_search_path,default_location);
+ }
+ PG(safe_mode) = 0;
+ PG(open_basedir) = NULL;
+
+
+ fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path);
+ free(php_ini_search_path);
+ if (free_default_location) {
+ free(default_location);
+ }
+ PG(safe_mode) = safe_mode_state;
+ PG(open_basedir) = open_basedir;
+
+ if (!fh.handle.fp) {
+ return SUCCESS; /* having no configuration file is ok */
+ }
+ fh.type = ZEND_HANDLE_FP;
+ fh.filename = opened_path;
+
+ zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, NULL);
+
+ if (opened_path) {
+ zval tmp;
+
+ tmp.value.str.val = strdup(opened_path);
+ tmp.value.str.len = strlen(opened_path);
+ tmp.type = IS_STRING;
+ zend_hash_update(&configuration_hash,"cfg_file_path",sizeof("cfg_file_path"),(void *) &tmp,sizeof(zval),NULL);
+#if DEBUG_CFG_PARSER
+ php_printf("INI file opened at '%s'\n",opened_path);
+#endif
+ efree(opened_path);
+ }
+ }
+
+#endif
+
+ return SUCCESS;
+}
+
+
+int php_shutdown_config(void)
+{
+ zend_hash_destroy(&configuration_hash);
+ return SUCCESS;
+}
+
+
+zval *cfg_get_entry(char *name, uint name_length)
+{
+ zval *tmp;
+
+ if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp)==SUCCESS) {
+ return tmp;
+ } else {
+ return NULL;
+ }
+}
+
+
+PHPAPI int cfg_get_long(char *varname,long *result)
+{
+ zval *tmp,var;
+
+ if (zend_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
+ *result=(long)NULL;
+ return FAILURE;
+ }
+ var = *tmp;
+ zval_copy_ctor(&var);
+ convert_to_long(&var);
+ *result = var.value.lval;
+ return SUCCESS;
+}
+
+
+PHPAPI int cfg_get_double(char *varname,double *result)
+{
+ zval *tmp,var;
+
+ if (zend_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
+ *result=(double)0;
+ return FAILURE;
+ }
+ var = *tmp;
+ zval_copy_ctor(&var);
+ convert_to_double(&var);
+ *result = var.value.dval;
+ return SUCCESS;
+}
+
+
+PHPAPI int cfg_get_string(char *varname, char **result)
+{
+ zval *tmp;
+
+ if (zend_hash_find(&configuration_hash,varname,strlen(varname)+1,(void **) &tmp)==FAILURE) {
+ *result=NULL;
+ return FAILURE;
+ }
+ *result = tmp->value.str.val;
+ return SUCCESS;
+}
diff --git a/main/php_ini.h b/main/php_ini.h
index 0321c1fa68..cd1b2b00a6 100644
--- a/main/php_ini.h
+++ b/main/php_ini.h
@@ -21,6 +21,9 @@
#include "zend_ini.h"
+int php_init_config(void);
+int php_shutdown_config(void);
+
#define PHP_INI_USER ZEND_INI_USER
#define PHP_INI_PERDIR ZEND_INI_PERDIR
#define PHP_INI_SYSTEM ZEND_INI_SYSTEM
diff --git a/main/php_main.h b/main/php_main.h
index 22b1bbc8c4..09ec56d0cb 100644
--- a/main/php_main.h
+++ b/main/php_main.h
@@ -49,11 +49,6 @@ PHPAPI int php_handle_auth_data(const char *auth SLS_DC);
extern void php_call_shutdown_functions(void);
-
-/* configuration module */
-extern int php_init_config(void);
-extern int php_shutdown_config(void);
-
/* environment module */
extern int php_init_environ(void);
extern int php_shutdown_environ(void);