cvs: php4 /main fopen_wrappers.c fopen_wrappers.h /sapi/cgi cgi_main.c /sapi/servlet servlet.c
| From: | Andi Gutmans | Date: | Sat, 21 Jul 2001 15:11:33 +0000 |
| Subject: | cvs: php4 /main fopen_wrappers.c fopen_wrappers.h /sapi/cgi cgi_main.c /sapi/servlet servlet.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-6305@lists.php.net to get a copy of this message | ||
andi Sat Jul 21 11:11:33 2001 EDT
Modified files:
/php4/main fopen_wrappers.c fopen_wrappers.h
/php4/sapi/cgi cgi_main.c
/php4/sapi/servlet servlet.c
Log:
- Fix __FILE__ in the main script in CGI/command line mode.
Index: php4/main/fopen_wrappers.c
diff -u php4/main/fopen_wrappers.c:1.125 php4/main/fopen_wrappers.c:1.126
--- php4/main/fopen_wrappers.c:1.125 Mon Jul 16 09:48:07 2001
+++ php4/main/fopen_wrappers.c Sat Jul 21 11:11:21 2001
@@ -16,7 +16,7 @@
| Jim Winstead <jimw@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: fopen_wrappers.c,v 1.125 2001/07/16 13:48:07 zeev Exp $ */
+/* $Id: fopen_wrappers.c,v 1.126 2001/07/21 15:11:21 andi Exp $ */
/* {{{ includes
*/
@@ -86,9 +86,6 @@
static FILE *php_fopen_url_wrapper(const char *, char *, int, int *, int *, char **);
-PHPAPI char *expand_filepath(const char *filepath, char *real_path);
-
-
HashTable fopen_url_wrappers_hash;
/* {{{ php_register_url_wrapper
@@ -250,7 +247,7 @@
}
fp = VCWD_FOPEN(path, mode);
if (fp && opened_path) {
- *opened_path = expand_filepath(path,NULL);
+ *opened_path = expand_filepath(path, NULL);
}
return fp;
}
@@ -288,7 +285,7 @@
/* {{{ php_fopen_primary_script
*/
-PHPAPI FILE *php_fopen_primary_script(void)
+PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
{
FILE *fp;
struct stat st;
@@ -355,7 +352,8 @@
we're not adding it in this case */
STR_FREE(SG(request_info).path_translated);
SG(request_info).path_translated = NULL;
- return NULL;
+ file_handle->handle.fp = NULL;
+ return FAILURE;
}
fp = VCWD_FOPEN(filename, "rb");
@@ -367,14 +365,23 @@
if (!fp) {
php_error(E_ERROR, "Unable to open %s", filename);
STR_FREE(SG(request_info).path_translated); /* for same reason as above */
- return NULL;
+ file_handle->handle.fp = NULL;
+ return FAILURE;
}
+
+ file_handle->opened_path = expand_filepath(filename, NULL);
+
if (!(SG(options) & SAPI_OPTION_NO_CHDIR)) {
VCWD_CHDIR_FILE(filename);
}
SG(request_info).path_translated = filename;
- return fp;
+ file_handle->filename = SG(request_info).path_translated;
+ file_handle->free_filename = 0;
+ file_handle->handle.fp = fp;
+ file_handle->type = ZEND_HANDLE_FP;
+
+ return SUCCESS;
}
/* }}} */
@@ -643,7 +650,7 @@
if(real_path) {
int copy_len = new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length;
- memcpy(real_path,new_state.cwd,copy_len);
+ memcpy(real_path, new_state.cwd, copy_len);
real_path[copy_len]='\0';
} else {
real_path = estrndup(new_state.cwd, new_state.cwd_length);
Index: php4/main/fopen_wrappers.h
diff -u php4/main/fopen_wrappers.h:1.24 php4/main/fopen_wrappers.h:1.25
--- php4/main/fopen_wrappers.h:1.24 Mon Feb 26 01:07:31 2001
+++ php4/main/fopen_wrappers.h Sat Jul 21 11:11:29 2001
@@ -15,7 +15,7 @@
| Authors: Jim Winstead <jimw@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: fopen_wrappers.h,v 1.24 2001/02/26 06:07:31 andi Exp $ */
+/* $Id: fopen_wrappers.h,v 1.25 2001/07/21 15:11:29 andi Exp $ */
#ifndef FOPEN_WRAPPERS_H
#define FOPEN_WRAPPERS_H
@@ -66,7 +66,8 @@
PHPAPI FILE *php_fopen_wrapper(char *filename, char *mode, int options, int *issock, int *socketd,
char **opened_path);
-PHPAPI FILE *php_fopen_primary_script(void);
+PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle);
+PHPAPI char *expand_filepath(const char *filepath, char *real_path);
PHPAPI int php_check_open_basedir(char *path);
PHPAPI int php_check_specific_open_basedir(char *basedir, char *path PLS_DC);
Index: php4/sapi/cgi/cgi_main.c
diff -u php4/sapi/cgi/cgi_main.c:1.117 php4/sapi/cgi/cgi_main.c:1.118
--- php4/sapi/cgi/cgi_main.c:1.117 Sat Jul 21 10:27:55 2001
+++ php4/sapi/cgi/cgi_main.c Sat Jul 21 11:11:29 2001
@@ -368,6 +368,7 @@
int exit_status = SUCCESS;
int cgi = 0, c, i, len;
zend_file_handle file_handle;
+ int retval = FAILURE;
char *s;
/* temporary locals */
int behavior=PHP_MODE_STANDARD;
@@ -676,6 +677,7 @@
file_handle.type = ZEND_HANDLE_FP;
file_handle.handle.fp = stdin;
file_handle.opened_path = NULL;
+ file_handle.free_filename = 0;
/* This actually destructs the elements of the list - ugly hack */
zend_llist_apply(&global_vars, (llist_apply_func_t) php_register_command_line_global_vars);
@@ -703,11 +705,10 @@
}
}
if (cgi || SG(request_info).path_translated) {
- file_handle.handle.fp = php_fopen_primary_script();
- file_handle.filename = SG(request_info).path_translated;
+ retval = php_fopen_primary_script(&file_handle);
}
- if (cgi && !file_handle.handle.fp) {
+ if (cgi && (retval == FAILURE)) {
if(!argv0 || !(file_handle.handle.fp = VCWD_FOPEN(argv0, "rb"))) {
PUTS("No input file specified.\n");
php_request_shutdown((void *) 0);
@@ -715,7 +716,8 @@
return FAILURE;
}
file_handle.filename = argv0;
- } else if (file_handle.handle.fp && file_handle.handle.fp!=stdin) {
+ file_handle.opened_path = expand_filepath(argv0, NULL);
+ } else if (retval == SUCCESS) {
/* #!php support */
c = fgetc(file_handle.handle.fp);
if (c == '#') {
@@ -728,7 +730,6 @@
}
}
- file_handle.free_filename = 0;
switch (behavior) {
case PHP_MODE_STANDARD:
exit_status = php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC);
Index: php4/sapi/servlet/servlet.c
diff -u php4/sapi/servlet/servlet.c:1.47 php4/sapi/servlet/servlet.c:1.48
--- php4/sapi/servlet/servlet.c:1.47 Sat Jul 21 10:27:56 2001
+++ php4/sapi/servlet/servlet.c Sat Jul 21 11:11:30 2001
@@ -315,6 +315,7 @@
jstring authUser, jboolean display_source_mode)
{
zend_file_handle file_handle;
+ int retval;
#ifndef VIRTUAL_DIR
char cwd[MAXPATHLEN];
#endif
@@ -352,7 +353,7 @@
*/
SETSTRING( SG(request_info).path_translated, pathTranslated );
#ifdef VIRTUAL_DIR
- file_handle.handle.fp = php_fopen_primary_script();
+ retval = php_fopen_primary_script(&file_handle);
#else
/*
* The java runtime doesn't like the working directory to be
@@ -360,15 +361,11 @@
* in the hopes that Java doesn't notice.
*/
getcwd(cwd,MAXPATHLEN);
- file_handle.handle.fp = php_fopen_primary_script();
+ retval = php_fopen_primary_script(&file_handle);
chdir(cwd);
#endif
- file_handle.filename = SG(request_info).path_translated;
- file_handle.opened_path = NULL;
- file_handle.free_filename = 0;
- file_handle.type = ZEND_HANDLE_FP;
-
- if (!file_handle.handle.fp) {
+
+ if (retval == FAILURE) {
php_request_shutdown((void *) 0);
php_module_shutdown();
ThrowIOException(jenv,file_handle.filename);
@@ -385,7 +382,7 @@
if (open_file_for_scanning(&file_handle CLS_CC)==SUCCESS) {
php_get_highlight_struct(&syntax_highlighter_ini);
- sapi_send_headers();
+ sapi_send_headers();
zend_highlight(&syntax_highlighter_ini);
}
} else {