cvs: php4 /ext/standard ftp_fopen_wrapper.c
| From: | Sara Golemon | Date: | Thu, 24 Apr 2003 21:21:41 +0000 |
| Subject: | cvs: php4 /ext/standard ftp_fopen_wrapper.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-20475@lists.php.net to get a copy of this message | ||
pollita Thu Apr 24 17:21:41 2003 EDT
Modified files:
/php4/ext/standard ftp_fopen_wrapper.c
Log:
Fix error handling bug I just introduced (php_ftp_fopen_connect == NULL) and add append support to
wrapper
Index: php4/ext/standard/ftp_fopen_wrapper.c
diff -u php4/ext/standard/ftp_fopen_wrapper.c:1.49 php4/ext/standard/ftp_fopen_wrapper.c:1.50
--- php4/ext/standard/ftp_fopen_wrapper.c:1.49 Thu Apr 24 16:32:14 2003
+++ php4/ext/standard/ftp_fopen_wrapper.c Thu Apr 24 17:21:41 2003
@@ -17,7 +17,7 @@
| Hartmut Holzgraefe <hholzgra@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: ftp_fopen_wrapper.c,v 1.49 2003/04/24 20:32:14 pollita Exp $ */
+/* $Id: ftp_fopen_wrapper.c,v 1.50 2003/04/24 21:21:41 pollita Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -382,15 +382,34 @@
size_t file_size = 0;
zval **tmpzval;
int allow_overwrite = 0;
+ int read_write = 0;
tmp_line[0] = '\0';
- if (strpbrk(mode, "a+")) {
- php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "FTP does not support simultaneous
read/write connections.");
+ if (strpbrk(mode, "r+")) {
+ read_write = 1; /* Open for reading */
+ }
+ if (strpbrk(mode, "wa+")) {
+ if (read_write) {
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "FTP does not support simultaneous
read/write connections.");
+ return NULL;
+ }
+ if (strchr(mode, 'a')) {
+ read_write = 3; /* Open for Appending */
+ } else {
+ read_write = 2; /* Open for writting */
+ }
+ }
+ if (!read_write) {
+ /* No mode specified? */
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Unknown file open mode.");
return NULL;
}
stream = php_ftp_fopen_connect(wrapper, path, mode, options, opened_path, context, &reuseid,
&resource, &use_ssl, &use_ssl_on_data STREAMS_CC TSRMLS_CC);
+ if (!stream) {
+ goto errext;
+ }
/* set the connection to be binary */
php_stream_write_string(stream, "TYPE I\r\n");
@@ -405,7 +424,8 @@
/* read the response */
result = GET_FTP_RESULT(stream);
- if (mode[0] == 'r') {
+ if (read_write == 1) {
+ /* Read Mode */
char *sizestr;
/* when reading file, it must exist */
@@ -420,8 +440,8 @@
file_size = atoi(sizestr);
php_stream_notify_file_size(context, file_size, tmp_line, result);
}
- } else {
- /* when writing file, it must NOT exist, unless a context option exists which allows it */
+ } else if (read_write == 2) {
+ /* when writing file (but not appending), it must NOT exist, unless a context option exists which
allows it */
if (context && php_stream_context_get_option(context, "ftp",
"overwrite", &tmpzval) == SUCCESS) {
allow_overwrite = Z_LVAL_PP(tmpzval);
}
@@ -451,12 +471,15 @@
}
/* Send RETR/STOR command */
- if (mode[0] == 'r') {
+ if (read_write == 1) {
/* retrieve file */
php_stream_write_string(stream, "RETR ");
- } else {
- /* store file */
+ } else if (read_write == 2) {
+ /* Write new file */
php_stream_write_string(stream, "STOR ");
+ } else {
+ /* Append */
+ php_stream_write_string(stream, "APPE ");
}
if (resource->path != NULL) {
php_stream_write_string(stream, resource->path);