cvs: php4 /ext/ftp ftp.c ftp.h php_ftp.c
| From: | Jason Greene | Date: | Tue, 17 Jul 2001 05:53:03 +0000 |
| Subject: | cvs: php4 /ext/ftp ftp.c ftp.h php_ftp.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-6247@lists.php.net to get a copy of this message | ||
jason Tue Jul 17 01:53:03 2001 EDT
Modified files:
/php4/ext/ftp ftp.c ftp.h php_ftp.c
Log:
@Added support for socket and popen file types to ftp_fput (Jason)
Index: php4/ext/ftp/ftp.c
diff -u php4/ext/ftp/ftp.c:1.33 php4/ext/ftp/ftp.c:1.34
--- php4/ext/ftp/ftp.c:1.33 Tue Jun 19 17:25:53 2001
+++ php4/ext/ftp/ftp.c Tue Jul 17 01:53:03 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: ftp.c,v 1.33 2001/06/19 21:25:53 sbergmann Exp $ */
+/* $Id: ftp.c,v 1.34 2001/07/17 05:53:03 jason Exp $ */
#include "php.h"
@@ -582,7 +582,7 @@
/* {{{ ftp_put
*/
int
-ftp_put(ftpbuf_t *ftp, const char *path, FILE *infp, ftptype_t type)
+ftp_put(ftpbuf_t *ftp, const char *path, FILE *infp, int insocket, int issock, ftptype_t type)
{
databuf_t *data = NULL;
int size;
@@ -608,7 +608,7 @@
size = 0;
ptr = data->buf;
- while ((ch = getc(infp)) != EOF) {
+ while ((ch = FP_FGETC(insocket, infp, issock))!=EOF && !FP_FEOF(insocket, infp, issock)) {
/* flush if necessary */
if (FTP_BUFSIZE - size < 2) {
if (my_send(data->fd, data->buf, size) != size)
@@ -629,7 +629,7 @@
if (size && my_send(data->fd, data->buf, size) != size)
goto bail;
- if (ferror(infp))
+ if (!issock && ferror(infp))
goto bail;
data = data_close(data);
Index: php4/ext/ftp/ftp.h
diff -u php4/ext/ftp/ftp.h:1.16 php4/ext/ftp/ftp.h:1.17
--- php4/ext/ftp/ftp.h:1.16 Tue Jun 19 17:25:53 2001
+++ php4/ext/ftp/ftp.h Tue Jul 17 01:53:03 2001
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: ftp.h,v 1.16 2001/06/19 21:25:53 sbergmann Exp $ */
+/* $Id: ftp.h,v 1.17 2001/07/17 05:53:03 jason Exp $ */
#ifndef FTP_H
#define FTP_H
@@ -130,11 +130,11 @@
int ftp_get(ftpbuf_t *ftp, FILE *outfp, const char *path,
ftptype_t type);
-/* stores the data from infp as a file on the remote server
+/* stores the data from a file, socket, or process as a file on the remote server
* returns true on success, false on error
*/
int ftp_put(ftpbuf_t *ftp, const char *path, FILE *infp,
- ftptype_t type);
+ int insocket, int issock, ftptype_t type);
/* returns the size of the given file, or -1 on error */
int ftp_size(ftpbuf_t *ftp, const char *path);
Index: php4/ext/ftp/php_ftp.c
diff -u php4/ext/ftp/php_ftp.c:1.34 php4/ext/ftp/php_ftp.c:1.35
--- php4/ext/ftp/php_ftp.c:1.34 Tue Jun 19 17:25:53 2001
+++ php4/ext/ftp/php_ftp.c Tue Jul 17 01:53:03 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_ftp.c,v 1.34 2001/06/19 21:25:53 sbergmann Exp $ */
+/* $Id: php_ftp.c,v 1.35 2001/07/17 05:53:03 jason Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -618,7 +618,8 @@
pval *arg1, *arg2, *arg3, *arg4;
ftpbuf_t *ftp;
ftptype_t xtype;
- FILE *fp;
+ int type;
+ void *rsrc;
/* arg1 - ftp
* arg2 - remote file
@@ -633,10 +634,11 @@
FTPBUF(ftp, arg1);
convert_to_string(arg2);
- FILEP(fp, arg3);
+ rsrc =
zend_fetch_resource(&arg3,-1,"File-Handle",&type,3,php_file_le_fopen(),php_file_le_popen(),php_file_le_socket());
+ ZEND_VERIFY_RESOURCE(rsrc);
XTYPE(xtype, arg4);
- if (!ftp_put(ftp, Z_STRVAL_P(arg2), fp, xtype)) {
+ if (!ftp_put(ftp, Z_STRVAL_P(arg2), (FILE*)rsrc, *(int*) rsrc, (type==php_file_le_socket()),
xtype)) {
php_error(E_WARNING, "ftp_put: %s", ftp->inbuf);
RETURN_FALSE;
}
@@ -679,7 +681,7 @@
php_error(E_WARNING, "error opening %s", Z_STRVAL_P(arg3));
RETURN_FALSE;
}
- if ( !ftp_put(ftp, Z_STRVAL_P(arg2), infp, xtype) ||
+ if ( !ftp_put(ftp, Z_STRVAL_P(arg2), infp, 0, 0, xtype) ||
ferror(infp))
{
fclose(infp);