zend_variables.c zend.c zend_API.c zend_extensions.c zend_hash.c \
zend_list.c zend_indent.c zend_builtin_functions.c zend_sprintf.c \
zend_ini.c zend_qsort.c zend_objects.c zend_object_handlers.c \
- zend_object_API.c
+ zend_object_API.c zend_ts_hash.c zend_stream.c
libZend_la_LDFLAGS =
libZend_la_LIBADD = @ZEND_EXTRA_LIBS@
/* Scanner skeleton version:
* $Header$
+ * vim:ft=lex:
*/
#define FLEX_SCANNER
struct yy_buffer_state
{
%-
- FILE *yy_input_file;
+ struct _zend_file_handle *yy_input_file;
%+
istream* yy_input_file;
%*
/* static int yy_did_buffer_switch_on_eof; */
#define yy_did_buffer_switch_on_eof SCNG(_yy_did_buffer_switch_on_eof)
-void yyrestart YY_PROTO(( FILE *input_file TSRMLS_DC ));
+void yyrestart YY_PROTO(( struct _zend_file_handle *input_file TSRMLS_DC ));
void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer TSRMLS_DC ));
void yy_load_buffer_state YY_PROTO(( TSRMLS_D ));
-YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size TSRMLS_DC ));
+YY_BUFFER_STATE yy_create_buffer YY_PROTO(( struct _zend_file_handle *file, int size TSRMLS_DC ));
void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b TSRMLS_DC ));
-void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file TSRMLS_DC ));
+void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, struct _zend_file_handle *file TSRMLS_DC ));
void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b TSRMLS_DC ));
#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer TSRMLS_CC )
/* Copy whatever the last rule matched to the standard output. */
+/* Zend file handle reading */
+#ifndef ECHO
+#define ECHO /* There is no output */
+#endif
+
+#define YY_INPUT(buf, result, max_size) \
+ if ( ((result = zend_stream_read(yyin, buf, max_size TSRMLS_CC)) == 0) \
+ && zend_stream_ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" );
+
+
+
#ifndef ECHO
%- Standard (non-C++) definition
/* This used to be an fputs(), but since the string might contain NUL's,
if ( ! yy_start )
yy_start = 1; /* first start state */
+#if 0
if ( ! SCNG(yy_in) )
%-
SCNG(yy_in) = stdin;
%+
SCNG(yy_out) = &cout;
%*
+#endif
if ( ! yy_current_buffer )
yy_current_buffer =
%-
#ifdef YY_USE_PROTOS
-void yyrestart( FILE *input_file TSRMLS_DC )
+void yyrestart( struct _zend_file_handle *input_file TSRMLS_DC )
#else
void yyrestart( input_file TSRMLS_CC )
-FILE *input_file;
+struct _zend_file_handle *input_file;
#endif
%+
void yyFlexLexer::yyrestart( istream* input_file TSRMLS_DC )
%-
#ifdef YY_USE_PROTOS
-YY_BUFFER_STATE yy_create_buffer( FILE *file, int size TSRMLS_DC )
+YY_BUFFER_STATE yy_create_buffer( struct _zend_file_handle *file, int size TSRMLS_DC )
#else
YY_BUFFER_STATE yy_create_buffer( file, size TSRMLS_CC )
-FILE *file;
+struct _zend_file_handle *file;
int size;
#ifdef ZTS
void ***tsrm_ls;
%-
-#ifndef YY_ALWAYS_INTERACTIVE
-#ifndef YY_NEVER_INTERACTIVE
-ZEND_DLIMPORT int isatty YY_PROTO(( int ));
-#endif
-#endif
#ifdef YY_USE_PROTOS
-void yy_init_buffer( YY_BUFFER_STATE b, FILE *file TSRMLS_DC )
+void yy_init_buffer( YY_BUFFER_STATE b, struct _zend_file_handle *file TSRMLS_DC )
#else
void yy_init_buffer( b, file TSRMLS_CC )
YY_BUFFER_STATE b;
-FILE *file;
+struct _zend_file_handle *file;
#ifdef ZTS
void ***tsrm_ls;
#endif
#if YY_NEVER_INTERACTIVE
b->yy_is_interactive = 0;
#else
- b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+ b->yy_is_interactive = file->handle.stream.interactive;
#endif
#endif
%+
ZEND_API int (*zend_printf)(const char *format, ...);
ZEND_API zend_write_func_t zend_write;
ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
+ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
ZEND_API void (*zend_block_interruptions)(void);
ZEND_API void (*zend_unblock_interruptions)(void);
ZEND_API void (*zend_ticks_function)(int ticks);
if (!zend_fopen) {
zend_fopen = zend_fopen_wrapper;
}
+ zend_stream_open_function = utility_functions->stream_open_function;
zend_message_dispatcher_p = utility_functions->message_handler;
zend_block_interruptions = utility_functions->block_interruptions;
zend_unblock_interruptions = utility_functions->unblock_interruptions;
typedef struct _zend_class_entry zend_namespace; /* namespace is the same as class */
+#include "zend_stream.h"
typedef struct _zend_utility_functions {
void (*error_function)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
int (*printf_function)(const char *format, ...);
int (*get_configuration_directive)(char *name, uint name_length, zval *contents);
void (*ticks_function)(int ticks);
void (*on_timeout)(int seconds TSRMLS_DC);
+ int (*stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
} zend_utility_functions;
extern ZEND_API void (*zend_ticks_function)(int ticks);
extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
extern void (*zend_on_timeout)(int seconds TSRMLS_DC);
+extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
ZEND_API void zend_error(int type, const char *format, ...);
znode value;
} list_llist_element;
-
-typedef struct _zend_file_handle {
- zend_uchar type;
- char *filename;
- char *opened_path;
- union {
- int fd;
- FILE *fp;
- } handle;
- zend_bool free_filename;
-} zend_file_handle;
-
union _temp_variable;
struct _zend_execute_data {
#define ZEND_HANDLE_FP 2
#define ZEND_HANDLE_STDIOSTREAM 3
#define ZEND_HANDLE_FSTREAM 4
+#define ZEND_HANDLE_STREAM 5
#define ZEND_FETCH_STANDARD 0
#define ZEND_FETCH_ADD_LOCK 1
switch (EX(opline)->op2.u.constant.value.lval) {
case ZEND_INCLUDE_ONCE:
case ZEND_REQUIRE_ONCE: {
- char *opened_path=NULL;
int dummy = 1;
zend_file_handle file_handle;
- file_handle.handle.fp = zend_fopen(inc_filename->value.str.val, &opened_path);
- file_handle.type = ZEND_HANDLE_FP;
- file_handle.filename = inc_filename->value.str.val;
- file_handle.opened_path = opened_path;
- file_handle.free_filename = 0;
+ if (SUCCESS == zend_stream_open(inc_filename->value.str.val, &file_handle TSRMLS_CC)) {
- if (file_handle.handle.fp) {
- if (!opened_path) {
- opened_path = file_handle.opened_path = estrndup(inc_filename->value.str.val, inc_filename->value.str.len);
+ if (!file_handle.opened_path) {
+ file_handle.opened_path = estrndup(inc_filename->value.str.val, inc_filename->value.str.len);
}
- if (zend_hash_add(&EG(included_files), opened_path, strlen(opened_path)+1, (void *)&dummy, sizeof(int), NULL)==SUCCESS) {
+ if (zend_hash_add(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path)+1, (void *)&dummy, sizeof(int), NULL)==SUCCESS) {
CG(active_namespace) = EG(active_namespace);
new_op_array = zend_compile_file(&file_handle, (EX(opline)->op2.u.constant.value.lval==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE) TSRMLS_CC);
zend_destroy_file_handle(&file_handle TSRMLS_CC);
- opened_path = NULL; /* zend_destroy_file_handle() already frees it */
} else {
- fclose(file_handle.handle.fp);
+ zend_file_handle_dtor(&file_handle);
failure_retval=1;
}
} else {
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle.filename);
}
}
- if (opened_path) {
- efree(opened_path);
- }
break;
}
break;
};
struct _zend_scanner_globals {
- FILE *yy_in;
- FILE *yy_out;
+ zend_file_handle *yy_in;
+ zend_file_handle *yy_out;
int yy_leng;
char *yy_text;
struct yy_buffer_state *current_buffer;
int zend_ini_open_file_for_scanning(zend_file_handle *fh TSRMLS_DC)
{
- FILE *fp;
-
- switch (fh->type) {
- case ZEND_HANDLE_FP:
- fp = fh->handle.fp;
- break;
- case ZEND_HANDLE_FILENAME:
- fp = zend_fopen(fh->filename, NULL);
- fh->type = ZEND_HANDLE_FP;
- break;
- default:
- return FAILURE;
+ if (FAILURE == zend_stream_fixup(fh TSRMLS_CC)) {
+ return FAILURE;
}
init_ini_scanner(TSRMLS_C);
- yyin = fp;
+ yyin = fh;
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE TSRMLS_CC) TSRMLS_CC);
ini_filename = fh->filename;
return SUCCESS;
void zend_ini_close_file(zend_file_handle *fh TSRMLS_DC)
{
- switch (fh->type) {
- case ZEND_HANDLE_FP:
- fclose(fh->handle.fp);
- break;
- }
+ zend_stream_close(fh);
}
%}
typedef struct _zend_lex_state {
YY_BUFFER_STATE buffer_state;
int state;
- FILE *in;
+ zend_file_handle *in;
uint lineno;
char *filename;
} zend_lex_state;
ZEND_API void zend_file_handle_dtor(zend_file_handle *fh)
{
+ TSRMLS_FETCH();
+
switch (fh->type) {
case ZEND_HANDLE_FP:
fclose(fh->handle.fp);
break;
+ case ZEND_HANDLE_STREAM:
+ fh->handle.stream.closer(fh->handle.stream.handle TSRMLS_CC);
+ break;
case ZEND_HANDLE_FILENAME:
/* We're only supposed to get here when destructing the used_files hash,
* which doesn't really contain open files, but references to their names/paths
}
if (fh->opened_path) {
efree(fh->opened_path);
+ fh->opened_path = NULL;
}
if (fh->free_filename && fh->filename) {
efree(fh->filename);
+ fh->filename = NULL;
}
}
case ZEND_HANDLE_FP:
return fh1->handle.fp==fh2->handle.fp;
break;
+ case ZEND_HANDLE_STREAM:
+ return fh1->handle.stream.handle == fh2->handle.stream.handle;
+ break;
}
return 0;
}
{
char *file_path=NULL;
- switch (file_handle->type) {
- case ZEND_HANDLE_FILENAME:
- file_handle->handle.fp = zend_fopen(file_handle->filename, &file_handle->opened_path);
- break;
- case ZEND_HANDLE_FD:
- file_handle->handle.fp = fdopen(file_handle->handle.fd, "r");
- break;
- case ZEND_HANDLE_FP:
- file_handle->handle.fp = file_handle->handle.fp;
- break;
- }
- if (!file_handle->handle.fp) {
+ if (FAILURE == zend_stream_fixup(file_handle TSRMLS_CC)) {
return FAILURE;
}
- file_handle->type = ZEND_HANDLE_FP;
- if (file_handle->handle.fp != stdin) {
- zend_llist_add_element(&CG(open_files), file_handle);
- }
+ zend_llist_add_element(&CG(open_files), file_handle);
+
/* Reset the scanner for scanning the new file */
- SCNG(yy_in) = file_handle->handle.fp;
+ SCNG(yy_in) = file_handle;
yy_switch_to_buffer(yy_create_buffer(SCNG(yy_in), YY_BUF_SIZE TSRMLS_CC) TSRMLS_CC);
BEGIN(INITIAL);
retval = zend_compile_file(&file_handle, type TSRMLS_CC);
- if (retval && file_handle.handle.fp) {
+ if (retval && file_handle.handle.stream.handle) {
int dummy = 1;
if (!file_handle.opened_path) {
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | Zend Engine |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1998-2003 Zend Technologies Ltd. (http://www.zend.com) |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.00 of the Zend license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.zend.com/license/2_00.txt. |
+ | 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. |
+ +----------------------------------------------------------------------+
+ | Authors: Wez Furlong <wez@thebrainroom.com> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+
+#include "zend.h"
+#include "zend_compile.h"
+
+ZEND_DLIMPORT int isatty(int fd);
+
+static size_t zend_stream_stdio_reader(void *handle, char *buf, size_t len TSRMLS_DC)
+{
+ return fread(buf, 1, len, (FILE*)handle);
+}
+
+static void zend_stream_stdio_closer(void *handle TSRMLS_DC)
+{
+ if ((FILE*)handle != stdin)
+ fclose((FILE*)handle);
+}
+
+int zend_stream_open(const char *filename, zend_file_handle *handle TSRMLS_DC)
+{
+ if (zend_stream_open) {
+ return zend_stream_open_function(filename, handle TSRMLS_CC);
+ }
+ handle->type = ZEND_HANDLE_FP;
+ handle->opened_path = NULL;
+ handle->handle.fp = zend_fopen(filename, &handle->opened_path);
+ handle->filename = (char *)filename;
+ handle->free_filename = 0;
+
+ return (handle->handle.fp) ? SUCCESS : FAILURE;
+}
+
+int zend_stream_fixup(zend_file_handle *file_handle TSRMLS_DC)
+{
+ switch (file_handle->type) {
+ case ZEND_HANDLE_FILENAME:
+ if (FAILURE == zend_stream_open(file_handle->filename, file_handle TSRMLS_CC)) {
+ return FAILURE;
+ }
+ break;
+
+ case ZEND_HANDLE_FD:
+ file_handle->handle.fp = fdopen(file_handle->handle.fd, "rb");
+ file_handle->type = ZEND_HANDLE_FP;
+ break;
+
+ case ZEND_HANDLE_FP:
+ file_handle->handle.fp = file_handle->handle.fp;
+ break;
+
+ case ZEND_HANDLE_STREAM:
+ /* nothing to do */
+ return SUCCESS;
+
+ default:
+ return FAILURE;
+ }
+ if (file_handle->type == ZEND_HANDLE_FP) {
+ if (!file_handle->handle.fp) {
+ return FAILURE;
+ }
+
+ /* promote to stream */
+ file_handle->handle.stream.handle = file_handle->handle.fp;
+ file_handle->handle.stream.reader = zend_stream_stdio_reader;
+ file_handle->handle.stream.closer = zend_stream_stdio_closer;
+ file_handle->type = ZEND_HANDLE_STREAM;
+
+ file_handle->handle.stream.interactive = isatty(fileno(file_handle->handle.stream.handle));
+ }
+ return SUCCESS;
+}
+
+size_t zend_stream_read(zend_file_handle *file_handle, char *buf, size_t len TSRMLS_DC)
+{
+ if (file_handle->handle.stream.interactive) {
+ int c = '*', n;
+
+ for ( n = 0; n < len && (c = zend_stream_getc( file_handle TSRMLS_CC)) != EOF && c != '\n'; ++n )
+ buf[n] = (char) c;
+ if ( c == '\n' )
+ buf[n++] = (char) c;
+
+ return n;
+ }
+ return file_handle->handle.stream.reader(file_handle->handle.stream.handle, buf, len TSRMLS_CC);
+}
+
+int zend_stream_getc(zend_file_handle *file_handle TSRMLS_DC)
+{
+ char buf;
+
+ if (zend_stream_read(file_handle, &buf, sizeof(buf) TSRMLS_CC)) {
+ return buf;
+ }
+ return EOF;
+}
+
+int zend_stream_ferror(zend_file_handle *file_handle TSRMLS_DC)
+{
+ return 0;
+}
+
+
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | Zend Engine |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1998-2003 Zend Technologies Ltd. (http://www.zend.com) |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.00 of the Zend license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.zend.com/license/2_00.txt. |
+ | 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. |
+ +----------------------------------------------------------------------+
+ | Authors: Wez Furlong <wez@thebrainroom.com> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef ZEND_STREAM_H
+#define ZEND_STREAM_H
+
+/* Lightweight stream implementation for the ZE scanners.
+ * These functions are private to the engine.
+ * */
+
+typedef size_t (*zend_stream_reader_t)(void *handle, char *buf, size_t len TSRMLS_DC);
+typedef void (*zend_stream_closer_t)(void *handle TSRMLS_DC);
+
+typedef struct _zend_stream {
+ void *handle;
+ zend_stream_reader_t reader;
+ zend_stream_closer_t closer;
+ int interactive;
+} zend_stream;
+
+typedef struct _zend_file_handle {
+ zend_uchar type;
+ char *filename;
+ char *opened_path;
+ union {
+ int fd;
+ FILE *fp;
+ zend_stream stream;
+ } handle;
+ zend_bool free_filename;
+} zend_file_handle;
+
+int zend_stream_open(const char *filename, zend_file_handle *handle TSRMLS_DC);
+int zend_stream_ferror(zend_file_handle *file_handle TSRMLS_DC);
+int zend_stream_getc(zend_file_handle *file_handle TSRMLS_DC);
+size_t zend_stream_read(zend_file_handle *file_handle, char *buf, size_t len TSRMLS_DC);
+int zend_stream_fixup(zend_file_handle *file_handle TSRMLS_DC);
+
+#define zend_stream_close(handle) zend_file_handle_dtor((handle))
+
+#endif
+
zend_opcode.c zend_operators.c zend_ptr_stack.c zend_stack.c \
zend_variables.c zend.c zend_API.c zend_extensions.c zend_hash.c \
zend_list.c zend_indent.c zend_builtin_functions.c zend_sprintf.c \
- zend_ini.c zend_qsort.c zend_multibyte.c)
+ zend_ini.c zend_qsort.c zend_multibyte.c zend_ts_hash.c zend_stream.c)
if test -r "$abs_srcdir/Zend/zend_objects.c"; then
PHP_ADD_SOURCES(Zend, zend_objects.c zend_object_handlers.c zend_objects_API.c zend_mm.c)
convert_to_string_ex(filename);
- if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_ONLY_FILE))) {
- RETURN_FALSE;
- }
-
- if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
- fh.handle.fp = VCWD_FOPEN(Z_STRVAL_PP(filename), "r");
- if (!fh.handle.fp) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot open '%s' for reading", Z_STRVAL_PP(filename));
- RETURN_FALSE;
- }
- Z_TYPE(fh) = ZEND_HANDLE_FP;
+ memset(&fh, 0, sizeof(fh));
fh.filename = Z_STRVAL_PP(filename);
+ Z_TYPE(fh) = ZEND_HANDLE_FILENAME;
+
array_init(return_value);
zend_parse_ini_file(&fh, 0, ini_parser_cb, return_value);
}
}
/* }}} */
+static void stream_closer_for_zend(void *handle TSRMLS_DC)
+{
+ php_stream_close((php_stream*)handle);
+}
+
+static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle TSRMLS_DC)
+{
+ php_stream *stream;
+
+ stream = php_stream_open_wrapper((char *)filename, "rb", ENFORCE_SAFE_MODE|USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, &handle->opened_path);
+
+ if (stream) {
+ handle->type = ZEND_HANDLE_STREAM;
+ handle->filename = (char*)filename;
+ handle->free_filename = 0;
+ handle->handle.stream.handle = stream;
+ handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read;
+ handle->handle.stream.closer = stream_closer_for_zend;
+ handle->handle.stream.interactive = 0;
+
+ return SUCCESS;
+ }
+ return FAILURE;
+}
+
+
/* {{{ php_get_configuration_directive_for_zend
*/
static int php_get_configuration_directive_for_zend(char *name, uint name_length, zval *contents)
zuf.get_configuration_directive = php_get_configuration_directive_for_zend;
zuf.ticks_function = php_run_ticks;
zuf.on_timeout = php_on_timeout;
+ zuf.stream_open_function = php_stream_open_for_zend;
zend_startup(&zuf, NULL, 1);
#ifdef ZTS
PG(safe_mode) = 0;
PG(open_basedir) = NULL;
- fh.handle.fp = NULL;
+ memset(&fh, 0, sizeof(fh));
/* Check if php_ini_path_override is a file */
if (!sapi_module.php_ini_ignore) {
if (sapi_module.php_ini_path_override && sapi_module.php_ini_path_override[0]) {