diff options
author | Sara Golemon <pollita@php.net> | 2003-09-18 17:36:08 +0000 |
---|---|---|
committer | Sara Golemon <pollita@php.net> | 2003-09-18 17:36:08 +0000 |
commit | c553af47e06c434ea943d51a386c5f156ce34875 (patch) | |
tree | f0efa9faaf4208575dcc52b0606d5e58a24bf2db | |
parent | 3efe102a4801a36f5515e8166c967ac595b4876e (diff) | |
download | php-git-c553af47e06c434ea943d51a386c5f156ce34875.tar.gz |
Add ftp_alloc() for servers which require client to predeclare filesize to be sent.
-rw-r--r-- | ext/ftp/ftp.c | 32 | ||||
-rw-r--r-- | ext/ftp/ftp.h | 7 | ||||
-rw-r--r-- | ext/ftp/php_ftp.c | 37 | ||||
-rw-r--r-- | ext/ftp/php_ftp.h | 1 |
4 files changed, 77 insertions, 0 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 03425a2d36..152b678b6b 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -605,6 +605,38 @@ ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filenam } /* }}} */ +/* {{{ ftp_alloc + */ +int +ftp_alloc(ftpbuf_t *ftp, const int size, char **response) +{ + char buffer[64]; + + if (ftp == NULL || size <= 0) { + return 0; + } + + snprintf(buffer, 64, "%d", size); + + if (!ftp_putcmd(ftp, "ALLO", buffer)) { + return 0; + } + + if (!ftp_getresp(ftp)) { + return 0; + } + + if (response && ftp->inbuf) { + *response = estrdup(ftp->inbuf); + } + + if (ftp->resp < 200 || ftp->resp >= 300) { + return 0; + } + + return 1; +} +/* }}} */ /* {{{ ftp_nlist */ diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h index 0628a0dfcf..35eb376ac4 100644 --- a/ext/ftp/ftp.h +++ b/ext/ftp/ftp.h @@ -141,6 +141,13 @@ int ftp_rmdir(ftpbuf_t *ftp, const char *dir); /* Set permissions on a file */ int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len); +/* Allocate space on remote server with ALLO command + * Many servers will respond with 202 Allocation not necessary, + * however some servers will not accept STOR or APPE until ALLO is confirmed. + * If response is passed, it is estrdup()ed from ftp->inbuf and must be freed + * or assigned to a zval returned to the user */ +int ftp_alloc(ftpbuf_t *ftp, const int size, char **response); + /* returns a NULL-terminated array of filenames in the given path * or NULL on error. the return array must be freed (but don't * free the array elements) diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c index 0d0d7e0ae9..e6a496a2ce 100644 --- a/ext/ftp/php_ftp.c +++ b/ext/ftp/php_ftp.c @@ -50,6 +50,13 @@ static int le_ftpbuf; #define le_ftpbuf_name "FTP Buffer" +static + ZEND_BEGIN_ARG_INFO(third_and_rest_force_ref, 1) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(1) + ZEND_END_ARG_INFO() + function_entry php_ftp_functions[] = { PHP_FE(ftp_connect, NULL) #ifdef HAVE_OPENSSL_EXT @@ -64,6 +71,7 @@ function_entry php_ftp_functions[] = { PHP_FE(ftp_mkdir, NULL) PHP_FE(ftp_rmdir, NULL) PHP_FE(ftp_chmod, NULL) + PHP_FE(ftp_alloc, third_and_rest_force_ref) PHP_FE(ftp_nlist, NULL) PHP_FE(ftp_rawlist, NULL) PHP_FE(ftp_systype, NULL) @@ -430,6 +438,35 @@ PHP_FUNCTION(ftp_chmod) } /* }}} */ +/* {{{ proto bool ftp_alloc(resource stream, int size[, &response]) + Attempt to allocate space on the remote FTP server */ +PHP_FUNCTION(ftp_alloc) +{ + zval *z_ftp, *zresponse = NULL; + ftpbuf_t *ftp; + int size, ret; + char *response = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z", &z_ftp, &size, &zresponse) == FAILURE) { + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf); + + ret = ftp_alloc(ftp, size, zresponse ? &response : NULL); + if (response) { + zval_dtor(zresponse); + ZVAL_STRING(zresponse, response, 0); + } + + if (!ret) { + RETURN_FALSE; + } + + RETURN_TRUE; +} +/* }}} */ + /* {{{ proto array ftp_nlist(resource stream, string directory) Returns an array of filenames in the given directory */ PHP_FUNCTION(ftp_nlist) diff --git a/ext/ftp/php_ftp.h b/ext/ftp/php_ftp.h index a8bb36f93a..d7a6d26c3f 100644 --- a/ext/ftp/php_ftp.h +++ b/ext/ftp/php_ftp.h @@ -47,6 +47,7 @@ PHP_FUNCTION(ftp_raw); PHP_FUNCTION(ftp_mkdir); PHP_FUNCTION(ftp_rmdir); PHP_FUNCTION(ftp_chmod); +PHP_FUNCTION(ftp_alloc); PHP_FUNCTION(ftp_nlist); PHP_FUNCTION(ftp_rawlist); PHP_FUNCTION(ftp_systype); |