|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.1.0alpha1
+- FTP:
+ . Convert resource<ftp> to object \FTPConnection. (Sara)
+
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
/** @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 {}
/* 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")
#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()
#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")
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")
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")
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")
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")
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")
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")
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")
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()
#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()
#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,
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();
#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);
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;
}
/* }}} */
/* 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)
{
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)) {
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);
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);
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)) {
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)) {
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);
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))) {
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)) {
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);
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);
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))) {
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))) {
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))) {
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);
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);
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);
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;
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 */
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 */
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");
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);
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);
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))) {
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))) {
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))) {
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));
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));
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)) {
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)) {
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)) {
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;
}
/* }}} */
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:
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:
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
--- /dev/null
+--TEST--
+Attempt to use a closed FTPConnection
+--SKIPIF--
+<?php
+require 'skipif.inc';
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+if (!$ftp) die("Couldn't connect to the server");
+var_dump(ftp_login($ftp, 'user', 'pass'));
+var_dump(ftp_close($ftp));
+
+try {
+ var_dump(ftp_login($ftp, 'user', 'pass'));
+ echo "Login did not throw\n";
+} catch (ValueError $ex) {
+ echo "Exception: ", $ex->getMessage(), "\n";
+}
+--EXPECT--
+bool(true)
+bool(true)
+Exception: FTPConnection is already closed
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