2000-10-29 22:56:16 +08:00
|
|
|
%{
|
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:23:23 +08:00
|
|
|
| Copyright (c) 1998-2004 Zend Technologies Ltd. (http://www.zend.com) |
|
2000-10-29 22:56:16 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:16:21 +08:00
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
2000-10-29 22:56:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2001-12-11 23:16:21 +08:00
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
2000-10-29 22:56:16 +08:00
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Author: Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#define DEBUG_CFG_PARSER 0
|
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_API.h"
|
|
|
|
#include "zend_ini.h"
|
|
|
|
#include "zend_constants.h"
|
2000-10-30 02:23:51 +08:00
|
|
|
#include "zend_ini_scanner.h"
|
2000-10-29 22:56:16 +08:00
|
|
|
#include "zend_extensions.h"
|
|
|
|
|
|
|
|
#define YYSTYPE zval
|
|
|
|
|
2001-08-06 21:48:51 +08:00
|
|
|
#ifdef ZTS
|
|
|
|
#define YYPARSE_PARAM tsrm_ls
|
|
|
|
#define YYLEX_PARAM tsrm_ls
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ZEND_INI_PARSER_CB (CG(ini_parser_param))->ini_parser_cb
|
|
|
|
#define ZEND_INI_PARSER_ARG (CG(ini_parser_param))->arg
|
2000-10-30 02:23:51 +08:00
|
|
|
|
2001-08-06 21:48:51 +08:00
|
|
|
int ini_lex(zval *ini_lval TSRMLS_DC);
|
|
|
|
#ifdef ZTS
|
|
|
|
int ini_parse(void *arg);
|
|
|
|
#else
|
|
|
|
int ini_parse(void);
|
|
|
|
#endif
|
2000-10-30 02:23:51 +08:00
|
|
|
|
2000-10-29 22:56:16 +08:00
|
|
|
zval yylval;
|
|
|
|
|
2000-10-30 02:23:51 +08:00
|
|
|
#ifndef ZTS
|
2001-08-06 21:48:51 +08:00
|
|
|
extern int ini_lex(zval *ini_lval TSRMLS_DC);
|
2000-10-30 02:23:51 +08:00
|
|
|
extern FILE *ini_in;
|
2000-10-29 22:56:16 +08:00
|
|
|
extern void init_cfg_scanner(void);
|
|
|
|
#endif
|
|
|
|
|
2000-10-30 06:40:01 +08:00
|
|
|
void zend_ini_do_op(char type, zval *result, zval *op1, zval *op2)
|
2000-10-29 22:56:16 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-30 06:40:01 +08:00
|
|
|
void zend_ini_get_constant(zval *result, zval *name)
|
2000-10-29 22:56:16 +08:00
|
|
|
{
|
|
|
|
zval z_constant;
|
2001-07-30 15:43:02 +08:00
|
|
|
TSRMLS_FETCH();
|
2000-10-29 22:56:16 +08:00
|
|
|
|
2004-01-14 01:00:10 +08:00
|
|
|
if (!memchr(name->value.str.val, ':', name->value.str.len)
|
|
|
|
&& zend_get_constant(name->value.str.val, name->value.str.len, &z_constant TSRMLS_CC)) {
|
2000-10-29 22:56:16 +08:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-30 02:23:51 +08:00
|
|
|
static void ini_error(char *str)
|
|
|
|
{
|
|
|
|
char *error_buf;
|
|
|
|
int error_buf_len;
|
2001-07-31 14:07:25 +08:00
|
|
|
char *currently_parsed_filename;
|
2001-07-28 18:51:54 +08:00
|
|
|
TSRMLS_FETCH();
|
2000-10-30 02:23:51 +08:00
|
|
|
|
2001-07-31 14:07:25 +08:00
|
|
|
currently_parsed_filename = zend_ini_scanner_get_filename(TSRMLS_C);
|
2000-10-30 02:23:51 +08:00
|
|
|
error_buf_len = 128+strlen(currently_parsed_filename); /* should be more than enough */
|
|
|
|
error_buf = (char *) emalloc(error_buf_len);
|
|
|
|
|
2001-07-30 12:54:16 +08:00
|
|
|
sprintf(error_buf, "Error parsing %s on line %d\n", currently_parsed_filename, zend_ini_scanner_get_lineno(TSRMLS_C));
|
2000-10-31 07:19:48 +08:00
|
|
|
|
|
|
|
if (CG(ini_parser_unbuffered_errors)) {
|
2000-10-30 02:23:51 +08:00
|
|
|
#ifdef PHP_WIN32
|
2000-10-31 07:19:48 +08:00
|
|
|
MessageBox(NULL, error_buf, "PHP Error", MB_OK|MB_TOPMOST|0x00200000L);
|
2000-10-30 02:23:51 +08:00
|
|
|
#else
|
2000-10-31 07:19:48 +08:00
|
|
|
fprintf(stderr, "PHP: %s", error_buf);
|
2000-10-30 02:23:51 +08:00
|
|
|
#endif
|
2000-10-31 07:19:48 +08:00
|
|
|
} else {
|
2003-10-17 10:47:44 +08:00
|
|
|
zend_error(E_WARNING, "%s", error_buf);
|
2000-10-31 07:19:48 +08:00
|
|
|
}
|
2000-10-30 02:23:51 +08:00
|
|
|
efree(error_buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-31 07:19:48 +08:00
|
|
|
int zend_parse_ini_file(zend_file_handle *fh, zend_bool unbuffered_errors, zend_ini_parser_cb_t ini_parser_cb, void *arg)
|
2000-10-30 06:40:01 +08:00
|
|
|
{
|
2000-10-30 07:10:04 +08:00
|
|
|
int retval;
|
2001-08-06 21:48:51 +08:00
|
|
|
zend_ini_parser_param ini_parser_param;
|
2001-07-28 18:51:54 +08:00
|
|
|
TSRMLS_FETCH();
|
2000-10-30 06:40:01 +08:00
|
|
|
|
|
|
|
ini_parser_param.ini_parser_cb = ini_parser_cb;
|
|
|
|
ini_parser_param.arg = arg;
|
|
|
|
|
2001-08-06 21:48:51 +08:00
|
|
|
CG(ini_parser_param) = &ini_parser_param;
|
2001-07-31 14:07:25 +08:00
|
|
|
if (zend_ini_open_file_for_scanning(fh TSRMLS_CC)==FAILURE) {
|
2000-10-30 06:40:01 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2000-10-30 07:10:04 +08:00
|
|
|
|
2000-10-31 07:19:48 +08:00
|
|
|
CG(ini_parser_unbuffered_errors) = unbuffered_errors;
|
2001-08-06 21:48:51 +08:00
|
|
|
retval = ini_parse(TSRMLS_C);
|
2000-10-30 07:10:04 +08:00
|
|
|
|
2001-07-31 14:07:25 +08:00
|
|
|
zend_ini_close_file(fh TSRMLS_CC);
|
2000-10-30 07:10:04 +08:00
|
|
|
|
|
|
|
if (retval==0) {
|
2000-10-30 06:40:01 +08:00
|
|
|
return SUCCESS;
|
|
|
|
} else {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-29 22:56:16 +08:00
|
|
|
%}
|
|
|
|
|
|
|
|
%pure_parser
|
|
|
|
%token TC_STRING
|
|
|
|
%token TC_ENCAPSULATED_STRING
|
2003-01-19 20:01:38 +08:00
|
|
|
%token BRACK
|
2000-10-29 22:56:16 +08:00
|
|
|
%token SECTION
|
|
|
|
%token CFG_TRUE
|
|
|
|
%token CFG_FALSE
|
|
|
|
%left '|' '&'
|
|
|
|
%right '~' '!'
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
statement_list:
|
|
|
|
statement_list statement
|
|
|
|
| /* empty */
|
|
|
|
;
|
|
|
|
|
|
|
|
statement:
|
|
|
|
TC_STRING '=' string_or_value {
|
|
|
|
#if DEBUG_CFG_PARSER
|
2000-10-30 07:10:04 +08:00
|
|
|
printf("'%s' = '%s'\n", $1.value.str.val, $3.value.str.val);
|
2000-10-29 22:56:16 +08:00
|
|
|
#endif
|
2000-10-30 06:40:01 +08:00
|
|
|
ZEND_INI_PARSER_CB(&$1, &$3, ZEND_INI_PARSER_ENTRY, ZEND_INI_PARSER_ARG);
|
2000-10-30 07:10:04 +08:00
|
|
|
free($1.value.str.val);
|
|
|
|
free($3.value.str.val);
|
2000-10-29 22:56:16 +08:00
|
|
|
}
|
2003-01-19 20:01:38 +08:00
|
|
|
| TC_STRING BRACK '=' string_or_value {
|
|
|
|
#if DEBUG_CFG_PARSER
|
|
|
|
printf("'%s'[ ] = '%s'\n", $1.value.str.val, $4.value.str.val);
|
|
|
|
#endif
|
|
|
|
ZEND_INI_PARSER_CB(&$1, &$4, ZEND_INI_PARSER_POP_ENTRY, ZEND_INI_PARSER_ARG);
|
|
|
|
free($1.value.str.val);
|
|
|
|
free($4.value.str.val);
|
|
|
|
}
|
2000-10-30 07:10:04 +08:00
|
|
|
| TC_STRING { ZEND_INI_PARSER_CB(&$1, NULL, ZEND_INI_PARSER_ENTRY, ZEND_INI_PARSER_ARG); free($1.value.str.val); }
|
|
|
|
| SECTION { ZEND_INI_PARSER_CB(&$1, NULL, ZEND_INI_PARSER_SECTION, ZEND_INI_PARSER_ARG); free($1.value.str.val); }
|
2000-10-29 22:56:16 +08:00
|
|
|
| '\n'
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
string_or_value:
|
|
|
|
expr { $$ = $1; }
|
2004-05-18 04:09:37 +08:00
|
|
|
| TC_ENCAPSULATED_STRING { $$ = $1; }
|
2000-10-29 22:56:16 +08:00
|
|
|
| CFG_TRUE { $$ = $1; }
|
|
|
|
| CFG_FALSE { $$ = $1; }
|
2004-05-18 04:09:37 +08:00
|
|
|
| '\n' { $$.value.str.val = strdup(""); $$.value.str.len=0; $$.type = IS_STRING; }
|
|
|
|
| /* empty */ { $$.value.str.val = strdup(""); $$.value.str.len=0; $$.type = IS_STRING; }
|
2004-05-18 01:12:07 +08:00
|
|
|
;
|
2004-05-15 04:58:15 +08:00
|
|
|
|
2000-10-29 22:56:16 +08:00
|
|
|
expr:
|
|
|
|
constant_string { $$ = $1; }
|
2000-10-30 06:40:01 +08:00
|
|
|
| expr '|' expr { zend_ini_do_op('|', &$$, &$1, &$3); }
|
|
|
|
| expr '&' expr { zend_ini_do_op('&', &$$, &$1, &$3); }
|
|
|
|
| '~' expr { zend_ini_do_op('~', &$$, &$2, NULL); }
|
|
|
|
| '!' expr { zend_ini_do_op('!', &$$, &$2, NULL); }
|
2000-10-29 22:56:16 +08:00
|
|
|
| '(' expr ')' { $$ = $2; }
|
|
|
|
;
|
|
|
|
|
|
|
|
constant_string:
|
2000-10-30 06:40:01 +08:00
|
|
|
TC_STRING { zend_ini_get_constant(&$$, &$1); }
|
2000-10-29 22:56:16 +08:00
|
|
|
;
|
2003-02-01 09:49:15 +08:00
|
|
|
|
2000-10-29 22:56:16 +08:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
2003-02-01 09:49:15 +08:00
|
|
|
* indent-tabs-mode: t
|
2000-10-29 22:56:16 +08:00
|
|
|
* End:
|
|
|
|
*/
|