From: Sara Golemon Date: Wed, 21 Oct 2020 22:09:08 +0000 (+0000) Subject: Convert FTP resource to object X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4503fbf882e490f16d85915e83173bd1e414e84;p=php Convert FTP resource to object --- diff --git a/NEWS b/NEWS index d184029a6a..6ba5082877 100644 --- a/NEWS +++ b/NEWS @@ -2,4 +2,7 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.1.0alpha1 +- FTP: + . Convert resource to object \FTPConnection. (Sara) + <<< NOTE: Insert NEWS from last stable release here prior to actual release! >>> diff --git a/ext/ftp/ftp.stub.php b/ext/ftp/ftp.stub.php index f4812655a4..698cfe215c 100644 --- a/ext/ftp/ftp.stub.php +++ b/ext/ftp/ftp.stub.php @@ -2,133 +2,57 @@ /** @generate-function-entries */ -/** @return resource|false */ -function ftp_connect(string $hostname, int $port = 21, int $timeout = 90) {} +function ftp_connect(string $hostname, int $port = 21, int $timeout = 90): FTPConnection|false {} #ifdef HAVE_FTP_SSL -/** @return resource|false */ -function ftp_ssl_connect(string $hostname, int $port = 21, int $timeout = 90) {} +function ftp_ssl_connect(string $hostname, int $port = 21, int $timeout = 90): FTPConnection|false {} #endif -/** @param resource $ftp */ -function ftp_login($ftp, string $username, string $password): bool {} - -/** @param resource $ftp */ -function ftp_pwd($ftp): string|false {} - -/** @param resource $ftp */ -function ftp_cdup($ftp): bool {} - -/** @param resource $ftp */ -function ftp_chdir($ftp, string $directory): bool {} - -/** @param resource $ftp */ -function ftp_exec($ftp, string $command): bool {} - -/** @param resource $ftp */ -function ftp_raw($ftp, string $command): array {} - -/** @param resource $ftp */ -function ftp_mkdir($ftp, string $directory): string|false {} - -/** @param resource $ftp */ -function ftp_rmdir($ftp, string $directory): bool {} - -/** @param resource $ftp */ -function ftp_chmod($ftp, int $permissions, string $filename): int|false {} - -/** - * @param resource $ftp - * @param string $response - */ -function ftp_alloc($ftp, int $size, &$response = null): bool {} - -/** @param resource $ftp */ -function ftp_nlist($ftp, string $directory): array|false {} - -/** @param resource $ftp */ -function ftp_rawlist($ftp, string $directory, bool $recursive = false): array|false {} - -/** @param resource $ftp */ -function ftp_mlsd($ftp, string $directory): array|false {} - -/** @param resource $ftp */ -function ftp_systype($ftp): string|false {} - -/** - * @param resource $ftp - * @param resource $stream - */ -function ftp_fget($ftp, $stream, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): bool {} - -/** - * @param resource $ftp - * @param resource $stream - */ -function ftp_nb_fget($ftp, $stream, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): int {} - -/** @param resource $ftp */ -function ftp_pasv($ftp, bool $enable): bool {} - -/** @param resource $ftp */ -function ftp_get($ftp, string $local_filename, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): bool {} - -/** @param resource $ftp */ -function ftp_nb_get($ftp, string $local_filename, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): int {} - -/** @param resource $ftp */ -function ftp_nb_continue($ftp): int {} - -/** - * @param resource $ftp - * @param resource $stream - */ -function ftp_fput($ftp, string $remote_filename, $stream, int $mode = FTP_BINARY, int $offset = 0): bool {} - -/** - * @param resource $ftp - * @param resource $stream - */ -function ftp_nb_fput($ftp, string $remote_filename, $stream, int $mode = FTP_BINARY, int $offset = 0): int {} - -/** @param resource $ftp */ -function ftp_put($ftp, string $remote_filename, string $local_filename, int $mode = FTP_BINARY, int $offset = 0): bool {} - -/** @param resource $ftp */ -function ftp_append($ftp, string $remote_filename, string $local_filename, int $mode = FTP_BINARY): bool {} - -/** @param resource $ftp */ -function ftp_nb_put($ftp, string $remote_filename, string $local_filename, int $mode = FTP_BINARY, int $offset = 0): int|false {} - -/** @param resource $ftp */ -function ftp_size($ftp, string $filename): int {} - -/** @param resource $ftp */ -function ftp_mdtm($ftp, string $filename): int {} - -/** @param resource $ftp */ -function ftp_rename($ftp, string $from, string $to): bool {} - -/** @param resource $ftp */ -function ftp_delete($ftp, string $filename): bool {} - -/** @param resource $ftp */ -function ftp_site($ftp, string $command): bool {} - -/** @param resource $ftp */ -function ftp_close($ftp): bool {} - -/** - * @param resource $ftp - * @alias ftp_close - */ -function ftp_quit($ftp): bool {} - -/** - * @param resource $ftp - * @param int|bool $value - */ -function ftp_set_option($ftp, int $option, $value): bool {} - -/** @param resource $ftp */ -function ftp_get_option($ftp, int $option): int|bool {} +function ftp_login(FTPConnection $ftp, string $username, string $password): bool {} +function ftp_pwd(FTPConnection $ftp): string|false {} +function ftp_cdup(FTPConnection $ftp): bool {} +function ftp_chdir(FTPConnection $ftp, string $directory): bool {} +function ftp_exec(FTPConnection $ftp, string $command): bool {} +function ftp_raw(FTPConnection $ftp, string $command): array {} +function ftp_mkdir(FTPConnection $ftp, string $directory): string|false {} +function ftp_rmdir(FTPConnection $ftp, string $directory): bool {} +function ftp_chmod(FTPConnection $ftp, int $permissions, string $filename): int|false {} + +/** @param string $response */ +function ftp_alloc(FTPConnection $ftp, int $size, &$response = null): bool {} +function ftp_nlist(FTPConnection $ftp, string $directory): array|false {} +function ftp_rawlist(FTPConnection $ftp, string $directory, bool $recursive = false): array|false {} +function ftp_mlsd(FTPConnection $ftp, string $directory): array|false {} +function ftp_systype(FTPConnection $ftp): string|false {} + +/** @param resource $stream */ +function ftp_fget(FTPConnection $ftp, $stream, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): bool {} + +/** @param resource $stream */ +function ftp_nb_fget(FTPConnection $ftp, $stream, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): int {} +function ftp_pasv(FTPConnection $ftp, bool $enable): bool {} +function ftp_get(FTPConnection $ftp, string $local_filename, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): bool {} +function ftp_nb_get(FTPConnection $ftp, string $local_filename, string $remote_filename, int $mode = FTP_BINARY, int $offset = 0): int {} +function ftp_nb_continue(FTPConnection $ftp): int {} + +/** @param resource $stream */ +function ftp_fput(FTPConnection $ftp, string $remote_filename, $stream, int $mode = FTP_BINARY, int $offset = 0): bool {} + +/** @param resource $stream */ +function ftp_nb_fput(FTPConnection $ftp, string $remote_filename, $stream, int $mode = FTP_BINARY, int $offset = 0): int {} +function ftp_put(FTPConnection $ftp, string $remote_filename, string $local_filename, int $mode = FTP_BINARY, int $offset = 0): bool {} +function ftp_append(FTPConnection $ftp, string $remote_filename, string $local_filename, int $mode = FTP_BINARY): bool {} +function ftp_nb_put(FTPConnection $ftp, string $remote_filename, string $local_filename, int $mode = FTP_BINARY, int $offset = 0): int|false {} +function ftp_size(FTPConnection $ftp, string $filename): int {} +function ftp_mdtm(FTPConnection $ftp, string $filename): int {} +function ftp_rename(FTPConnection $ftp, string $from, string $to): bool {} +function ftp_delete(FTPConnection $ftp, string $filename): bool {} +function ftp_site(FTPConnection $ftp, string $command): bool {} +function ftp_close(FTPConnection $ftp): bool {} + +/** @alias ftp_close */ +function ftp_quit(FTPConnection $ftp): bool {} + +/** @param int|bool $value */ +function ftp_set_option(FTPConnection $ftp, int $option, $value): bool {} +function ftp_get_option(FTPConnection $ftp, int $option): int|bool {} diff --git a/ext/ftp/ftp_arginfo.h b/ext/ftp/ftp_arginfo.h index e1a9d770bc..30251b87ee 100644 --- a/ext/ftp/ftp_arginfo.h +++ b/ext/ftp/ftp_arginfo.h @@ -1,14 +1,14 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 4957601533b387d70ebb15811821fc06507cdbc2 */ + * Stub hash: 151310a13eeeb2bbf4df1ab38a3a29506b26a570 */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_connect, 0, 0, 1) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_ftp_connect, 0, 1, FTPConnection, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, port, IS_LONG, 0, "21") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_LONG, 0, "90") ZEND_END_ARG_INFO() #if defined(HAVE_FTP_SSL) -ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_ssl_connect, 0, 0, 1) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_ftp_ssl_connect, 0, 1, FTPConnection, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, port, IS_LONG, 0, "21") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_LONG, 0, "90") @@ -16,60 +16,60 @@ ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_login, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, username, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ftp_pwd, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_cdup, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_chdir, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, directory, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_exec, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, command, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_raw, 0, 2, IS_ARRAY, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, command, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ftp_mkdir, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, directory, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_ftp_rmdir arginfo_ftp_chdir ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ftp_chmod, 0, 3, MAY_BE_LONG|MAY_BE_FALSE) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, permissions, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_alloc, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0) ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, response, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ftp_nlist, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, directory, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ftp_rawlist, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, directory, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, recursive, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO() @@ -79,7 +79,7 @@ ZEND_END_ARG_INFO() #define arginfo_ftp_systype arginfo_ftp_pwd ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_fget, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_INFO(0, stream) ZEND_ARG_TYPE_INFO(0, remote_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "FTP_BINARY") @@ -87,7 +87,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_fget, 0, 3, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_nb_fget, 0, 3, IS_LONG, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_INFO(0, stream) ZEND_ARG_TYPE_INFO(0, remote_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "FTP_BINARY") @@ -95,12 +95,12 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_nb_fget, 0, 3, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_pasv, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, enable, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_get, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, local_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, remote_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "FTP_BINARY") @@ -108,7 +108,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_get, 0, 3, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_nb_get, 0, 3, IS_LONG, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, local_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, remote_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "FTP_BINARY") @@ -116,11 +116,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_nb_get, 0, 3, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_nb_continue, 0, 1, IS_LONG, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_fput, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, remote_filename, IS_STRING, 0) ZEND_ARG_INFO(0, stream) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "FTP_BINARY") @@ -128,7 +128,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_fput, 0, 3, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_nb_fput, 0, 3, IS_LONG, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, remote_filename, IS_STRING, 0) ZEND_ARG_INFO(0, stream) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "FTP_BINARY") @@ -136,7 +136,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_nb_fput, 0, 3, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_put, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, remote_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, local_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "FTP_BINARY") @@ -144,14 +144,14 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_put, 0, 3, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_append, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, remote_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, local_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "FTP_BINARY") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ftp_nb_put, 0, 3, MAY_BE_LONG|MAY_BE_FALSE) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, remote_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, local_filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "FTP_BINARY") @@ -159,20 +159,20 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ftp_nb_put, 0, 3, MAY_BE_LONG|MA ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_size, 0, 2, IS_LONG, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_ftp_mdtm arginfo_ftp_size ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_rename, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, from, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, to, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_delete, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -183,13 +183,13 @@ ZEND_END_ARG_INFO() #define arginfo_ftp_quit arginfo_ftp_cdup ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_set_option, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ftp_get_option, 0, 2, MAY_BE_LONG|MAY_BE_BOOL) - ZEND_ARG_INFO(0, ftp) + ZEND_ARG_OBJ_INFO(0, ftp, FTPConnection, 0) ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0) ZEND_END_ARG_INFO() diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c index a6dca8c874..30bffbdd8c 100644 --- a/ext/ftp/php_ftp.c +++ b/ext/ftp/php_ftp.c @@ -29,13 +29,15 @@ #include "ext/standard/info.h" #include "ext/standard/file.h" +#include "Zend/zend_exceptions.h" +#include "Zend/zend_interfaces.h" #include "php_ftp.h" #include "ftp.h" #include "ftp_arginfo.h" -static int le_ftpbuf; -#define le_ftpbuf_name "FTP Buffer" +static zend_class_entry *php_ftp_ce = NULL; +static zend_object_handlers ftp_object_handlers; zend_module_entry php_ftp_module_entry = { STANDARD_MODULE_HEADER_EX, @@ -56,15 +58,42 @@ zend_module_entry php_ftp_module_entry = { ZEND_GET_MODULE(php_ftp) #endif -static void ftp_destructor_ftpbuf(zend_resource *rsrc) -{ - ftpbuf_t *ftp = (ftpbuf_t *)rsrc->ptr; +typedef struct _php_ftp_object { + ftpbuf_t *ftp; + zend_object std; +} php_ftp_object; + +static inline zend_object *ftp_object_to_zend_object(php_ftp_object *obj) { + return ((zend_object*)(obj + 1)) - 1; +} + +static inline php_ftp_object *ftp_object_from_zend_object(zend_object *zobj) { + return ((php_ftp_object*)(zobj + 1)) - 1; +} + +static zend_object* ftp_object_create(zend_class_entry* ce) { + php_ftp_object *obj = zend_object_alloc(sizeof(php_ftp_object), ce); + zend_object *zobj = ftp_object_to_zend_object(obj); + obj->ftp = NULL; + zend_object_std_init(zobj, ce); + object_properties_init(zobj, ce); + zobj->handlers = &ftp_object_handlers; - ftp_close(ftp); + return zobj; +} + +static void ftp_object_destroy(zend_object *zobj) { + php_ftp_object *obj = ftp_object_from_zend_object(zobj); + + if (obj->ftp) { + ftp_close(obj->ftp); + } } PHP_MINIT_FUNCTION(ftp) { + zend_class_entry ce; + #ifdef HAVE_FTP_SSL #if OPENSSL_VERSION_NUMBER < 0x10101000 && !defined(LIBRESSL_VERSION_NUMBER) SSL_library_init(); @@ -76,7 +105,18 @@ PHP_MINIT_FUNCTION(ftp) #endif #endif - le_ftpbuf = zend_register_list_destructors_ex(ftp_destructor_ftpbuf, NULL, le_ftpbuf_name, module_number); + INIT_CLASS_ENTRY(ce, "FTPConnection", NULL); + php_ftp_ce = zend_register_internal_class(&ce); + php_ftp_ce->ce_flags |= ZEND_ACC_FINAL | ZEND_ACC_NO_DYNAMIC_PROPERTIES; + php_ftp_ce->create_object = ftp_object_create; + php_ftp_ce->serialize = zend_class_serialize_deny; + php_ftp_ce->unserialize = zend_class_unserialize_deny; + + memcpy(&ftp_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); + ftp_object_handlers.offset = XtOffsetOf(php_ftp_object, std); + ftp_object_handlers.dtor_obj = ftp_object_destroy; + ftp_object_handlers.clone_obj = NULL; + REGISTER_LONG_CONSTANT("FTP_ASCII", FTPTYPE_ASCII, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("FTP_TEXT", FTPTYPE_ASCII, CONST_PERSISTENT | CONST_CS); REGISTER_LONG_CONSTANT("FTP_BINARY", FTPTYPE_IMAGE, CONST_PERSISTENT | CONST_CS); @@ -143,7 +183,8 @@ PHP_FUNCTION(ftp_connect) ftp->use_ssl = 0; #endif - RETURN_RES(zend_register_resource(ftp, le_ftpbuf)); + object_init_ex(return_value, php_ftp_ce); + ftp_object_from_zend_object(Z_OBJ_P(return_value))->ftp = ftp; } /* }}} */ @@ -177,11 +218,19 @@ PHP_FUNCTION(ftp_ssl_connect) /* enable ssl */ ftp->use_ssl = 1; - RETURN_RES(zend_register_resource(ftp, le_ftpbuf)); + object_init_ex(return_value, php_ftp_ce); + ftp_object_from_zend_object(Z_OBJ_P(return_value))->ftp = ftp; } /* }}} */ #endif +#define GET_FTPBUF(ftpbuf, zftp) \ + ftpbuf = ftp_object_from_zend_object(Z_OBJ_P(zftp))->ftp; \ + if (!ftpbuf) { \ + zend_throw_exception(zend_ce_value_error, "FTPConnection is already closed", 0); \ + RETURN_THROWS(); \ + } + /* {{{ Logs into the FTP server */ PHP_FUNCTION(ftp_login) { @@ -190,13 +239,10 @@ PHP_FUNCTION(ftp_login) char *user, *pass; size_t user_len, pass_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &z_ftp, &user, &user_len, &pass, &pass_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oss", &z_ftp, php_ftp_ce, &user, &user_len, &pass, &pass_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* log in */ if (!ftp_login(ftp, user, user_len, pass, pass_len)) { @@ -215,13 +261,10 @@ PHP_FUNCTION(ftp_pwd) ftpbuf_t *ftp; const char *pwd; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ftp) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_ftp, php_ftp_ce) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); if (!(pwd = ftp_pwd(ftp))) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); @@ -238,13 +281,10 @@ PHP_FUNCTION(ftp_cdup) zval *z_ftp; ftpbuf_t *ftp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ftp) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_ftp, php_ftp_ce) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); if (!ftp_cdup(ftp)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); @@ -263,13 +303,10 @@ PHP_FUNCTION(ftp_chdir) char *dir; size_t dir_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &dir, &dir_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &z_ftp, php_ftp_ce, &dir, &dir_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* change directories */ if (!ftp_chdir(ftp, dir, dir_len)) { @@ -289,13 +326,10 @@ PHP_FUNCTION(ftp_exec) char *cmd; size_t cmd_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &z_ftp, php_ftp_ce, &cmd, &cmd_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* execute serverside command */ if (!ftp_exec(ftp, cmd, cmd_len)) { @@ -315,13 +349,10 @@ PHP_FUNCTION(ftp_raw) char *cmd; size_t cmd_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &z_ftp, php_ftp_ce, &cmd, &cmd_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* execute arbitrary ftp command */ ftp_raw(ftp, cmd, cmd_len, return_value); @@ -337,13 +368,10 @@ PHP_FUNCTION(ftp_mkdir) zend_string *tmp; size_t dir_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &dir, &dir_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &z_ftp, php_ftp_ce, &dir, &dir_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* create directory */ if (NULL == (tmp = ftp_mkdir(ftp, dir, dir_len))) { @@ -363,13 +391,10 @@ PHP_FUNCTION(ftp_rmdir) char *dir; size_t dir_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &dir, &dir_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &z_ftp, php_ftp_ce, &dir, &dir_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* remove directorie */ if (!ftp_rmdir(ftp, dir, dir_len)) { @@ -390,13 +415,10 @@ PHP_FUNCTION(ftp_chmod) size_t filename_len; zend_long mode; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlp", &z_ftp, &mode, &filename, &filename_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olp", &z_ftp, php_ftp_ce, &mode, &filename, &filename_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); if (!ftp_chmod(ftp, mode, filename, filename_len)) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); @@ -415,13 +437,10 @@ PHP_FUNCTION(ftp_alloc) zend_long size, ret; zend_string *response = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|z", &z_ftp, &size, &zresponse) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol|z", &z_ftp, php_ftp_ce, &size, &zresponse) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); ret = ftp_alloc(ftp, size, zresponse ? &response : NULL); @@ -445,13 +464,10 @@ PHP_FUNCTION(ftp_nlist) char **nlist, **ptr, *dir; size_t dir_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rp", &z_ftp, &dir, &dir_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op", &z_ftp, php_ftp_ce, &dir, &dir_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* get list of files */ if (NULL == (nlist = ftp_nlist(ftp, dir, dir_len))) { @@ -475,13 +491,10 @@ PHP_FUNCTION(ftp_rawlist) size_t dir_len; zend_bool recursive = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|b", &z_ftp, &dir, &dir_len, &recursive) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os|b", &z_ftp, php_ftp_ce, &dir, &dir_len, &recursive) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* get raw directory listing */ if (NULL == (llist = ftp_list(ftp, dir, dir_len, recursive))) { @@ -505,13 +518,10 @@ PHP_FUNCTION(ftp_mlsd) size_t dir_len; zval entry; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &dir, &dir_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &z_ftp, php_ftp_ce, &dir, &dir_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* get raw directory listing */ if (NULL == (llist = ftp_mlsd(ftp, dir, dir_len))) { @@ -539,13 +549,10 @@ PHP_FUNCTION(ftp_systype) ftpbuf_t *ftp; const char *syst; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ftp) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_ftp, php_ftp_ce) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); if (NULL == (syst = ftp_syst(ftp))) { php_error_docref(NULL, E_WARNING, "%s", ftp->inbuf); @@ -567,13 +574,10 @@ PHP_FUNCTION(ftp_fget) size_t file_len; zend_long mode=FTPTYPE_IMAGE, resumepos=0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrs|ll", &z_ftp, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ors|ll", &z_ftp, php_ftp_ce, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); php_stream_from_res(stream, Z_RES_P(z_file)); XTYPE(xtype, mode); @@ -612,13 +616,10 @@ PHP_FUNCTION(ftp_nb_fget) size_t file_len; zend_long mode=FTPTYPE_IMAGE, resumepos=0, ret; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrs|ll", &z_ftp, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ors|ll", &z_ftp, php_ftp_ce, &z_file, &file, &file_len, &mode, &resumepos) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); php_stream_from_res(stream, Z_RES_P(z_file)); XTYPE(xtype, mode); @@ -657,13 +658,10 @@ PHP_FUNCTION(ftp_pasv) ftpbuf_t *ftp; zend_bool pasv; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rb", &z_ftp, &pasv) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ob", &z_ftp, php_ftp_ce, &pasv) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); if (!ftp_pasv(ftp, pasv ? 1 : 0)) { RETURN_FALSE; @@ -684,13 +682,10 @@ PHP_FUNCTION(ftp_get) size_t local_len, remote_len; zend_long mode=FTPTYPE_IMAGE, resumepos=0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rpp|ll", &z_ftp, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opp|ll", &z_ftp, php_ftp_ce, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); XTYPE(xtype, mode); /* ignore autoresume if autoseek is switched off */ @@ -749,13 +744,10 @@ PHP_FUNCTION(ftp_nb_get) int ret; zend_long mode=FTPTYPE_IMAGE, resumepos=0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss|ll", &z_ftp, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oss|ll", &z_ftp, php_ftp_ce, &local, &local_len, &remote, &remote_len, &mode, &resumepos) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); XTYPE(xtype, mode); /* ignore autoresume if autoseek is switched off */ @@ -816,13 +808,10 @@ PHP_FUNCTION(ftp_nb_continue) ftpbuf_t *ftp; zend_long ret; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ftp) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_ftp, php_ftp_ce) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); if (!ftp->nb) { php_error_docref(NULL, E_WARNING, "No nbronous transfer to continue"); @@ -859,13 +848,10 @@ PHP_FUNCTION(ftp_fput) php_stream *stream; char *remote; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsr|ll", &z_ftp, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Osr|ll", &z_ftp, php_ftp_ce, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); php_stream_from_zval(stream, z_file); XTYPE(xtype, mode); @@ -908,13 +894,10 @@ PHP_FUNCTION(ftp_nb_fput) php_stream *stream; char *remote; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsr|ll", &z_ftp, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Osr|ll", &z_ftp, php_ftp_ce, &remote, &remote_len, &z_file, &mode, &startpos) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); php_stream_from_res(stream, Z_RES_P(z_file)); XTYPE(xtype, mode); @@ -961,13 +944,10 @@ PHP_FUNCTION(ftp_put) zend_long mode=FTPTYPE_IMAGE, startpos=0; php_stream *instream; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rpp|ll", &z_ftp, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opp|ll", &z_ftp, php_ftp_ce, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); XTYPE(xtype, mode); if (!(instream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt" : "rb", REPORT_ERRORS, NULL))) { @@ -1014,13 +994,10 @@ PHP_FUNCTION(ftp_append) zend_long mode=FTPTYPE_IMAGE; php_stream *instream; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rpp|l", &z_ftp, &remote, &remote_len, &local, &local_len, &mode) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opp|l", &z_ftp, php_ftp_ce, &remote, &remote_len, &local, &local_len, &mode) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); XTYPE(xtype, mode); if (!(instream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt" : "rb", REPORT_ERRORS, NULL))) { @@ -1049,13 +1026,10 @@ PHP_FUNCTION(ftp_nb_put) zend_long mode=FTPTYPE_IMAGE, startpos=0, ret; php_stream *instream; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rpp|ll", &z_ftp, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opp|ll", &z_ftp, php_ftp_ce, &remote, &remote_len, &local, &local_len, &mode, &startpos) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); XTYPE(xtype, mode); if (!(instream = php_stream_open_wrapper(local, mode == FTPTYPE_ASCII ? "rt" : "rb", REPORT_ERRORS, NULL))) { @@ -1107,13 +1081,10 @@ PHP_FUNCTION(ftp_size) char *file; size_t file_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rp", &z_ftp, &file, &file_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op", &z_ftp, php_ftp_ce, &file, &file_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* get file size */ RETURN_LONG(ftp_size(ftp, file, file_len)); @@ -1128,13 +1099,10 @@ PHP_FUNCTION(ftp_mdtm) char *file; size_t file_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rp", &z_ftp, &file, &file_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op", &z_ftp, php_ftp_ce, &file, &file_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* get file mod time */ RETURN_LONG(ftp_mdtm(ftp, file, file_len)); @@ -1149,13 +1117,10 @@ PHP_FUNCTION(ftp_rename) char *src, *dest; size_t src_len, dest_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &z_ftp, &src, &src_len, &dest, &dest_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oss", &z_ftp, php_ftp_ce, &src, &src_len, &dest, &dest_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* rename the file */ if (!ftp_rename(ftp, src, src_len, dest, dest_len)) { @@ -1175,13 +1140,10 @@ PHP_FUNCTION(ftp_delete) char *file; size_t file_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &file, &file_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &z_ftp, php_ftp_ce, &file, &file_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* delete the file */ if (!ftp_delete(ftp, file, file_len)) { @@ -1201,13 +1163,10 @@ PHP_FUNCTION(ftp_site) char *cmd; size_t cmd_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &z_ftp, &cmd, &cmd_len) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &z_ftp, php_ftp_ce, &cmd, &cmd_len) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); /* send the site command */ if (!ftp_site(ftp, cmd, cmd_len)) { @@ -1223,18 +1182,19 @@ PHP_FUNCTION(ftp_site) PHP_FUNCTION(ftp_close) { zval *z_ftp; - ftpbuf_t *ftp; + php_ftp_object *obj; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ftp) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &z_ftp, php_ftp_ce) == FAILURE) { RETURN_THROWS(); } - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { - RETURN_THROWS(); + obj = ftp_object_from_zend_object(Z_OBJ_P(z_ftp)); + if (obj->ftp) { + ftp_quit(obj->ftp); + ftp_close(obj->ftp); + obj->ftp = NULL; } - ftp_quit(ftp); - RETURN_TRUE; } /* }}} */ @@ -1246,13 +1206,10 @@ PHP_FUNCTION(ftp_set_option) zend_long option; ftpbuf_t *ftp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &z_ftp, &option, &z_value) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olz", &z_ftp, php_ftp_ce, &option, &z_value) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); switch (option) { case PHP_FTP_OPT_TIMEOUT_SEC: @@ -1298,13 +1255,10 @@ PHP_FUNCTION(ftp_get_option) zend_long option; ftpbuf_t *ftp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &z_ftp, &option) == FAILURE) { - RETURN_THROWS(); - } - - if ((ftp = (ftpbuf_t *)zend_fetch_resource(Z_RES_P(z_ftp), le_ftpbuf_name, le_ftpbuf)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &z_ftp, php_ftp_ce, &option) == FAILURE) { RETURN_THROWS(); } + GET_FTPBUF(ftp, z_ftp); switch (option) { case PHP_FTP_OPT_TIMEOUT_SEC: diff --git a/ext/ftp/tests/007.phpt b/ext/ftp/tests/007.phpt index 0520b37293..1ae879f901 100644 --- a/ext/ftp/tests/007.phpt +++ b/ext/ftp/tests/007.phpt @@ -180,36 +180,36 @@ try { fclose($ftp); ?> --EXPECT-- -ftp_login(): supplied resource is not a valid FTP Buffer resource -ftp_pwd(): supplied resource is not a valid FTP Buffer resource -ftp_cdup(): supplied resource is not a valid FTP Buffer resource -ftp_chdir(): supplied resource is not a valid FTP Buffer resource -ftp_exec(): supplied resource is not a valid FTP Buffer resource -ftp_raw(): supplied resource is not a valid FTP Buffer resource -ftp_mkdir(): supplied resource is not a valid FTP Buffer resource -ftp_rmdir(): supplied resource is not a valid FTP Buffer resource -ftp_chmod(): supplied resource is not a valid FTP Buffer resource -ftp_alloc(): supplied resource is not a valid FTP Buffer resource -ftp_nlist(): supplied resource is not a valid FTP Buffer resource -ftp_rawlist(): supplied resource is not a valid FTP Buffer resource -ftp_mlsd(): supplied resource is not a valid FTP Buffer resource -ftp_systype(): supplied resource is not a valid FTP Buffer resource -ftp_fget(): supplied resource is not a valid FTP Buffer resource -ftp_nb_fget(): supplied resource is not a valid FTP Buffer resource -ftp_pasv(): supplied resource is not a valid FTP Buffer resource -ftp_get(): supplied resource is not a valid FTP Buffer resource -ftp_nb_get(): supplied resource is not a valid FTP Buffer resource -ftp_nb_continue(): supplied resource is not a valid FTP Buffer resource -ftp_fput(): supplied resource is not a valid FTP Buffer resource -ftp_nb_fput(): supplied resource is not a valid FTP Buffer resource -ftp_put(): supplied resource is not a valid FTP Buffer resource -ftp_append(): supplied resource is not a valid FTP Buffer resource -ftp_nb_put(): supplied resource is not a valid FTP Buffer resource -ftp_size(): supplied resource is not a valid FTP Buffer resource -ftp_mdtm(): supplied resource is not a valid FTP Buffer resource -ftp_rename(): supplied resource is not a valid FTP Buffer resource -ftp_delete(): supplied resource is not a valid FTP Buffer resource -ftp_site(): supplied resource is not a valid FTP Buffer resource -ftp_close(): supplied resource is not a valid FTP Buffer resource -ftp_set_option(): supplied resource is not a valid FTP Buffer resource -ftp_get_option(): supplied resource is not a valid FTP Buffer resource +ftp_login(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_pwd(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_cdup(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_chdir(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_exec(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_raw(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_mkdir(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_rmdir(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_chmod(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_alloc(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_nlist(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_rawlist(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_mlsd(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_systype(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_fget(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_nb_fget(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_pasv(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_get(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_nb_get(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_nb_continue(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_fput(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_nb_fput(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_put(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_append(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_nb_put(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_size(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_mdtm(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_rename(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_delete(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_site(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_close(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_set_option(): Argument #1 ($ftp) must be of type FTPConnection, resource given +ftp_get_option(): Argument #1 ($ftp) must be of type FTPConnection, resource given diff --git a/ext/ftp/tests/dead-resource.phpt b/ext/ftp/tests/dead-resource.phpt new file mode 100644 index 0000000000..75a9931d54 --- /dev/null +++ b/ext/ftp/tests/dead-resource.phpt @@ -0,0 +1,24 @@ +--TEST-- +Attempt to use a closed FTPConnection +--SKIPIF-- +getMessage(), "\n"; +} +--EXPECT-- +bool(true) +bool(true) +Exception: FTPConnection is already closed diff --git a/ext/ftp/tests/ftp_set_option_errors.phpt b/ext/ftp/tests/ftp_set_option_errors.phpt index 3f5476f6c3..5e5ef328f3 100644 --- a/ext/ftp/tests/ftp_set_option_errors.phpt +++ b/ext/ftp/tests/ftp_set_option_errors.phpt @@ -13,40 +13,22 @@ $ftp = ftp_connect('127.0.0.1', $port); ftp_login($ftp, 'user', 'pass'); $ftp or die("Couldn't connect to the server"); -try { - ftp_set_option($ftp, FTP_TIMEOUT_SEC, 0); -} catch (ValueError $exception) { - echo $exception->getMessage() . "\n"; +$options = [ + [ 'option' => FTP_TIMEOUT_SEC, 'value' => 0 ], + [ 'option' => FTP_TIMEOUT_SEC, 'value' => '0' ], + [ 'option' => FTP_USEPASVADDRESS, 'value' => ['1'] ], + [ 'option' => FTP_AUTOSEEK, 'value' => 'true' ], + [ 'option' => FOO_BAR, 'value' => 1 ], +]; +foreach ($options as $option) try { + var_dump(ftp_set_option($ftp, $option['option'], $option['value'])); +} catch (\Throwable $ex) { + echo "Exception: ", $ex->getMessage(), "\n"; } -try { - ftp_set_option($ftp, FTP_TIMEOUT_SEC, '0'); -} catch (TypeError $exception) { - echo $exception->getMessage() . "\n"; -} - -try { - ftp_set_option($ftp, FTP_USEPASVADDRESS, ['1']); -} catch (TypeError $exception) { - echo $exception->getMessage() . "\n"; -} - -try { - ftp_set_option($ftp, FTP_AUTOSEEK, 'true'); -} catch (TypeError $exception) { - echo $exception->getMessage() . "\n"; -} - -try { - ftp_set_option($ftp, FOO_BAR, 1); -} catch (ValueError $exception) { - echo $exception->getMessage() . "\n"; -} - -?> --EXPECT-- -ftp_set_option(): Argument #3 ($value) must be greater than 0 for the FTP_TIMEOUT_SEC option -ftp_set_option(): Argument #3 ($value) must be of type int for the FTP_TIMEOUT_SEC option, string given -ftp_set_option(): Argument #3 ($value) must be of type bool for the FTP_USEPASVADDRESS option, array given -ftp_set_option(): Argument #3 ($value) must be of type bool for the FTP_AUTOSEEK option, string given -ftp_set_option(): Argument #2 ($option) must be one of FTP_TIMEOUT_SEC, FTP_AUTOSEEK, or FTP_USEPASVADDRESS +Exception: ftp_set_option(): Argument #3 ($value) must be greater than 0 for the FTP_TIMEOUT_SEC option +Exception: ftp_set_option(): Argument #3 ($value) must be of type int for the FTP_TIMEOUT_SEC option, string given +Exception: ftp_set_option(): Argument #3 ($value) must be of type bool for the FTP_USEPASVADDRESS option, array given +Exception: ftp_set_option(): Argument #3 ($value) must be of type bool for the FTP_AUTOSEEK option, string given +Exception: ftp_set_option(): Argument #2 ($option) must be one of FTP_TIMEOUT_SEC, FTP_AUTOSEEK, or FTP_USEPASVADDRESS